From 6baa213e1806af132b1f0b1170343c5ac2bf75d3 Mon Sep 17 00:00:00 2001 From: Nicolas Roard Date: Sat, 12 May 2012 17:12:36 -0700 Subject: Fix memory leak and repaint issues with fixed background elements bug:6522485 bug:6486951 Change-Id: Ia707efed9311e4352eed3ab005ec7ca93b8444e4 --- .../graphics/android/GraphicsLayerAndroid.cpp | 35 +++++++++++++--------- .../graphics/android/GraphicsLayerAndroid.h | 4 +-- .../graphics/android/layers/BaseLayerAndroid.cpp | 3 ++ .../graphics/android/layers/LayerAndroid.cpp | 2 +- 4 files changed, 27 insertions(+), 17 deletions(-) (limited to 'Source/WebCore/platform/graphics') diff --git a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp index 3975545..ef355c7 100644 --- a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp @@ -124,7 +124,7 @@ GraphicsLayerAndroid::~GraphicsLayerAndroid() if (m_image) m_image->deref(); - m_contentLayer->unref(); + SkSafeUnref(m_contentLayer); SkSafeUnref(m_fixedBackgroundLayer); SkSafeUnref(m_foregroundLayer); SkSafeUnref(m_foregroundClipLayer); @@ -591,10 +591,10 @@ void GraphicsLayerAndroid::updateFixedBackgroundLayers() { return; if (!view->style()->hasFixedBackgroundImage()) return; - if (m_contentLayer->isFixedBackground()) - return; - if (m_fixedBackgroundLayer) // already created - return; + + SkSafeUnref(m_foregroundClipLayer); + SkSafeUnref(m_fixedBackgroundLayer); + SkSafeUnref(m_foregroundLayer); // we will have: // m_contentLayer @@ -602,11 +602,10 @@ void GraphicsLayerAndroid::updateFixedBackgroundLayers() { // \- m_fixedBackgroundLayer // \- m_foregroundLayer - // Grab the background image and create a layer for it + // use the background image and create a layer for it // the layer will be fixed positioned. Image* image = FixedBackgroundImageLayerAndroid::GetCachedImage(view->style()); - if (!image) return; @@ -634,15 +633,23 @@ void GraphicsLayerAndroid::updateFixedBackgroundLayers() { m_foregroundLayer->setIntrinsicallyComposited(true); // Finally, let's assemble all the layers under a FixedBackgroundLayerAndroid layer - LayerAndroid* layer = new FixedBackgroundLayerAndroid(*m_contentLayer); - m_contentLayer->unref(); - m_contentLayer = layer; - - m_contentLayer->addChild(m_foregroundClipLayer); - m_contentLayer->addChild(m_foregroundLayer); + if (!m_contentLayer->isFixedBackground()) { + m_contentLayer->removeChildren(); + LayerAndroid* layer = new FixedBackgroundLayerAndroid(*m_contentLayer); + m_contentLayer->unref(); + m_contentLayer = layer; + } - m_needsRepaint = true; + if (m_parent) { + // The content layer has changed so the parent needs to sync + // children. + static_cast(m_parent)->m_needsSyncChildren = true; + } + // Children are all re-parented. m_needsSyncChildren = true; + + setNeedsDisplay(); + askForSync(); } void GraphicsLayerAndroid::updateScrollOffset() { diff --git a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.h b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.h index 0fc0790..460e00f 100644 --- a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.h @@ -29,13 +29,13 @@ #include "SkBitmapRef.h" #include "Vector.h" -class FloatPoint3D; -class Image; class SkBitmapRef; class SkRegion; namespace WebCore { +class FloatPoint3D; +class Image; class LayerAndroid; class FixedBackgroundImageLayerAndroid; class ScrollableLayerAndroid; diff --git a/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.cpp index a0a1b58..283fa58 100644 --- a/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.cpp @@ -244,6 +244,9 @@ Image* FixedBackgroundImageLayerAndroid::GetCachedImage(PassRefPtr Image* image = cachedImage->image(); + if (image && !image->nativeImageForCurrentFrame()) + return 0; + if (image == Image::nullImage()) return 0; diff --git a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp index 95e6825..6e88081 100644 --- a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp @@ -601,7 +601,7 @@ void LayerAndroid::showLayer(int indent) int count = this->countChildren(); for (int i = 0; i < count; i++) - this->getChild(i)->showLayer(indent + 1); + this->getChild(i)->showLayer(indent + 2); } void LayerAndroid::mergeInvalsInto(LayerAndroid* replacementTree) -- cgit v1.1