summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/RenderSkinRadio.cpp
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-08-17 02:28:37 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-08-17 02:28:37 -0700
commit2d9e4c5514130be5468050cdf7b1ad8c5a57ac39 (patch)
tree2368bb5a21956acb815e5b5fafb91eaeb8f1ba5c /Source/WebKit/android/RenderSkinRadio.cpp
parent41b52b2ab048f02c6ec7732f1e1a3430d8272da9 (diff)
parentce03c1c1203621e552d41a8b3831837636f364a9 (diff)
downloadexternal_webkit-2d9e4c5514130be5468050cdf7b1ad8c5a57ac39.zip
external_webkit-2d9e4c5514130be5468050cdf7b1ad8c5a57ac39.tar.gz
external_webkit-2d9e4c5514130be5468050cdf7b1ad8c5a57ac39.tar.bz2
Merge "Lazily decode assets for form controls."
Diffstat (limited to 'Source/WebKit/android/RenderSkinRadio.cpp')
-rw-r--r--Source/WebKit/android/RenderSkinRadio.cpp47
1 files changed, 30 insertions, 17 deletions
diff --git a/Source/WebKit/android/RenderSkinRadio.cpp b/Source/WebKit/android/RenderSkinRadio.cpp
index 46198d3..3c29818 100644
--- a/Source/WebKit/android/RenderSkinRadio.cpp
+++ b/Source/WebKit/android/RenderSkinRadio.cpp
@@ -36,41 +36,54 @@
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkRect.h"
+#include <utils/AssetManager.h>
#include <wtf/text/CString.h>
+extern android::AssetManager* globalAssetManager();
+
static const char* checks[] = { "btn_check_off_holo.png",
"btn_check_on_holo.png",
"btn_radio_off_holo.png",
"btn_radio_on_holo.png"};
// Matches the width of the bitmap
-static SkScalar SIZE;
+static SkScalar s_bitmapWidth;
namespace WebCore {
static SkBitmap s_bitmap[4];
-static bool s_decoded;
+static bool s_decodingAttempted = false;
+static bool s_decoded = false;
-void RenderSkinRadio::Init(android::AssetManager* am, String drawableDirectory)
-{
- if (s_decoded)
+void RenderSkinRadio::Decode() {
+ if (s_decodingAttempted)
return;
- String path = drawableDirectory + checks[0];
- s_decoded = RenderSkinAndroid::DecodeBitmap(am, path.utf8().data(), &s_bitmap[0]);
- path = drawableDirectory + checks[1];
- s_decoded = RenderSkinAndroid::DecodeBitmap(am, path.utf8().data(), &s_bitmap[1]) && s_decoded;
- path = drawableDirectory + checks[2];
- s_decoded = RenderSkinAndroid::DecodeBitmap(am, path.utf8().data(), &s_bitmap[2]) && s_decoded;
- path = drawableDirectory + checks[3];
- s_decoded = RenderSkinAndroid::DecodeBitmap(am, path.utf8().data(), &s_bitmap[3]) && s_decoded;
- SIZE = SkIntToScalar(s_bitmap[0].width());
+
+ s_decodingAttempted = true;
+ s_decoded = false;
+
+ android::AssetManager* am = globalAssetManager();
+ String drawableDir = RenderSkinAndroid::DrawableDirectory();
+ for (int i = 0; i < 4; i++) {
+ String path = drawableDir + checks[i];
+ if (!RenderSkinAndroid::DecodeBitmap(am, path.utf8().data(), &s_bitmap[i]))
+ return;
+ }
+ s_decoded = true;
+ s_bitmapWidth = SkIntToScalar(s_bitmap[0].width());
}
void RenderSkinRadio::Draw(SkCanvas* canvas, Node* element, const IntRect& ir,
bool isCheckBox)
{
- if (!s_decoded || !element) {
+ if (!element)
return;
- }
+
+ if (!s_decodingAttempted)
+ Decode();
+
+ if (!s_decoded)
+ return;
+
SkRect r(ir);
// Set up a paint to with filtering to look better.
SkPaint paint;
@@ -82,7 +95,7 @@ void RenderSkinRadio::Draw(SkCanvas* canvas, Node* element, const IntRect& ir,
paint.setAlpha(0x80);
}
SkScalar width = r.width();
- SkScalar scale = SkScalarDiv(width, SIZE);
+ SkScalar scale = SkScalarDiv(width, s_bitmapWidth);
saveScaleCount = canvas->save();
canvas->translate(r.fLeft, r.fTop);
canvas->scale(scale, scale);