<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[161303] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/161303">161303</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2014-01-03 18:04:34 -0800 (Fri, 03 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Simplify ScrollingStateNode references to various layer types
https://bugs.webkit.org/show_bug.cgi?id=126477

Reviewed by Tim Horton.

ScrollingStateNodes referenced both GraphicsLayer and PlatformLayers, in
confusing ways. In the main thread they have a GraphicsLayer*, but need
to check to see if the underlying PlatformLayer changed. Then, when
cloned to commit to the scrolling thread, they drop the GraphicsLayer
and store a PlatformLayer.

Hide the complexity (and prepare for the future) by adding LayerRepresentation,
which wraps various different flavors of layers, and knows how to check whether
the PlatformLayer underlying a GraphicsLayer changed.

ScrollingStateNode layer setters then just take and compare LayerRepresentations.
Copy constructors convert to a PlatformLayer representation (though not really
in the right place currently), and ScrollingTreeNodes get PlatformLayers.

* page/scrolling/AsyncScrollingCoordinator.cpp:
(WebCore::AsyncScrollingCoordinator::updateScrollingNode):
(WebCore::AsyncScrollingCoordinator::setScrollLayerForNode):
* page/scrolling/ScrollingStateFixedNode.cpp:
(WebCore::ScrollingStateFixedNode::syncLayerPositionForViewportRect):
* page/scrolling/ScrollingStateNode.cpp:
(WebCore::ScrollingStateNode::ScrollingStateNode):
(WebCore::ScrollingStateNode::setLayer):
* page/scrolling/ScrollingStateNode.h:
(WebCore::LayerRepresentation::LayerRepresentation):
(WebCore::LayerRepresentation::operator GraphicsLayer*):
(WebCore::LayerRepresentation::operator PlatformLayer*):
(WebCore::LayerRepresentation::operator GraphicsLayer::PlatformLayerID):
(WebCore::LayerRepresentation::operator ==):
(WebCore::LayerRepresentation::toPlatformLayer):
(WebCore::LayerRepresentation::representsGraphicsLayer):
(WebCore::LayerRepresentation::representsPlatformLayer):
(WebCore::LayerRepresentation::representsPlatformLayerID):
(WebCore::ScrollingStateNode::layer):
* page/scrolling/ScrollingStateScrollingNode.cpp:
(WebCore::ScrollingStateScrollingNode::ScrollingStateScrollingNode):
(WebCore::ScrollingStateScrollingNode::setCounterScrollingLayer):
(WebCore::ScrollingStateScrollingNode::setHeaderLayer):
(WebCore::ScrollingStateScrollingNode::setFooterLayer):
* page/scrolling/ScrollingStateScrollingNode.h:
* page/scrolling/ScrollingStateStickyNode.cpp:
(WebCore::ScrollingStateStickyNode::syncLayerPositionForViewportRect):
* page/scrolling/mac/ScrollingStateNodeMac.mm:
* page/scrolling/mac/ScrollingStateScrollingNodeMac.mm:
* page/scrolling/mac/ScrollingTreeFixedNode.mm:
(WebCore::ScrollingTreeFixedNode::updateBeforeChildren):
* page/scrolling/mac/ScrollingTreeScrollingNodeMac.mm:
(WebCore::ScrollingTreeScrollingNodeMac::updateBeforeChildren):
* page/scrolling/mac/ScrollingTreeStickyNode.mm:
(WebCore::ScrollingTreeStickyNode::updateBeforeChildren):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepagescrollingAsyncScrollingCoordinatorcpp">trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollingStateFixedNodecpp">trunk/Source/WebCore/page/scrolling/ScrollingStateFixedNode.cpp</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollingStateNodecpp">trunk/Source/WebCore/page/scrolling/ScrollingStateNode.cpp</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollingStateNodeh">trunk/Source/WebCore/page/scrolling/ScrollingStateNode.h</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollingStateScrollingNodecpp">trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.cpp</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollingStateScrollingNodeh">trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.h</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollingStateStickyNodecpp">trunk/Source/WebCore/page/scrolling/ScrollingStateStickyNode.cpp</a></li>
<li><a href="#trunkSourceWebCorepagescrollingmacScrollingStateNodeMacmm">trunk/Source/WebCore/page/scrolling/mac/ScrollingStateNodeMac.mm</a></li>
<li><a href="#trunkSourceWebCorepagescrollingmacScrollingStateScrollingNodeMacmm">trunk/Source/WebCore/page/scrolling/mac/ScrollingStateScrollingNodeMac.mm</a></li>
<li><a href="#trunkSourceWebCorepagescrollingmacScrollingTreeFixedNodemm">trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFixedNode.mm</a></li>
<li><a href="#trunkSourceWebCorepagescrollingmacScrollingTreeScrollingNodeMacmm">trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeMac.mm</a></li>
<li><a href="#trunkSourceWebCorepagescrollingmacScrollingTreeStickyNodemm">trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeStickyNode.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/ChangeLog        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -1,3 +1,60 @@
</span><ins>+2014-01-03  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        Simplify ScrollingStateNode references to various layer types
+        https://bugs.webkit.org/show_bug.cgi?id=126477
+
+        Reviewed by Tim Horton.
+        
+        ScrollingStateNodes referenced both GraphicsLayer and PlatformLayers, in
+        confusing ways. In the main thread they have a GraphicsLayer*, but need
+        to check to see if the underlying PlatformLayer changed. Then, when
+        cloned to commit to the scrolling thread, they drop the GraphicsLayer
+        and store a PlatformLayer.
+        
+        Hide the complexity (and prepare for the future) by adding LayerRepresentation,
+        which wraps various different flavors of layers, and knows how to check whether
+        the PlatformLayer underlying a GraphicsLayer changed.
+        
+        ScrollingStateNode layer setters then just take and compare LayerRepresentations.
+        Copy constructors convert to a PlatformLayer representation (though not really
+        in the right place currently), and ScrollingTreeNodes get PlatformLayers.
+
+        * page/scrolling/AsyncScrollingCoordinator.cpp:
+        (WebCore::AsyncScrollingCoordinator::updateScrollingNode):
+        (WebCore::AsyncScrollingCoordinator::setScrollLayerForNode):
+        * page/scrolling/ScrollingStateFixedNode.cpp:
+        (WebCore::ScrollingStateFixedNode::syncLayerPositionForViewportRect):
+        * page/scrolling/ScrollingStateNode.cpp:
+        (WebCore::ScrollingStateNode::ScrollingStateNode):
+        (WebCore::ScrollingStateNode::setLayer):
+        * page/scrolling/ScrollingStateNode.h:
+        (WebCore::LayerRepresentation::LayerRepresentation):
+        (WebCore::LayerRepresentation::operator GraphicsLayer*):
+        (WebCore::LayerRepresentation::operator PlatformLayer*):
+        (WebCore::LayerRepresentation::operator GraphicsLayer::PlatformLayerID):
+        (WebCore::LayerRepresentation::operator ==):
+        (WebCore::LayerRepresentation::toPlatformLayer):
+        (WebCore::LayerRepresentation::representsGraphicsLayer):
+        (WebCore::LayerRepresentation::representsPlatformLayer):
+        (WebCore::LayerRepresentation::representsPlatformLayerID):
+        (WebCore::ScrollingStateNode::layer):
+        * page/scrolling/ScrollingStateScrollingNode.cpp:
+        (WebCore::ScrollingStateScrollingNode::ScrollingStateScrollingNode):
+        (WebCore::ScrollingStateScrollingNode::setCounterScrollingLayer):
+        (WebCore::ScrollingStateScrollingNode::setHeaderLayer):
+        (WebCore::ScrollingStateScrollingNode::setFooterLayer):
+        * page/scrolling/ScrollingStateScrollingNode.h:
+        * page/scrolling/ScrollingStateStickyNode.cpp:
+        (WebCore::ScrollingStateStickyNode::syncLayerPositionForViewportRect):
+        * page/scrolling/mac/ScrollingStateNodeMac.mm:
+        * page/scrolling/mac/ScrollingStateScrollingNodeMac.mm:
+        * page/scrolling/mac/ScrollingTreeFixedNode.mm:
+        (WebCore::ScrollingTreeFixedNode::updateBeforeChildren):
+        * page/scrolling/mac/ScrollingTreeScrollingNodeMac.mm:
+        (WebCore::ScrollingTreeScrollingNodeMac::updateBeforeChildren):
+        * page/scrolling/mac/ScrollingTreeStickyNode.mm:
+        (WebCore::ScrollingTreeStickyNode::updateBeforeChildren):
+
</ins><span class="cx"> 2014-01-03  Brent Fulgham  &lt;bfulgham@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WebGL] Blit operation from Multisample FBO to rendering FBO must ignore GL_SCISSOR test
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingAsyncScrollingCoordinatorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -206,7 +206,7 @@
</span><span class="cx">     if (!node)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    node-&gt;setScrollLayer(scrollLayer);
</del><ins>+    node-&gt;setLayer(scrollLayer);
</ins><span class="cx">     node-&gt;setCounterScrollingLayer(counterScrollingLayer);
</span><span class="cx">     scheduleTreeStateCommit();
</span><span class="cx"> }
</span><span class="lines">@@ -238,7 +238,8 @@
</span><span class="cx"> 
</span><span class="cx"> void AsyncScrollingCoordinator::setScrollLayerForNode(GraphicsLayer* scrollLayer, ScrollingStateNode* node)
</span><span class="cx"> {
</span><del>-    node-&gt;setScrollLayer(scrollLayer);
</del><ins>+    node-&gt;setLayer(scrollLayer);
+    // FIXME: only schedule a commit if something changed.
</ins><span class="cx">     scheduleTreeStateCommit();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollingStateFixedNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollingStateFixedNode.cpp (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollingStateFixedNode.cpp        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/ScrollingStateFixedNode.cpp        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx"> void ScrollingStateFixedNode::syncLayerPositionForViewportRect(const LayoutRect&amp; viewportRect)
</span><span class="cx"> {
</span><span class="cx">     FloatPoint position = m_constraints.layerPositionForViewportRect(viewportRect);
</span><del>-    graphicsLayer()-&gt;syncPosition(position);
</del><ins>+    static_cast&lt;GraphicsLayer*&gt;(layer())-&gt;syncPosition(position);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ScrollingStateFixedNode::dumpProperties(TextStream&amp; ts, int indent) const
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollingStateNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollingStateNode.cpp (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollingStateNode.cpp        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/ScrollingStateNode.cpp        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -46,8 +46,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // This copy constructor is used for cloning nodes in the tree, and it doesn't make sense
</span><del>-// to clone the relationship pointers, so don't copy that information from the original
-// node.
</del><ins>+// to clone the relationship pointers, so don't copy that information from the original node.
</ins><span class="cx"> ScrollingStateNode::ScrollingStateNode(const ScrollingStateNode&amp; stateNode, ScrollingStateTree&amp; adoptiveTree)
</span><span class="cx">     : m_nodeType(stateNode.nodeType())
</span><span class="cx">     , m_nodeID(stateNode.scrollingNodeID())
</span><span class="lines">@@ -55,8 +54,9 @@
</span><span class="cx">     , m_scrollingStateTree(adoptiveTree)
</span><span class="cx">     , m_parent(0)
</span><span class="cx"> {
</span><del>-    // FIXME: why doesn't this set the GraphicsLayer?
-    setScrollPlatformLayer(stateNode.platformScrollLayer());
</del><ins>+    // The cloned tree references PlatformLayers, which are safe to send to the scrolling thread.
+    // FIXME: this Mac threaded-scrolling assumption doesn't belong here.
+    setLayer(stateNode.layer().toPlatformLayer());
</ins><span class="cx">     scrollingStateTree().addNode(this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -127,6 +127,17 @@
</span><span class="cx">         m_children-&gt;at(i)-&gt;willBeRemovedFromStateTree();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ScrollingStateNode::setLayer(const LayerRepresentation&amp; layerRepresentation)
+{
+    if (layerRepresentation == m_layer)
+        return;
+    
+    m_layer = layerRepresentation;
+
+    setPropertyChanged(ScrollLayer);
+    scrollingStateTree().setHasChangedProperties(true);
+}
+
</ins><span class="cx"> void ScrollingStateNode::dump(TextStream&amp; ts, int indent) const
</span><span class="cx"> {
</span><span class="cx">     writeIndent(ts, indent);
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollingStateNodeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollingStateNode.h (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollingStateNode.h        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/ScrollingStateNode.h        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -28,7 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)
</span><span class="cx"> 
</span><del>-#include &quot;PlatformLayer.h&quot;
</del><ins>+#include &quot;GraphicsLayer.h&quot;
</ins><span class="cx"> #include &quot;ScrollingCoordinator.h&quot;
</span><span class="cx"> #include &lt;wtf/OwnPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/PassOwnPtr.h&gt;
</span><span class="lines">@@ -44,6 +44,102 @@
</span><span class="cx"> class ScrollingStateTree;
</span><span class="cx"> class TextStream;
</span><span class="cx"> 
</span><ins>+// Used to allow ScrollingStateNodes to refer to layers in various contexts:
+// a) Async scrolling, main thread: ScrollingStateNode holds onto a GraphicsLayer, and uses m_layerID
+//    to detect whether that GraphicsLayer's underlying PlatformLayer changed.
+// b) Threaded scrolling, commit to scrolling thread: ScrollingStateNode wraps a PlatformLayer, which
+//    can be passed to the Scrolling Thread
+// c) Remote scrolling UI process, where LayerRepresentation wraps just a PlatformLayerID.
+class LayerRepresentation {
+public:
+    enum LayerRepresentationType {
+        EmptyRepresentation,
+        GraphicsLayerRepresentation,
+        PlatformLayerRepresentation,
+        PlatformLayerIDRepresentation
+    };
+
+    LayerRepresentation()
+        : m_graphicsLayer(nullptr)
+        , m_layerID(0)
+        , m_representation(EmptyRepresentation)
+    { }
+
+    LayerRepresentation(GraphicsLayer* graphicsLayer)
+        : m_graphicsLayer(graphicsLayer)
+        , m_layerID(graphicsLayer ? graphicsLayer-&gt;primaryLayerID() : 0)
+        , m_representation(GraphicsLayerRepresentation)
+    { }
+
+    LayerRepresentation(PlatformLayer* platformLayer)
+        : m_platformLayer(platformLayer)
+        , m_layerID(0)
+        , m_representation(PlatformLayerRepresentation)
+    { }
+
+    LayerRepresentation(GraphicsLayer::PlatformLayerID layerID)
+        : m_graphicsLayer(nullptr)
+        , m_layerID(layerID)
+        , m_representation(PlatformLayerIDRepresentation)
+    { }
+    
+    operator GraphicsLayer*() const
+    {
+        ASSERT(m_representation == GraphicsLayerRepresentation);
+        return m_graphicsLayer;
+    }
+
+    operator PlatformLayer*() const
+    {
+        ASSERT(m_representation == PlatformLayerRepresentation);
+        return m_platformLayer;
+    }
+
+    operator GraphicsLayer::PlatformLayerID() const
+    {
+        ASSERT(m_representation == PlatformLayerIDRepresentation || m_representation == GraphicsLayerRepresentation);
+        return m_layerID;
+    }
+    
+    bool operator ==(const LayerRepresentation&amp; other) const
+    {
+        if (m_representation != other.m_representation)
+            return false;
+        switch (m_representation) {
+        case EmptyRepresentation:
+            return true;
+        case GraphicsLayerRepresentation:
+            return m_graphicsLayer == other.m_graphicsLayer
+                &amp;&amp; m_layerID == other.m_layerID;
+        case PlatformLayerRepresentation:
+            return m_platformLayer == other.m_platformLayer;
+        case PlatformLayerIDRepresentation:
+            return m_layerID == other.m_layerID;
+        }
+        ASSERT_NOT_REACHED();
+        return true;
+    }
+    
+    LayerRepresentation toPlatformLayer() const
+    {
+        ASSERT(m_representation == GraphicsLayerRepresentation);
+        return m_graphicsLayer ? m_graphicsLayer-&gt;platformLayer() : nullptr;
+    }
+    
+    bool representsGraphicsLayer() const { return m_representation == GraphicsLayerRepresentation; }
+    bool representsPlatformLayer() const { return m_representation == PlatformLayerRepresentation; }
+    bool representsPlatformLayerID() const { return m_representation == PlatformLayerIDRepresentation; }
+
+private:
+    union {
+        GraphicsLayer* m_graphicsLayer;
+        PlatformLayer *m_platformLayer;
+    };
+
+    GraphicsLayer::PlatformLayerID m_layerID;
+    LayerRepresentationType m_representation;
+};
+
</ins><span class="cx"> class ScrollingStateNode {
</span><span class="cx"> public:
</span><span class="cx">     ScrollingStateNode(ScrollingNodeType, ScrollingStateTree&amp;, ScrollingNodeID);
</span><span class="lines">@@ -68,10 +164,8 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void syncLayerPositionForViewportRect(const LayoutRect&amp; /*viewportRect*/) { }
</span><span class="cx"> 
</span><del>-    GraphicsLayer* graphicsLayer() { return m_graphicsLayer; }
-    PlatformLayer* platformScrollLayer() const;
-    void setScrollLayer(GraphicsLayer*);
-    void setScrollPlatformLayer(PlatformLayer*);
</del><ins>+    const LayerRepresentation&amp; layer() const { return m_layer; }
+    void setLayer(const LayerRepresentation&amp;);
</ins><span class="cx"> 
</span><span class="cx">     ScrollingStateTree&amp; scrollingStateTree() const { return m_scrollingStateTree; }
</span><span class="cx"> 
</span><span class="lines">@@ -106,10 +200,7 @@
</span><span class="cx">     ScrollingStateNode* m_parent;
</span><span class="cx">     OwnPtr&lt;Vector&lt;OwnPtr&lt;ScrollingStateNode&gt;&gt;&gt; m_children;
</span><span class="cx"> 
</span><del>-#if PLATFORM(MAC)
-    RetainPtr&lt;PlatformLayer&gt; m_platformScrollLayer;
-#endif
-    GraphicsLayer* m_graphicsLayer;
</del><ins>+    LayerRepresentation m_layer;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> #define SCROLLING_STATE_NODE_TYPE_CASTS(ToValueTypeName, predicate) \
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollingStateScrollingNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.cpp (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.cpp        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.cpp        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -41,9 +41,6 @@
</span><span class="cx"> 
</span><span class="cx"> ScrollingStateScrollingNode::ScrollingStateScrollingNode(ScrollingStateTree&amp; stateTree, ScrollingNodeID nodeID)
</span><span class="cx">     : ScrollingStateNode(ScrollingNode, stateTree, nodeID)
</span><del>-    , m_counterScrollingLayer(0)
-    , m_headerLayer(0)
-    , m_footerLayer(0)
</del><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     , m_verticalScrollbarPainter(0)
</span><span class="cx">     , m_horizontalScrollbarPainter(0)
</span><span class="lines">@@ -78,9 +75,11 @@
</span><span class="cx">     , m_requestedScrollPosition(stateNode.requestedScrollPosition())
</span><span class="cx">     , m_requestedScrollPositionRepresentsProgrammaticScroll(stateNode.requestedScrollPositionRepresentsProgrammaticScroll())
</span><span class="cx"> {
</span><del>-    setCounterScrollingLayer(stateNode.counterScrollingLayer());
-    setHeaderLayer(stateNode.headerLayer());
-    setFooterLayer(stateNode.footerLayer());
</del><ins>+    // The cloned tree references PlatformLayers, which are safe to send to the scrolling thread.
+    // FIXME: this Mac threaded-scrolling assumption doesn't belong here.
+    setCounterScrollingLayer(stateNode.counterScrollingLayer().toPlatformLayer());
+    setHeaderLayer(stateNode.headerLayer().toPlatformLayer());
+    setFooterLayer(stateNode.footerLayer().toPlatformLayer());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ScrollingStateScrollingNode::~ScrollingStateScrollingNode()
</span><span class="lines">@@ -211,6 +210,40 @@
</span><span class="cx">     scrollingStateTree().setHasChangedProperties(true);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ScrollingStateScrollingNode::setCounterScrollingLayer(const LayerRepresentation&amp; layerRepresentation)
+{
+    if (layerRepresentation == m_counterScrollingLayer)
+        return;
+    
+    m_counterScrollingLayer = layerRepresentation;
+
+    setPropertyChanged(CounterScrollingLayer);
+    scrollingStateTree().setHasChangedProperties(true);
+}
+
+void ScrollingStateScrollingNode::setHeaderLayer(const LayerRepresentation&amp; layerRepresentation)
+{
+    if (layerRepresentation == m_headerLayer)
+        return;
+    
+    m_headerLayer = layerRepresentation;
+
+    setPropertyChanged(HeaderLayer);
+    scrollingStateTree().setHasChangedProperties(true);
+}
+
+
+void ScrollingStateScrollingNode::setFooterLayer(const LayerRepresentation&amp; layerRepresentation)
+{
+    if (layerRepresentation == m_footerLayer)
+        return;
+    
+    m_footerLayer = layerRepresentation;
+
+    setPropertyChanged(FooterLayer);
+    scrollingStateTree().setHasChangedProperties(true);
+}
+
</ins><span class="cx"> void ScrollingStateScrollingNode::dumpProperties(TextStream&amp; ts, int indent) const
</span><span class="cx"> {
</span><span class="cx">     ts &lt;&lt; &quot;(&quot; &lt;&lt; &quot;Scrolling node&quot; &lt;&lt; &quot;\n&quot;;
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollingStateScrollingNodeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.h (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.h        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.h        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS)
</span><span class="cx"> 
</span><ins>+#include &quot;GraphicsLayer.h&quot;
</ins><span class="cx"> #include &quot;IntRect.h&quot;
</span><span class="cx"> #include &quot;Region.h&quot;
</span><span class="cx"> #include &quot;ScrollTypes.h&quot;
</span><span class="lines">@@ -104,19 +105,16 @@
</span><span class="cx">     void setFooterHeight(int);
</span><span class="cx"> 
</span><span class="cx">     // This is a layer moved in the opposite direction to scrolling, for example for background-attachment:fixed
</span><del>-    GraphicsLayer* counterScrollingLayer() const { return m_counterScrollingLayer; }
-    void setCounterScrollingLayer(GraphicsLayer*);
-    PlatformLayer* counterScrollingPlatformLayer() const;
</del><ins>+    const LayerRepresentation&amp; counterScrollingLayer() const { return m_counterScrollingLayer; }
+    void setCounterScrollingLayer(const LayerRepresentation&amp;);
</ins><span class="cx"> 
</span><span class="cx">     // The header and footer layers scroll vertically with the page, they should remain fixed when scrolling horizontally.
</span><del>-    GraphicsLayer* headerLayer() const { return m_headerLayer; }
-    void setHeaderLayer(GraphicsLayer*);
-    PlatformLayer* headerPlatformLayer() const;
</del><ins>+    const LayerRepresentation&amp; headerLayer() const { return m_headerLayer; }
+    void setHeaderLayer(const LayerRepresentation&amp;);
</ins><span class="cx"> 
</span><span class="cx">     // The header and footer layers scroll vertically with the page, they should remain fixed when scrolling horizontally.
</span><del>-    GraphicsLayer* footerLayer() const { return m_footerLayer; }
-    void setFooterLayer(GraphicsLayer*);
-    PlatformLayer* footerPlatformLayer() const;
</del><ins>+    const LayerRepresentation&amp; footerLayer() const { return m_footerLayer; }
+    void setFooterLayer(const LayerRepresentation&amp;);
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     ScrollbarPainter verticalScrollbarPainter() const { return m_verticalScrollbarPainter; }
</span><span class="lines">@@ -132,13 +130,11 @@
</span><span class="cx">     ScrollingStateScrollingNode(ScrollingStateTree&amp;, ScrollingNodeID);
</span><span class="cx">     ScrollingStateScrollingNode(const ScrollingStateScrollingNode&amp;, ScrollingStateTree&amp;);
</span><span class="cx"> 
</span><del>-    GraphicsLayer* m_counterScrollingLayer;
-    GraphicsLayer* m_headerLayer;
-    GraphicsLayer* m_footerLayer;
</del><ins>+    LayerRepresentation m_counterScrollingLayer;
+    LayerRepresentation m_headerLayer;
+    LayerRepresentation m_footerLayer;
+
</ins><span class="cx"> #if PLATFORM(MAC)
</span><del>-    RetainPtr&lt;PlatformLayer&gt; m_counterScrollingPlatformLayer;
-    RetainPtr&lt;PlatformLayer&gt; m_headerPlatformLayer;
-    RetainPtr&lt;PlatformLayer&gt; m_footerPlatformLayer;
</del><span class="cx">     ScrollbarPainter m_verticalScrollbarPainter;
</span><span class="cx">     ScrollbarPainter m_horizontalScrollbarPainter;
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollingStateStickyNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollingStateStickyNode.cpp (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollingStateStickyNode.cpp        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/ScrollingStateStickyNode.cpp        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx"> void ScrollingStateStickyNode::syncLayerPositionForViewportRect(const LayoutRect&amp; viewportRect)
</span><span class="cx"> {
</span><span class="cx">     FloatPoint position = m_constraints.layerPositionForConstrainingRect(viewportRect);
</span><del>-    graphicsLayer()-&gt;syncPosition(position);
</del><ins>+    static_cast&lt;GraphicsLayer*&gt;(layer())-&gt;syncPosition(position);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ScrollingStateStickyNode::dumpProperties(TextStream&amp; ts, int indent) const
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingmacScrollingStateNodeMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingStateNodeMac.mm (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/mac/ScrollingStateNodeMac.mm        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingStateNodeMac.mm        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -33,30 +33,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-PlatformLayer* ScrollingStateNode::platformScrollLayer() const
-{
-    return m_platformScrollLayer.get();
-}
-
-void ScrollingStateNode::setScrollPlatformLayer(PlatformLayer* platformLayer)
-{
-    m_platformScrollLayer = platformLayer;
-}
-
-void ScrollingStateNode::setScrollLayer(GraphicsLayer* graphicsLayer)
-{
-    PlatformLayer* platformScrollLayer = graphicsLayer ? graphicsLayer-&gt;platformLayer() : nil;
-
-    if (m_platformScrollLayer == platformScrollLayer)
-        return;
-
-    m_platformScrollLayer = platformScrollLayer;
-    m_graphicsLayer = graphicsLayer;
-
-    setPropertyChanged(ScrollLayer);
-    scrollingStateTree().setHasChangedProperties(true);
-}
-
</del><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(ASYNC_SCROLLING)
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingmacScrollingStateScrollingNodeMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingStateScrollingNodeMac.mm (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/mac/ScrollingStateScrollingNodeMac.mm        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingStateScrollingNodeMac.mm        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -34,61 +34,6 @@
</span><span class="cx"> #if ENABLE(ASYNC_SCROLLING)
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><del>-
-PlatformLayer* ScrollingStateScrollingNode::counterScrollingPlatformLayer() const
-{
-    return m_counterScrollingPlatformLayer.get();
-}
-
-void ScrollingStateScrollingNode::setCounterScrollingLayer(GraphicsLayer* graphicsLayer)
-{
-    PlatformLayer* platformScrollLayer = graphicsLayer ? graphicsLayer-&gt;platformLayer() : nil;
-    if (m_counterScrollingPlatformLayer == platformScrollLayer)
-        return;
-
-    m_counterScrollingPlatformLayer = platformScrollLayer;
-    m_counterScrollingLayer = graphicsLayer;
-
-    setPropertyChanged(CounterScrollingLayer);
-    scrollingStateTree().setHasChangedProperties(true);
-}
-
-PlatformLayer* ScrollingStateScrollingNode::headerPlatformLayer() const
-{
-    return m_headerPlatformLayer.get();
-}
-
-void ScrollingStateScrollingNode::setHeaderLayer(GraphicsLayer* graphicsLayer)
-{
-    PlatformLayer* platformHeaderLayer = graphicsLayer ? graphicsLayer-&gt;platformLayer() : nil;
-    if (m_headerPlatformLayer == platformHeaderLayer)
-        return;
-
-    m_headerPlatformLayer = platformHeaderLayer;
-    m_headerLayer = graphicsLayer;
-
-    setPropertyChanged(HeaderLayer);
-    scrollingStateTree().setHasChangedProperties(true);
-}
-
-PlatformLayer* ScrollingStateScrollingNode::footerPlatformLayer() const
-{
-    return m_footerPlatformLayer.get();
-}
-
-void ScrollingStateScrollingNode::setFooterLayer(GraphicsLayer* graphicsLayer)
-{
-    PlatformLayer* platformFooterLayer = graphicsLayer ? graphicsLayer-&gt;platformLayer() : nil;
-    if (m_footerPlatformLayer == platformFooterLayer)
-        return;
-
-    m_footerPlatformLayer = platformFooterLayer;
-    m_footerLayer = graphicsLayer;
-
-    setPropertyChanged(FooterLayer);
-    scrollingStateTree().setHasChangedProperties(true);
-}
-
</del><span class="cx"> void ScrollingStateScrollingNode::setScrollbarPaintersFromScrollbars(Scrollbar* verticalScrollbar, Scrollbar* horizontalScrollbar)
</span><span class="cx"> {
</span><span class="cx">     ScrollbarTheme* scrollbarTheme = ScrollbarTheme::theme();
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingmacScrollingTreeFixedNodemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFixedNode.mm (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFixedNode.mm        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFixedNode.mm        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx">     const ScrollingStateFixedNode&amp; fixedStateNode = toScrollingStateFixedNode(stateNode);
</span><span class="cx"> 
</span><span class="cx">     if (fixedStateNode.hasChangedProperty(ScrollingStateNode::ScrollLayer))
</span><del>-        m_layer = fixedStateNode.platformScrollLayer();
</del><ins>+        m_layer = fixedStateNode.layer();
</ins><span class="cx"> 
</span><span class="cx">     if (stateNode.hasChangedProperty(ScrollingStateFixedNode::ViewportConstraints))
</span><span class="cx">         m_constraints = fixedStateNode.viewportConstraints();
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingmacScrollingTreeScrollingNodeMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeMac.mm (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeMac.mm        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeMac.mm        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -76,16 +76,16 @@
</span><span class="cx">     const auto&amp; scrollingStateNode = toScrollingStateScrollingNode(stateNode);
</span><span class="cx"> 
</span><span class="cx">     if (scrollingStateNode.hasChangedProperty(ScrollingStateNode::ScrollLayer))
</span><del>-        m_scrollLayer = scrollingStateNode.platformScrollLayer();
</del><ins>+        m_scrollLayer = scrollingStateNode.layer();
</ins><span class="cx"> 
</span><span class="cx">     if (scrollingStateNode.hasChangedProperty(ScrollingStateScrollingNode::CounterScrollingLayer))
</span><del>-        m_counterScrollingLayer = scrollingStateNode.counterScrollingPlatformLayer();
</del><ins>+        m_counterScrollingLayer = scrollingStateNode.counterScrollingLayer();
</ins><span class="cx"> 
</span><span class="cx">     if (scrollingStateNode.hasChangedProperty(ScrollingStateScrollingNode::HeaderLayer))
</span><del>-        m_headerLayer = scrollingStateNode.headerPlatformLayer();
</del><ins>+        m_headerLayer = scrollingStateNode.headerLayer();
</ins><span class="cx"> 
</span><span class="cx">     if (scrollingStateNode.hasChangedProperty(ScrollingStateScrollingNode::FooterLayer))
</span><del>-        m_footerLayer = scrollingStateNode.footerPlatformLayer();
</del><ins>+        m_footerLayer = scrollingStateNode.footerLayer();
</ins><span class="cx"> 
</span><span class="cx">     if (scrollingStateNode.hasChangedProperty(ScrollingStateScrollingNode::PainterForScrollbar)) {
</span><span class="cx">         m_verticalScrollbarPainter = scrollingStateNode.verticalScrollbarPainter();
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingmacScrollingTreeStickyNodemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeStickyNode.mm (161302 => 161303)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeStickyNode.mm        2014-01-04 02:01:19 UTC (rev 161302)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeStickyNode.mm        2014-01-04 02:04:34 UTC (rev 161303)
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx">     const ScrollingStateStickyNode&amp; stickyStateNode = toScrollingStateStickyNode(stateNode);
</span><span class="cx"> 
</span><span class="cx">     if (stickyStateNode.hasChangedProperty(ScrollingStateNode::ScrollLayer))
</span><del>-        m_layer = stickyStateNode.platformScrollLayer();
</del><ins>+        m_layer = stickyStateNode.layer();
</ins><span class="cx"> 
</span><span class="cx">     if (stateNode.hasChangedProperty(ScrollingStateStickyNode::ViewportConstraints))
</span><span class="cx">         m_constraints = stickyStateNode.viewportConstraints();
</span></span></pre>
</div>
</div>

</body>
</html>