[chromium] Drop tiles completely outside of layer bounds when resizing to a smaller...
authorjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Feb 2012 00:25:16 +0000 (00:25 +0000)
committerjamesr@google.com <jamesr@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Feb 2012 00:25:16 +0000 (00:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77910

Reviewed by Kenneth Russell.

Source/WebCore:

When resizing a tiled layer to a smaller size, drop all tiles that lie completely outside the new layer bounds.
This avoids attempting to access out-of-bounds tiles when iterating over all tiles in the tiler, which triggers
ASSERT()s, as well as saves some memory.

New unit test added to TiledLayerChromiumTest.

* platform/graphics/chromium/TiledLayerChromium.cpp:
(WebCore::TiledLayerChromium::invalidateRect):
* platform/graphics/chromium/cc/CCLayerTilingData.cpp:
(WebCore::CCLayerTilingData::setBounds):

Source/WebKit/chromium:

Adds test for resizing a layer to cover fewer tiles. Test hits ASSERT()s without any code changes.

* tests/TiledLayerChromiumTest.cpp:
(::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@106870 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerTilingData.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp

index e4ffe87..85004e4 100644 (file)
@@ -1,3 +1,21 @@
+2012-02-06  James Robinson  <jamesr@chromium.org>
+
+        [chromium] Drop tiles completely outside of layer bounds when resizing to a smaller size
+        https://bugs.webkit.org/show_bug.cgi?id=77910
+
+        Reviewed by Kenneth Russell.
+
+        When resizing a tiled layer to a smaller size, drop all tiles that lie completely outside the new layer bounds.
+        This avoids attempting to access out-of-bounds tiles when iterating over all tiles in the tiler, which triggers
+        ASSERT()s, as well as saves some memory.
+
+        New unit test added to TiledLayerChromiumTest.
+
+        * platform/graphics/chromium/TiledLayerChromium.cpp:
+        (WebCore::TiledLayerChromium::invalidateRect):
+        * platform/graphics/chromium/cc/CCLayerTilingData.cpp:
+        (WebCore::CCLayerTilingData::setBounds):
+
 2012-02-06  Chris Rogers  <crogers@google.com>
 
         zvmul incorrectly multiplies complex arrays on Windows.
index e979361..2367763 100644 (file)
@@ -312,6 +312,7 @@ void TiledLayerChromium::setIsNonCompositedContent(bool isNonCompositedContent)
 
 void TiledLayerChromium::invalidateRect(const IntRect& layerRect)
 {
+    updateBounds();
     if (m_tiler->isEmpty() || layerRect.isEmpty() || m_skipsDraw)
         return;
 
index 92637fc..27705f3 100644 (file)
@@ -117,6 +117,17 @@ IntRect CCLayerTilingData::tileRect(const Tile* tile) const
 void CCLayerTilingData::setBounds(const IntSize& size)
 {
     m_tilingData.setTotalSize(size.width(), size.height());
+
+    // Any tiles completely outside our new bounds are invalid and should be dropped.
+    int left, top, right, bottom;
+    layerRectToTileIndices(IntRect(IntPoint(), size), left, top, right, bottom);
+    Vector<TileMapKey> invalidTileKeys;
+    for (TileMap::const_iterator it = m_tiles.begin(); it != m_tiles.end(); ++it) {
+        if (it->first.first > right || it->first.second > bottom)
+            invalidTileKeys.append(it->first);
+    }
+    for (size_t i = 0; i < invalidTileKeys.size(); ++i)
+        m_tiles.remove(invalidTileKeys[i]);
 }
 
 IntSize CCLayerTilingData::bounds() const
index 3550981..cd6bf56 100644 (file)
@@ -1,3 +1,15 @@
+2012-02-06  James Robinson  <jamesr@chromium.org>
+
+        [chromium] Drop tiles completely outside of layer bounds when resizing to a smaller size
+        https://bugs.webkit.org/show_bug.cgi?id=77910
+
+        Reviewed by Kenneth Russell.
+
+        Adds test for resizing a layer to cover fewer tiles. Test hits ASSERT()s without any code changes.
+
+        * tests/TiledLayerChromiumTest.cpp:
+        (::TEST):
+
 2012-02-06  Ryosuke Niwa  <rniwa@webkit.org>
 
         Revert r106859. It was completely bogus.
index 0c55090..1c075fb 100644 (file)
@@ -565,4 +565,17 @@ TEST(TiledLayerChromiumTest, layerAddsSelfToOccludedRegion)
     EXPECT_EQ(0u, occluded.rects().size());
 }
 
+TEST(TiledLayerChromiumTest, resizeToSmaller)
+{
+    OwnPtr<TextureManager> textureManager = TextureManager::create(60*1024*1024, 60*1024*1024, 1024);
+    RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(textureManager.get()));
+
+    layer->setBounds(IntSize(700, 700));
+    layer->invalidateRect(IntRect(0, 0, 700, 700));
+    layer->prepareToUpdate(IntRect(0, 0, 700, 700));
+
+    layer->setBounds(IntSize(200, 200));
+    layer->invalidateRect(IntRect(0, 0, 200, 200));
+}
+
 } // namespace