summaryrefslogtreecommitdiffstats
path: root/WebKit/android/RenderSkinButton.cpp
diff options
context:
space:
mode:
authorLeon Scroggins <scroggo@google.com>2011-03-03 16:05:45 -0500
committerLeon Scroggins <scroggo@google.com>2011-03-04 13:23:32 -0500
commit4de82d04a6a82fee6e2d924768e88af58e966982 (patch)
tree8bc313070b3e945a10581c403bd8bbce0c87b2ba /WebKit/android/RenderSkinButton.cpp
parent00e711a28c6fe463e2c728c0bd926b949c1a8798 (diff)
downloadexternal_webkit-4de82d04a6a82fee6e2d924768e88af58e966982.zip
external_webkit-4de82d04a6a82fee6e2d924768e88af58e966982.tar.gz
external_webkit-4de82d04a6a82fee6e2d924768e88af58e966982.tar.bz2
Use members rather than globals to avoid leaking memory.
Part of bug:3009375 Requires a change to frameworks/base. Change-Id: I9f5e86afff4c87e16889eadf0ad0049120885480
Diffstat (limited to 'WebKit/android/RenderSkinButton.cpp')
-rw-r--r--WebKit/android/RenderSkinButton.cpp29
1 files changed, 9 insertions, 20 deletions
diff --git a/WebKit/android/RenderSkinButton.cpp b/WebKit/android/RenderSkinButton.cpp
index ec85790..8fdd21f 100644
--- a/WebKit/android/RenderSkinButton.cpp
+++ b/WebKit/android/RenderSkinButton.cpp
@@ -49,14 +49,6 @@ static const char* gFiles[] = {
"btn_default_pressed_holo.9.png"
};
-static bool gDecoded;
-
-struct NinePatch {
- SkBitmap m_bitmap;
- void* m_serializedPatchData;
-};
-
-static NinePatch gButtons[4];
class SkRegion;
using namespace android;
@@ -67,14 +59,9 @@ extern void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds,
namespace WebCore {
-void RenderSkinButton::Init(android::AssetManager* am, String drawableDirectory)
+RenderSkinButton::RenderSkinButton(android::AssetManager* am, String drawableDirectory)
{
- static bool gInited;
- if (gInited)
- return;
-
- gInited = true;
- gDecoded = true;
+ m_decoded = true;
for (size_t i = 0; i < 4; i++) {
String path = String(drawableDirectory.impl());
path.append(String(gFiles[i]));
@@ -82,12 +69,13 @@ void RenderSkinButton::Init(android::AssetManager* am, String drawableDirectory)
if (!asset) {
asset = am->openNonAsset(path.utf8().data(), android::Asset::ACCESS_BUFFER);
if (!asset) {
- gDecoded = false;
+ m_decoded = false;
LOGE("RenderSkinButton::Init: button assets failed to decode\n\tBrowser buttons will not draw");
return;
}
}
- RenderSkinNinePatch::decodeAsset(asset, &gButtons[i].m_bitmap, &gButtons[i].m_serializedPatchData);
+ RenderSkinNinePatch::decodeAsset(asset, &m_buttons[i].m_bitmap,
+ &m_buttons[i].m_serializedPatchData);
asset->close();
}
@@ -98,11 +86,12 @@ void RenderSkinButton::Init(android::AssetManager* am, String drawableDirectory)
android::CompileTimeAssert<(RenderSkinAndroid::kPressed == 3)> a4;
}
-void RenderSkinButton::Draw(SkCanvas* canvas, const IntRect& r, RenderSkinAndroid::State newState)
+void RenderSkinButton::draw(SkCanvas* canvas, const IntRect& r,
+ RenderSkinAndroid::State newState) const
{
// 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 (!gDecoded) {
+ if (!m_decoded) {
return;
}
@@ -111,7 +100,7 @@ void RenderSkinButton::Draw(SkCanvas* canvas, const IntRect& r, RenderSkinAndroi
static_cast<unsigned>(RenderSkinAndroid::kNumStates));
SkRect bounds(r);
- NinePatch* patch = &gButtons[newState];
+ const NinePatch* patch = &m_buttons[newState];
Res_png_9patch* data = Res_png_9patch::deserialize(patch->m_serializedPatchData);
NinePatch_Draw(canvas, bounds, patch->m_bitmap, *data, 0, 0);
}