Commit 7df39b2d authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[BGPT] More presice detection of 2d-axis alignment change

The new condition is the same as cc::PropertyTreeBuilder.
This avoids unnecessary PAC::Update in js_poster_circle benchmark.

Bug: 954520
Change-Id: Ib547c828d4dee7e97fe8e72e2ed69f7a2545d63c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1597209
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657445}
parent 5695de7e
......@@ -114,6 +114,11 @@ class PaintPropertyNodeTest : public testing::Test {
ExpectUnchangedState(effect);
}
template <typename NodeType>
PaintPropertyChangeType NodeChanged(const NodeType& node) {
return node.NodeChanged();
}
Tree<TransformPaintPropertyNode> transform;
Tree<ClipPaintPropertyNode> clip;
Tree<EffectPaintPropertyNode> effect;
......@@ -612,4 +617,52 @@ TEST_F(PaintPropertyNodeTest, EffectLocalTransformSpaceChange) {
ExpectUnchangedState();
}
TEST_F(PaintPropertyNodeTest, TransformChange2dAxisAlignment) {
auto t = Create2DTranslation(t0(), 10, 20);
EXPECT_EQ(PaintPropertyChangeType::kNodeAddedOrRemoved, NodeChanged(*t));
t->ClearChangedToRoot();
EXPECT_EQ(PaintPropertyChangeType::kUnchanged, NodeChanged(*t));
// Translation doesn't affect 2d axis alignment.
t->Update(t0(), TransformPaintPropertyNode::State{FloatSize(30, 40)});
EXPECT_EQ(PaintPropertyChangeType::kChangedOnlySimpleValues, NodeChanged(*t));
t->ClearChangedToRoot();
EXPECT_EQ(PaintPropertyChangeType::kUnchanged, NodeChanged(*t));
// Scale doesn't affect 2d axis alignment.
t->Update(t0(), TransformPaintPropertyNode::State{
TransformationMatrix().Scale3d(2, 3, 4)});
EXPECT_EQ(PaintPropertyChangeType::kChangedOnlySimpleValues, NodeChanged(*t));
t->ClearChangedToRoot();
EXPECT_EQ(PaintPropertyChangeType::kUnchanged, NodeChanged(*t));
// Rotation affects 2d axis alignment.
t->Update(t0(), TransformPaintPropertyNode::State{
TransformationMatrix(t->Matrix()).Rotate(45)});
EXPECT_EQ(PaintPropertyChangeType::kChangedOnlyValues, NodeChanged(*t));
t->ClearChangedToRoot();
EXPECT_EQ(PaintPropertyChangeType::kUnchanged, NodeChanged(*t));
// Changing scale but keeping original rotation doesn't change 2d axis
// alignment and is treated as simple.
t->Update(t0(), TransformPaintPropertyNode::State{
TransformationMatrix(t->Matrix()).Scale3d(3, 4, 5)});
EXPECT_EQ(PaintPropertyChangeType::kChangedOnlySimpleValues, NodeChanged(*t));
t->ClearChangedToRoot();
EXPECT_EQ(PaintPropertyChangeType::kUnchanged, NodeChanged(*t));
// Change rotation rotation again changes 2d axis alignment.
t->Update(t0(), TransformPaintPropertyNode::State{
TransformationMatrix(t->Matrix()).Rotate(10)});
EXPECT_EQ(PaintPropertyChangeType::kChangedOnlyValues, NodeChanged(*t));
t->ClearChangedToRoot();
EXPECT_EQ(PaintPropertyChangeType::kUnchanged, NodeChanged(*t));
// Reset the transform back to simple translation changes 2d axis alignment.
t->Update(t0(), TransformPaintPropertyNode::State{FloatSize(1, 2)});
EXPECT_EQ(PaintPropertyChangeType::kChangedOnlyValues, NodeChanged(*t));
t->ClearChangedToRoot();
EXPECT_EQ(PaintPropertyChangeType::kUnchanged, NodeChanged(*t));
}
} // namespace blink
......@@ -95,6 +95,17 @@ class PLATFORM_EXPORT TransformPaintPropertyNode
matrix_and_origin_->matrix == other.matrix_and_origin_->matrix));
}
bool ChangePreserves2dAxisAlignment(const TransformAndOrigin& other) const {
if (IsIdentityOr2DTranslation() && other.IsIdentityOr2DTranslation())
return true;
if (IsIdentityOr2DTranslation())
return other.Matrix().Preserves2dAxisAlignment();
if (other.IsIdentityOr2DTranslation())
return Matrix().Preserves2dAxisAlignment();
// TODO(crbug.com/960481): Consider more rare corner cases.
return (Matrix().Inverse() * other.Matrix()).Preserves2dAxisAlignment();
}
private:
struct MatrixAndOrigin {
TransformationMatrix matrix;
......@@ -148,19 +159,15 @@ class PLATFORM_EXPORT TransformPaintPropertyNode
transform_has_simple_change = false;
} else if (animation_state.is_running_animation_on_compositor) {
transform_has_simple_change = false;
} else if (matrix_changed) {
} else if (matrix_changed &&
!transform_and_origin.ChangePreserves2dAxisAlignment(
other.transform_and_origin)) {
// An additional cc::EffectNode may be required if
// blink::TransformPaintPropertyNode is not axis-aligned (see:
// PropertyTreeManager::NeedsSyntheticEffect). Changes to axis alignment
// are therefore treated as non-simple. By ensuring both |this| and
// |other| preserve axis alignment, this check is more conservative than
// PropertyTreeManager. We do not need to set
// transform_has_simple_change = false if the origin changes because
// axis alignment is not affected by transform origin.
if (!TransformPreservesAxisAlignment(transform_and_origin) ||
!TransformPreservesAxisAlignment(other.transform_and_origin)) {
transform_has_simple_change = false;
}
// are therefore treated as non-simple. We do not need to check origin
// because axis alignment is not affected by transform origin.
transform_has_simple_change = false;
}
// If the transform changed, and it's not simple then we need to report
......@@ -196,15 +203,6 @@ class PLATFORM_EXPORT TransformPaintPropertyNode
return sticky_constraint && other.sticky_constraint &&
*sticky_constraint == *other.sticky_constraint;
}
private:
// Returns true if the given transform preserves axis alignment.
static bool TransformPreservesAxisAlignment(
const TransformAndOrigin& transform) {
return transform.IsIdentityOr2DTranslation() ||
(transform.Matrix().Is2dTransform() &&
transform.Matrix().Preserves2dAxisAlignment());
}
};
// This node is really a sentinel, and does not represent a real transform
......
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