Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1526)

Unified Diff: third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositor.cpp

Issue 2334403002: Construct cc scroll tree from blink [spv2] (Closed)
Patch Set: Fix horizontal scroll direction Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositor.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositor.cpp b/third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositor.cpp
index 5a94eac8308d9986e88965a9f25243733b548e52..5cf2e4ee659a4ce257d9e676148f62a88ac70702 100644
--- a/third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositor.cpp
+++ b/third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositor.cpp
@@ -15,6 +15,7 @@
#include "cc/trees/effect_node.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/property_tree.h"
+#include "cc/trees/scroll_node.h"
#include "cc/trees/transform_node.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/graphics/paint/ClipPaintPropertyNode.h"
@@ -23,6 +24,7 @@
#include "platform/graphics/paint/ForeignLayerDisplayItem.h"
#include "platform/graphics/paint/PaintArtifact.h"
#include "platform/graphics/paint/PropertyTreeState.h"
+#include "platform/graphics/paint/ScrollPaintPropertyNode.h"
#include "platform/graphics/paint/TransformPaintPropertyNode.h"
#include "public/platform/Platform.h"
#include "public/platform/WebCompositorSupport.h"
@@ -175,6 +177,10 @@ void setMinimalPropertyTrees(cc::PropertyTrees* propertyTrees, int ownerId)
cc::ScrollTree& scrollTree = propertyTrees->scroll_tree;
scrollTree.clear();
+ cc::ScrollNode& scrollNode = *scrollTree.Node(scrollTree.Insert(cc::ScrollNode(), kRealRootNodeId));
+ DCHECK_EQ(scrollNode.id, kSecondaryRootNodeId);
+ scrollNode.owner_id = ownerId;
+ scrollNode.transform_id = kRealRootNodeId;
}
} // namespace
@@ -225,6 +231,10 @@ public:
int compositorIdForClipNode(const ClipPaintPropertyNode*);
int switchToEffectNode(const EffectPaintPropertyNode& nextEffect);
int compositorIdForCurrentEffectNode() const { return m_effectStack.last().id; }
+ int compositorIdForScrollNode(const ScrollPaintPropertyNode*);
+
+ // Scroll offset has special treatment in the transform and scroll trees.
+ void updateScrollOffset(int layerId, int scrollId);
private:
void buildEffectNodesRecursively(const EffectPaintPropertyNode* nextEffect);
@@ -232,6 +242,7 @@ private:
cc::TransformTree& transformTree() { return m_propertyTrees.transform_tree; }
cc::ClipTree& clipTree() { return m_propertyTrees.clip_tree; }
cc::EffectTree& effectTree() { return m_propertyTrees.effect_tree; }
+ cc::ScrollTree& scrollTree() { return m_propertyTrees.scroll_tree; }
const EffectPaintPropertyNode* currentEffectNode() const { return m_effectStack.last().effect; }
@@ -245,6 +256,7 @@ private:
// Maps from Blink-side property tree nodes to cc property node indices.
HashMap<const TransformPaintPropertyNode*, int> m_transformNodeMap;
HashMap<const ClipPaintPropertyNode*, int> m_clipNodeMap;
+ HashMap<const ScrollPaintPropertyNode*, int> m_scrollNodeMap;
struct BlinkEffectAndCcIdPair {
const EffectPaintPropertyNode* effect;
@@ -342,6 +354,55 @@ int PropertyTreeManager::compositorIdForClipNode(const ClipPaintPropertyNode* cl
return id;
}
+int PropertyTreeManager::compositorIdForScrollNode(const ScrollPaintPropertyNode* scrollNode)
+{
+ if (!scrollNode)
+ return kSecondaryRootNodeId;
+
+ auto it = m_scrollNodeMap.find(scrollNode);
+ if (it != m_scrollNodeMap.end())
+ return it->value;
+
+ int parentId = compositorIdForScrollNode(scrollNode->parent());
+ int id = scrollTree().Insert(cc::ScrollNode(), parentId);
+
+ cc::ScrollNode& compositorNode = *scrollTree().Node(id);
+ compositorNode.owner_id = parentId;
+
+ compositorNode.scrollable = true;
+
+ // TODO(pdr): Set main thread scrolling reasons.
+ compositorNode.scroll_clip_layer_bounds.SetSize(scrollNode->clip().width(), scrollNode->clip().height());
+ compositorNode.bounds.SetSize(scrollNode->bounds().width(), scrollNode->bounds().height());
+ compositorNode.user_scrollable_horizontal = scrollNode->userScrollableHorizontal();
+ compositorNode.user_scrollable_vertical = scrollNode->userScrollableVertical();
+ compositorNode.transform_id = compositorIdForTransformNode(scrollNode->scrollOffsetTranslation());
+
+ auto result = m_scrollNodeMap.set(scrollNode, id);
+ DCHECK(result.isNewEntry);
+ scrollTree().set_needs_update(true);
+
+ return id;
+}
+
+void PropertyTreeManager::updateScrollOffset(int layerId, int scrollId)
+{
+ cc::ScrollNode& scrollNode = *scrollTree().Node(scrollId);
+ cc::TransformNode& transformNode = *transformTree().Node(scrollNode.transform_id);
+
+ transformNode.scrolls = true;
+
+ // Blink creates a 2d transform node just for scroll offset whereas cc's
+ // transform node has a special scroll offset field. To handle this we
+ // adjust cc's transform node to remove the 2d scroll translation and
+ // let the cc scroll tree update the cc scroll offset.
+ DCHECK(transformNode.local.IsIdentityOr2DTranslation());
+ auto offset = transformNode.local.To2dTranslation();
+ transformNode.local.MakeIdentity();
+ scrollTree().SetScrollOffset(layerId, gfx::ScrollOffset(-offset.x(), -offset.y()));
+ scrollTree().set_needs_update(true);
+}
+
unsigned depth(const EffectPaintPropertyNode* node)
{
unsigned result = 0;
@@ -461,9 +522,12 @@ void PaintArtifactCompositor::update(const PaintArtifact& paintArtifact)
scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paintChunk, layerOffset);
int transformId = propertyTreeManager.compositorIdForTransformNode(paintChunk.properties.transform.get());
+ int scrollId = propertyTreeManager.compositorIdForScrollNode(paintChunk.properties.scroll.get());
int clipId = propertyTreeManager.compositorIdForClipNode(paintChunk.properties.clip.get());
int effectId = propertyTreeManager.switchToEffectNode(*paintChunk.properties.effect.get());
+ propertyTreeManager.updateScrollOffset(layer->id(), scrollId);
+
layer->set_offset_to_transform_parent(layerOffset);
m_rootLayer->AddChild(layer);
@@ -471,7 +535,7 @@ void PaintArtifactCompositor::update(const PaintArtifact& paintArtifact)
layer->SetTransformTreeIndex(transformId);
layer->SetClipTreeIndex(clipId);
layer->SetEffectTreeIndex(effectId);
- layer->SetScrollTreeIndex(kRealRootNodeId);
+ layer->SetScrollTreeIndex(scrollId);
// TODO(jbroman): This probably shouldn't be necessary, but it is still
// queried by RenderSurfaceImpl.
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698