summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/RenderSkinButton.cpp
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-07-27 13:53:42 +0100
committerBen Murdoch <benm@google.com>2011-08-16 16:40:55 +0100
commitce03c1c1203621e552d41a8b3831837636f364a9 (patch)
treed2ec3d82cadc9d5a66ea73ade2932de955e4618f /Source/WebKit/android/RenderSkinButton.cpp
parent0f0dadb092f4aaa1a34d293f9c4b2a14e3b3e3df (diff)
downloadexternal_webkit-ce03c1c1203621e552d41a8b3831837636f364a9.zip
external_webkit-ce03c1c1203621e552d41a8b3831837636f364a9.tar.gz
external_webkit-ce03c1c1203621e552d41a8b3831837636f364a9.tar.bz2
Lazily decode assets for form controls.
Rather than decoding the graphics when we create a WebView, wait until we actually need them. This saves about 50ms on native WebView creation time. Requires frameworks/base change: I5a2e87d03d73fa74ebb00c33567783225ed97d3a Bug: 5084146 Change-Id: Ia6c17634f535ed75b2a0757ac4d53f1a0befb78a
Diffstat (limited to 'Source/WebKit/android/RenderSkinButton.cpp')
-rw-r--r--Source/WebKit/android/RenderSkinButton.cpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/Source/WebKit/android/RenderSkinButton.cpp b/Source/WebKit/android/RenderSkinButton.cpp
index 6a0ae54..11e2fa8 100644
--- a/Source/WebKit/android/RenderSkinButton.cpp
+++ b/Source/WebKit/android/RenderSkinButton.cpp
@@ -42,6 +42,8 @@
#include <utils/ResourceTypes.h>
#include <wtf/text/CString.h>
+extern android::AssetManager* globalAssetManager();
+
static const char* gFiles[] = {
"btn_default_disabled_holo.9.png",
"btn_default_normal_holo.9.png",
@@ -51,29 +53,42 @@ static const char* gFiles[] = {
namespace WebCore {
-RenderSkinButton::RenderSkinButton(android::AssetManager* am, String drawableDirectory)
+RenderSkinButton::RenderSkinButton(String drawableDirectory)
+ : m_decoded(false)
+ , m_decodingAttempted(false)
+ , m_drawableDirectory(drawableDirectory)
{
- m_decoded = true;
+ // Ensure our enums properly line up with our arrays.
+ android::CompileTimeAssert<(RenderSkinAndroid::kDisabled == 0)> a1;
+ android::CompileTimeAssert<(RenderSkinAndroid::kNormal == 1)> a2;
+ android::CompileTimeAssert<(RenderSkinAndroid::kFocused == 2)> a3;
+ android::CompileTimeAssert<(RenderSkinAndroid::kPressed == 3)> a4;
+}
+
+void RenderSkinButton::decode()
+{
+ m_decodingAttempted = true;
+
+ android::AssetManager* am = globalAssetManager();
+
for (size_t i = 0; i < 4; i++) {
- String path = String(drawableDirectory.impl());
+ String path = m_drawableDirectory;
path.append(String(gFiles[i]));
if (!RenderSkinNinePatch::decodeAsset(am, path.utf8().data(), &m_buttons[i])) {
m_decoded = false;
- LOGE("RenderSkinButton::Init: button assets failed to decode\n\tBrowser buttons will not draw");
+ LOGE("RenderSkinButton::decode: button assets failed to decode\n\tWebView buttons will not draw");
return;
}
}
-
- // Ensure our enums properly line up with our arrays.
- android::CompileTimeAssert<(RenderSkinAndroid::kDisabled == 0)> a1;
- android::CompileTimeAssert<(RenderSkinAndroid::kNormal == 1)> a2;
- android::CompileTimeAssert<(RenderSkinAndroid::kFocused == 2)> a3;
- android::CompileTimeAssert<(RenderSkinAndroid::kPressed == 3)> a4;
+ m_decoded = true;
}
void RenderSkinButton::draw(SkCanvas* canvas, const IntRect& r,
- RenderSkinAndroid::State newState) const
+ RenderSkinAndroid::State newState)
{
+ if (!m_decodingAttempted)
+ decode();
+
// If we failed to decode, do nothing. This way the browser still works,
// and webkit will still draw the label and layout space for us.
if (!m_decoded) {