summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics
diff options
context:
space:
mode:
authorNicolas Roard <nicolas@android.com>2010-04-15 12:51:53 -0700
committerNicolas Roard <nicolas@android.com>2010-04-16 13:22:38 -0700
commitdf81a920f9fec6f2853b6ed1bf1a0a2a89a6cc29 (patch)
treec0e7d01a498bc2c2d2392646701d76b18d1f7727 /WebCore/platform/graphics
parente95c070f82eadda193a0c0efaec7e63fa00e75ce (diff)
downloadexternal_webkit-df81a920f9fec6f2853b6ed1bf1a0a2a89a6cc29.zip
external_webkit-df81a920f9fec6f2853b6ed1bf1a0a2a89a6cc29.tar.gz
external_webkit-df81a920f9fec6f2853b6ed1bf1a0a2a89a6cc29.tar.bz2
Performance improvements in GraphicsLayer: implement the simple image code path.
Bug:2599955 Change-Id: I530a02c64abff40223005d6dc07c7495ca475ffe
Diffstat (limited to 'WebCore/platform/graphics')
-rw-r--r--WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp11
-rw-r--r--WebCore/platform/graphics/android/LayerAndroid.cpp18
-rw-r--r--WebCore/platform/graphics/android/LayerAndroid.h15
3 files changed, 37 insertions, 7 deletions
diff --git a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp
index b8a3610..201022a 100644
--- a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp
+++ b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp
@@ -451,7 +451,7 @@ bool GraphicsLayerAndroid::repaint(const FloatRect& rect)
this, rect.x(), rect.y(), rect.width(), rect.height(),
gPaused, m_needsRepaint, m_haveContents);
- if (!gPaused && m_haveContents && m_needsRepaint) {
+ if (!gPaused && m_haveContents && m_needsRepaint && !m_haveImage) {
SkAutoPictureRecord arp(m_contentLayer->recordContext(), m_size.width(), m_size.height());
SkCanvas* recordingCanvas = arp.getRecordingCanvas();
@@ -814,11 +814,10 @@ void GraphicsLayerAndroid::setContentsToImage(Image* image)
TLOG("(%x) setContentsToImage", this, image);
if (image) {
m_haveContents = true;
- if (!m_haveImage) {
- m_haveImage = true;
- setNeedsDisplay();
- askForSync();
- }
+ m_haveImage = true;
+ m_contentLayer->setContentsImage(image->nativeImageForCurrentFrame());
+ setNeedsDisplay();
+ askForSync();
}
}
diff --git a/WebCore/platform/graphics/android/LayerAndroid.cpp b/WebCore/platform/graphics/android/LayerAndroid.cpp
index d6ba0a1..7c3f5d4 100644
--- a/WebCore/platform/graphics/android/LayerAndroid.cpp
+++ b/WebCore/platform/graphics/android/LayerAndroid.cpp
@@ -5,6 +5,7 @@
#include "AndroidAnimation.h"
#include "DrawExtra.h"
+#include "SkBitmapRef.h"
#include "SkCanvas.h"
#include "SkDrawFilter.h"
#include "SkPaint.h"
@@ -50,6 +51,7 @@ LayerAndroid::LayerAndroid(bool isRootLayer) : SkLayer(),
m_doRotation(false),
m_isFixed(false),
m_recordingPicture(0),
+ m_contentsImage(0),
m_extra(0),
m_uniqueId(++gUniqueId)
{
@@ -69,6 +71,8 @@ LayerAndroid::LayerAndroid(const LayerAndroid& layer) : SkLayer(layer),
{
m_doRotation = layer.m_doRotation;
m_isFixed = layer.m_isFixed;
+ m_contentsImage = layer.m_contentsImage;
+ m_contentsImage->safeRef();
m_angleTransform = layer.m_angleTransform;
m_translation = layer.m_translation;
@@ -106,6 +110,7 @@ LayerAndroid::LayerAndroid(SkPicture* picture) : SkLayer(),
m_doRotation(false),
m_isFixed(false),
m_recordingPicture(picture),
+ m_contentsImage(0),
m_extra(0),
m_uniqueId(-1)
{
@@ -120,6 +125,7 @@ LayerAndroid::LayerAndroid(SkPicture* picture) : SkLayer(),
LayerAndroid::~LayerAndroid()
{
removeChildren();
+ m_contentsImage->safeUnref();
m_recordingPicture->safeUnref();
m_animations.clear();
gDebugLayerAndroidInstances--;
@@ -318,6 +324,10 @@ void LayerAndroid::updatePositions() {
}
}
+void LayerAndroid::setContentsImage(SkBitmapRef* img) {
+ SkRefCnt_SafeAssign(m_contentsImage, img);
+}
+
void LayerAndroid::onDraw(SkCanvas* canvas, SkScalar opacity) {
if (m_haveClip) {
SkRect r;
@@ -335,7 +345,13 @@ void LayerAndroid::onDraw(SkCanvas* canvas, SkScalar opacity) {
if (canvasOpacity < 255)
canvas->setDrawFilter(new OpacityDrawFilter(canvasOpacity));
- canvas->drawPicture(*m_recordingPicture);
+ if (m_contentsImage) {
+ SkRect dest;
+ dest.set(0, 0, getSize().width(), getSize().height());
+ canvas->drawBitmapRect(m_contentsImage->bitmap(), 0, dest);
+ } else {
+ canvas->drawPicture(*m_recordingPicture);
+ }
if (m_extra)
m_extra->draw(canvas, this);
diff --git a/WebCore/platform/graphics/android/LayerAndroid.h b/WebCore/platform/graphics/android/LayerAndroid.h
index ef6af3b..2b106d1 100644
--- a/WebCore/platform/graphics/android/LayerAndroid.h
+++ b/WebCore/platform/graphics/android/LayerAndroid.h
@@ -32,6 +32,7 @@
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
#endif
+class SkBitmapRef;
class SkCanvas;
class SkMatrix;
class SkPicture;
@@ -174,6 +175,13 @@ public:
int getFixedWidth() { return m_fixedWidth; }
int getFixedHeight() { return m_fixedHeight; }
+ /** This sets a content image -- calling it means we will use
+ the image directly when drawing the layer instead of using
+ the content painted by WebKit. See comments below for
+ m_recordingPicture and m_contentsImage.
+ */
+ void setContentsImage(SkBitmapRef* img);
+
protected:
virtual void onDraw(SkCanvas*, SkScalar opacity);
@@ -209,7 +217,14 @@ private:
SkScalar m_angleTransform;
SkColor m_backgroundColor;
+ // Note that m_recordingPicture and m_contentsImage are mutually exclusive;
+ // m_recordingPicture is used when WebKit is asked to paint the layer's
+ // content, while m_contentsImage contains an image that we directly
+ // composite, using the layer's dimensions as a destination rect.
+ // We do this as if the layer only contains an image, directly compositing
+ // it is a much faster method than using m_recordingPicture.
SkPicture* m_recordingPicture;
+ SkBitmapRef* m_contentsImage;
typedef HashMap<String, RefPtr<AndroidAnimation> > KeyframesMap;
KeyframesMap m_animations;