Commit 140a4bab authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[BGPT] Optimize blink -> cc transform conversion

- For scroll offset translation, set cc::TransformNode::scroll_offset
  directly instead of setting cc::TransformNode::local then clearing it
  and setting scroll_offset.

- Avoiding TransformPaintPropertyNode::SlowMatrix().

Bug: 954520
Change-Id: I14ceeb938c915e8f8b382568ec96496c317634c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1594172Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#656470}
parent 65322165
...@@ -112,11 +112,9 @@ bool PropertyTreeManager::DirectlyUpdateScrollOffsetTransform( ...@@ -112,11 +112,9 @@ bool PropertyTreeManager::DirectlyUpdateScrollOffsetTransform(
DCHECK(!cc_transform->is_currently_animating); DCHECK(!cc_transform->is_currently_animating);
UpdateCcTransformLocalMatrix(*cc_transform, transform); UpdateCcTransformLocalMatrix(*cc_transform, transform);
SetCcTransformNodeScrollToTransformTranslation(*cc_transform, transform);
property_trees->scroll_tree.SetScrollOffset( property_trees->scroll_tree.SetScrollOffset(
scroll_node->GetCompositorElementId(), cc_transform->scroll_offset); scroll_node->GetCompositorElementId(), cc_transform->scroll_offset);
cc_transform->transform_changed = true;
property_trees->transform_tree.set_needs_update(true); property_trees->transform_tree.set_needs_update(true);
property_trees->scroll_tree.set_needs_update(true); property_trees->scroll_tree.set_needs_update(true);
return true; return true;
...@@ -141,7 +139,6 @@ bool PropertyTreeManager::DirectlyUpdateTransform( ...@@ -141,7 +139,6 @@ bool PropertyTreeManager::DirectlyUpdateTransform(
// flag, we should clear it to let the compositor respect the new value. // flag, we should clear it to let the compositor respect the new value.
cc_transform->is_currently_animating = false; cc_transform->is_currently_animating = false;
cc_transform->transform_changed = true;
property_trees->transform_tree.set_needs_update(true); property_trees->transform_tree.set_needs_update(true);
return true; return true;
} }
...@@ -158,7 +155,6 @@ bool PropertyTreeManager::DirectlyUpdatePageScaleTransform( ...@@ -158,7 +155,6 @@ bool PropertyTreeManager::DirectlyUpdatePageScaleTransform(
UpdateCcTransformLocalMatrix(*cc_transform, transform); UpdateCcTransformLocalMatrix(*cc_transform, transform);
AdjustPageScaleToUsePostLocal(*cc_transform); AdjustPageScaleToUsePostLocal(*cc_transform);
cc_transform->transform_changed = true;
SetTransformTreePageScaleFactor(&property_trees->transform_tree, SetTransformTreePageScaleFactor(&property_trees->transform_tree,
cc_transform); cc_transform);
...@@ -351,7 +347,6 @@ int PropertyTreeManager::EnsureCompositorTransformNode( ...@@ -351,7 +347,6 @@ int PropertyTreeManager::EnsureCompositorTransformNode(
compositor_node.source_node_id = parent_id; compositor_node.source_node_id = parent_id;
UpdateCcTransformLocalMatrix(compositor_node, transform_node); UpdateCcTransformLocalMatrix(compositor_node, transform_node);
compositor_node.transform_changed = true;
compositor_node.flattens_inherited_transform = compositor_node.flattens_inherited_transform =
transform_node.FlattensInheritedTransform(); transform_node.FlattensInheritedTransform();
compositor_node.sorting_context_id = transform_node.RenderingContextId(); compositor_node.sorting_context_id = transform_node.RenderingContextId();
...@@ -402,12 +397,8 @@ int PropertyTreeManager::EnsureCompositorTransformNode( ...@@ -402,12 +397,8 @@ int PropertyTreeManager::EnsureCompositorTransformNode(
// compositor scroll property node and adjust the compositor transform node's // compositor scroll property node and adjust the compositor transform node's
// scroll offset. // scroll offset.
if (auto* scroll_node = transform_node.ScrollNode()) { if (auto* scroll_node = transform_node.ScrollNode()) {
// Blink creates a 2d transform node just for scroll offset whereas cc's compositor_node.scrolls = true;
// transform node has a special scroll offset field. To handle this we compositor_node.should_be_snapped = true;
// adjust cc's transform node to remove the 2d scroll translation and
// instead set the scroll_offset field.
SetCcTransformNodeScrollToTransformTranslation(compositor_node,
transform_node);
CreateCompositorScrollNode(*scroll_node, compositor_node); CreateCompositorScrollNode(*scroll_node, compositor_node);
} }
...@@ -434,33 +425,43 @@ int PropertyTreeManager::EnsureCompositorTransformNode( ...@@ -434,33 +425,43 @@ int PropertyTreeManager::EnsureCompositorTransformNode(
void PropertyTreeManager::UpdateCcTransformLocalMatrix( void PropertyTreeManager::UpdateCcTransformLocalMatrix(
cc::TransformNode& compositor_node, cc::TransformNode& compositor_node,
const TransformPaintPropertyNode& transform_node) { const TransformPaintPropertyNode& transform_node) {
FloatPoint3D origin = transform_node.Origin(); if (transform_node.GetStickyConstraint()) {
compositor_node.pre_local.matrix().setTranslate(-origin.X(), -origin.Y(), // The sticky offset on the blink transform node is pre-computed and stored
-origin.Z()); // to the local matrix. Cc applies sticky offset dynamically on top of the
// The sticky offset on the blink transform node is pre-computed and stored // local matrix. We should not set the local matrix on cc node if it is a
// to the local matrix. Cc applies sticky offset dynamically on top of the // sticky node because the sticky offset would be applied twice otherwise.
// local matrix. We should not set the local matrix on cc node if it is a DCHECK(compositor_node.local.IsIdentity());
// sticky node because the sticky offset would be applied twice otherwise. DCHECK(compositor_node.pre_local.IsIdentity());
if (!transform_node.GetStickyConstraint()) { DCHECK(compositor_node.post_local.IsIdentity());
} else if (transform_node.IsIdentityOr2DTranslation()) {
auto translation = transform_node.Translation2D();
if (transform_node.ScrollNode()) {
// Blink creates a 2d transform node just for scroll offset whereas cc's
// transform node has a special scroll offset field.
compositor_node.scroll_offset =
gfx::ScrollOffset(-translation.Width(), -translation.Height());
DCHECK(compositor_node.local.IsIdentity());
DCHECK(compositor_node.pre_local.IsIdentity());
DCHECK(compositor_node.post_local.IsIdentity());
} else {
compositor_node.local.matrix().setTranslate(translation.Width(),
translation.Height(), 0);
DCHECK_EQ(FloatPoint3D(), transform_node.Origin());
compositor_node.pre_local.matrix().setIdentity();
compositor_node.post_local.matrix().setIdentity();
}
} else {
DCHECK(!transform_node.ScrollNode());
FloatPoint3D origin = transform_node.Origin();
compositor_node.pre_local.matrix().setTranslate(-origin.X(), -origin.Y(),
-origin.Z());
compositor_node.local.matrix() = compositor_node.local.matrix() =
TransformationMatrix::ToSkMatrix44(transform_node.SlowMatrix()); TransformationMatrix::ToSkMatrix44(transform_node.Matrix());
compositor_node.post_local.matrix().setTranslate(origin.X(), origin.Y(),
origin.Z());
} }
compositor_node.post_local.matrix().setTranslate(origin.X(), origin.Y(),
origin.Z());
compositor_node.needs_local_transform_update = true; compositor_node.needs_local_transform_update = true;
} compositor_node.transform_changed = true;
void PropertyTreeManager::SetCcTransformNodeScrollToTransformTranslation(
cc::TransformNode& cc_transform,
const TransformPaintPropertyNode& transform) {
auto scroll_offset_size = transform.Translation2D();
auto scroll_offset = gfx::ScrollOffset(-scroll_offset_size.Width(),
-scroll_offset_size.Height());
DCHECK(cc_transform.local.IsIdentityOr2DTranslation());
cc_transform.scroll_offset = scroll_offset;
cc_transform.local.MakeIdentity();
cc_transform.scrolls = true;
cc_transform.should_be_snapped = true;
} }
int PropertyTreeManager::EnsureCompositorPageScaleTransformNode( int PropertyTreeManager::EnsureCompositorPageScaleTransformNode(
...@@ -470,7 +471,6 @@ int PropertyTreeManager::EnsureCompositorPageScaleTransformNode( ...@@ -470,7 +471,6 @@ int PropertyTreeManager::EnsureCompositorPageScaleTransformNode(
DCHECK(GetTransformTree().Node(id)); DCHECK(GetTransformTree().Node(id));
cc::TransformNode& compositor_node = *GetTransformTree().Node(id); cc::TransformNode& compositor_node = *GetTransformTree().Node(id);
AdjustPageScaleToUsePostLocal(compositor_node); AdjustPageScaleToUsePostLocal(compositor_node);
compositor_node.transform_changed = true;
SetTransformTreePageScaleFactor(&GetTransformTree(), &compositor_node); SetTransformTreePageScaleFactor(&GetTransformTree(), &compositor_node);
GetTransformTree().set_needs_update(true); GetTransformTree().set_needs_update(true);
...@@ -487,6 +487,7 @@ void PropertyTreeManager::AdjustPageScaleToUsePostLocal( ...@@ -487,6 +487,7 @@ void PropertyTreeManager::AdjustPageScaleToUsePostLocal(
page_scale.post_local.matrix() = page_scale.local.matrix(); page_scale.post_local.matrix() = page_scale.local.matrix();
page_scale.pre_local.matrix().setIdentity(); page_scale.pre_local.matrix().setIdentity();
page_scale.local.matrix().setIdentity(); page_scale.local.matrix().setIdentity();
page_scale.transform_changed = true;
} }
void PropertyTreeManager::SetTransformTreePageScaleFactor( void PropertyTreeManager::SetTransformTreePageScaleFactor(
......
...@@ -166,13 +166,6 @@ class PropertyTreeManager { ...@@ -166,13 +166,6 @@ class PropertyTreeManager {
// scale node. // scale node.
void SetTransformTreePageScaleFactor(cc::TransformTree*, void SetTransformTreePageScaleFactor(cc::TransformTree*,
cc::TransformNode* page_scale_node); cc::TransformNode* page_scale_node);
// Move the local translation into the scroll_offset field of the compositor
// transform node. The compositor uses a speical scroll_offset field instead
// of the local matrix for scroll nodes, whereas
// blink::TransformPaintPropertyNode represents this as a 2d translation.
void SetCcTransformNodeScrollToTransformTranslation(
cc::TransformNode&,
const TransformPaintPropertyNode&);
bool IsCurrentCcEffectSynthetic() const { return current_.effect_type; } bool IsCurrentCcEffectSynthetic() const { return current_.effect_type; }
bool IsCurrentCcEffectSyntheticForNonTrivialClip() const { bool IsCurrentCcEffectSyntheticForNonTrivialClip() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment