OSDN Git Service

am c3da3ea3: DO NOT MERGE
authorNicolas Roard <nicolasroard@google.com>
Tue, 10 May 2011 01:04:35 +0000 (18:04 -0700)
committerAndroid Git Automerger <android-git-automerger@android.com>
Tue, 10 May 2011 01:04:35 +0000 (18:04 -0700)
* commit 'c3da3ea3d67930a5593b455cdc697171a9115cae':
  DO NOT MERGE

WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp
WebCore/platform/graphics/android/GraphicsLayerAndroid.h
WebCore/platform/graphics/android/LayerAndroid.cpp
WebCore/platform/graphics/android/LayerAndroid.h

index 96cfd3d..59f8408 100644 (file)
@@ -120,6 +120,8 @@ GraphicsLayerAndroid::GraphicsLayerAndroid(GraphicsLayerClient* client) :
     m_needsNotifyClient(false),
     m_haveContents(false),
     m_haveImage(false),
+    m_newImage(false),
+    m_imageRef(0),
     m_foregroundLayer(0),
     m_foregroundClipLayer(0)
 {
@@ -623,6 +625,14 @@ bool GraphicsLayerAndroid::repaint()
 
         return true;
     }
+    if (m_needsRepaint && m_haveImage && m_newImage) {
+        // We need to tell the GL thread that we will need to repaint the
+        // texture. Only do so if we effectively have a new image!
+        m_contentLayer->needsRepaint();
+        m_newImage = false;
+        m_needsRepaint = false;
+        return true;
+    }
     return false;
 }
 
@@ -834,9 +844,15 @@ void GraphicsLayerAndroid::setContentsToImage(Image* image)
     if (image) {
         m_haveContents = true;
         m_haveImage = true;
-        m_contentLayer->setContentsImage(image->nativeImageForCurrentFrame());
-        setNeedsDisplay();
-        askForSync();
+        // Only pass the new image if it's a different one
+        if (image->nativeImageForCurrentFrame() != m_imageRef) {
+            m_newImage = true;
+            m_contentLayer->setContentsImage(image->nativeImageForCurrentFrame());
+            // remember the passed image.
+            m_imageRef = image->nativeImageForCurrentFrame();
+            setNeedsDisplay();
+            askForSync();
+        }
     }
 }
 
index da247ca..94b828b 100644 (file)
 #include "GraphicsLayerClient.h"
 #include "LayerAndroid.h"
 #include "RefPtr.h"
+#include "SkBitmapRef.h"
 #include "Vector.h"
 
 class FloatPoint3D;
 class Image;
+class SkBitmapRef;
 
 namespace WebCore {
 
@@ -142,6 +144,8 @@ private:
 
     bool m_haveContents;
     bool m_haveImage;
+    bool m_newImage;
+    SkBitmapRef* m_imageRef; // only used to remember previously passed images
 
     Vector<FloatRect> m_invalidatedRects;
 
index 53edb45..4ba2da0 100644 (file)
@@ -92,6 +92,7 @@ LayerAndroid::LayerAndroid(RenderLayer* owner) : SkLayer(),
 LayerAndroid::LayerAndroid(const LayerAndroid& layer) : SkLayer(layer),
     m_haveClip(layer.m_haveClip),
     m_isIframe(layer.m_isIframe),
+    m_contentsImage(0),
     m_extra(0), // deliberately not copied
     m_uniqueId(layer.m_uniqueId),
     m_drawingTexture(0),
@@ -100,8 +101,7 @@ LayerAndroid::LayerAndroid(const LayerAndroid& layer) : SkLayer(layer),
     m_owningLayer(layer.m_owningLayer)
 {
     m_isFixed = layer.m_isFixed;
-    m_contentsImage = layer.m_contentsImage;
-    SkSafeRef(m_contentsImage);
+    copyBitmap(layer.m_contentsImage);
     m_renderLayerPos = layer.m_renderLayerPos;
     m_transform = layer.m_transform;
     m_backgroundColor = layer.m_backgroundColor;
@@ -202,7 +202,7 @@ LayerAndroid::~LayerAndroid()
     removeTexture(0);
     removeChildren();
     delete m_extra;
-    SkSafeUnref(m_contentsImage);
+    delete m_contentsImage;
     SkSafeUnref(m_recordingPicture);
     m_animations.clear();
 #ifdef DEBUG_COUNT
@@ -650,9 +650,23 @@ void LayerAndroid::updateGLPositions(const TransformationMatrix& parentMatrix,
         this->getChild(i)->updateGLPositions(localMatrix, drawClip(), opacity);
 }
 
+void LayerAndroid::copyBitmap(SkBitmap* bitmap)
+{
+    if (!bitmap)
+        return;
+
+    delete m_contentsImage;
+    m_contentsImage = new SkBitmap();
+    SkBitmap::Config config = bitmap->config();
+    int w = bitmap->width();
+    int h = bitmap->height();
+    m_contentsImage->setConfig(config, w, h);
+    bitmap->copyTo(m_contentsImage, config);
+}
+
 void LayerAndroid::setContentsImage(SkBitmapRef* img)
 {
-    SkRefCnt_SafeAssign(m_contentsImage, img);
+    copyBitmap(&img->bitmap());
 }
 
 bool LayerAndroid::needsTexture()
@@ -930,9 +944,8 @@ bool LayerAndroid::drawGL(GLWebViewState* glWebViewState, SkMatrix& matrix)
 
     if (m_drawingTexture) {
         TextureInfo* textureInfo = m_drawingTexture->consumerLock();
-        if (!m_drawingTexture->readyFor(this))
-            m_dirty = true;
-        if (textureInfo) {
+        bool ready = m_drawingTexture->readyFor(this);
+        if (textureInfo && (!m_contentsImage || (ready && m_contentsImage))) {
             SkRect bounds;
             bounds.set(m_drawingTexture->rect());
             XLOG("LayerAndroid %d %x (%.2f, %.2f) drawGL (texture %x, %d, %d, %d, %d)",
@@ -944,6 +957,8 @@ bool LayerAndroid::drawGL(GLWebViewState* glWebViewState, SkMatrix& matrix)
                                                               textureInfo->m_textureId,
                                                               m_drawOpacity, true);
         }
+        if (!ready)
+            m_dirty = true;
         m_drawingTexture->consumerRelease();
     } else if (needsTexture()) {
         m_dirty = true;
@@ -1034,14 +1049,18 @@ void LayerAndroid::paintBitmapGL()
     IntRect textureRect = texture->rect();
     canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode);
 
-    SkPicture picture;
-    SkCanvas* nCanvas = picture.beginRecording(textureRect.width(),
-                                               textureRect.height());
-    nCanvas->scale(scale, scale);
-    nCanvas->translate(-textureRect.x(), -textureRect.y());
-    contentDraw(nCanvas);
-    picture.endRecording();
-    picture.draw(canvas);
+    if (m_contentsImage) {
+        contentDraw(canvas);
+    } else {
+        SkPicture picture;
+        SkCanvas* nCanvas = picture.beginRecording(textureRect.width(),
+                                                   textureRect.height());
+        nCanvas->scale(scale, scale);
+        nCanvas->translate(-textureRect.x(), -textureRect.y());
+        contentDraw(nCanvas);
+        picture.endRecording();
+        picture.draw(canvas);
+    }
     extraDraw(canvas);
 
     m_atomicSync.lock();
@@ -1071,7 +1090,7 @@ void LayerAndroid::contentDraw(SkCanvas* canvas)
     if (m_contentsImage) {
       SkRect dest;
       dest.set(0, 0, getSize().width(), getSize().height());
-      canvas->drawBitmapRect(m_contentsImage->bitmap(), 0, dest);
+      canvas->drawBitmapRect(*m_contentsImage, 0, dest);
     } else {
       canvas->drawPicture(*m_recordingPicture);
     }
index 0846930..e01a9a7 100644 (file)
@@ -234,6 +234,7 @@ public:
     */
     void setContentsImage(SkBitmapRef* img);
     bool hasContentsImage() { return m_contentsImage; }
+    void copyBitmap(SkBitmap*);
 
     void bounds(SkRect*) const;
 
@@ -304,7 +305,7 @@ private:
     // it is a much faster method than using m_recordingPicture.
     SkPicture* m_recordingPicture;
 
-    SkBitmapRef* m_contentsImage;
+    SkBitmap* m_contentsImage;
 
     typedef HashMap<pair<String, int>, RefPtr<AndroidAnimation> > KeyframesMap;
     KeyframesMap m_animations;