Title: [163837] trunk/Source/WebKit2
Revision
163837
Author
simon.fra...@apple.com
Date
2014-02-10 16:24:58 -0800 (Mon, 10 Feb 2014)

Log Message

Show a debug tile map indicator for UI-side compositing
https://bugs.webkit.org/show_bug.cgi?id=128553

Reviewed by Tim Horton.

Implement a tiled scrolling indicator for UI-side compositing.

The indicator is created by making another RemoteLayerTreeHost,
and decoding the transaction in it a second time to create a cloned
layer tree. In that clone commit, we modify some layer properties to
make things easier to see.

The cloned layer tree is hosted in the root layer of the main
RemoteLayerTreeHost.

RemoteLayerTreeHost was changed to not need a pointer to the WebPageProxy,
which it only used in the "root layer changed" case; instead, it now just
returns a bool from updateLayerTree() in that situation.

* UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.cpp: Explanatory comment.
* UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.h:
* UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.mm:
(WebKit::RemoteLayerTreeDrawingAreaProxy::RemoteLayerTreeDrawingAreaProxy):
(WebKit::RemoteLayerTreeDrawingAreaProxy::commitLayerTree):
(WebKit::RemoteLayerTreeDrawingAreaProxy::setExposedRect):
(WebKit::RemoteLayerTreeDrawingAreaProxy::indicatorLocation):
(WebKit::RemoteLayerTreeDrawingAreaProxy::updateDebugIndicatorPosition):
(WebKit::RemoteLayerTreeDrawingAreaProxy::indicatorScale):
(WebKit::RemoteLayerTreeDrawingAreaProxy::updateDebugIndicator):
(WebKit::RemoteLayerTreeDrawingAreaProxy::showDebugIndicator):
* UIProcess/mac/RemoteLayerTreeHost.h:
(WebKit::RemoteLayerTreeHost::rootLayer):
(WebKit::RemoteLayerTreeHost::setIsDebugLayerTreeHost):
(WebKit::RemoteLayerTreeHost::isDebugLayerTreeHost):
* UIProcess/mac/RemoteLayerTreeHost.mm:
(WebKit::RemoteLayerTreeHost::RemoteLayerTreeHost):
(WebKit::RemoteLayerTreeHost::updateLayerTree):
(WebKit::RemoteLayerTreeHost::createLayer):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (163836 => 163837)


--- trunk/Source/WebKit2/ChangeLog	2014-02-11 00:24:55 UTC (rev 163836)
+++ trunk/Source/WebKit2/ChangeLog	2014-02-11 00:24:58 UTC (rev 163837)
@@ -1,5 +1,46 @@
 2014-02-10  Simon Fraser  <simon.fra...@apple.com>
 
+        Show a debug tile map indicator for UI-side compositing
+        https://bugs.webkit.org/show_bug.cgi?id=128553
+
+        Reviewed by Tim Horton.
+        
+        Implement a tiled scrolling indicator for UI-side compositing.
+        
+        The indicator is created by making another RemoteLayerTreeHost,
+        and decoding the transaction in it a second time to create a cloned
+        layer tree. In that clone commit, we modify some layer properties to
+        make things easier to see.
+        
+        The cloned layer tree is hosted in the root layer of the main
+        RemoteLayerTreeHost.
+        
+        RemoteLayerTreeHost was changed to not need a pointer to the WebPageProxy,
+        which it only used in the "root layer changed" case; instead, it now just
+        returns a bool from updateLayerTree() in that situation.
+
+        * UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.cpp: Explanatory comment.
+        * UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.h:
+        * UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.mm:
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::RemoteLayerTreeDrawingAreaProxy):
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::commitLayerTree):
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::setExposedRect):
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::indicatorLocation):
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::updateDebugIndicatorPosition):
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::indicatorScale):
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::updateDebugIndicator):
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::showDebugIndicator):
+        * UIProcess/mac/RemoteLayerTreeHost.h:
+        (WebKit::RemoteLayerTreeHost::rootLayer):
+        (WebKit::RemoteLayerTreeHost::setIsDebugLayerTreeHost):
+        (WebKit::RemoteLayerTreeHost::isDebugLayerTreeHost):
+        * UIProcess/mac/RemoteLayerTreeHost.mm:
+        (WebKit::RemoteLayerTreeHost::RemoteLayerTreeHost):
+        (WebKit::RemoteLayerTreeHost::updateLayerTree):
+        (WebKit::RemoteLayerTreeHost::createLayer):
+
+2014-02-10  Simon Fraser  <simon.fra...@apple.com>
+
         Put a delegatesScrolling flag on WebPageProxy so that the UI process knows when scrolling is delegated
         https://bugs.webkit.org/show_bug.cgi?id=128429
 

Modified: trunk/Source/WebKit2/UIProcess/DrawingAreaProxy.h (163836 => 163837)


--- trunk/Source/WebKit2/UIProcess/DrawingAreaProxy.h	2014-02-11 00:24:55 UTC (rev 163836)
+++ trunk/Source/WebKit2/UIProcess/DrawingAreaProxy.h	2014-02-11 00:24:58 UTC (rev 163837)
@@ -74,13 +74,16 @@
     virtual void commitTransientZoom(double, WebCore::FloatPoint) { }
 
 #if PLATFORM(MAC)
-    void setExposedRect(const WebCore::FloatRect&);
+    virtual void setExposedRect(const WebCore::FloatRect&);
     WebCore::FloatRect exposedRect() const { return m_exposedRect; }
     void exposedRectChangedTimerFired(WebCore::Timer<DrawingAreaProxy>*);
     
     void setCustomFixedPositionRect(const WebCore::FloatRect&);
 #endif
 
+    virtual void showDebugIndicator(bool) { }
+    virtual bool isShowingDebugIndicator() const { return false; }
+
 protected:
     explicit DrawingAreaProxy(DrawingAreaType, WebPageProxy*);
 

Modified: trunk/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.cpp (163836 => 163837)


--- trunk/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.cpp	2014-02-11 00:24:55 UTC (rev 163836)
+++ trunk/Source/WebKit2/UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.cpp	2014-02-11 00:24:58 UTC (rev 163837)
@@ -139,6 +139,7 @@
     m_scrollingTree->scrollPositionChangedViaDelegatedScrolling(nodeID, offset);
 }
 
+// This comes from the scrolling tree.
 void RemoteScrollingCoordinatorProxy::scrollPositionChanged(WebCore::ScrollingNodeID scrolledNodeID, const WebCore::FloatPoint& newScrollPosition)
 {
     m_webPageProxy.send(Messages::RemoteScrollingCoordinator::ScrollPositionChangedForNode(scrolledNodeID, newScrollPosition));

Modified: trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.h (163836 => 163837)


--- trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.h	2014-02-11 00:24:55 UTC (rev 163836)
+++ trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.h	2014-02-11 00:24:58 UTC (rev 163837)
@@ -28,6 +28,7 @@
 
 #include "DrawingAreaProxy.h"
 #include "RemoteLayerTreeHost.h"
+#include <WebCore/FloatPoint.h>
 #include <WebCore/IntPoint.h>
 #include <WebCore/IntSize.h>
 
@@ -42,12 +43,22 @@
     virtual ~RemoteLayerTreeDrawingAreaProxy();
 
     const RemoteLayerTreeHost& remoteLayerTreeHost() const { return m_remoteLayerTreeHost; }
-    
+
 private:
     virtual void sizeDidChange() override;
     virtual void deviceScaleFactorDidChange() override;
     virtual void didUpdateGeometry() override;
 
+    void showDebugIndicator(bool);
+
+    virtual void setExposedRect(const WebCore::FloatRect&) override;
+
+    float indicatorScale(WebCore::IntSize contentsSize) const;
+    void updateDebugIndicator(WebCore::IntSize contentsSize, bool rootLayerChanged, float scale);
+    void updateDebugIndicatorPosition();
+    
+    WebCore::FloatPoint indicatorLocation() const;
+
     // IPC::MessageReceiver
     virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override;
 
@@ -61,6 +72,10 @@
 
     WebCore::IntSize m_lastSentSize;
     WebCore::IntSize m_lastSentLayerPosition;
+
+    std::unique_ptr<RemoteLayerTreeHost> m_debugIndicatorLayerTreeHost;
+    RetainPtr<CALayer> m_tileMapHostLayer;
+    RetainPtr<CALayer> m_exposedRectIndicatorLayer;
 };
 
 DRAWING_AREA_PROXY_TYPE_CASTS(RemoteLayerTreeDrawingAreaProxy, type() == DrawingAreaTypeRemoteLayerTree);

Modified: trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.mm (163836 => 163837)


--- trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.mm	2014-02-11 00:24:55 UTC (rev 163836)
+++ trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.mm	2014-02-11 00:24:58 UTC (rev 163837)
@@ -31,12 +31,15 @@
 #import "RemoteScrollingCoordinatorProxy.h"
 #import "WebPageProxy.h"
 #import "WebProcessProxy.h"
+#import <WebCore/WebCoreCALayerExtras.h>
 
+using namespace WebCore;
+
 namespace WebKit {
 
 RemoteLayerTreeDrawingAreaProxy::RemoteLayerTreeDrawingAreaProxy(WebPageProxy* webPageProxy)
     : DrawingAreaProxy(DrawingAreaTypeRemoteLayerTree, webPageProxy)
-    , m_remoteLayerTreeHost(webPageProxy)
+    , m_remoteLayerTreeHost()
     , m_isWaitingForDidUpdateGeometry(false)
 {
     m_webPageProxy->process().addMessageReceiver(Messages::RemoteLayerTreeDrawingAreaProxy::messageReceiverName(), m_webPageProxy->pageID(), *this);
@@ -85,13 +88,152 @@
 
 void RemoteLayerTreeDrawingAreaProxy::commitLayerTree(const RemoteLayerTreeTransaction& layerTreeTransaction, const RemoteScrollingCoordinatorTransaction& scrollingTreeTransaction)
 {
-    m_remoteLayerTreeHost.updateLayerTree(layerTreeTransaction);
+    if (m_remoteLayerTreeHost.updateLayerTree(layerTreeTransaction))
+        m_webPageProxy->setAcceleratedCompositingRootLayer(m_remoteLayerTreeHost.rootLayer());
+
 #if ENABLE(ASYNC_SCROLLING)
     m_webPageProxy->scrollingCoordinatorProxy()->updateScrollingTree(scrollingTreeTransaction);
 #endif
 #if PLATFORM(IOS)
     m_webPageProxy->didCommitLayerTree(layerTreeTransaction);
 #endif
+
+    showDebugIndicator(m_webPageProxy->preferences().tiledScrollingIndicatorVisible());
+
+    if (m_debugIndicatorLayerTreeHost) {
+        float scale = indicatorScale(layerTreeTransaction.contentsSize());
+        bool rootLayerChanged = m_debugIndicatorLayerTreeHost->updateLayerTree(layerTreeTransaction, scale);
+        updateDebugIndicator(layerTreeTransaction.contentsSize(), rootLayerChanged, scale);
+        m_debugIndicatorLayerTreeHost->rootLayer().name = @"Indicator host root";
+    }
 }
 
+static const float indicatorInset = 10;
+static const float indicatorTopInset = 100;
+
+void RemoteLayerTreeDrawingAreaProxy::setExposedRect(const WebCore::FloatRect& r)
+{
+    DrawingAreaProxy::setExposedRect(r);
+    updateDebugIndicatorPosition();
+}
+
+FloatPoint RemoteLayerTreeDrawingAreaProxy::indicatorLocation() const
+{
+    if (m_webPageProxy->delegatesScrolling()) {
+        FloatPoint tiledMapLocation = exposedRect().location();
+        tiledMapLocation += FloatSize(indicatorInset, indicatorTopInset);
+        float scale = 1 / m_webPageProxy->pageScaleFactor();
+        tiledMapLocation.scale(scale, scale);
+        return tiledMapLocation;
+    }
+    
+    return FloatPoint(indicatorInset, indicatorInset);
+}
+
+void RemoteLayerTreeDrawingAreaProxy::updateDebugIndicatorPosition()
+{
+    if (!m_tileMapHostLayer)
+        return;
+
+    [m_tileMapHostLayer setPosition:indicatorLocation()];
+}
+
+float RemoteLayerTreeDrawingAreaProxy::indicatorScale(IntSize contentsSize) const
+{
+    // Pick a good scale.
+    IntSize viewSize = m_webPageProxy->viewSize();
+
+    float scale = 1;
+    if (!contentsSize.isEmpty()) {
+        float widthScale = std::min<float>((viewSize.width() - 2 * indicatorInset) / contentsSize.width(), 0.05);
+        scale = std::min(widthScale, static_cast<float>(viewSize.height() - indicatorTopInset - indicatorInset) / contentsSize.height());
+    }
+    
+    return scale;
+}
+
+void RemoteLayerTreeDrawingAreaProxy::updateDebugIndicator(IntSize contentsSize, bool rootLayerChanged, float scale)
+{
+    // Make sure we're the last sublayer.
+    CALayer *rootLayer = m_remoteLayerTreeHost.rootLayer();
+    [m_tileMapHostLayer removeFromSuperlayer];
+    [rootLayer addSublayer:m_tileMapHostLayer.get()];
+
+    // Pick a good scale.
+    IntSize viewSize = m_webPageProxy->viewSize();
+
+    [m_tileMapHostLayer setBounds:FloatRect(FloatPoint(), contentsSize)];
+    [m_tileMapHostLayer setPosition:indicatorLocation()];
+    [m_tileMapHostLayer setTransform:CATransform3DMakeScale(scale, scale, 1)];
+
+    if (rootLayerChanged) {
+        [m_tileMapHostLayer setSublayers:@[]];
+        [m_tileMapHostLayer addSublayer:m_debugIndicatorLayerTreeHost->rootLayer()];
+        [m_tileMapHostLayer addSublayer:m_exposedRectIndicatorLayer.get()];
+    }
+    
+    const float indicatorBorderWidth = 1;
+    float counterScaledBorder = indicatorBorderWidth / scale;
+
+    [m_exposedRectIndicatorLayer setBorderWidth:counterScaledBorder];
+
+    if (m_webPageProxy->delegatesScrolling()) {
+        FloatRect scaledExposedRect = exposedRect();
+        float scale = 1 / m_webPageProxy->pageScaleFactor();
+        scaledExposedRect.scale(scale, scale);
+
+        [m_exposedRectIndicatorLayer setPosition:scaledExposedRect.location()];
+        [m_exposedRectIndicatorLayer setBounds:FloatRect(FloatPoint(), scaledExposedRect.size())];
+    } else {
+        // FIXME: Get the correct scroll position.
+        [m_exposedRectIndicatorLayer setBounds:FloatRect(FloatPoint(), viewSize)];
+    }
+}
+
+void RemoteLayerTreeDrawingAreaProxy::showDebugIndicator(bool show)
+{
+    if (show == !!m_debugIndicatorLayerTreeHost)
+        return;
+    
+    if (!show) {
+        [m_tileMapHostLayer removeFromSuperlayer];
+        m_tileMapHostLayer = nullptr;
+        m_exposedRectIndicatorLayer = nullptr;
+        m_debugIndicatorLayerTreeHost = nullptr;
+        return;
+    }
+    
+    m_debugIndicatorLayerTreeHost = std::make_unique<RemoteLayerTreeHost>();
+    m_debugIndicatorLayerTreeHost->setIsDebugLayerTreeHost(true);
+
+    m_tileMapHostLayer = adoptNS([[CALayer alloc] init]);
+    [m_tileMapHostLayer setName:@"Tile map host"];
+    [m_tileMapHostLayer web_disableAllActions];
+    [m_tileMapHostLayer setAnchorPoint:CGPointZero];
+    [m_tileMapHostLayer setOpacity:0.8];
+    [m_tileMapHostLayer setMasksToBounds:YES];
+    [m_tileMapHostLayer setBorderWidth:2];
+
+    RetainPtr<CGColorSpaceRef> colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());
+    {
+        const CGFloat components[] = { 1, 1, 1, 0.6 };
+        RetainPtr<CGColorRef> color = adoptCF(CGColorCreate(colorSpace.get(), components));
+        [m_tileMapHostLayer setBackgroundColor:color.get()];
+
+        const CGFloat borderCmponents[] = { 0, 0, 0, 1 };
+        RetainPtr<CGColorRef> borderColor = adoptCF(CGColorCreate(colorSpace.get(), borderCmponents));
+        [m_tileMapHostLayer setBorderColor:borderColor.get()];
+    }
+    
+    m_exposedRectIndicatorLayer = adoptNS([[CALayer alloc] init]);
+    [m_exposedRectIndicatorLayer web_disableAllActions];
+    [m_exposedRectIndicatorLayer setAnchorPoint:CGPointZero];
+
+    {
+        const CGFloat components[] = { 0, 1, 0, 1 };
+        RetainPtr<CGColorRef> color = adoptCF(CGColorCreate(colorSpace.get(), components));
+        [m_exposedRectIndicatorLayer setBorderColor:color.get()];
+    }
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeHost.h (163836 => 163837)


--- trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeHost.h	2014-02-11 00:24:55 UTC (rev 163836)
+++ trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeHost.h	2014-02-11 00:24:58 UTC (rev 163837)
@@ -39,20 +39,24 @@
 
 class RemoteLayerTreeHost {
 public:
-    explicit RemoteLayerTreeHost(WebPageProxy*);
+    explicit RemoteLayerTreeHost();
     virtual ~RemoteLayerTreeHost();
 
     CALayer *getLayer(WebCore::GraphicsLayer::PlatformLayerID) const;
+    CALayer *rootLayer() const { return m_rootLayer; }
 
-    void updateLayerTree(const RemoteLayerTreeTransaction&);
+    // Returns true if the root layer changed.
+    bool updateLayerTree(const RemoteLayerTreeTransaction&, float indicatorScaleFactor  = 1);
 
+    void setIsDebugLayerTreeHost(bool flag) { m_isDebugLayerTreeHost = flag; }
+    bool isDebugLayerTreeHost() const { return m_isDebugLayerTreeHost; }
+
 private:
     CALayer *createLayer(RemoteLayerTreeTransaction::LayerCreationProperties);
 
-    WebPageProxy* m_webPageProxy;
-
     CALayer *m_rootLayer;
     HashMap<WebCore::GraphicsLayer::PlatformLayerID, RetainPtr<CALayer>> m_layers;
+    bool m_isDebugLayerTreeHost;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeHost.mm (163836 => 163837)


--- trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeHost.mm	2014-02-11 00:24:55 UTC (rev 163836)
+++ trunk/Source/WebKit2/UIProcess/mac/RemoteLayerTreeHost.mm	2014-02-11 00:24:58 UTC (rev 163837)
@@ -42,9 +42,9 @@
 
 namespace WebKit {
 
-RemoteLayerTreeHost::RemoteLayerTreeHost(WebPageProxy* webPageProxy)
-    : m_webPageProxy(webPageProxy)
-    , m_rootLayer(nullptr)
+RemoteLayerTreeHost::RemoteLayerTreeHost()
+    : m_rootLayer(nullptr)
+    , m_isDebugLayerTreeHost(false)
 {
 }
 
@@ -52,17 +52,18 @@
 {
 }
 
-void RemoteLayerTreeHost::updateLayerTree(const RemoteLayerTreeTransaction& transaction)
+bool RemoteLayerTreeHost::updateLayerTree(const RemoteLayerTreeTransaction& transaction, float indicatorScaleFactor)
 {
     LOG(RemoteLayerTree, "%s", transaction.description().data());
 
     for (auto createdLayer : transaction.createdLayers())
         createLayer(createdLayer);
 
+    bool rootLayerChanged = false;
     CALayer *rootLayer = getLayer(transaction.rootLayerID());
     if (m_rootLayer != rootLayer) {
         m_rootLayer = rootLayer;
-        m_webPageProxy->setAcceleratedCompositingRootLayer(m_rootLayer);
+        rootLayerChanged = true;
     }
 
     for (auto changedLayer : transaction.changedLayers()) {
@@ -81,11 +82,21 @@
         if (properties.changedProperties & RemoteLayerTreeTransaction::MaskLayerChanged && properties.maskLayerID)
             relatedLayers.set(properties.maskLayerID, getLayer(properties.maskLayerID));
 
-        RemoteLayerTreePropertyApplier::applyPropertiesToLayer(layer, properties, relatedLayers);
+        if (m_isDebugLayerTreeHost) {
+            RemoteLayerTreeTransaction::LayerProperties propertiesCopy(properties);
+            propertiesCopy.masksToBounds = false;
+            if (propertiesCopy.changedProperties & RemoteLayerTreeTransaction::BorderWidthChanged)
+                propertiesCopy.borderWidth *= 1 / indicatorScaleFactor;
+            
+            RemoteLayerTreePropertyApplier::applyPropertiesToLayer(layer, propertiesCopy, relatedLayers);
+        } else
+            RemoteLayerTreePropertyApplier::applyPropertiesToLayer(layer, properties, relatedLayers);
     }
 
     for (auto destroyedLayer : transaction.destroyedLayers())
         m_layers.remove(destroyedLayer);
+
+    return rootLayerChanged;
 }
 
 CALayer *RemoteLayerTreeHost::getLayer(GraphicsLayer::PlatformLayerID layerID) const
@@ -116,7 +127,10 @@
         layer = adoptNS([[CATransformLayer alloc] init]);
         break;
     case PlatformCALayer::LayerTypeCustom:
-        layer = WKMakeRenderLayer(properties.hostingContextID);
+        if (!m_isDebugLayerTreeHost)
+            layer = WKMakeRenderLayer(properties.hostingContextID);
+        else
+            layer = adoptNS([[CALayer alloc] init]);
         break;
     default:
         ASSERT_NOT_REACHED();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to