Title: [166997] trunk/Source/WebCore
Revision
166997
Author
an...@apple.com
Date
2014-04-08 22:01:54 -0700 (Tue, 08 Apr 2014)

Log Message

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):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (166996 => 166997)


--- trunk/Source/WebCore/ChangeLog	2014-04-09 03:52:53 UTC (rev 166996)
+++ trunk/Source/WebCore/ChangeLog	2014-04-09 05:01:54 UTC (rev 166997)
@@ -1,3 +1,46 @@
+2014-04-08  Antti Koivisto  <an...@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  <za...@apple.com>
 
         Subpixel rendering: Clip outer rounded border rect on device pixel boundaries.

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (166996 => 166997)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-04-09 03:52:53 UTC (rev 166996)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-04-09 05:01:54 UTC (rev 166997)
@@ -6050,6 +6050,8 @@
 		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 */; };
@@ -13435,6 +13437,8 @@
 		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>"; };
@@ -15619,6 +15623,8 @@
 				4958782012A57DDF007238AC /* PlatformCALayerMac.mm */,
 				1AA71609149BC4DB0016EC19 /* TileController.h */,
 				1AA71608149BC4DA0016EC19 /* TileController.mm */,
+				E4830A3C18F4C5B700154A1B /* TileCoverageMap.h */,
+				E4830A3818F4C59400154A1B /* TileCoverageMap.mm */,
 				E4C274CB18E988F500602C76 /* TileGrid.h */,
 				E4C274C918E988EA00602C76 /* TileGrid.mm */,
 				0F580FA11496939100FB5BD8 /* WebTiledBackingLayer.h */,
@@ -24684,6 +24690,7 @@
 				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 */,
@@ -26866,6 +26873,7 @@
 				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 */,

Modified: trunk/Source/WebCore/platform/graphics/ca/PlatformCALayerClient.h (166996 => 166997)


--- trunk/Source/WebCore/platform/graphics/ca/PlatformCALayerClient.h	2014-04-09 03:52:53 UTC (rev 166996)
+++ trunk/Source/WebCore/platform/graphics/ca/PlatformCALayerClient.h	2014-04-09 05:01:54 UTC (rev 166997)
@@ -36,19 +36,19 @@
 
 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;

Modified: trunk/Source/WebCore/platform/graphics/ca/mac/TileController.h (166996 => 166997)


--- trunk/Source/WebCore/platform/graphics/ca/mac/TileController.h	2014-04-09 03:52:53 UTC (rev 166996)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/TileController.h	2014-04-09 05:01:54 UTC (rev 166997)
@@ -43,6 +43,7 @@
 class FloatRect;
 class IntPoint;
 class IntRect;
+class TileCoverageMap;
 class TileGrid;
 
 typedef Vector<RetainPtr<PlatformLayer>> PlatformLayerList;
@@ -69,6 +70,7 @@
     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 @@
 #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 @@
 
     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 @@
     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 @@
 
     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;

Modified: trunk/Source/WebCore/platform/graphics/ca/mac/TileController.mm (166996 => 166997)


--- trunk/Source/WebCore/platform/graphics/ca/mac/TileController.mm	2014-04-09 03:52:53 UTC (rev 166996)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/TileController.mm	2014-04-09 05:01:54 UTC (rev 166997)
@@ -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 @@
 #if PLATFORM(IOS)
     tileControllerMemoryHandler().removeTileController(this);
 #endif
-
-    if (m_tiledScrollingIndicatorLayer)
-        m_tiledScrollingIndicatorLayer->setOwner(nullptr);
 }
 
 void TileController::tileCacheLayerBoundsChanged()
@@ -112,11 +110,6 @@
         WebThreadLock();
 #endif
 
-    if (platformCALayer == m_tiledScrollingIndicatorLayer.get()) {
-        tileGrid().drawTileMapContents(context.platformContext(), m_tiledScrollingIndicatorLayer->bounds());
-        return;
-    }
-
     {
         GraphicsContextStateSaver stateSaver(context);
 
@@ -214,10 +207,10 @@
 
 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::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 @@
 
 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));
+    if (!m_coverageMap)
+        m_coverageMap = std::make_unique<TileCoverageMap>(*this);
 
-        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();
-    }
-
-    return m_tiledScrollingIndicatorLayer.get();
+    return &m_coverageMap->layer();
 }
 
 void TileController::setScrollingModeIndication(ScrollingModeIndication scrollingMode)

Added: trunk/Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.h (0 => 166997)


--- trunk/Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.h	2014-04-09 05:01:54 UTC (rev 166997)
@@ -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

Added: trunk/Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.mm (0 => 166997)


--- trunk/Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/TileCoverageMap.mm	2014-04-09 05:01:54 UTC (rev 166997)
@@ -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();
+}
+
+}

Modified: trunk/Source/WebCore/platform/graphics/ca/mac/TileGrid.h (166996 => 166997)


--- trunk/Source/WebCore/platform/graphics/ca/mac/TileGrid.h	2014-04-09 03:52:53 UTC (rev 166996)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/TileGrid.h	2014-04-09 05:01:54 UTC (rev 166997)
@@ -67,7 +67,7 @@
     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(); }

Modified: trunk/Source/WebCore/platform/graphics/ca/mac/TileGrid.mm (166996 => 166997)


--- trunk/Source/WebCore/platform/graphics/ca/mac/TileGrid.mm	2014-04-09 03:52:53 UTC (rev 166996)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/TileGrid.mm	2014-04-09 05:01:54 UTC (rev 166997)
@@ -598,7 +598,7 @@
     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);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to