From: Nicolas Roard Date: Tue, 10 May 2011 01:04:35 +0000 (-0700) Subject: am c3da3ea3: DO NOT MERGE X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=aecd2790ab5d8d358eb7a7ee0181a52ca18bc179;hp=1d62edecbc901d7d88ac6729e25aa0ad44b3aa04;p=android-x86%2Fexternal-webkit.git am c3da3ea3: DO NOT MERGE * commit 'c3da3ea3d67930a5593b455cdc697171a9115cae': DO NOT MERGE --- diff --git a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp index 96cfd3dd3..59f840821 100644 --- a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp +++ b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp @@ -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(); + } } } diff --git a/WebCore/platform/graphics/android/GraphicsLayerAndroid.h b/WebCore/platform/graphics/android/GraphicsLayerAndroid.h index da247ca57..94b828bb0 100644 --- a/WebCore/platform/graphics/android/GraphicsLayerAndroid.h +++ b/WebCore/platform/graphics/android/GraphicsLayerAndroid.h @@ -25,10 +25,12 @@ #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 m_invalidatedRects; diff --git a/WebCore/platform/graphics/android/LayerAndroid.cpp b/WebCore/platform/graphics/android/LayerAndroid.cpp index 53edb45cb..4ba2da0e1 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -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); } diff --git a/WebCore/platform/graphics/android/LayerAndroid.h b/WebCore/platform/graphics/android/LayerAndroid.h index 0846930b9..e01a9a772 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.h +++ b/WebCore/platform/graphics/android/LayerAndroid.h @@ -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, RefPtr > KeyframesMap; KeyframesMap m_animations;