[CoordinatedGraphics] Remove RefCounted from Tile
authorryuan.choi@navercorp.com <ryuan.choi@navercorp.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 22:20:56 +0000 (22:20 +0000)
committerryuan.choi@navercorp.com <ryuan.choi@navercorp.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jun 2015 22:20:56 +0000 (22:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145788

Reviewed by Darin Adler.

Since r185140, Tile does not need to be RefCounted.

No new tests, no behavior changes.

* platform/graphics/texmap/coordinated/Tile.cpp:
(WebCore::Tile::create): Deleted.
* platform/graphics/texmap/coordinated/Tile.h:
* platform/graphics/texmap/coordinated/TiledBackingStore.cpp:
(WebCore::TiledBackingStore::invalidate):
(WebCore::TiledBackingStore::updateTileBuffers): Simplifies not to use unnecessary Vector.
(WebCore::TiledBackingStore::coverageRatio):
(WebCore::TiledBackingStore::createTiles):
(WebCore::TiledBackingStore::resizeEdgeTiles):
(WebCore::TiledBackingStore::setKeepRect):
(WebCore::TiledBackingStore::tileAt): Deleted one line wrapper.
(WebCore::TiledBackingStore::setTile): Ditto.
(WebCore::TiledBackingStore::removeTile): Ditto.
* platform/graphics/texmap/coordinated/TiledBackingStore.h:

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/texmap/coordinated/Tile.cpp
Source/WebCore/platform/graphics/texmap/coordinated/Tile.h
Source/WebCore/platform/graphics/texmap/coordinated/TiledBackingStore.cpp
Source/WebCore/platform/graphics/texmap/coordinated/TiledBackingStore.h

index b3c987d..cc50944 100644 (file)
@@ -1,3 +1,29 @@
+2015-06-09  Ryuan Choi  <ryuan.choi@navercorp.com>
+
+        [CoordinatedGraphics] Remove RefCounted from Tile
+        https://bugs.webkit.org/show_bug.cgi?id=145788
+
+        Reviewed by Darin Adler.
+
+        Since r185140, Tile does not need to be RefCounted.
+
+        No new tests, no behavior changes.
+
+        * platform/graphics/texmap/coordinated/Tile.cpp:
+        (WebCore::Tile::create): Deleted.
+        * platform/graphics/texmap/coordinated/Tile.h:
+        * platform/graphics/texmap/coordinated/TiledBackingStore.cpp:
+        (WebCore::TiledBackingStore::invalidate):
+        (WebCore::TiledBackingStore::updateTileBuffers): Simplifies not to use unnecessary Vector.
+        (WebCore::TiledBackingStore::coverageRatio):
+        (WebCore::TiledBackingStore::createTiles):
+        (WebCore::TiledBackingStore::resizeEdgeTiles):
+        (WebCore::TiledBackingStore::setKeepRect):
+        (WebCore::TiledBackingStore::tileAt): Deleted one line wrapper.
+        (WebCore::TiledBackingStore::setTile): Ditto.
+        (WebCore::TiledBackingStore::removeTile): Ditto.
+        * platform/graphics/texmap/coordinated/TiledBackingStore.h:
+
 2015-06-09  Chris Dumez  <cdumez@apple.com>
 
         Allow one sync GC per gcTimer interval on critical memory pressure warning
index 60e52c2..757a4dc 100644 (file)
@@ -36,11 +36,6 @@ namespace WebCore {
 
 static const uint32_t InvalidTileID = 0;
 
-PassRefPtr<Tile> Tile::create(TiledBackingStore& tiledBackingStore, const Coordinate& tileCoordinate)
-{
-    return adoptRef(new Tile(tiledBackingStore, tileCoordinate));
-}
-
 Tile::Tile(TiledBackingStore& tiledBackingStore, const Coordinate& tileCoordinate)
     : m_tiledBackingStore(tiledBackingStore)
     , m_coordinate(tileCoordinate)
index a34b220..86a080d 100644 (file)
@@ -38,12 +38,11 @@ namespace WebCore {
 class GraphicsContext;
 class TiledBackingStore;
 
-class Tile : public RefCounted<Tile>, public CoordinatedSurface::Client {
+class Tile : public CoordinatedSurface::Client {
 public:
     typedef IntPoint Coordinate;
 
-    static PassRefPtr<Tile> create(TiledBackingStore&, const Coordinate&);
-
+    Tile(TiledBackingStore&, const Coordinate&);
     ~Tile();
 
     bool isDirty() const;
@@ -58,8 +57,6 @@ public:
     virtual void paintToSurfaceContext(GraphicsContext*) override;
 
 private:
-    Tile(TiledBackingStore&, const Coordinate&);
-
     TiledBackingStore& m_tiledBackingStore;
     Coordinate m_coordinate;
     IntRect m_rect;
index 92d27e6..d8327ee 100644 (file)
@@ -83,7 +83,7 @@ void TiledBackingStore::invalidate(const IntRect& contentsDirtyRect)
 
     for (int yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) {
         for (int xCoordinate = topLeft.x(); xCoordinate <= bottomRight.x(); ++xCoordinate) {
-            RefPtr<Tile> currentTile = tileAt(Tile::Coordinate(xCoordinate, yCoordinate));
+            Tile* currentTile = m_tiles.get(Tile::Coordinate(xCoordinate, yCoordinate));
             if (!currentTile)
                 continue;
             // Pass the full rect to each tile as coveredDirtyRect might not
@@ -95,22 +95,16 @@ void TiledBackingStore::invalidate(const IntRect& contentsDirtyRect)
 
 void TiledBackingStore::updateTileBuffers()
 {
-    Vector<RefPtr<Tile>> dirtyTiles;
-    for (auto& tile : m_tiles.values()) {
-        if (!tile->isDirty())
-            continue;
-        dirtyTiles.append(tile);
-    }
-
-    if (dirtyTiles.isEmpty())
-        return;
-
     // FIXME: In single threaded case, tile back buffers could be updated asynchronously 
     // one by one and then swapped to front in one go. This would minimize the time spent
     // blocking on tile updates.
     bool updated = false;
-    for (auto& tile : dirtyTiles)
+    for (auto& tile : m_tiles.values()) {
+        if (!tile->isDirty())
+            continue;
+
         updated |= tile->updateBackBuffer();
+    }
 
     if (updated)
         m_client->didUpdateTileBuffers();
@@ -155,7 +149,7 @@ float TiledBackingStore::coverageRatio(const WebCore::IntRect& contentsRect) con
     for (int yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) {
         for (int xCoordinate = topLeft.x(); xCoordinate <= bottomRight.x(); ++xCoordinate) {
             Tile::Coordinate currentCoordinate(xCoordinate, yCoordinate);
-            RefPtr<Tile> currentTile = tileAt(currentCoordinate);
+            Tile* currentTile = m_tiles.get(currentCoordinate);
             if (currentTile && currentTile->isReadyToPaint()) {
                 IntRect coverRect = intersection(dirtyRect, currentTile->rect());
                 coverArea += coverRect.width() * coverRect.height();
@@ -236,7 +230,7 @@ void TiledBackingStore::createTiles()
     for (int yCoordinate = topLeft.y(); yCoordinate <= bottomRight.y(); ++yCoordinate) {
         for (int xCoordinate = topLeft.x(); xCoordinate <= bottomRight.x(); ++xCoordinate) {
             Tile::Coordinate currentCoordinate(xCoordinate, yCoordinate);
-            if (tileAt(currentCoordinate))
+            if (m_tiles.contains(currentCoordinate))
                 continue;
             ++requiredTileCount;
             double distance = tileDistance(m_visibleRect, currentCoordinate);
@@ -254,7 +248,7 @@ void TiledBackingStore::createTiles()
     unsigned tilesToCreateCount = tilesToCreate.size();
     for (unsigned n = 0; n < tilesToCreateCount; ++n) {
         Tile::Coordinate coordinate = tilesToCreate[n];
-        setTile(coordinate, Tile::create(*this, coordinate));
+        m_tiles.add(coordinate, std::make_unique<Tile>(*this, coordinate));
     }
     requiredTileCount -= tilesToCreateCount;
 
@@ -368,9 +362,10 @@ bool TiledBackingStore::resizeEdgeTiles()
             wasResized = true;
         }
     }
-    unsigned removeCount = tilesToRemove.size();
-    for (unsigned n = 0; n < removeCount; ++n)
-        removeTile(tilesToRemove[n]);
+
+    for (auto& coordinateToRemove : tilesToRemove)
+        m_tiles.remove(coordinateToRemove);
+
     return wasResized;
 }
 
@@ -387,9 +382,9 @@ void TiledBackingStore::setKeepRect(const IntRect& keepRect)
         if (!tileRect.intersects(keepRectF))
             toRemove.append(coordinate);
     }
-    unsigned removeCount = toRemove.size();
-    for (unsigned n = 0; n < removeCount; ++n)
-        removeTile(toRemove[n]);
+
+    for (auto& coordinateToRemove : toRemove)
+        m_tiles.remove(coordinateToRemove);
 
     m_keepRect = keepRect;
 }
@@ -400,21 +395,6 @@ void TiledBackingStore::removeAllNonVisibleTiles()
     setKeepRect(boundedVisibleRect);
 }
 
-PassRefPtr<Tile> TiledBackingStore::tileAt(const Tile::Coordinate& coordinate) const
-{
-    return m_tiles.get(coordinate);
-}
-
-void TiledBackingStore::setTile(const Tile::Coordinate& coordinate, PassRefPtr<Tile> tile)
-{
-    m_tiles.set(coordinate, tile);
-}
-
-void TiledBackingStore::removeTile(const Tile::Coordinate& coordinate)
-{
-    m_tiles.remove(coordinate);
-}
-
 IntRect TiledBackingStore::mapToContents(const IntRect& rect) const
 {
     return enclosingIntRect(FloatRect(rect.x() / m_contentsScale,
index 36fa278..543780c 100644 (file)
@@ -29,7 +29,6 @@
 #include "Timer.h"
 #include <wtf/Assertions.h>
 #include <wtf/HashMap.h>
-#include <wtf/RefPtr.h>
 
 namespace WebCore {
 
@@ -79,10 +78,6 @@ private:
     void setCoverRect(const IntRect& rect) { m_coverRect = rect; }
     void setKeepRect(const IntRect&);
 
-    PassRefPtr<Tile> tileAt(const Tile::Coordinate&) const;
-    void setTile(const Tile::Coordinate&, PassRefPtr<Tile>);
-    void removeTile(const Tile::Coordinate&);
-
     IntRect visibleRect() const;
 
     float coverageRatio(const IntRect&) const;
@@ -93,7 +88,7 @@ private:
 private:
     TiledBackingStoreClient* m_client;
 
-    typedef HashMap<Tile::Coordinate, RefPtr<Tile> > TileMap;
+    typedef HashMap<Tile::Coordinate, std::unique_ptr<Tile>> TileMap;
     TileMap m_tiles;
 
     IntSize m_tileSize;