Title: [106397] trunk/Source/WebCore
Revision
106397
Author
[email protected]
Date
2012-01-31 14:46:39 -0800 (Tue, 31 Jan 2012)

Log Message

Put tiles in a HashMap
https://bugs.webkit.org/show_bug.cgi?id=77480

Reviewed by Antti Koivisto.

Put tiles in a hash map keyed off the tile index.

* platform/graphics/ca/mac/TileCache.h:
Shuffle member variables around so the order makes more sense.
Add the tile map.

* platform/graphics/ca/mac/TileCache.mm:
(WebCore::TileCache::TileCache):
Update member initializers.

(WebCore::TileCache::setNeedsDisplayInRect):
Call tileLayerAtIndex instead of tileLayerAtPosition.

(WebCore::TileCache::setAcceleratesDrawing):
(WebCore::TileCache::setTileDebugBorderWidth):
(WebCore::TileCache::setTileDebugBorderColor):
Iterate over the hash map instead of the sublayers.

(WebCore::TileCache::resizeTileGrid):
Add the created layers to the map.

(WebCore::TileCache::tileLayerAtIndex):
Rename from tileLayerAtPoint to better reflect that this member function
returns a tile layer at the given index and not the given point.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (106396 => 106397)


--- trunk/Source/WebCore/ChangeLog	2012-01-31 22:45:22 UTC (rev 106396)
+++ trunk/Source/WebCore/ChangeLog	2012-01-31 22:46:39 UTC (rev 106397)
@@ -1,3 +1,35 @@
+2012-01-31  Anders Carlsson  <[email protected]>
+
+        Put tiles in a HashMap
+        https://bugs.webkit.org/show_bug.cgi?id=77480
+
+        Reviewed by Antti Koivisto.
+
+        Put tiles in a hash map keyed off the tile index.
+
+        * platform/graphics/ca/mac/TileCache.h:
+        Shuffle member variables around so the order makes more sense.
+        Add the tile map.
+
+        * platform/graphics/ca/mac/TileCache.mm:
+        (WebCore::TileCache::TileCache):
+        Update member initializers.
+
+        (WebCore::TileCache::setNeedsDisplayInRect):
+        Call tileLayerAtIndex instead of tileLayerAtPosition.
+
+        (WebCore::TileCache::setAcceleratesDrawing):
+        (WebCore::TileCache::setTileDebugBorderWidth):
+        (WebCore::TileCache::setTileDebugBorderColor):
+        Iterate over the hash map instead of the sublayers.
+
+        (WebCore::TileCache::resizeTileGrid):
+        Add the created layers to the map.
+
+        (WebCore::TileCache::tileLayerAtIndex):
+        Rename from tileLayerAtPoint to better reflect that this member function
+        returns a tile layer at the given index and not the given point.
+
 2012-01-31  Antti Koivisto  <[email protected]>
 
         Make CSSOM style() return CSSStyleDeclaration*

Modified: trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.h (106396 => 106397)


--- trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.h	2012-01-31 22:45:22 UTC (rev 106396)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.h	2012-01-31 22:46:39 UTC (rev 106397)
@@ -26,7 +26,9 @@
 #ifndef TileCache_h
 #define TileCache_h
 
+#include "IntPointHash.h"
 #include "IntSize.h"
+#include <wtf/HashMap.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/RetainPtr.h>
@@ -66,6 +68,8 @@
     void setTileDebugBorderColor(CGColorRef);
 
 private:
+    typedef IntPoint TileIndex;
+
     TileCache(WebTileCacheLayer*, const IntSize& tileSize);
 
     FloatRect visibleRect() const;
@@ -76,23 +80,25 @@
     IntSize numTilesForGridSize(const IntSize&) const;
     void resizeTileGrid(const IntSize& numTiles);
 
-    WebTileLayer* tileLayerAtPosition(const IntPoint&) const;
+    WebTileLayer* tileLayerAtIndex(const TileIndex&) const;
     RetainPtr<WebTileLayer> createTileLayer();
 
     bool shouldShowRepaintCounters() const;
 
     WebTileCacheLayer* m_tileCacheLayer;
+    RetainPtr<CALayer> m_tileContainerLayer;
     const IntSize m_tileSize;
 
-    RetainPtr<CALayer> m_tileContainerLayer;
-
-    RetainPtr<CGColorRef> m_tileDebugBorderColor;
-    float m_tileDebugBorderWidth;
-
     // Number of tiles in each dimension.
     IntSize m_numTilesInGrid;
 
+    typedef HashMap<TileIndex, RetainPtr<WebTileLayer> > TileMap;
+    TileMap m_tiles;
+
     bool m_acceleratesDrawing;
+
+    RetainPtr<CGColorRef> m_tileDebugBorderColor;
+    float m_tileDebugBorderWidth;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.mm (106396 => 106397)


--- trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.mm	2012-01-31 22:45:22 UTC (rev 106396)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.mm	2012-01-31 22:46:39 UTC (rev 106397)
@@ -50,10 +50,10 @@
 
 TileCache::TileCache(WebTileCacheLayer* tileCacheLayer, const IntSize& tileSize)
     : m_tileCacheLayer(tileCacheLayer)
+    , m_tileContainerLayer(adoptCF([[CALayer alloc] init]))
     , m_tileSize(tileSize)
-    , m_tileContainerLayer(adoptCF([[CALayer alloc] init]))
+    , m_acceleratesDrawing(false)
     , m_tileDebugBorderWidth(0)
-    , m_acceleratesDrawing(false)
 {
     [CATransaction begin];
     [CATransaction setDisableActions:YES];
@@ -87,7 +87,7 @@
 
     for (int y = topLeft.y(); y <= bottomRight.y(); ++y) {
         for (int x = topLeft.x(); x <= bottomRight.x(); ++x) {
-            WebTileLayer* tileLayer = tileLayerAtPosition(IntPoint(x, y));
+            WebTileLayer* tileLayer = tileLayerAtIndex(IntPoint(x, y));
 
             CGRect tileRect = [m_tileCacheLayer convertRect:rect toLayer:tileLayer];
 
@@ -158,8 +158,8 @@
 
     m_acceleratesDrawing = acceleratesDrawing;
 
-    for (WebTileLayer* tileLayer in [m_tileContainerLayer.get() sublayers])
-        [tileLayer setAcceleratesDrawing:m_acceleratesDrawing];
+    for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it)
+        [it->second.get() setAcceleratesDrawing:m_acceleratesDrawing];
 #else
     UNUSED_PARAM(acceleratesDrawing);
 #endif
@@ -176,8 +176,8 @@
         return;
 
     m_tileDebugBorderWidth = borderWidth;
-    for (WebTileLayer* tileLayer in [m_tileContainerLayer.get() sublayers])
-        [tileLayer setBorderWidth:m_tileDebugBorderWidth];
+    for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it)
+        [it->second.get() setBorderWidth:m_tileDebugBorderWidth];
 }
 
 void TileCache::setTileDebugBorderColor(CGColorRef borderColor)
@@ -186,8 +186,8 @@
         return;
 
     m_tileDebugBorderColor = borderColor;
-    for (WebTileLayer* tileLayer in [m_tileContainerLayer.get() sublayers])
-        [tileLayer setBorderColor:m_tileDebugBorderColor.get()];
+    for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it)
+        [it->second.get() setBorderColor:m_tileDebugBorderColor.get()];
 }
 
 FloatRect TileCache::visibleRect() const
@@ -245,10 +245,11 @@
             RetainPtr<WebTileLayer> tileLayer;
 
             if (x < m_numTilesInGrid.width() && y < m_numTilesInGrid.height()) {
-                // We can reuse the tile layer at this position.
-                tileLayer = tileLayerAtPosition(IntPoint(x, y));
+                // We can reuse the tile layer at this index.
+                tileLayer = tileLayerAtIndex(IntPoint(x, y));
             } else {
                 tileLayer = createTileLayer();
+                m_tiles.set(IntPoint(x, y), tileLayer.get());
             }
 
             [tileLayer.get() setPosition:CGPointMake(x * m_tileSize.width(), y * m_tileSize.height())];
@@ -263,14 +264,14 @@
     [CATransaction commit];
 }
 
-WebTileLayer* TileCache::tileLayerAtPosition(const IntPoint& point) const
+WebTileLayer* TileCache::tileLayerAtIndex(const TileIndex& index) const
 {
-    ASSERT(point.x() >= 0);
-    ASSERT(point.x() <= m_numTilesInGrid.width());
-    ASSERT(point.y() >= 0);
-    ASSERT(point.y() <= m_numTilesInGrid.height());
+    ASSERT(index.x() >= 0);
+    ASSERT(index.x() <= m_numTilesInGrid.width());
+    ASSERT(index.y() >= 0);
+    ASSERT(index.y() <= m_numTilesInGrid.height());
 
-    return [[m_tileContainerLayer.get() sublayers] objectAtIndex:point.y() * m_numTilesInGrid.width() + point.x()];
+    return m_tiles.get(index).get();
 }
 
 RetainPtr<WebTileLayer> TileCache::createTileLayer()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to