TileGrid should be PlatformCALayerClient instead of TileController
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Apr 2014 22:29:15 +0000 (22:29 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Apr 2014 22:29:15 +0000 (22:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131456

Reviewed by Tim Horton.

The client interface is for the tiles in the grid.

* platform/graphics/ca/mac/TileController.h:
* platform/graphics/ca/mac/TileController.mm:
(WebCore::TileController::setContentsScale):
(WebCore::TileController::createTileLayer):
(WebCore::TileController::platformCALayerPaintContents): Deleted.
(WebCore::TileController::platformCALayerDeviceScaleFactor): Deleted.
(WebCore::TileController::platformCALayerShowDebugBorders): Deleted.
(WebCore::TileController::platformCALayerShowRepaintCounter): Deleted.
(WebCore::TileController::platformCALayerIncrementRepaintCount): Deleted.
* platform/graphics/ca/mac/TileGrid.h:

    Move repaint counter to TileGrid too.

* platform/graphics/ca/mac/TileGrid.mm:
(WebCore::TileGrid::removeTiles):
(WebCore::TileGrid::removeAllSecondaryTiles):
(WebCore::TileGrid::removeTilesInCohort):

   Cleaned up tile removal.

(WebCore::TileGrid::revalidateTiles):
(WebCore::TileGrid::ensureTilesForRect):
(WebCore::TileGrid::platformCALayerPaintContents):
(WebCore::TileGrid::platformCALayerDeviceScaleFactor):
(WebCore::TileGrid::platformCALayerShowDebugBorders):
(WebCore::TileGrid::platformCALayerShowRepaintCounter):
(WebCore::TileGrid::platformCALayerContentsOpaque):
(WebCore::TileGrid::platformCALayerIncrementRepaintCount):
(WebCore::queueTileForRemoval): Deleted.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ca/mac/TileController.h
Source/WebCore/platform/graphics/ca/mac/TileController.mm
Source/WebCore/platform/graphics/ca/mac/TileGrid.h
Source/WebCore/platform/graphics/ca/mac/TileGrid.mm

index f4bfa1c..b341698 100644 (file)
@@ -1,3 +1,42 @@
+2014-04-09  Antti Koivisto  <antti@apple.com>
+
+        TileGrid should be PlatformCALayerClient instead of TileController
+        https://bugs.webkit.org/show_bug.cgi?id=131456
+
+        Reviewed by Tim Horton.
+
+        The client interface is for the tiles in the grid.
+
+        * platform/graphics/ca/mac/TileController.h:
+        * platform/graphics/ca/mac/TileController.mm:
+        (WebCore::TileController::setContentsScale):
+        (WebCore::TileController::createTileLayer):
+        (WebCore::TileController::platformCALayerPaintContents): Deleted.
+        (WebCore::TileController::platformCALayerDeviceScaleFactor): Deleted.
+        (WebCore::TileController::platformCALayerShowDebugBorders): Deleted.
+        (WebCore::TileController::platformCALayerShowRepaintCounter): Deleted.
+        (WebCore::TileController::platformCALayerIncrementRepaintCount): Deleted.
+        * platform/graphics/ca/mac/TileGrid.h:
+        
+            Move repaint counter to TileGrid too.
+
+        * platform/graphics/ca/mac/TileGrid.mm:
+        (WebCore::TileGrid::removeTiles):
+        (WebCore::TileGrid::removeAllSecondaryTiles):
+        (WebCore::TileGrid::removeTilesInCohort):
+        
+           Cleaned up tile removal.
+
+        (WebCore::TileGrid::revalidateTiles):
+        (WebCore::TileGrid::ensureTilesForRect):
+        (WebCore::TileGrid::platformCALayerPaintContents):
+        (WebCore::TileGrid::platformCALayerDeviceScaleFactor):
+        (WebCore::TileGrid::platformCALayerShowDebugBorders):
+        (WebCore::TileGrid::platformCALayerShowRepaintCounter):
+        (WebCore::TileGrid::platformCALayerContentsOpaque):
+        (WebCore::TileGrid::platformCALayerIncrementRepaintCount):
+        (WebCore::queueTileForRemoval): Deleted.
+
 2014-04-09  Alexey Proskuryakov  <ap@apple.com>
 
         Rename some dragging functions
index c8dc45b..e1d0a36 100644 (file)
@@ -48,9 +48,8 @@ class TileGrid;
 
 typedef Vector<RetainPtr<PlatformLayer>> PlatformLayerList;
 
-class TileController final : public TiledBacking, public PlatformCALayerClient {
-    WTF_MAKE_NONCOPYABLE(TileController);
-
+class TileController final : public TiledBacking {
+    WTF_MAKE_NONCOPYABLE(TileController); WTF_MAKE_FAST_ALLOCATED;
 public:
     static PassOwnPtr<TileController> create(PlatformCALayer*);
     ~TileController();
@@ -104,6 +103,7 @@ public:
     virtual int rightMarginWidth() const override;
     virtual TileCoverage tileCoverage() const override { return m_tileCoverage; }
     virtual bool unparentsOffscreenTiles() const override { return m_unparentsOffscreenTiles; }
+    virtual bool scrollingPerformanceLoggingEnabled() const override { return m_scrollingPerformanceLoggingEnabled; }
 
     IntRect boundsWithoutMargin() const;
 
@@ -117,12 +117,9 @@ public:
     bool shouldAggressivelyRetainTiles() const;
     bool shouldTemporarilyRetainTileCohorts() const;
 
-    typedef HashMap<PlatformCALayer*, int> RepaintCountMap;
-    RepaintCountMap& repaintCountMap() { return m_tileRepaintCounts; }
-
     void updateTileCoverageMap();
 
-    RefPtr<PlatformCALayer> createTileLayer(const IntRect&);
+    RefPtr<PlatformCALayer> createTileLayer(const IntRect&, TileGrid&);
 
     const TileGrid& tileGrid() const { return *m_tileGrid; }
 
@@ -144,7 +141,6 @@ private:
     virtual void forceRepaint() override;
     virtual IntRect tileGridExtent() const override;
     virtual void setScrollingPerformanceLoggingEnabled(bool flag) override { m_scrollingPerformanceLoggingEnabled = flag; }
-    virtual bool scrollingPerformanceLoggingEnabled() const override { return m_scrollingPerformanceLoggingEnabled; }
     virtual void setUnparentsOffscreenTiles(bool flag) override { m_unparentsOffscreenTiles = flag; }
     virtual double retainedTileBackingStoreMemory() const override;
     virtual IntRect tileCoverageRect() const override;
@@ -152,15 +148,6 @@ private:
     virtual void setScrollingModeIndication(ScrollingModeIndication) override;
     virtual void setTileMargins(int marginTop, int marginBottom, int marginLeft, int marginRight) override;
 
-    // PlatformCALayerClient
-    virtual void platformCALayerPaintContents(PlatformCALayer*, GraphicsContext&, const FloatRect&) override;
-    virtual bool platformCALayerShowDebugBorders() const override;
-    virtual bool platformCALayerShowRepaintCounter(PlatformCALayer*) const override;
-    virtual int platformCALayerIncrementRepaintCount(PlatformCALayer*) override;
-    virtual bool platformCALayerContentsOpaque() const override { return m_tilesAreOpaque; }
-    virtual bool platformCALayerDrawsContent() const override { return true; }
-    virtual float platformCALayerDeviceScaleFactor() const override;
-
     void scheduleTileRevalidation(double interval);
     void tileRevalidationTimerFired(Timer<TileController>*);
 
@@ -181,8 +168,6 @@ private:
 
     Timer<TileController> m_tileRevalidationTimer;
 
-    RepaintCountMap m_tileRepaintCounts;
-
     float m_contentsScale;
     float m_deviceScaleFactor;
 
index a371ae1..14bb878 100644 (file)
@@ -26,7 +26,6 @@
 #import "config.h"
 #import "TileController.h"
 
-#import "GraphicsContext.h"
 #import "IntRect.h"
 #import "PlatformCALayer.h"
 #import "Region.h"
@@ -35,7 +34,6 @@
 #if !PLATFORM(IOS)
 #import "LayerPool.h"
 #endif
-#import "WebLayer.h"
 #import <wtf/MainThread.h>
 #import <utility>
 
@@ -103,59 +101,13 @@ void TileController::setNeedsDisplayInRect(const IntRect& rect)
     tileGrid().setNeedsDisplayInRect(rect);
 }
 
-void TileController::platformCALayerPaintContents(PlatformCALayer* platformCALayer, GraphicsContext& context, const FloatRect&)
-{
-#if PLATFORM(IOS)
-    if (pthread_main_np())
-        WebThreadLock();
-#endif
-
-    {
-        GraphicsContextStateSaver stateSaver(context);
-
-        FloatPoint3D layerOrigin = platformCALayer->position();
-        context.translate(-layerOrigin.x(), -layerOrigin.y());
-        context.scale(FloatSize(tileGrid().scale(), tileGrid().scale()));
-
-        RepaintRectList dirtyRects = collectRectsToPaint(context.platformContext(), platformCALayer);
-        drawLayerContents(context.platformContext(), m_tileCacheLayer, dirtyRects);
-    }
-
-    int repaintCount = platformCALayerIncrementRepaintCount(platformCALayer);
-    if (owningGraphicsLayer()->platformCALayerShowRepaintCounter(0))
-        drawRepaintIndicator(context.platformContext(), platformCALayer, repaintCount, cachedCGColor(m_tileDebugBorderColor, ColorSpaceDeviceRGB));
-
-    if (scrollingPerformanceLoggingEnabled()) {
-        FloatRect visiblePart(platformCALayer->position().x(), platformCALayer->position().y(), platformCALayer->bounds().size().width(), platformCALayer->bounds().size().height());
-        visiblePart.intersect(visibleRect());
-
-        if (repaintCount == 1 && !visiblePart.isEmpty())
-            WTFLogAlways("SCROLLING: Filled visible fresh tile. Time: %f Unfilled Pixels: %u\n", WTF::monotonicallyIncreasingTime(), blankPixelCount());
-    }
-}
-
-float TileController::platformCALayerDeviceScaleFactor() const
-{
-    return owningGraphicsLayer()->platformCALayerDeviceScaleFactor();
-}
-
-bool TileController::platformCALayerShowDebugBorders() const
-{
-    return owningGraphicsLayer()->platformCALayerShowDebugBorders();
-}
-
-bool TileController::platformCALayerShowRepaintCounter(PlatformCALayer*) const
-{
-    return owningGraphicsLayer()->platformCALayerShowRepaintCounter(0);
-}
-
 void TileController::setContentsScale(float scale)
 {
     m_contentsScale = scale;
     
     ASSERT(owningGraphicsLayer()->isCommittingChanges());
 
-    float deviceScaleFactor = platformCALayerDeviceScaleFactor();
+    float deviceScaleFactor = owningGraphicsLayer()->platformCALayerDeviceScaleFactor();
 
     // The scale we get is the product of the page scale factor and device scale factor.
     // Divide by the device scale factor so we'll get the page scale factor.
@@ -478,7 +430,7 @@ int TileController::rightMarginWidth() const
     return m_marginRight;
 }
 
-RefPtr<PlatformCALayer> TileController::createTileLayer(const IntRect& tileRect)
+RefPtr<PlatformCALayer> TileController::createTileLayer(const IntRect& tileRect, TileGrid& grid)
 {
 #if PLATFORM(IOS)
     RefPtr<PlatformCALayer> layer;
@@ -486,11 +438,10 @@ RefPtr<PlatformCALayer> TileController::createTileLayer(const IntRect& tileRect)
     RefPtr<PlatformCALayer> layer = LayerPool::sharedPool()->takeLayerWithSize(tileRect.size());
 #endif
 
-    if (layer) {
-        m_tileRepaintCounts.remove(layer.get());
-        layer->setOwner(this);
-    } else
-        layer = m_tileCacheLayer->createCompatibleLayer(PlatformCALayer::LayerTypeTiledBackingTileLayer, this);
+    if (layer)
+        layer->setOwner(&grid);
+    else
+        layer = m_tileCacheLayer->createCompatibleLayer(PlatformCALayer::LayerTypeTiledBackingTileLayer, &grid);
 
     layer->setAnchorPoint(FloatPoint3D());
     layer->setBounds(FloatRect(FloatPoint(), tileRect.size()));
@@ -514,18 +465,6 @@ RefPtr<PlatformCALayer> TileController::createTileLayer(const IntRect& tileRect)
     return layer;
 }
 
-int TileController::platformCALayerIncrementRepaintCount(PlatformCALayer* platformCALayer)
-{
-    int repaintCount = 0;
-
-    if (m_tileRepaintCounts.contains(platformCALayer))
-        repaintCount = m_tileRepaintCounts.get(platformCALayer);
-
-    m_tileRepaintCounts.set(platformCALayer, ++repaintCount);
-
-    return repaintCount;
-}
-
 Vector<RefPtr<PlatformCALayer>> TileController::containerLayers()
 {
     Vector<RefPtr<PlatformCALayer>> layerList(1);
index 9c961bf..9f467a5 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "IntPointHash.h"
 #include "IntRect.h"
+#include "PlatformCALayerClient.h"
 #include "Timer.h"
 #include <wtf/Deque.h>
 #include <wtf/HashMap.h>
 
 namespace WebCore {
 
+class GraphicsContext;
 class PlatformCALayer;
 class TileController;
 
-class TileGrid {
-    WTF_MAKE_NONCOPYABLE(TileGrid);
+class TileGrid : public PlatformCALayerClient {
+    WTF_MAKE_NONCOPYABLE(TileGrid); WTF_MAKE_FAST_ALLOCATED;
 public:
     TileGrid(TileController&);
     ~TileGrid();
@@ -109,6 +111,17 @@ private:
     TileCohort newestTileCohort() const;
     TileCohort oldestTileCohort() const;
 
+    void removeTiles(Vector<TileGrid::TileIndex>& toRemove);
+
+    // PlatformCALayerClient
+    virtual void platformCALayerPaintContents(PlatformCALayer*, GraphicsContext&, const FloatRect&) override;
+    virtual bool platformCALayerShowDebugBorders() const override;
+    virtual bool platformCALayerShowRepaintCounter(PlatformCALayer*) const override;
+    virtual int platformCALayerIncrementRepaintCount(PlatformCALayer*) override;
+    virtual bool platformCALayerContentsOpaque() const override;
+    virtual bool platformCALayerDrawsContent() const override { return true; }
+    virtual float platformCALayerDeviceScaleFactor() const override;
+
     TileController& m_controller;
     Ref<PlatformCALayer> m_containerLayer;
 
@@ -132,6 +145,9 @@ private:
     TileCohortList m_cohortList;
 
     Timer<TileGrid> m_cohortRemovalTimer;
+
+    typedef HashMap<PlatformCALayer*, int> RepaintCountMap;
+    RepaintCountMap m_tileRepaintCounts;
 };
 
 }
index 1ac3854..a8f6c29 100644 (file)
 #import "config.h"
 #import "TileGrid.h"
 
+#import "GraphicsContext.h"
 #import "LayerPool.h"
 #import "PlatformCALayer.h"
 #import "TileController.h"
+#import "WebLayer.h"
 #import <wtf/MainThread.h>
 
 #if PLATFORM(IOS)
@@ -280,31 +282,30 @@ unsigned TileGrid::blankPixelCount() const
     return TileController::blankPixelCountForTiles(tiles, m_controller.visibleRect(), IntPoint(0,0));
 }
 
-static inline void queueTileForRemoval(const TileGrid::TileIndex& tileIndex, const TileGrid::TileInfo& tileInfo, Vector<TileGrid::TileIndex>& tilesToRemove, TileController::RepaintCountMap& repaintCounts)
+void TileGrid::removeTiles(Vector<TileGrid::TileIndex>& toRemove)
 {
-    tileInfo.layer->removeFromSuperlayer();
-    repaintCounts.remove(tileInfo.layer.get());
-    tilesToRemove.append(tileIndex);
+    for (size_t i = 0; i < toRemove.size(); ++i) {
+        TileInfo tileInfo = m_tiles.take(toRemove[i]);
+        tileInfo.layer->removeFromSuperlayer();
+        m_tileRepaintCounts.remove(tileInfo.layer.get());
+#if !PLATFORM(IOS)
+        LayerPool::sharedPool()->addLayer(tileInfo.layer);
+#endif
+    }
 }
 
 void TileGrid::removeAllSecondaryTiles()
 {
     Vector<TileIndex> tilesToRemove;
 
-    for (TileMap::iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it) {
-        const TileInfo& tileInfo = it->value;
+    for (auto& entry : m_tiles) {
+        const TileInfo& tileInfo = entry.value;
         if (tileInfo.cohort == VisibleTileCohort)
             continue;
-
-        queueTileForRemoval(it->key, it->value, tilesToRemove, m_controller.repaintCountMap());
+        tilesToRemove.append(entry.key);
     }
 
-    for (size_t i = 0; i < tilesToRemove.size(); ++i) {
-        TileInfo tileInfo = m_tiles.take(tilesToRemove[i]);
-#if !PLATFORM(IOS)
-        LayerPool::sharedPool()->addLayer(tileInfo.layer);
-#endif
-    }
+    removeTiles(tilesToRemove);
 }
 
 void TileGrid::removeTilesInCohort(TileCohort cohort)
@@ -312,20 +313,14 @@ void TileGrid::removeTilesInCohort(TileCohort cohort)
     ASSERT(cohort != VisibleTileCohort);
     Vector<TileIndex> tilesToRemove;
 
-    for (TileMap::iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it) {
-        const TileInfo& tileInfo = it->value;
+    for (auto& entry : m_tiles) {
+        const TileInfo& tileInfo = entry.value;
         if (tileInfo.cohort != cohort)
             continue;
-
-        queueTileForRemoval(it->key, it->value, tilesToRemove, m_controller.repaintCountMap());
+        tilesToRemove.append(entry.key);
     }
 
-    for (size_t i = 0; i < tilesToRemove.size(); ++i) {
-        TileInfo tileInfo = m_tiles.take(tilesToRemove[i]);
-#if !PLATFORM(IOS)
-        LayerPool::sharedPool()->addLayer(tileInfo.layer);
-#endif
-    }
+    removeTiles(tilesToRemove);
 }
 
 void TileGrid::revalidateTiles(TileValidationPolicyFlags validationPolicy)
@@ -429,13 +424,9 @@ void TileGrid::revalidateTiles(TileValidationPolicyFlags validationPolicy)
         getTileIndexRangeForRect(boundsInTileCoords, topLeftForBounds, bottomRightForBounds);
 
         Vector<TileIndex> tilesToRemove;
-        for (TileMap::iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it) {
-            const TileIndex& index = it->key;
-            if (index.y() < topLeftForBounds.y()
-                || index.y() > bottomRightForBounds.y()
-                || index.x() < topLeftForBounds.x()
-                || index.x() > bottomRightForBounds.x())
-                queueTileForRemoval(index, it->value, tilesToRemove, m_controller.repaintCountMap());
+        for (auto& index : m_tiles.keys()) {
+            if (index.y() < topLeftForBounds.y() || index.y() > bottomRightForBounds.y() || index.x() < topLeftForBounds.x() || index.x() > bottomRightForBounds.x())
+                tilesToRemove.append(index);
         }
 
         for (size_t i = 0, size = tilesToRemove.size(); i < size; ++i) {
@@ -532,9 +523,10 @@ IntRect TileGrid::ensureTilesForRect(const FloatRect& rect, CoverageType newTile
 
             bool shouldChangeTileLayerFrame = false;
 
-            if (!tileInfo.layer)
-                tileInfo.layer = m_controller.createTileLayer(tileRect);
-            else {
+            if (!tileInfo.layer) {
+                tileInfo.layer = m_controller.createTileLayer(tileRect, *this);
+                ASSERT(!m_tileRepaintCounts.contains(tileInfo.layer.get()));
+            } else {
                 // We already have a layer for this tile. Ensure that its size is correct.
                 FloatSize tileLayerSize(tileInfo.layer->bounds().size());
                 shouldChangeTileLayerFrame = tileLayerSize != FloatSize(tileRect.size());
@@ -644,6 +636,69 @@ void TileGrid::drawTileMapContents(CGContextRef context, CGRect layerBounds) con
     }
 }
 
+void TileGrid::platformCALayerPaintContents(PlatformCALayer* platformCALayer, GraphicsContext& context, const FloatRect&)
+{
+#if PLATFORM(IOS)
+    if (pthread_main_np())
+        WebThreadLock();
+#endif
+
+    {
+        GraphicsContextStateSaver stateSaver(context);
+
+        FloatPoint3D layerOrigin = platformCALayer->position();
+        context.translate(-layerOrigin.x(), -layerOrigin.y());
+        context.scale(FloatSize(m_scale, m_scale));
+
+        RepaintRectList dirtyRects = collectRectsToPaint(context.platformContext(), platformCALayer);
+        drawLayerContents(context.platformContext(), &m_controller.rootLayer(), dirtyRects);
+    }
+
+    int repaintCount = platformCALayerIncrementRepaintCount(platformCALayer);
+    if (m_controller.rootLayer().owner()->platformCALayerShowRepaintCounter(0))
+        drawRepaintIndicator(context.platformContext(), platformCALayer, repaintCount, cachedCGColor(m_controller.tileDebugBorderColor(), ColorSpaceDeviceRGB));
+
+    if (m_controller.scrollingPerformanceLoggingEnabled()) {
+        FloatRect visiblePart(platformCALayer->position().x(), platformCALayer->position().y(), platformCALayer->bounds().size().width(), platformCALayer->bounds().size().height());
+        visiblePart.intersect(m_controller.visibleRect());
+
+        if (repaintCount == 1 && !visiblePart.isEmpty())
+            WTFLogAlways("SCROLLING: Filled visible fresh tile. Time: %f Unfilled Pixels: %u\n", WTF::monotonicallyIncreasingTime(), blankPixelCount());
+    }
+}
+
+float TileGrid::platformCALayerDeviceScaleFactor() const
+{
+    return m_controller.rootLayer().owner()->platformCALayerDeviceScaleFactor();
+}
+
+bool TileGrid::platformCALayerShowDebugBorders() const
+{
+    return m_controller.rootLayer().owner()->platformCALayerShowDebugBorders();
+}
+
+bool TileGrid::platformCALayerShowRepaintCounter(PlatformCALayer*) const
+{
+    return m_controller.rootLayer().owner()->platformCALayerShowRepaintCounter(0);
+}
+
+bool TileGrid::platformCALayerContentsOpaque() const
+{
+    return m_controller.tilesAreOpaque();
+}
+
+int TileGrid::platformCALayerIncrementRepaintCount(PlatformCALayer* platformCALayer)
+{
+    int repaintCount = 0;
+
+    if (m_tileRepaintCounts.contains(platformCALayer))
+        repaintCount = m_tileRepaintCounts.get(platformCALayer);
+
+    m_tileRepaintCounts.set(platformCALayer, ++repaintCount);
+
+    return repaintCount;
+}
+
 #if PLATFORM(IOS)
 void TileGrid::removeUnparentedTilesNow()
 {