Factor tile coverage map into a class
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Apr 2014 05:01:54 +0000 (05:01 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Apr 2014 05:01:54 +0000 (05:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131417

Reviewed by Tim Horton.

* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/ca/PlatformCALayerClient.h:
(WebCore::PlatformCALayerClient::platformCALayerLayoutSublayersOfLayer):
(WebCore::PlatformCALayerClient::platformCALayerRespondsToLayoutChanges):
(WebCore::PlatformCALayerClient::platformCALayerAnimationStarted):
(WebCore::PlatformCALayerClient::platformCALayerContentsOrientation):
(WebCore::PlatformCALayerClient::platformCALayerShowDebugBorders):
(WebCore::PlatformCALayerClient::platformCALayerShowRepaintCounter):
(WebCore::PlatformCALayerClient::platformCALayerIncrementRepaintCount):
(WebCore::PlatformCALayerClient::platformCALayerLayerDidDisplay):

    Added default implementation to some of these to make clients less messy.

* platform/graphics/ca/mac/TileController.h:
* platform/graphics/ca/mac/TileController.mm:
(WebCore::TileController::~TileController):
(WebCore::TileController::platformCALayerPaintContents):
(WebCore::TileController::setTiledScrollingIndicatorPosition):
(WebCore::TileController::updateTileCoverageMap):
(WebCore::TileController::tiledScrollingIndicatorLayer):
* platform/graphics/ca/mac/TileCoverageMap.h: Added.
(WebCore::TileCoverageMap::setPosition):
(WebCore::TileCoverageMap::layer):
* platform/graphics/ca/mac/TileCoverageMap.mm: Added.

    The new class.

(WebCore::TileCoverageMap::TileCoverageMap):
(WebCore::TileCoverageMap::~TileCoverageMap):
(WebCore::TileCoverageMap::update):
(WebCore::TileCoverageMap::platformCALayerPaintContents):
(WebCore::TileCoverageMap::platformCALayerDeviceScaleFactor):
* platform/graphics/ca/mac/TileGrid.h:
* platform/graphics/ca/mac/TileGrid.mm:
(WebCore::TileGrid::drawTileMapContents):

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/graphics/ca/PlatformCALayerClient.h
Source/WebCore/platform/graphics/ca/mac/TileController.h
Source/WebCore/platform/graphics/ca/mac/TileController.mm
Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.h [new file with mode: 0644]
Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.mm [new file with mode: 0644]
Source/WebCore/platform/graphics/ca/mac/TileGrid.h
Source/WebCore/platform/graphics/ca/mac/TileGrid.mm

index 4e6bc70..499e29b 100644 (file)
@@ -1,3 +1,46 @@
+2014-04-08  Antti Koivisto  <antti@apple.com>
+
+        Factor tile coverage map into a class
+        https://bugs.webkit.org/show_bug.cgi?id=131417
+
+        Reviewed by Tim Horton.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/ca/PlatformCALayerClient.h:
+        (WebCore::PlatformCALayerClient::platformCALayerLayoutSublayersOfLayer):
+        (WebCore::PlatformCALayerClient::platformCALayerRespondsToLayoutChanges):
+        (WebCore::PlatformCALayerClient::platformCALayerAnimationStarted):
+        (WebCore::PlatformCALayerClient::platformCALayerContentsOrientation):
+        (WebCore::PlatformCALayerClient::platformCALayerShowDebugBorders):
+        (WebCore::PlatformCALayerClient::platformCALayerShowRepaintCounter):
+        (WebCore::PlatformCALayerClient::platformCALayerIncrementRepaintCount):
+        (WebCore::PlatformCALayerClient::platformCALayerLayerDidDisplay):
+        
+            Added default implementation to some of these to make clients less messy.
+
+        * platform/graphics/ca/mac/TileController.h:
+        * platform/graphics/ca/mac/TileController.mm:
+        (WebCore::TileController::~TileController):
+        (WebCore::TileController::platformCALayerPaintContents):
+        (WebCore::TileController::setTiledScrollingIndicatorPosition):
+        (WebCore::TileController::updateTileCoverageMap):
+        (WebCore::TileController::tiledScrollingIndicatorLayer):
+        * platform/graphics/ca/mac/TileCoverageMap.h: Added.
+        (WebCore::TileCoverageMap::setPosition):
+        (WebCore::TileCoverageMap::layer):
+        * platform/graphics/ca/mac/TileCoverageMap.mm: Added.
+        
+            The new class.
+
+        (WebCore::TileCoverageMap::TileCoverageMap):
+        (WebCore::TileCoverageMap::~TileCoverageMap):
+        (WebCore::TileCoverageMap::update):
+        (WebCore::TileCoverageMap::platformCALayerPaintContents):
+        (WebCore::TileCoverageMap::platformCALayerDeviceScaleFactor):
+        * platform/graphics/ca/mac/TileGrid.h:
+        * platform/graphics/ca/mac/TileGrid.mm:
+        (WebCore::TileGrid::drawTileMapContents):
+
 2014-04-08  Zalan Bujtas  <zalan@apple.com>
 
         Subpixel rendering: Clip outer rounded border rect on device pixel boundaries.
index 341ab05..e52bf29 100644 (file)
                E47B4BE90E71241600038854 /* CachedResourceHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47B4BE70E71241600038854 /* CachedResourceHandle.cpp */; };
                E47E276516036ED200EE2AFB /* DocumentStyleSheetCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = E47E276416036ED200EE2AFB /* DocumentStyleSheetCollection.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E47E276816036EDC00EE2AFB /* DocumentStyleSheetCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47E276716036EDC00EE2AFB /* DocumentStyleSheetCollection.cpp */; };
+               E4830A3918F4C59400154A1B /* TileCoverageMap.mm in Sources */ = {isa = PBXBuildFile; fileRef = E4830A3818F4C59400154A1B /* TileCoverageMap.mm */; };
+               E4830A3D18F4C5B700154A1B /* TileCoverageMap.h in Headers */ = {isa = PBXBuildFile; fileRef = E4830A3C18F4C5B700154A1B /* TileCoverageMap.h */; };
                E48944A2180B57D800F165D8 /* SimpleLineLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48944A0180B57D800F165D8 /* SimpleLineLayout.cpp */; };
                E48944A3180B57D800F165D8 /* SimpleLineLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = E48944A1180B57D800F165D8 /* SimpleLineLayout.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E4946EAE156E64DD00D3297F /* StyleRuleImport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4946EAC156E64DD00D3297F /* StyleRuleImport.cpp */; };
                E47B4BE70E71241600038854 /* CachedResourceHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedResourceHandle.cpp; sourceTree = "<group>"; };
                E47E276416036ED200EE2AFB /* DocumentStyleSheetCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentStyleSheetCollection.h; sourceTree = "<group>"; };
                E47E276716036EDC00EE2AFB /* DocumentStyleSheetCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentStyleSheetCollection.cpp; sourceTree = "<group>"; };
+               E4830A3818F4C59400154A1B /* TileCoverageMap.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TileCoverageMap.mm; path = ca/mac/TileCoverageMap.mm; sourceTree = "<group>"; };
+               E4830A3C18F4C5B700154A1B /* TileCoverageMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TileCoverageMap.h; path = ca/mac/TileCoverageMap.h; sourceTree = "<group>"; };
                E48944A0180B57D800F165D8 /* SimpleLineLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleLineLayout.cpp; sourceTree = "<group>"; };
                E48944A1180B57D800F165D8 /* SimpleLineLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleLineLayout.h; sourceTree = "<group>"; };
                E4946EAC156E64DD00D3297F /* StyleRuleImport.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleRuleImport.cpp; sourceTree = "<group>"; };
                                4958782012A57DDF007238AC /* PlatformCALayerMac.mm */,
                                1AA71609149BC4DB0016EC19 /* TileController.h */,
                                1AA71608149BC4DA0016EC19 /* TileController.mm */,
+                               E4830A3C18F4C5B700154A1B /* TileCoverageMap.h */,
+                               E4830A3818F4C59400154A1B /* TileCoverageMap.mm */,
                                E4C274CB18E988F500602C76 /* TileGrid.h */,
                                E4C274C918E988EA00602C76 /* TileGrid.mm */,
                                0F580FA11496939100FB5BD8 /* WebTiledBackingLayer.h */,
                                B2FA3DB70AB75A6F000E5AC4 /* JSSVGPathSeg.h in Headers */,
                                B2FA3DB90AB75A6F000E5AC4 /* JSSVGPathSegArcAbs.h in Headers */,
                                B2FA3DBB0AB75A6F000E5AC4 /* JSSVGPathSegArcRel.h in Headers */,
+                               E4830A3D18F4C5B700154A1B /* TileCoverageMap.h in Headers */,
                                B2FA3DBD0AB75A6F000E5AC4 /* JSSVGPathSegClosePath.h in Headers */,
                                B2FA3DBF0AB75A6F000E5AC4 /* JSSVGPathSegCurvetoCubicAbs.h in Headers */,
                                B2FA3DC10AB75A6F000E5AC4 /* JSSVGPathSegCurvetoCubicRel.h in Headers */,
                                E125F8351822F18A00D84CD9 /* CryptoKeyHMAC.cpp in Sources */,
                                E19AC3F9182566F700349426 /* CryptoKeyMac.cpp in Sources */,
                                E1F80B8718317252007885C3 /* CryptoKeyPair.cpp in Sources */,
+                               E4830A3918F4C59400154A1B /* TileCoverageMap.mm in Sources */,
                                E164FAA518315E1A00DB4E61 /* CryptoKeyRSAMac.cpp in Sources */,
                                E125F859182C1AA600D84CD9 /* CryptoKeySerializationRaw.cpp in Sources */,
                                CAE9F90F146441F000C245B0 /* CSSAspectRatioValue.cpp in Sources */,
index 6f5661b..cfcddf4 100644 (file)
@@ -36,19 +36,19 @@ class PlatformCALayer;
 
 class PlatformCALayerClient {
 public:
-    virtual void platformCALayerLayoutSublayersOfLayer(PlatformCALayer*) = 0;
-    virtual bool platformCALayerRespondsToLayoutChanges() const = 0;
+    virtual void platformCALayerLayoutSublayersOfLayer(PlatformCALayer*) { }
+    virtual bool platformCALayerRespondsToLayoutChanges() const { return false; }
 
-    virtual void platformCALayerAnimationStarted(CFTimeInterval beginTime) = 0;
-    virtual GraphicsLayer::CompositingCoordinatesOrientation platformCALayerContentsOrientation() const = 0;
+    virtual void platformCALayerAnimationStarted(CFTimeInterval) { }
+    virtual GraphicsLayer::CompositingCoordinatesOrientation platformCALayerContentsOrientation() const { return GraphicsLayer::CompositingCoordinatesTopDown; }
     virtual void platformCALayerPaintContents(PlatformCALayer*, GraphicsContext&, const FloatRect& inClip) = 0;
-    virtual bool platformCALayerShowDebugBorders() const = 0;
-    virtual bool platformCALayerShowRepaintCounter(PlatformCALayer*) const = 0;
-    virtual int platformCALayerIncrementRepaintCount(PlatformCALayer*) = 0;
+    virtual bool platformCALayerShowDebugBorders() const { return false; }
+    virtual bool platformCALayerShowRepaintCounter(PlatformCALayer*) const { return false; }
+    virtual int platformCALayerIncrementRepaintCount(PlatformCALayer*) { return 0; }
     
     virtual bool platformCALayerContentsOpaque() const = 0;
     virtual bool platformCALayerDrawsContent() const = 0;
-    virtual void platformCALayerLayerDidDisplay(PlatformLayer*) = 0;
+    virtual void platformCALayerLayerDidDisplay(PlatformLayer*)  { }
 
     virtual void platformCALayerSetNeedsToRevalidateTiles() { }
     virtual float platformCALayerDeviceScaleFactor() const = 0;
index e747c14..c8dc45b 100644 (file)
@@ -43,6 +43,7 @@ namespace WebCore {
 class FloatRect;
 class IntPoint;
 class IntRect;
+class TileCoverageMap;
 class TileGrid;
 
 typedef Vector<RetainPtr<PlatformLayer>> PlatformLayerList;
@@ -69,6 +70,7 @@ public:
     bool tilesAreOpaque() const { return m_tilesAreOpaque; }
 
     PlatformCALayer& rootLayer() { return *m_tileCacheLayer; }
+    const PlatformCALayer& rootLayer() const { return *m_tileCacheLayer; }
 
     void setTileDebugBorderWidth(float);
     void setTileDebugBorderColor(Color);
@@ -84,13 +86,14 @@ public:
 #endif
 
 public:
-    // Public for TileGrid
+    // Public for TileGrid and TileCoverageMap
     bool isInWindow() const { return m_isInWindow; }
 
     float deviceScaleFactor() const { return m_deviceScaleFactor; }
 
     Color tileDebugBorderColor() const { return m_tileDebugBorderColor; }
     float tileDebugBorderWidth() const { return m_tileDebugBorderWidth; }
+    ScrollingModeIndication indicatorMode() const { return m_indicatorMode; }
 
     virtual IntSize tileSize() const override { return m_tileSize; }
     virtual IntRect bounds() const override;
@@ -121,13 +124,14 @@ public:
 
     RefPtr<PlatformCALayer> createTileLayer(const IntRect&);
 
+    const TileGrid& tileGrid() const { return *m_tileGrid; }
+
     Vector<RefPtr<PlatformCALayer>> containerLayers();
 
 private:
     TileController(PlatformCALayer*);
 
     TileGrid& tileGrid() { return *m_tileGrid; }
-    const TileGrid& tileGrid() const { return *m_tileGrid; }
 
     // TiledBacking member functions.
     virtual void setVisibleRect(const FloatRect&) override;
@@ -149,20 +153,12 @@ private:
     virtual void setTileMargins(int marginTop, int marginBottom, int marginLeft, int marginRight) override;
 
     // PlatformCALayerClient
-    virtual void platformCALayerLayoutSublayersOfLayer(PlatformCALayer*) override { }
-    virtual bool platformCALayerRespondsToLayoutChanges() const override { return false; }
-    virtual void platformCALayerAnimationStarted(CFTimeInterval) override { }
-    virtual GraphicsLayer::CompositingCoordinatesOrientation platformCALayerContentsOrientation() const override { return GraphicsLayer::CompositingCoordinatesTopDown; }
     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 void platformCALayerLayerDidDisplay(PlatformLayer*) override { }
-
-    virtual void platformCALayerSetNeedsToRevalidateTiles() override { }
     virtual float platformCALayerDeviceScaleFactor() const override;
 
     void scheduleTileRevalidation(double interval);
@@ -170,20 +166,17 @@ private:
 
     void setNeedsRevalidateTiles();
 
-    void drawTileMapContents(CGContextRef, CGRect);
-
     PlatformCALayerClient* owningGraphicsLayer() const { return m_tileCacheLayer->owner(); }
 
     PlatformCALayer* m_tileCacheLayer;
-    RefPtr<PlatformCALayer> m_tiledScrollingIndicatorLayer; // Used for coverage visualization.
-    RefPtr<PlatformCALayer> m_visibleRectIndicatorLayer;
+
+    std::unique_ptr<TileCoverageMap> m_coverageMap;
 
     std::unique_ptr<TileGrid> m_tileGrid;
 
     IntSize m_tileSize;
     FloatRect m_visibleRect;
     FloatRect m_visibleRectAtLastRevalidate;
-    FloatPoint m_tiledScrollingIndicatorPosition;
     IntRect m_boundsAtLastRevalidate;
 
     Timer<TileController> m_tileRevalidationTimer;
index 950b7b3..a371ae1 100644 (file)
@@ -30,6 +30,7 @@
 #import "IntRect.h"
 #import "PlatformCALayer.h"
 #import "Region.h"
+#import "TileCoverageMap.h"
 #import "TileGrid.h"
 #if !PLATFORM(IOS)
 #import "LayerPool.h"
@@ -84,9 +85,6 @@ TileController::~TileController()
 #if PLATFORM(IOS)
     tileControllerMemoryHandler().removeTileController(this);
 #endif
-
-    if (m_tiledScrollingIndicatorLayer)
-        m_tiledScrollingIndicatorLayer->setOwner(nullptr);
 }
 
 void TileController::tileCacheLayerBoundsChanged()
@@ -112,11 +110,6 @@ void TileController::platformCALayerPaintContents(PlatformCALayer* platformCALay
         WebThreadLock();
 #endif
 
-    if (platformCALayer == m_tiledScrollingIndicatorLayer.get()) {
-        tileGrid().drawTileMapContents(context.platformContext(), m_tiledScrollingIndicatorLayer->bounds());
-        return;
-    }
-
     {
         GraphicsContextStateSaver stateSaver(context);
 
@@ -214,10 +207,10 @@ bool TileController::tilesWouldChangeForVisibleRect(const FloatRect& newVisibleR
 
 void TileController::setTiledScrollingIndicatorPosition(const FloatPoint& position)
 {
-    if (m_tiledScrollingIndicatorPosition == position)
+    if (!m_coverageMap)
         return;
-    m_tiledScrollingIndicatorPosition = position;
-    updateTileCoverageMap();
+    m_coverageMap->setPosition(position);
+    m_coverageMap->update();
 }
 
 void TileController::prepopulateRect(const FloatRect& rect)
@@ -412,46 +405,8 @@ void TileController::setNeedsRevalidateTiles()
 
 void TileController::updateTileCoverageMap()
 {
-    if (!m_tiledScrollingIndicatorLayer)
-        return;
-    FloatRect containerBounds = bounds();
-    FloatRect visibleRect = this->visibleRect();
-    visibleRect.contract(4, 4); // Layer is positioned 2px from top and left edges.
-
-    float widthScale = 1;
-    float scale = 1;
-    if (!containerBounds.isEmpty()) {
-        widthScale = std::min<float>(visibleRect.width() / containerBounds.width(), 0.1);
-        scale = std::min(widthScale, visibleRect.height() / containerBounds.height());
-    }
-    
-    float indicatorScale = scale * tileGrid().scale();
-    FloatRect mapBounds = containerBounds;
-    mapBounds.scale(indicatorScale, indicatorScale);
-
-    m_tiledScrollingIndicatorLayer->setPosition(m_tiledScrollingIndicatorPosition + FloatPoint(2, 2));
-    m_tiledScrollingIndicatorLayer->setBounds(mapBounds);
-    m_tiledScrollingIndicatorLayer->setNeedsDisplay();
-
-    visibleRect.scale(indicatorScale, indicatorScale);
-    visibleRect.expand(2, 2);
-    m_visibleRectIndicatorLayer->setPosition(visibleRect.location());
-    m_visibleRectIndicatorLayer->setBounds(FloatRect(FloatPoint(), visibleRect.size()));
-
-    Color visibleRectIndicatorColor;
-    switch (m_indicatorMode) {
-    case SynchronousScrollingBecauseOfStyleIndication:
-        visibleRectIndicatorColor = Color(255, 0, 0);
-        break;
-    case SynchronousScrollingBecauseOfEventHandlersIndication:
-        visibleRectIndicatorColor = Color(255, 255, 0);
-        break;
-    case AsyncScrollingIndication:
-        visibleRectIndicatorColor = Color(0, 200, 0);
-        break;
-    }
-
-    m_visibleRectIndicatorLayer->setBorderColor(visibleRectIndicatorColor);
+    if (m_coverageMap)
+        m_coverageMap->update();
 }
 
 IntRect TileController::tileGridExtent() const
@@ -472,25 +427,10 @@ IntRect TileController::tileCoverageRect() const
 
 PlatformCALayer* TileController::tiledScrollingIndicatorLayer()
 {
-    if (!m_tiledScrollingIndicatorLayer) {
-        m_tiledScrollingIndicatorLayer = m_tileCacheLayer->createCompatibleLayer(PlatformCALayer::LayerTypeSimpleLayer, this);
-        m_tiledScrollingIndicatorLayer->setOpacity(0.75);
-        m_tiledScrollingIndicatorLayer->setAnchorPoint(FloatPoint3D());
-        m_tiledScrollingIndicatorLayer->setBorderColor(Color::black);
-        m_tiledScrollingIndicatorLayer->setBorderWidth(1);
-        m_tiledScrollingIndicatorLayer->setPosition(FloatPoint(2, 2));
-
-        m_visibleRectIndicatorLayer = m_tileCacheLayer->createCompatibleLayer(PlatformCALayer::LayerTypeLayer, nullptr);
-        m_visibleRectIndicatorLayer->setBorderWidth(2);
-        m_visibleRectIndicatorLayer->setAnchorPoint(FloatPoint3D());
-        m_visibleRectIndicatorLayer->setBorderColor(Color(255, 0, 0));
-
-        m_tiledScrollingIndicatorLayer->appendSublayer(m_visibleRectIndicatorLayer.get());
-
-        updateTileCoverageMap();
-    }
+    if (!m_coverageMap)
+        m_coverageMap = std::make_unique<TileCoverageMap>(*this);
 
-    return m_tiledScrollingIndicatorLayer.get();
+    return &m_coverageMap->layer();
 }
 
 void TileController::setScrollingModeIndication(ScrollingModeIndication scrollingMode)
diff --git a/Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.h b/Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.h
new file mode 100644 (file)
index 0000000..3ad2198
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011-2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TileCoverageMap_h
+#define TileCoverageMap_h
+
+#include "FloatRect.h"
+#include "IntRect.h"
+#include "PlatformCALayer.h"
+#include "PlatformCALayerClient.h"
+#include <wtf/Noncopyable.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/RetainPtr.h>
+
+namespace WebCore {
+
+class FloatRect;
+class IntPoint;
+class IntRect;
+class TileController;
+
+class TileCoverageMap : public PlatformCALayerClient {
+    WTF_MAKE_NONCOPYABLE(TileCoverageMap); WTF_MAKE_FAST_ALLOCATED;
+public:
+    TileCoverageMap(const TileController&);
+    ~TileCoverageMap();
+
+    void update();
+    void setPosition(const FloatPoint& position) { m_position = position; }
+
+    PlatformCALayer& layer() { return m_layer.get(); }
+
+private:
+    // PlatformCALayerClient
+    virtual GraphicsLayer::CompositingCoordinatesOrientation platformCALayerContentsOrientation() const override { return GraphicsLayer::CompositingCoordinatesTopDown; }
+    virtual bool platformCALayerContentsOpaque() const override { return true; }
+    virtual bool platformCALayerDrawsContent() const override { return true; }
+    virtual void platformCALayerPaintContents(PlatformCALayer*, GraphicsContext&, const FloatRect&) override;
+    virtual float platformCALayerDeviceScaleFactor() const override;
+
+    const TileController& m_controller;
+
+    Ref<PlatformCALayer> m_layer;
+    Ref<PlatformCALayer> m_visibleRectIndicatorLayer;
+
+    FloatPoint m_position;
+};
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.mm b/Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.mm
new file mode 100644 (file)
index 0000000..2546120
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2011-2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "TileCoverageMap.h"
+
+#import "GraphicsContext.h"
+#import "TileController.h"
+#import "TileGrid.h"
+
+namespace WebCore {
+
+TileCoverageMap::TileCoverageMap(const TileController& controller)
+    : m_controller(controller)
+    , m_layer(*controller.rootLayer().createCompatibleLayer(PlatformCALayer::LayerTypeSimpleLayer, this))
+    , m_visibleRectIndicatorLayer(*controller.rootLayer().createCompatibleLayer(PlatformCALayer::LayerTypeLayer, nullptr))
+{
+    m_layer.get().setOpacity(0.75);
+    m_layer.get().setAnchorPoint(FloatPoint3D());
+    m_layer.get().setBorderColor(Color::black);
+    m_layer.get().setBorderWidth(1);
+    m_layer.get().setPosition(FloatPoint(2, 2));
+    m_visibleRectIndicatorLayer.get().setBorderWidth(2);
+    m_visibleRectIndicatorLayer.get().setAnchorPoint(FloatPoint3D());
+    m_visibleRectIndicatorLayer.get().setBorderColor(Color(255, 0, 0));
+
+    m_layer.get().appendSublayer(&m_visibleRectIndicatorLayer.get());
+
+    update();
+}
+
+TileCoverageMap::~TileCoverageMap()
+{
+    m_layer.get().setOwner(nullptr);
+}
+
+void TileCoverageMap::update()
+{
+    FloatRect containerBounds = m_controller.bounds();
+    FloatRect visibleRect = m_controller.visibleRect();
+    visibleRect.contract(4, 4); // Layer is positioned 2px from top and left edges.
+
+    float widthScale = 1;
+    float scale = 1;
+    if (!containerBounds.isEmpty()) {
+        widthScale = std::min<float>(visibleRect.width() / containerBounds.width(), 0.1);
+        scale = std::min(widthScale, visibleRect.height() / containerBounds.height());
+    }
+
+    float indicatorScale = scale * m_controller.tileGrid().scale();
+    FloatRect mapBounds = containerBounds;
+    mapBounds.scale(indicatorScale, indicatorScale);
+
+    m_layer.get().setPosition(m_position + FloatPoint(2, 2));
+    m_layer.get().setBounds(mapBounds);
+    m_layer.get().setNeedsDisplay();
+
+    visibleRect.scale(indicatorScale, indicatorScale);
+    visibleRect.expand(2, 2);
+    m_visibleRectIndicatorLayer->setPosition(visibleRect.location());
+    m_visibleRectIndicatorLayer->setBounds(FloatRect(FloatPoint(), visibleRect.size()));
+
+    Color visibleRectIndicatorColor;
+    switch (m_controller.indicatorMode()) {
+    case SynchronousScrollingBecauseOfStyleIndication:
+        visibleRectIndicatorColor = Color(255, 0, 0);
+        break;
+    case SynchronousScrollingBecauseOfEventHandlersIndication:
+        visibleRectIndicatorColor = Color(255, 255, 0);
+        break;
+    case AsyncScrollingIndication:
+        visibleRectIndicatorColor = Color(0, 200, 0);
+        break;
+    }
+
+    m_visibleRectIndicatorLayer.get().setBorderColor(visibleRectIndicatorColor);
+}
+
+void TileCoverageMap::platformCALayerPaintContents(PlatformCALayer* platformCALayer, GraphicsContext& context, const FloatRect&)
+{
+    ASSERT_UNUSED(platformCALayer, platformCALayer == &m_layer.get());
+    m_controller.tileGrid().drawTileMapContents(context.platformContext(), m_layer.get().bounds());
+}
+
+float TileCoverageMap::platformCALayerDeviceScaleFactor() const
+{
+    return m_controller.rootLayer().owner()->platformCALayerDeviceScaleFactor();
+}
+
+}
index 079b145..9c961bf 100644 (file)
@@ -67,7 +67,7 @@ public:
     double retainedTileBackingStoreMemory() const;
     unsigned blankPixelCount() const;
 
-    void drawTileMapContents(CGContextRef, CGRect layerBounds);
+    void drawTileMapContents(CGContextRef, CGRect layerBounds) const;
 
 #if PLATFORM(IOS)
     unsigned numberOfUnparentedTiles() const { return m_cohortList.size(); }
index 4d3afad..1ac3854 100644 (file)
@@ -598,7 +598,7 @@ IntRect TileGrid::tileCoverageRect() const
     return coverageRectInLayerCoords;
 }
 
-void TileGrid::drawTileMapContents(CGContextRef context, CGRect layerBounds)
+void TileGrid::drawTileMapContents(CGContextRef context, CGRect layerBounds) const
 {
     CGContextSetRGBFillColor(context, 0.3, 0.3, 0.3, 1);
     CGContextFillRect(context, layerBounds);