Changeset 106397 in webkit


Ignore:
Timestamp:
Jan 31, 2012 2:46:39 PM (12 years ago)
Author:
andersca@apple.com
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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106393 r106397  
     12012-01-31  Anders Carlsson  <andersca@apple.com>
     2
     3        Put tiles in a HashMap
     4        https://bugs.webkit.org/show_bug.cgi?id=77480
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Put tiles in a hash map keyed off the tile index.
     9
     10        * platform/graphics/ca/mac/TileCache.h:
     11        Shuffle member variables around so the order makes more sense.
     12        Add the tile map.
     13
     14        * platform/graphics/ca/mac/TileCache.mm:
     15        (WebCore::TileCache::TileCache):
     16        Update member initializers.
     17
     18        (WebCore::TileCache::setNeedsDisplayInRect):
     19        Call tileLayerAtIndex instead of tileLayerAtPosition.
     20
     21        (WebCore::TileCache::setAcceleratesDrawing):
     22        (WebCore::TileCache::setTileDebugBorderWidth):
     23        (WebCore::TileCache::setTileDebugBorderColor):
     24        Iterate over the hash map instead of the sublayers.
     25
     26        (WebCore::TileCache::resizeTileGrid):
     27        Add the created layers to the map.
     28
     29        (WebCore::TileCache::tileLayerAtIndex):
     30        Rename from tileLayerAtPoint to better reflect that this member function
     31        returns a tile layer at the given index and not the given point.
     32
    1332012-01-31  Antti Koivisto  <antti@apple.com>
    234
  • trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.h

    r106385 r106397  
    2727#define TileCache_h
    2828
     29#include "IntPointHash.h"
    2930#include "IntSize.h"
     31#include <wtf/HashMap.h>
    3032#include <wtf/Noncopyable.h>
    3133#include <wtf/PassOwnPtr.h>
     
    6769
    6870private:
     71    typedef IntPoint TileIndex;
     72
    6973    TileCache(WebTileCacheLayer*, const IntSize& tileSize);
    7074
     
    7781    void resizeTileGrid(const IntSize& numTiles);
    7882
    79     WebTileLayer* tileLayerAtPosition(const IntPoint&) const;
     83    WebTileLayer* tileLayerAtIndex(const TileIndex&) const;
    8084    RetainPtr<WebTileLayer> createTileLayer();
    8185
     
    8387
    8488    WebTileCacheLayer* m_tileCacheLayer;
     89    RetainPtr<CALayer> m_tileContainerLayer;
    8590    const IntSize m_tileSize;
    86 
    87     RetainPtr<CALayer> m_tileContainerLayer;
    88 
    89     RetainPtr<CGColorRef> m_tileDebugBorderColor;
    90     float m_tileDebugBorderWidth;
    9191
    9292    // Number of tiles in each dimension.
    9393    IntSize m_numTilesInGrid;
    9494
     95    typedef HashMap<TileIndex, RetainPtr<WebTileLayer> > TileMap;
     96    TileMap m_tiles;
     97
    9598    bool m_acceleratesDrawing;
     99
     100    RetainPtr<CGColorRef> m_tileDebugBorderColor;
     101    float m_tileDebugBorderWidth;
    96102};
    97103
  • trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.mm

    r106385 r106397  
    5151TileCache::TileCache(WebTileCacheLayer* tileCacheLayer, const IntSize& tileSize)
    5252    : m_tileCacheLayer(tileCacheLayer)
     53    , m_tileContainerLayer(adoptCF([[CALayer alloc] init]))
    5354    , m_tileSize(tileSize)
    54     , m_tileContainerLayer(adoptCF([[CALayer alloc] init]))
     55    , m_acceleratesDrawing(false)
    5556    , m_tileDebugBorderWidth(0)
    56     , m_acceleratesDrawing(false)
    5757{
    5858    [CATransaction begin];
     
    8888    for (int y = topLeft.y(); y <= bottomRight.y(); ++y) {
    8989        for (int x = topLeft.x(); x <= bottomRight.x(); ++x) {
    90             WebTileLayer* tileLayer = tileLayerAtPosition(IntPoint(x, y));
     90            WebTileLayer* tileLayer = tileLayerAtIndex(IntPoint(x, y));
    9191
    9292            CGRect tileRect = [m_tileCacheLayer convertRect:rect toLayer:tileLayer];
     
    159159    m_acceleratesDrawing = acceleratesDrawing;
    160160
    161     for (WebTileLayer* tileLayer in [m_tileContainerLayer.get() sublayers])
    162         [tileLayer setAcceleratesDrawing:m_acceleratesDrawing];
     161    for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it)
     162        [it->second.get() setAcceleratesDrawing:m_acceleratesDrawing];
    163163#else
    164164    UNUSED_PARAM(acceleratesDrawing);
     
    177177
    178178    m_tileDebugBorderWidth = borderWidth;
    179     for (WebTileLayer* tileLayer in [m_tileContainerLayer.get() sublayers])
    180         [tileLayer setBorderWidth:m_tileDebugBorderWidth];
     179    for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it)
     180        [it->second.get() setBorderWidth:m_tileDebugBorderWidth];
    181181}
    182182
     
    187187
    188188    m_tileDebugBorderColor = borderColor;
    189     for (WebTileLayer* tileLayer in [m_tileContainerLayer.get() sublayers])
    190         [tileLayer setBorderColor:m_tileDebugBorderColor.get()];
     189    for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it)
     190        [it->second.get() setBorderColor:m_tileDebugBorderColor.get()];
    191191}
    192192
     
    246246
    247247            if (x < m_numTilesInGrid.width() && y < m_numTilesInGrid.height()) {
    248                 // We can reuse the tile layer at this position.
    249                 tileLayer = tileLayerAtPosition(IntPoint(x, y));
     248                // We can reuse the tile layer at this index.
     249                tileLayer = tileLayerAtIndex(IntPoint(x, y));
    250250            } else {
    251251                tileLayer = createTileLayer();
     252                m_tiles.set(IntPoint(x, y), tileLayer.get());
    252253            }
    253254
     
    264265}
    265266
    266 WebTileLayer* TileCache::tileLayerAtPosition(const IntPoint& point) const
    267 {
    268     ASSERT(point.x() >= 0);
    269     ASSERT(point.x() <= m_numTilesInGrid.width());
    270     ASSERT(point.y() >= 0);
    271     ASSERT(point.y() <= m_numTilesInGrid.height());
    272 
    273     return [[m_tileContainerLayer.get() sublayers] objectAtIndex:point.y() * m_numTilesInGrid.width() + point.x()];
     267WebTileLayer* TileCache::tileLayerAtIndex(const TileIndex& index) const
     268{
     269    ASSERT(index.x() >= 0);
     270    ASSERT(index.x() <= m_numTilesInGrid.width());
     271    ASSERT(index.y() >= 0);
     272    ASSERT(index.y() <= m_numTilesInGrid.height());
     273
     274    return m_tiles.get(index).get();
    274275}
    275276
Note: See TracChangeset for help on using the changeset viewer.