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

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

Issue 2299533002: WIP: Construct SPV2's scroll paint property tree (Closed)
Patch Set: Add more paint property builder tests, update comments/documentation" 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
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 8e811bf0f93badfb6929d77332b80e14d94905fa..3ff0fcb4748b1ee10fc081f18cf670978638ddab 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
@@ -222,6 +228,16 @@ public:
int compositorIdForClipNode(const ClipPaintPropertyNode*);
int switchToEffectNode(const EffectPaintPropertyNode& nextEffect);
int compositorIdForCurrentEffectNode() const { return m_effectStack.last().id; }
+ int compositorIdForScrollNode(const ScrollPaintPropertyNode*);
+ bool compositorIdExistsForScrollNode(const ScrollPaintPropertyNode* scrollNode)
+ {
+ return m_scrollNodeMap.contains(scrollNode);
+ }
+
+ // Scroll offset has special treatment in the compositor and needs an
+ // adjustment to the transform node (to switch from a transform to a scroll
+ // offset) as well as an update to the ScrollTree scroll offset.
+ void updateScrollOffset(int layerId, int scrollId);
private:
void buildEffectNodesRecursively(const EffectPaintPropertyNode* nextEffect);
@@ -229,6 +245,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; }
@@ -242,6 +259,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;
@@ -333,6 +351,63 @@ 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;
+
+ // TODO(pdr): Set scrollable properly.
+ compositorNode.scrollable = true;
+
+ // TODO(pdr): Set main thread scrolling reasons.
+ IntSize snappedClip = roundedIntSize(scrollNode->clip());
+ compositorNode.scroll_clip_layer_bounds.SetSize(snappedClip.width(), snappedClip.height());
+ IntSize snappedBounds = roundedIntSize(scrollNode->bounds());
+ compositorNode.scroll_clip_layer_bounds.SetSize(snappedBounds.width(), snappedBounds.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);
+
+ // The transform associated with a scroll should only contain a 2d scroll offset.
+ DCHECK(transformNode.local.IsIdentityOr2DTranslation());
+
+ // TODO(pdr): Set the transform node's scrollable bit from scrollNode.
+
+ auto scrollOffsetVector = transformNode.local.To2dTranslation();
+
+ // Remove the 2d scroll translation set from blink's transform paint property
+ // node.
+ transformNode.local.MakeIdentity();
+
+ gfx::ScrollOffset scrollOffset(scrollOffsetVector.x(), -scrollOffsetVector.y());
+ scrollTree().SetScrollOffset(layerId, scrollOffset);
+
+ // TODO(pdr): Is this needed or can we rely on SetScrollOffset handling it?
+ transformNode.scroll_offset = scrollOffset;
+}
+
unsigned depth(const EffectPaintPropertyNode* node)
{
unsigned result = 0;
@@ -449,9 +524,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);
@@ -459,7 +537,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.

Powered by Google App Engine
This is Rietveld 408576698