Commit ee4a161f authored by George Steel's avatar George Steel Committed by Commit Bot

Make TransformOperations::DependsOnBoxSize return which dependencies

This is to prepare for using DependsOnBoxSize for invalidation of
compositor animations, allowing width and height changes to be
propagated separately. This is to enable acceleration of percent-
containing transform. See design doc
https://docs.google.com/document/d/1zgr5CHRMpvlqodn1e0eM9J3MjL2eEMfAHrHsZUK7gMM/

Bug: 389359
Change-Id: I2bf30bdd51b048bc6f1d330e4159c72c36a5f5ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422088Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Reviewed-by: default avatarKevin Ellis <kevers@chromium.org>
Commit-Queue: George Steel <gtsteel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814299}
parent 95d24127
......@@ -76,9 +76,9 @@ class PLATFORM_EXPORT InterpolatedTransformOperation final
return from_.PreservesAxisAlignment() && to_.PreservesAxisAlignment();
}
bool DependsOnBoxSize() const override {
return from_.DependsOnBoxSize(starting_index_) ||
to_.DependsOnBoxSize(starting_index_);
BoxSizeDependency DependsOnBoxSize() const override {
return CombineDependencies(from_.DependsOnBoxSize(starting_index_),
to_.DependsOnBoxSize(starting_index_));
}
InterpolatedTransformOperation(const TransformOperations& from,
......
......@@ -109,7 +109,18 @@ class PLATFORM_EXPORT TransformOperation
virtual bool HasNonTrivial3DComponent() const { return Is3DOperation(); }
virtual bool DependsOnBoxSize() const { return false; }
enum BoxSizeDependency {
kDependsNone = 0,
kDependsWidth = 0x01,
kDependsHeight = 0x02,
kDependsBoth = kDependsWidth | kDependsHeight
};
virtual BoxSizeDependency DependsOnBoxSize() const { return kDependsNone; }
static inline BoxSizeDependency CombineDependencies(BoxSizeDependency a,
BoxSizeDependency b) {
return static_cast<BoxSizeDependency>(a | b);
}
private:
DISALLOW_COPY_AND_ASSIGN(TransformOperation);
......
......@@ -93,6 +93,16 @@ void TransformOperations::ApplyRemaining(const FloatSize& border_box_size,
}
}
TransformOperation::BoxSizeDependency TransformOperations::DependsOnBoxSize(
wtf_size_t start) const {
TransformOperation::BoxSizeDependency deps = TransformOperation::kDependsNone;
for (wtf_size_t i = start; i < operations_.size(); i++) {
deps = TransformOperation::CombineDependencies(
deps, operations_[i]->DependsOnBoxSize());
}
return deps;
}
wtf_size_t TransformOperations::MatchingPrefixLength(
const TransformOperations& other) const {
wtf_size_t num_operations =
......
......@@ -109,13 +109,8 @@ class PLATFORM_EXPORT TransformOperations {
return false;
}
bool DependsOnBoxSize(wtf_size_t skip_prefix = 0) const {
for (wtf_size_t i = skip_prefix; i < operations_.size(); i++) {
if (operations_[i]->DependsOnBoxSize())
return true;
}
return false;
}
TransformOperation::BoxSizeDependency DependsOnBoxSize(
wtf_size_t start = 0) const;
wtf_size_t MatchingPrefixLength(const TransformOperations&) const;
......
......@@ -659,6 +659,7 @@ TEST(TransformOperationsTest, InterpolatedTransformBlendIdentityTest) {
TransformOperations ops_c = ops_a.Blend(ops_b, 0.5);
ASSERT_EQ(ops_c.Operations().size(), 1u);
ASSERT_TRUE(IsA<InterpolatedTransformOperation>(*ops_c.Operations()[0]));
EXPECT_EQ(ops_c.DependsOnBoxSize(), TransformOperation::kDependsWidth);
// Both should be the same and equal to translateX(12.5%) rotate(11.25deg);
TransformOperations ops_d1 = ops_c.Blend(ops_empty, 0.25);
......@@ -693,13 +694,13 @@ TEST(TransformOperationsTest, BlendPercentPrefixTest) {
ops_b.Operations().push_back(
ScaleTransformOperation::Create(2, 2, TransformOperation::kScale));
EXPECT_TRUE(ops_a.DependsOnBoxSize());
EXPECT_FALSE(ops_a.DependsOnBoxSize(1));
EXPECT_TRUE(ops_b.DependsOnBoxSize());
EXPECT_FALSE(ops_b.DependsOnBoxSize(1));
EXPECT_EQ(ops_a.DependsOnBoxSize(), TransformOperation::kDependsWidth);
EXPECT_EQ(ops_a.DependsOnBoxSize(1), TransformOperation::kDependsNone);
EXPECT_EQ(ops_b.DependsOnBoxSize(), TransformOperation::kDependsHeight);
EXPECT_EQ(ops_b.DependsOnBoxSize(1), TransformOperation::kDependsNone);
TransformOperations ops_c = ops_a.Blend(ops_b, 0.5);
EXPECT_TRUE(ops_c.DependsOnBoxSize());
EXPECT_EQ(ops_c.DependsOnBoxSize(), TransformOperation::kDependsBoth);
ASSERT_EQ(ops_c.Operations().size(), 2u);
ASSERT_TRUE(IsA<TranslateTransformOperation>(*ops_c.Operations()[0]));
......@@ -718,4 +719,21 @@ TEST(TransformOperationsTest, BlendPercentPrefixTest) {
EXPECT_TRANSFORMATION_MATRIX(mat_c, matrix_ref);
}
TEST(TransformOperationsTest, SizeDependenciesCombineTest) {
TransformOperations ops;
ops.Operations().push_back(
RotateTransformOperation::Create(90, TransformOperation::kRotate));
EXPECT_EQ(ops.DependsOnBoxSize(), TransformOperation::kDependsNone);
ops.Operations().push_back(TranslateTransformOperation::Create(
Length::Fixed(0), Length::Percent(50), TransformOperation::kTranslate));
EXPECT_EQ(ops.DependsOnBoxSize(), TransformOperation::kDependsHeight);
ops.Operations().push_back(TranslateTransformOperation::Create(
Length::Percent(100), Length::Fixed(0), TransformOperation::kTranslate));
EXPECT_EQ(ops.Operations()[2]->DependsOnBoxSize(),
TransformOperation::kDependsWidth);
EXPECT_EQ(ops.DependsOnBoxSize(), TransformOperation::kDependsBoth);
}
} // namespace blink
......@@ -52,8 +52,10 @@ class PLATFORM_EXPORT TranslateTransformOperation final
return *this == static_cast<const TransformOperation&>(other);
}
bool DependsOnBoxSize() const override {
return x_.IsPercentOrCalc() || y_.IsPercentOrCalc();
BoxSizeDependency DependsOnBoxSize() const override {
return CombineDependencies(
(x_.IsPercentOrCalc() ? kDependsWidth : kDependsNone),
(y_.IsPercentOrCalc() ? kDependsHeight : kDependsNone));
}
double X(const FloatSize& border_box_size) 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