summaryrefslogtreecommitdiffstats
path: root/Source/WebCore
diff options
context:
space:
mode:
authorNicolas Roard <nicolasroard@google.com>2011-10-13 08:47:58 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-10-13 08:47:58 -0700
commit9bd214662e776fb18e43d1ad32ce274803ec309a (patch)
tree6c41ab0ae4fff5c7cf62ea6ced261e28e62c0186 /Source/WebCore
parent5ed31e7bc52e99103e4da5755d944f9ca98305b3 (diff)
parent9651fe9381af8dcc55a6370c3d2a65fcbdab846e (diff)
downloadexternal_webkit-9bd214662e776fb18e43d1ad32ce274803ec309a.zip
external_webkit-9bd214662e776fb18e43d1ad32ce274803ec309a.tar.gz
external_webkit-9bd214662e776fb18e43d1ad32ce274803ec309a.tar.bz2
Merge "Refactor the image sharing code" into ics-mr0
Diffstat (limited to 'Source/WebCore')
-rw-r--r--Source/WebCore/Android.mk1
-rw-r--r--Source/WebCore/platform/graphics/android/GLWebViewState.cpp2
-rw-r--r--Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp1
-rw-r--r--Source/WebCore/platform/graphics/android/ImageTexture.cpp19
-rw-r--r--Source/WebCore/platform/graphics/android/ImageTexture.h8
-rw-r--r--Source/WebCore/platform/graphics/android/ImagesManager.cpp108
-rw-r--r--Source/WebCore/platform/graphics/android/ImagesManager.h58
-rw-r--r--Source/WebCore/platform/graphics/android/LayerAndroid.cpp25
-rw-r--r--Source/WebCore/platform/graphics/android/TilesManager.cpp46
-rw-r--r--Source/WebCore/platform/graphics/android/TilesManager.h7
10 files changed, 207 insertions, 68 deletions
diff --git a/Source/WebCore/Android.mk b/Source/WebCore/Android.mk
index 075dd71..5df4d93 100644
--- a/Source/WebCore/Android.mk
+++ b/Source/WebCore/Android.mk
@@ -656,6 +656,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
platform/graphics/android/ImageAndroid.cpp \
platform/graphics/android/ImageBufferAndroid.cpp \
platform/graphics/android/ImageSourceAndroid.cpp \
+ platform/graphics/android/ImagesManager.cpp \
platform/graphics/android/ImageTexture.cpp \
platform/graphics/android/Layer.cpp \
platform/graphics/android/LayerAndroid.cpp \
diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
index b096c20..efcf877 100644
--- a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
+++ b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp
@@ -526,7 +526,7 @@ bool GLWebViewState::drawGL(IntRect& rect, SkRect& viewport, IntRect* invalRect,
SkSafeUnref(baseLayer);
#ifdef DEBUG
TilesManager::instance()->getTilesTracker()->showTrackTextures();
- TilesManager::instance()->showImages();
+ ImagesManager::instance()->showImages();
#endif
return ret;
}
diff --git a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp
index eadac6b..89f96d8 100644
--- a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp
+++ b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp
@@ -24,6 +24,7 @@
#include "FloatRect.h"
#include "GraphicsContext.h"
#include "Image.h"
+#include "ImagesManager.h"
#include "Layer.h"
#include "Length.h"
#include "MediaLayer.h"
diff --git a/Source/WebCore/platform/graphics/android/ImageTexture.cpp b/Source/WebCore/platform/graphics/android/ImageTexture.cpp
index 7e71740..814373c 100644
--- a/Source/WebCore/platform/graphics/android/ImageTexture.cpp
+++ b/Source/WebCore/platform/graphics/android/ImageTexture.cpp
@@ -29,12 +29,15 @@
#include "SkDevice.h"
#include "TilesManager.h"
-#ifdef DEBUG
-
#include <cutils/log.h>
#include <wtf/CurrentTime.h>
#include <wtf/text/CString.h>
+#undef XLOGC
+#define XLOGC(...) android_printLog(ANDROID_LOG_DEBUG, "ImageTexture", __VA_ARGS__)
+
+#ifdef DEBUG
+
#undef XLOG
#define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "ImageTexture", __VA_ARGS__)
@@ -84,7 +87,7 @@ ImageTexture::~ImageTexture()
delete m_image;
}
-void ImageTexture::prepare()
+void ImageTexture::prepareGL()
{
if (m_textureId)
return;
@@ -93,7 +96,7 @@ void ImageTexture::prepare()
GLUtils::createTextureWithBitmap(m_textureId, *m_image);
}
-void ImageTexture::draw(LayerAndroid* layer)
+void ImageTexture::drawGL(LayerAndroid* layer)
{
if (!layer)
return;
@@ -112,6 +115,11 @@ void ImageTexture::draw(LayerAndroid* layer)
layer->drawOpacity(), true);
}
+void ImageTexture::drawCanvas(SkCanvas* canvas, SkRect& rect)
+{
+ canvas->drawBitmapRect(*m_image, 0, rect);
+}
+
void ImageTexture::release()
{
if (m_refCount >= 1)
@@ -122,7 +130,8 @@ void ImageTexture::release()
void ImageTexture::deleteTexture()
{
- glDeleteTextures(1, &m_textureId);
+ if (m_textureId)
+ glDeleteTextures(1, &m_textureId);
}
} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/android/ImageTexture.h b/Source/WebCore/platform/graphics/android/ImageTexture.h
index c2ea77c..18ff7ef 100644
--- a/Source/WebCore/platform/graphics/android/ImageTexture.h
+++ b/Source/WebCore/platform/graphics/android/ImageTexture.h
@@ -63,9 +63,9 @@ public:
ImageTexture(SkBitmapRef* img);
virtual ~ImageTexture();
- void prepare();
- void draw(LayerAndroid* painter);
- void deleteTexture();
+ void prepareGL();
+ void drawGL(LayerAndroid* painter);
+ void drawCanvas(SkCanvas*, SkRect&);
void retain() { m_refCount++; }
void release();
unsigned int refCount() { return m_refCount; }
@@ -74,6 +74,8 @@ public:
private:
+ void deleteTexture();
+
SkBitmapRef* m_imageRef;
SkBitmap* m_image;
GLuint m_textureId;
diff --git a/Source/WebCore/platform/graphics/android/ImagesManager.cpp b/Source/WebCore/platform/graphics/android/ImagesManager.cpp
new file mode 100644
index 0000000..3518832
--- /dev/null
+++ b/Source/WebCore/platform/graphics/android/ImagesManager.cpp
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2011, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ImagesManager.h"
+
+#include "ImageTexture.h"
+
+#include <cutils/log.h>
+#include <wtf/CurrentTime.h>
+#include <wtf/text/CString.h>
+
+#undef XLOGC
+#define XLOGC(...) android_printLog(ANDROID_LOG_DEBUG, "ImagesManager", __VA_ARGS__)
+
+#ifdef DEBUG
+
+#undef XLOG
+#define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "ImagesManager", __VA_ARGS__)
+
+#else
+
+#undef XLOG
+#define XLOG(...)
+
+#endif // DEBUG
+
+namespace WebCore {
+
+ImagesManager* ImagesManager::instance()
+{
+ if (!gInstance)
+ gInstance = new ImagesManager();
+
+ return gInstance;
+}
+
+ImagesManager* ImagesManager::gInstance = 0;
+
+void ImagesManager::addImage(SkBitmapRef* imgRef)
+{
+ if (!imgRef)
+ return;
+
+ android::Mutex::Autolock lock(m_imagesLock);
+ if (!m_images.contains(imgRef))
+ m_images.set(imgRef, new ImageTexture(imgRef));
+}
+
+void ImagesManager::removeImage(SkBitmapRef* imgRef)
+{
+ android::Mutex::Autolock lock(m_imagesLock);
+ if (!m_images.contains(imgRef))
+ return;
+
+ ImageTexture* image = m_images.get(imgRef);
+ image->release();
+
+ if (!image->refCount()) {
+ m_images.remove(imgRef);
+ delete image;
+ }
+}
+
+void ImagesManager::showImages()
+{
+ XLOGC("We have %d images", m_images.size());
+ HashMap<SkBitmapRef*, ImageTexture*>::iterator end = m_images.end();
+ int i = 0;
+ for (HashMap<SkBitmapRef*, ImageTexture*>::iterator it = m_images.begin(); it != end; ++it) {
+ XLOGC("Image %x (%d/%d) has %d references", it->first, i,
+ m_images.size(), it->second->refCount());
+ i++;
+ }
+}
+
+ImageTexture* ImagesManager::getTextureForImage(SkBitmapRef* img, bool retain)
+{
+ android::Mutex::Autolock lock(m_imagesLock);
+ ImageTexture* image = m_images.get(img);
+ if (retain && image)
+ image->retain();
+ return image;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/graphics/android/ImagesManager.h b/Source/WebCore/platform/graphics/android/ImagesManager.h
new file mode 100644
index 0000000..1b5d322
--- /dev/null
+++ b/Source/WebCore/platform/graphics/android/ImagesManager.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2011, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ImagesManager_h
+#define ImagesManager_h
+
+#include "HashMap.h"
+#include "SkBitmap.h"
+#include "SkBitmapRef.h"
+#include "SkRefCnt.h"
+
+namespace WebCore {
+
+class ImageTexture;
+
+class ImagesManager {
+public:
+ static ImagesManager* instance();
+
+ void addImage(SkBitmapRef* img);
+ void removeImage(SkBitmapRef* img);
+ ImageTexture* getTextureForImage(SkBitmapRef* img, bool retain = true);
+ void showImages();
+
+private:
+ ImagesManager() {}
+
+ static ImagesManager* gInstance;
+
+ android::Mutex m_imagesLock;
+ HashMap<SkBitmapRef*, ImageTexture*> m_images;
+};
+
+} // namespace WebCore
+
+#endif // ImagesManager
diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp
index 91c44c6..4162e0b 100644
--- a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp
+++ b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp
@@ -7,6 +7,7 @@
#include "ClassTracker.h"
#include "DrawExtra.h"
#include "GLUtils.h"
+#include "ImagesManager.h"
#include "MediaLayer.h"
#include "PaintedSurface.h"
#include "ParseCanvas.h"
@@ -16,6 +17,7 @@
#include "SkPaint.h"
#include "SkPicture.h"
#include "TilesManager.h"
+
#include <wtf/CurrentTime.h>
#include <math.h>
@@ -102,7 +104,7 @@ LayerAndroid::LayerAndroid(const LayerAndroid& layer) : Layer(layer),
m_isFixed = layer.m_isFixed;
m_imageRef = layer.m_imageRef;
if (m_imageRef)
- TilesManager::instance()->addImage(m_imageRef);
+ ImagesManager::instance()->addImage(m_imageRef);
m_renderLayerPos = layer.m_renderLayerPos;
m_transform = layer.m_transform;
m_backfaceVisibility = layer.m_backfaceVisibility;
@@ -177,7 +179,7 @@ LayerAndroid::LayerAndroid(SkPicture* picture) : Layer(),
LayerAndroid::~LayerAndroid()
{
if (m_imageTexture)
- TilesManager::instance()->removeImage(m_imageTexture->imageRef());
+ ImagesManager::instance()->removeImage(m_imageTexture->imageRef());
delete m_extra;
SkSafeUnref(m_recordingPicture);
m_animations.clear();
@@ -667,7 +669,7 @@ void LayerAndroid::setContentsImage(SkBitmapRef* img)
if (!img)
return;
- TilesManager::instance()->addImage(img);
+ ImagesManager::instance()->addImage(img);
}
bool LayerAndroid::needsTexture()
@@ -814,7 +816,7 @@ void LayerAndroid::createTexture()
if (m_imageRef) {
if (!m_imageTexture) {
- m_imageTexture = TilesManager::instance()->getTextureForImage(m_imageRef);
+ m_imageTexture = ImagesManager::instance()->getTextureForImage(m_imageRef);
m_dirtyRegion.setEmpty();
}
if (m_texture) {
@@ -876,7 +878,7 @@ void LayerAndroid::prepare(GLWebViewState* glWebViewState)
m_texture->prepare(glWebViewState);
if (m_imageTexture)
- m_imageTexture->prepare();
+ m_imageTexture->prepareGL();
}
bool LayerAndroid::drawGL(GLWebViewState* glWebViewState, SkMatrix& matrix)
@@ -891,7 +893,7 @@ bool LayerAndroid::drawGL(GLWebViewState* glWebViewState, SkMatrix& matrix)
askScreenUpdate |= m_texture->draw();
if (m_imageTexture)
- m_imageTexture->draw(this);
+ m_imageTexture->drawGL(this);
// When the layer is dirty, the UI thread should be notified to redraw.
askScreenUpdate |= drawChildrenGL(glWebViewState, matrix);
@@ -977,6 +979,17 @@ void LayerAndroid::onDraw(SkCanvas* canvas, SkScalar opacity)
if (canvasOpacity < 255)
canvas->setDrawFilter(new OpacityDrawFilter(canvasOpacity));
+ if (m_imageRef) {
+ if (!m_imageTexture) {
+ m_imageTexture = ImagesManager::instance()->getTextureForImage(m_imageRef);
+ m_dirtyRegion.setEmpty();
+ }
+ if (m_imageTexture) {
+ SkRect dest;
+ dest.set(0, 0, getSize().width(), getSize().height());
+ m_imageTexture->drawCanvas(canvas, dest);
+ }
+ }
contentDraw(canvas);
}
diff --git a/Source/WebCore/platform/graphics/android/TilesManager.cpp b/Source/WebCore/platform/graphics/android/TilesManager.cpp
index 2d0cc7f..74cc764 100644
--- a/Source/WebCore/platform/graphics/android/TilesManager.cpp
+++ b/Source/WebCore/platform/graphics/android/TilesManager.cpp
@@ -429,52 +429,6 @@ void TilesManager::unregisterGLWebViewState(GLWebViewState* state)
transferQueue()->discardQueue();
}
-void TilesManager::addImage(SkBitmapRef* imgRef)
-{
- if (!imgRef)
- return;
-
- android::Mutex::Autolock lock(m_imagesLock);
- if (!m_images.contains(imgRef))
- m_images.set(imgRef, new ImageTexture(imgRef));
-}
-
-void TilesManager::removeImage(SkBitmapRef* imgRef)
-{
- android::Mutex::Autolock lock(m_imagesLock);
- if (!m_images.contains(imgRef))
- return;
-
- ImageTexture* image = m_images.get(imgRef);
- image->release();
-
- if (!image->refCount()) {
- m_images.remove(imgRef);
- delete image;
- }
-}
-
-void TilesManager::showImages()
-{
- XLOGC("We have %d images", m_images.size());
- HashMap<SkBitmapRef*, ImageTexture*>::iterator end = m_images.end();
- int i = 0;
- for (HashMap<SkBitmapRef*, ImageTexture*>::iterator it = m_images.begin(); it != end; ++it) {
- XLOGC("Image %x (%d/%d) has %d references", it->first, i,
- m_images.size(), it->second->refCount());
- i++;
- }
-}
-
-ImageTexture* TilesManager::getTextureForImage(SkBitmapRef* img, bool retain)
-{
- android::Mutex::Autolock lock(m_imagesLock);
- ImageTexture* image = m_images.get(img);
- if (retain && image)
- image->retain();
- return image;
-}
-
TilesManager* TilesManager::instance()
{
if (!gInstance) {
diff --git a/Source/WebCore/platform/graphics/android/TilesManager.h b/Source/WebCore/platform/graphics/android/TilesManager.h
index b7d6aa6..4daecff 100644
--- a/Source/WebCore/platform/graphics/android/TilesManager.h
+++ b/Source/WebCore/platform/graphics/android/TilesManager.h
@@ -179,10 +179,6 @@ public:
{
return m_drawGLCount;
}
- void addImage(SkBitmapRef* img);
- void removeImage(SkBitmapRef* img);
- ImageTexture* getTextureForImage(SkBitmapRef* img, bool retain = true);
- void showImages();
private:
TilesManager();
@@ -215,7 +211,6 @@ private:
android::Mutex m_texturesLock;
android::Mutex m_generatorLock;
- android::Mutex m_imagesLock;
android::Condition m_generatorReadyCond;
static TilesManager* gInstance;
@@ -228,8 +223,6 @@ private:
TilesProfiler m_profiler;
TilesTracker m_tilesTracker;
unsigned long long m_drawGLCount;
-
- HashMap<SkBitmapRef*, ImageTexture*> m_images;
};
} // namespace WebCore