diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/platform/graphics/paint/cull_rect_test.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/platform/graphics/paint/cull_rect_test.cc | 402 |
1 files changed, 265 insertions, 137 deletions
diff --git a/chromium/third_party/blink/renderer/platform/graphics/paint/cull_rect_test.cc b/chromium/third_party/blink/renderer/platform/graphics/paint/cull_rect_test.cc index c381bd3ea5f..be468e895f6 100644 --- a/chromium/third_party/blink/renderer/platform/graphics/paint/cull_rect_test.cc +++ b/chromium/third_party/blink/renderer/platform/graphics/paint/cull_rect_test.cc @@ -21,14 +21,27 @@ class CullRectTest : public testing::Test { const CullRect::ApplyTransformResult kExpandedForWholeScrollingContents = CullRect::kExpandedForWholeScrollingContents; - CullRect::ApplyTransformResult ApplyTransform( + // Tests only transforms without clips. + void ApplyTransforms(CullRect& cull_rect, + const TransformPaintPropertyNode& source, + const TransformPaintPropertyNode& destination, + const base::Optional<CullRect>& old_cull_rect) { + PropertyTreeState source_state(source, c0(), e0()); + PropertyTreeState destination_state(destination, c0(), e0()); + cull_rect.ApplyPaintProperties(PropertyTreeState::Root(), source_state, + destination_state, old_cull_rect); + } + + CullRect::ApplyTransformResult ApplyScrollTranslation( CullRect& cull_rect, const TransformPaintPropertyNode& t) { - return cull_rect.ApplyTransformInternal(t); + return cull_rect.ApplyScrollTranslation(t, t); } - bool ChangedEnough(const IntRect& old_rect, const IntRect& new_rect) { - return CullRect(new_rect).ChangedEnough(CullRect(old_rect)); + bool ChangedEnough(const IntRect& old_rect, + const IntRect& new_rect, + const IntSize* bounds = nullptr) { + return CullRect(new_rect).ChangedEnough(CullRect(old_rect), bounds); } }; @@ -91,7 +104,7 @@ TEST_F(CullRectTest, ApplyTransform) { CullRect cull_rect(IntRect(1, 1, 50, 50)); auto transform = CreateTransform(t0(), TransformationMatrix().Translate(1, 1)); - EXPECT_EQ(kNotExpanded, ApplyTransform(cull_rect, *transform)); + cull_rect.ApplyTransform(*transform); EXPECT_EQ(IntRect(0, 0, 50, 50), cull_rect.Rect()); } @@ -100,13 +113,12 @@ TEST_F(CullRectTest, ApplyTransformInfinite) { CullRect cull_rect = CullRect::Infinite(); auto transform = CreateTransform(t0(), TransformationMatrix().Translate(1, 1)); - EXPECT_EQ(kNotExpanded, ApplyTransform(cull_rect, *transform)); - + cull_rect.ApplyTransform(*transform); EXPECT_TRUE(cull_rect.IsInfinite()); } TEST_F(CullRectTest, ApplyScrollTranslationPartialScrollingContents) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); ScrollPaintPropertyNode::State scroll_state; scroll_state.container_rect = IntRect(20, 10, 40, 50); @@ -118,24 +130,25 @@ TEST_F(CullRectTest, ApplyScrollTranslationPartialScrollingContents) { CullRect cull_rect(IntRect(0, 0, 50, 100)); EXPECT_EQ(kExpandedForPartialScrollingContents, - ApplyTransform(cull_rect, *scroll_translation)); + ApplyScrollTranslation(cull_rect, *scroll_translation)); // Clipped: (20, 10, 30, 50) // Inverse transformed: (3020, 5010, 30, 50) // Expanded: (-980, 1010, 8030, 8050) - EXPECT_EQ(IntRect(-980, 1010, 8030, 8050), cull_rect.Rect()); + // Then clipped by the contents rect. + EXPECT_EQ(IntRect(0, 1010, 7050, 6990), cull_rect.Rect()); cull_rect = CullRect::Infinite(); EXPECT_EQ(kExpandedForPartialScrollingContents, - ApplyTransform(cull_rect, *scroll_translation)); - // This result differs from the above result in height (8040 vs 8030) + ApplyScrollTranslation(cull_rect, *scroll_translation)); + // This result differs from the above result in height (7050 vs 7060) // because it's not clipped by the infinite input cull rect. - EXPECT_EQ(IntRect(-980, 1010, 8040, 8050), cull_rect.Rect()); + EXPECT_EQ(IntRect(0, 1010, 7060, 6990), cull_rect.Rect()); } TEST_F(CullRectTest, ApplyNonCompositedScrollTranslationPartialScrollingContents) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); ScrollPaintPropertyNode::State scroll_state; scroll_state.container_rect = IntRect(20, 10, 40, 50); @@ -146,21 +159,23 @@ TEST_F(CullRectTest, CreateScrollTranslation(t0(), -3000, -5000, *scroll); CullRect cull_rect(IntRect(0, 0, 50, 100)); - EXPECT_EQ(kNotExpanded, ApplyTransform(cull_rect, *scroll_translation)); + EXPECT_EQ(kNotExpanded, + ApplyScrollTranslation(cull_rect, *scroll_translation)); // Clipped: (20, 10, 30, 50) // Inverse transformed: (3020, 5010, 30, 50) EXPECT_EQ(IntRect(3020, 5010, 30, 50), cull_rect.Rect()); cull_rect = CullRect::Infinite(); - EXPECT_EQ(kNotExpanded, ApplyTransform(cull_rect, *scroll_translation)); + EXPECT_EQ(kNotExpanded, + ApplyScrollTranslation(cull_rect, *scroll_translation)); // This result differs from the above result in height (40 vs 30) // because it's not clipped by the infinite input cull rect. EXPECT_EQ(IntRect(3020, 5010, 40, 50), cull_rect.Rect()); } TEST_F(CullRectTest, ApplyScrollTranslationNoIntersectionWithContainerRect) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); ScrollPaintPropertyNode::State scroll_state; scroll_state.container_rect = IntRect(200, 100, 40, 50); @@ -171,13 +186,14 @@ TEST_F(CullRectTest, ApplyScrollTranslationNoIntersectionWithContainerRect) { CreateCompositedScrollTranslation(t0(), -10, -15, *scroll); CullRect cull_rect(IntRect(0, 0, 50, 100)); - EXPECT_EQ(kNotExpanded, ApplyTransform(cull_rect, *scroll_translation)); + EXPECT_EQ(kNotExpanded, + ApplyScrollTranslation(cull_rect, *scroll_translation)); EXPECT_TRUE(cull_rect.Rect().IsEmpty()); } TEST_F(CullRectTest, ApplyNonCompositedScrollTranslationNoIntersectionWithContainerRect) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); ScrollPaintPropertyNode::State scroll_state; scroll_state.container_rect = IntRect(200, 100, 40, 50); @@ -187,12 +203,13 @@ TEST_F(CullRectTest, auto scroll_translation = CreateScrollTranslation(t0(), -10, -15, *scroll); CullRect cull_rect(IntRect(0, 0, 50, 100)); - EXPECT_EQ(kNotExpanded, ApplyTransform(cull_rect, *scroll_translation)); + EXPECT_EQ(kNotExpanded, + ApplyScrollTranslation(cull_rect, *scroll_translation)); EXPECT_TRUE(cull_rect.Rect().IsEmpty()); } TEST_F(CullRectTest, ApplyScrollTranslationWholeScrollingContents) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); ScrollPaintPropertyNode::State scroll_state; scroll_state.container_rect = IntRect(20, 10, 40, 50); @@ -204,24 +221,23 @@ TEST_F(CullRectTest, ApplyScrollTranslationWholeScrollingContents) { CullRect cull_rect(IntRect(0, 0, 50, 100)); EXPECT_EQ(kExpandedForWholeScrollingContents, - ApplyTransform(cull_rect, *scroll_translation)); + ApplyScrollTranslation(cull_rect, *scroll_translation)); // Clipped: (20, 10, 30, 50) // Inverse transformed: (30, 25, 30, 50) // Expanded: (-3970, -3975, 8030, 8050) - EXPECT_EQ(IntRect(-3970, -3975, 8030, 8050), cull_rect.Rect()); + // Then clipped by the contents rect. + EXPECT_EQ(IntRect(0, 0, 2000, 2000), cull_rect.Rect()); cull_rect = CullRect::Infinite(); EXPECT_EQ(kExpandedForWholeScrollingContents, - ApplyTransform(cull_rect, *scroll_translation)); - // This result differs from the above result in height (8040 vs 8030) - // because it's not clipped by the infinite input cull rect. - EXPECT_EQ(IntRect(-3970, -3975, 8040, 8050), cull_rect.Rect()); + ApplyScrollTranslation(cull_rect, *scroll_translation)); + EXPECT_EQ(IntRect(0, 0, 2000, 2000), cull_rect.Rect()); } TEST_F(CullRectTest, ApplyNonCompositedScrollTranslationWholeScrollingContents) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); ScrollPaintPropertyNode::State scroll_state; scroll_state.container_rect = IntRect(20, 10, 40, 50); @@ -231,21 +247,23 @@ TEST_F(CullRectTest, auto scroll_translation = CreateScrollTranslation(t0(), -10, -15, *scroll); CullRect cull_rect(IntRect(0, 0, 50, 100)); - EXPECT_EQ(kNotExpanded, ApplyTransform(cull_rect, *scroll_translation)); + EXPECT_EQ(kNotExpanded, + ApplyScrollTranslation(cull_rect, *scroll_translation)); // Clipped: (20, 10, 30, 50) // Inverse transformed: (30, 25, 30, 50) EXPECT_EQ(IntRect(30, 25, 30, 50), cull_rect.Rect()); cull_rect = CullRect::Infinite(); - EXPECT_EQ(kNotExpanded, ApplyTransform(cull_rect, *scroll_translation)); + EXPECT_EQ(kNotExpanded, + ApplyScrollTranslation(cull_rect, *scroll_translation)); // This result differs from the above result in height (40 vs 30) // because it's not clipped by the infinite input cull rect. EXPECT_EQ(IntRect(30, 25, 40, 50), cull_rect.Rect()); } TEST_F(CullRectTest, ChangedEnoughEmpty) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); EXPECT_FALSE(ChangedEnough(IntRect(), IntRect())); EXPECT_FALSE(ChangedEnough(IntRect(1, 1, 0, 0), IntRect(2, 2, 0, 0))); EXPECT_TRUE(ChangedEnough(IntRect(), IntRect(0, 0, 1, 1))); @@ -253,7 +271,7 @@ TEST_F(CullRectTest, ChangedEnoughEmpty) { } TEST_F(CullRectTest, ChangedNotEnough) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); IntRect old_rect(100, 100, 100, 100); EXPECT_FALSE(ChangedEnough(old_rect, old_rect)); EXPECT_FALSE(ChangedEnough(old_rect, IntRect(100, 100, 90, 90))); @@ -261,8 +279,8 @@ TEST_F(CullRectTest, ChangedNotEnough) { EXPECT_FALSE(ChangedEnough(old_rect, IntRect(1, 1, 200, 200))); } -TEST_F(CullRectTest, ChangedEnoughScrollScenarios) { - ScopedCompositeAfterPaintForTest cap(true); +TEST_F(CullRectTest, ChangedEnoughOnMovement) { + ScopedCullRectUpdateForTest cull_rect_update(true); IntRect old_rect(100, 100, 100, 100); IntRect new_rect(old_rect); new_rect.Move(500, 0); @@ -275,241 +293,351 @@ TEST_F(CullRectTest, ChangedEnoughScrollScenarios) { EXPECT_TRUE(ChangedEnough(old_rect, new_rect)); } -TEST_F(CullRectTest, ApplyTransformsSameTransform) { - ScopedCompositeAfterPaintForTest cap(true); +TEST_F(CullRectTest, ChangedEnoughNewRectTouchingEdge) { + ScopedCullRectUpdateForTest cull_rect_update(true); + IntSize bounds(500, 500); + IntRect old_rect(100, 100, 100, 100); + // Top edge. + EXPECT_FALSE(ChangedEnough(old_rect, IntRect(100, 50, 100, 200), &bounds)); + EXPECT_TRUE(ChangedEnough(old_rect, IntRect(100, 0, 100, 200), &bounds)); + // Left edge. + EXPECT_FALSE(ChangedEnough(old_rect, IntRect(50, 100, 200, 100), &bounds)); + EXPECT_TRUE(ChangedEnough(old_rect, IntRect(0, 100, 200, 100), &bounds)); + // Bottom edge. + EXPECT_FALSE(ChangedEnough(old_rect, IntRect(100, 100, 100, 350), &bounds)); + EXPECT_TRUE(ChangedEnough(old_rect, IntRect(100, 100, 100, 400), &bounds)); + // Right edge. + EXPECT_FALSE(ChangedEnough(old_rect, IntRect(100, 100, 350, 100), &bounds)); + EXPECT_TRUE(ChangedEnough(old_rect, IntRect(100, 100, 400, 100), &bounds)); +} + +TEST_F(CullRectTest, ChangedEnoughOldRectTouchingEdge) { + ScopedCullRectUpdateForTest cull_rect_update(true); + IntSize bounds(500, 500); + IntRect new_rect(100, 100, 300, 300); + // Top edge. + EXPECT_FALSE(ChangedEnough(IntRect(100, 0, 100, 100), new_rect, &bounds)); + // Left edge. + EXPECT_FALSE(ChangedEnough(IntRect(0, 100, 100, 100), new_rect, &bounds)); + // Bottom edge. + EXPECT_FALSE(ChangedEnough(IntRect(300, 400, 100, 100), new_rect, &bounds)); + // Right edge. + EXPECT_FALSE(ChangedEnough(IntRect(400, 300, 100, 100), new_rect, &bounds)); +} + +TEST_F(CullRectTest, ApplyPaintPropertiesSameState) { + ScopedCullRectUpdateForTest cull_rect_update(true); auto transform = CreateTransform(t0(), TransformationMatrix().Translate(1, 2)); + auto clip = CreateClip(c0(), t0(), FloatRoundedRect(1, 2, 3, 4)); + PropertyTreeState root = PropertyTreeState::Root(); + PropertyTreeState state(*transform, *clip, e0()); + CullRect cull_rect1(IntRect(1, 1, 50, 50)); - cull_rect1.ApplyTransforms(*transform, *transform, base::nullopt); + cull_rect1.ApplyPaintProperties(state, state, state, base::nullopt); + EXPECT_EQ(IntRect(1, 1, 50, 50), cull_rect1.Rect()); + cull_rect1.ApplyPaintProperties(root, state, state, base::nullopt); EXPECT_EQ(IntRect(1, 1, 50, 50), cull_rect1.Rect()); CullRect old_cull_rect = cull_rect1; old_cull_rect.Move(IntSize(1, 1)); CullRect cull_rect2(IntRect(1, 1, 50, 50)); // Should ignore old_cull_rect. - cull_rect2.ApplyTransforms(*transform, *transform, old_cull_rect); + cull_rect2.ApplyPaintProperties(state, state, state, old_cull_rect); + EXPECT_EQ(cull_rect1, cull_rect2); + cull_rect2.ApplyPaintProperties(root, state, state, old_cull_rect); EXPECT_EQ(cull_rect1, cull_rect2); CullRect infinite = CullRect::Infinite(); - infinite.ApplyTransforms(*transform, *transform, base::nullopt); + infinite.ApplyPaintProperties(state, state, state, base::nullopt); + EXPECT_TRUE(infinite.IsInfinite()); + infinite.ApplyPaintProperties(root, state, state, base::nullopt); EXPECT_TRUE(infinite.IsInfinite()); } -TEST_F(CullRectTest, ApplyTransformsWithoutScroll) { - ScopedCompositeAfterPaintForTest cap(true); +TEST_F(CullRectTest, ApplyPaintPropertiesWithoutClipScroll) { + ScopedCullRectUpdateForTest cull_rect_update(true); auto t1 = CreateTransform(t0(), TransformationMatrix().Translate(1, 2)); auto t2 = CreateTransform(*t1, TransformationMatrix().Translate(10, 20)); + PropertyTreeState root = PropertyTreeState::Root(); + PropertyTreeState state1(*t1, c0(), e0()); + PropertyTreeState state2(*t2, c0(), e0()); CullRect cull_rect1(IntRect(1, 1, 50, 50)); - cull_rect1.ApplyTransforms(*t1, *t2, base::nullopt); + cull_rect1.ApplyPaintProperties(root, state1, state2, base::nullopt); EXPECT_EQ(IntRect(-9, -19, 50, 50), cull_rect1.Rect()); CullRect cull_rect2(IntRect(1, 1, 50, 50)); - cull_rect2.ApplyTransforms(t0(), *t2, base::nullopt); + cull_rect2.ApplyPaintProperties(root, root, state2, base::nullopt); EXPECT_EQ(IntRect(-10, -21, 50, 50), cull_rect2.Rect()); CullRect old_cull_rect = cull_rect2; old_cull_rect.Move(IntSize(1, 1)); CullRect cull_rect3(IntRect(1, 1, 50, 50)); // Should ignore old_cull_rect. - cull_rect3.ApplyTransforms(t0(), *t2, old_cull_rect); + cull_rect3.ApplyPaintProperties(root, root, state2, old_cull_rect); EXPECT_EQ(cull_rect2, cull_rect3); CullRect infinite = CullRect::Infinite(); - infinite.ApplyTransforms(t0(), *t2, base::nullopt); + infinite.ApplyPaintProperties(root, root, state2, base::nullopt); EXPECT_TRUE(infinite.IsInfinite()); } TEST_F(CullRectTest, ApplyTransformsSingleScrollWholeScrollingContents) { - ScopedCompositeAfterPaintForTest cap(true); - auto t1 = CreateTransform(t0(), TransformationMatrix().Translate(1, 2)); + ScopedCullRectUpdateForTest cull_rect_update(true); - ScrollPaintPropertyNode::State scroll_state; - scroll_state.container_rect = IntRect(20, 10, 40, 50); - scroll_state.contents_size = IntSize(2000, 2000); - auto scroll = ScrollPaintPropertyNode::Create(ScrollPaintPropertyNode::Root(), - std::move(scroll_state)); - auto scroll_translation = - CreateCompositedScrollTranslation(*t1, -10, -15, *scroll); + auto t1 = CreateTransform(t0(), TransformationMatrix().Translate(1, 2)); + PropertyTreeState state1(*t1, c0(), e0()); + auto ref_scroll_translation_state = CreateCompositedScrollTranslationState( + state1, -10, -15, IntRect(20, 10, 40, 50), IntSize(2000, 2000)); + auto scroll_translation_state = + ref_scroll_translation_state.GetPropertyTreeState().Unalias(); // Same as ApplyScrollTranslationWholeScrollingContents. CullRect cull_rect1(IntRect(0, 0, 50, 100)); - cull_rect1.ApplyTransforms(*t1, *scroll_translation, base::nullopt); - EXPECT_EQ(IntRect(-3970, -3975, 8030, 8050), cull_rect1.Rect()); + cull_rect1.ApplyPaintProperties(state1, state1, scroll_translation_state, + base::nullopt); + EXPECT_EQ(IntRect(0, 0, 2000, 2000), cull_rect1.Rect()); CullRect old_cull_rect = cull_rect1; old_cull_rect.Move(IntSize(1, 1)); CullRect cull_rect2(IntRect(0, 0, 50, 100)); // Should ignore old_cull_rect. - cull_rect2.ApplyTransforms(*t1, *scroll_translation, old_cull_rect); + cull_rect2.ApplyPaintProperties(state1, state1, scroll_translation_state, + old_cull_rect); EXPECT_EQ(cull_rect1, cull_rect2); CullRect cull_rect3 = CullRect::Infinite(); - cull_rect3.ApplyTransforms(*t1, *scroll_translation, base::nullopt); - // This result differs from the first result in height (8040 vs 8030) - // because it's not clipped by the infinite input cull rect. - EXPECT_EQ(IntRect(-3970, -3975, 8040, 8050), cull_rect3.Rect()); + cull_rect3.ApplyPaintProperties(state1, state1, scroll_translation_state, + base::nullopt); + EXPECT_EQ(IntRect(0, 0, 2000, 2000), cull_rect3.Rect()); } TEST_F(CullRectTest, ApplyTransformsWithOrigin) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); auto t1 = CreateTransform(t0(), TransformationMatrix().Translate(1, 2)); auto t2 = CreateTransform(*t1, TransformationMatrix().Scale(0.5), FloatPoint3D(50, 100, 0)); + PropertyTreeState root = PropertyTreeState::Root(); + PropertyTreeState state1(*t1, c0(), e0()); + PropertyTreeState state2(*t2, c0(), e0()); CullRect cull_rect1(IntRect(0, 0, 50, 200)); - cull_rect1.ApplyTransforms(*t1, *t2, base::nullopt); + cull_rect1.ApplyPaintProperties(root, state1, state2, base::nullopt); EXPECT_EQ(IntRect(-50, -100, 100, 400), cull_rect1.Rect()); } TEST_F(CullRectTest, ApplyTransformsSingleScrollPartialScrollingContents) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); + auto t1 = CreateTransform(t0(), TransformationMatrix().Translate(1, 2)); + PropertyTreeState state1(*t1, c0(), e0()); - ScrollPaintPropertyNode::State scroll_state; - scroll_state.container_rect = IntRect(20, 10, 40, 50); - scroll_state.contents_size = IntSize(8000, 8000); - auto scroll = ScrollPaintPropertyNode::Create(ScrollPaintPropertyNode::Root(), - std::move(scroll_state)); - auto scroll_translation = - CreateCompositedScrollTranslation(*t1, -3000, -5000, *scroll); + auto ref_scroll_translation_state = CreateCompositedScrollTranslationState( + state1, -3000, -5000, IntRect(20, 10, 40, 50), IntSize(8000, 8000)); + auto scroll_translation_state = + ref_scroll_translation_state.GetPropertyTreeState().Unalias(); // Same as ApplyScrollTranslationPartialScrollingContents. CullRect cull_rect1(IntRect(0, 0, 50, 100)); - cull_rect1.ApplyTransforms(*t1, *scroll_translation, base::nullopt); - EXPECT_EQ(IntRect(-980, 1010, 8030, 8050), cull_rect1.Rect()); + cull_rect1.ApplyPaintProperties(state1, state1, scroll_translation_state, + base::nullopt); + EXPECT_EQ(IntRect(0, 1010, 7050, 6990), cull_rect1.Rect()); - CullRect old_cull_rect = cull_rect1; - old_cull_rect.Move(IntSize(1, 1)); + CullRect old_cull_rect(IntRect(0, 1100, 7050, 6900)); CullRect cull_rect2(IntRect(0, 0, 50, 100)); // Use old_cull_rect if the new cull rect didn't change enough. - cull_rect2.ApplyTransforms(*t1, *scroll_translation, old_cull_rect); + cull_rect2.ApplyPaintProperties(state1, state1, scroll_translation_state, + old_cull_rect); EXPECT_EQ(old_cull_rect, cull_rect2); old_cull_rect.Move(IntSize(1000, 1000)); CullRect cull_rect3(IntRect(0, 0, 50, 100)); // Use the new cull rect if it changed enough. - cull_rect3.ApplyTransforms(*t1, *scroll_translation, old_cull_rect); + cull_rect3.ApplyPaintProperties(state1, state1, scroll_translation_state, + old_cull_rect); EXPECT_EQ(cull_rect1, cull_rect3); CullRect cull_rect4 = CullRect::Infinite(); - cull_rect4.ApplyTransforms(*t1, *scroll_translation, base::nullopt); - // This result differs from the first result in height (8040 vs 8030) + cull_rect4.ApplyPaintProperties(state1, state1, scroll_translation_state, + base::nullopt); + // This result differs from the first result in height (7050 vs 7060) // because it's not clipped by the infinite input cull rect. - EXPECT_EQ(IntRect(-980, 1010, 8040, 8050), cull_rect4.Rect()); + EXPECT_EQ(IntRect(0, 1010, 7060, 6990), cull_rect4.Rect()); } TEST_F(CullRectTest, ApplyTransformsEscapingScroll) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); + + PropertyTreeState root = PropertyTreeState::Root(); auto t1 = CreateTransform(t0(), TransformationMatrix().Translate(1, 2)); + auto c1 = CreateClip(c0(), t0(), FloatRoundedRect(111, 222, 333, 444)); + PropertyTreeState state1(*t1, *c1, e0()); - ScrollPaintPropertyNode::State scroll_state; - scroll_state.container_rect = IntRect(20, 10, 40, 50); - scroll_state.contents_size = IntSize(8000, 8000); - auto scroll = ScrollPaintPropertyNode::Create(ScrollPaintPropertyNode::Root(), - std::move(scroll_state)); - auto scroll_translation = - CreateCompositedScrollTranslation(*t1, -3000, -5000, *scroll); - auto t2 = CreateTransform(*scroll_translation, + auto ref_scroll_translation_state = CreateCompositedScrollTranslationState( + state1, -3000, -5000, IntRect(20, 10, 40, 50), IntSize(8000, 8000)); + auto scroll_translation_state = + ref_scroll_translation_state.GetPropertyTreeState().Unalias(); + + auto t2 = CreateTransform(scroll_translation_state.Transform(), TransformationMatrix().Translate(100, 200)); + PropertyTreeState state2(*t2, scroll_translation_state.Clip(), e0()); CullRect cull_rect1(IntRect(0, 0, 50, 100)); - // Just apply tranforms without clipping and expansion for scroll translation. - cull_rect1.ApplyTransforms(*t2, *t1, base::nullopt); - EXPECT_EQ(IntRect(-2900, -4800, 50, 100), cull_rect1.Rect()); + // Ignore the current cull rect, and apply paint properties from root to + // state1 on infinite cull rect instead. + cull_rect1.ApplyPaintProperties(root, state2, state1, base::nullopt); + EXPECT_EQ(IntRect(110, 220, 333, 444), cull_rect1.Rect()); CullRect old_cull_rect = cull_rect1; old_cull_rect.Move(IntSize(1, 1)); CullRect cull_rect2(IntRect(0, 0, 50, 100)); // Should ignore old_cull_rect. - cull_rect2.ApplyTransforms(*t2, *t1, old_cull_rect); + cull_rect2.ApplyPaintProperties(root, state2, state1, old_cull_rect); EXPECT_EQ(cull_rect1, cull_rect2); - CullRect infinite = CullRect::Infinite(); - infinite.ApplyTransforms(*t2, *t1, base::nullopt); - EXPECT_TRUE(infinite.IsInfinite()); + CullRect cull_rect3 = CullRect::Infinite(); + cull_rect3.ApplyPaintProperties(root, state2, state1, base::nullopt); + EXPECT_EQ(cull_rect1, cull_rect3); } TEST_F(CullRectTest, ApplyTransformsSmallScrollContentsAfterBigScrollContents) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); + auto t1 = CreateTransform(t0(), TransformationMatrix().Translate(1, 2)); + PropertyTreeState state1(*t1, c0(), e0()); - ScrollPaintPropertyNode::State scroll_state1; - scroll_state1.container_rect = IntRect(20, 10, 40, 50); - scroll_state1.contents_size = IntSize(8000, 8000); - auto scroll1 = ScrollPaintPropertyNode::Create( - ScrollPaintPropertyNode::Root(), std::move(scroll_state1)); - auto scroll_translation1 = - CreateCompositedScrollTranslation(*t1, -10, -15, *scroll1); + auto ref_scroll_translation_state1 = CreateCompositedScrollTranslationState( + state1, -10, -15, IntRect(20, 10, 40, 50), IntSize(8000, 8000)); + auto scroll_translation_state1 = + ref_scroll_translation_state1.GetPropertyTreeState().Unalias(); - auto t2 = CreateTransform(*scroll_translation1, + auto t2 = CreateTransform(scroll_translation_state1.Transform(), TransformationMatrix().Translate(2000, 3000)); + PropertyTreeState state2(*t2, scroll_translation_state1.Clip(), e0()); - ScrollPaintPropertyNode::State scroll_state2; - scroll_state2.container_rect = IntRect(30, 20, 100, 200); - scroll_state2.contents_size = IntSize(200, 400); - auto scroll2 = ScrollPaintPropertyNode::Create( - ScrollPaintPropertyNode::Root(), std::move(scroll_state2)); - auto scroll_translation2 = - CreateCompositedScrollTranslation(*t2, -10, -15, *scroll2); + auto ref_scroll_translation_state2 = CreateCompositedScrollTranslationState( + state2, -10, -15, IntRect(30, 20, 100, 200), IntSize(200, 400)); + auto scroll_translation_state2 = + ref_scroll_translation_state2.GetPropertyTreeState().Unalias(); CullRect cull_rect1(IntRect(0, 0, 50, 100)); - cull_rect1.ApplyTransforms(*t1, *scroll_translation2, base::nullopt); - EXPECT_EQ(IntRect(-3960, -3965, 8100, 8200), cull_rect1.Rect()); + cull_rect1.ApplyPaintProperties(state1, state1, scroll_translation_state2, + base::nullopt); + EXPECT_EQ(IntRect(0, 0, 200, 400), cull_rect1.Rect()); CullRect old_cull_rect = cull_rect1; old_cull_rect.Move(IntSize(1, 1)); CullRect cull_rect2(IntRect(0, 0, 50, 100)); // Should ignore old_cull_rect. - cull_rect2.ApplyTransforms(*t1, *scroll_translation2, old_cull_rect); + cull_rect2.ApplyPaintProperties(state1, state1, scroll_translation_state2, + old_cull_rect); EXPECT_EQ(cull_rect1, cull_rect2); } TEST_F(CullRectTest, ApplyTransformsBigScrollContentsAfterSmallScrollContents) { - ScopedCompositeAfterPaintForTest cap(true); + ScopedCullRectUpdateForTest cull_rect_update(true); + auto t1 = CreateTransform(t0(), TransformationMatrix().Translate(1, 2)); + PropertyTreeState state1(*t1, c0(), e0()); - ScrollPaintPropertyNode::State scroll_state1; - scroll_state1.container_rect = IntRect(30, 20, 100, 200); - scroll_state1.contents_size = IntSize(200, 400); - auto scroll1 = ScrollPaintPropertyNode::Create( - ScrollPaintPropertyNode::Root(), std::move(scroll_state1)); - auto scroll_translation1 = - CreateCompositedScrollTranslation(*t1, -10, -15, *scroll1); + auto ref_scroll_translation_state1 = CreateCompositedScrollTranslationState( + state1, -10, -15, IntRect(30, 20, 100, 200), IntSize(200, 400)); + auto scroll_translation_state1 = + ref_scroll_translation_state1.GetPropertyTreeState().Unalias(); - auto t2 = CreateTransform(*scroll_translation1, + auto t2 = CreateTransform(scroll_translation_state1.Transform(), TransformationMatrix().Translate(10, 20)); + PropertyTreeState state2(*t2, scroll_translation_state1.Clip(), e0()); - ScrollPaintPropertyNode::State scroll_state2; - scroll_state2.container_rect = IntRect(20, 10, 50, 100); - scroll_state2.contents_size = IntSize(10000, 20000); - auto scroll2 = ScrollPaintPropertyNode::Create( - ScrollPaintPropertyNode::Root(), std::move(scroll_state2)); - auto scroll_translation2 = - CreateCompositedScrollTranslation(*t2, -3000, -5000, *scroll2); + auto ref_scroll_translation_state2 = CreateCompositedScrollTranslationState( + state2, -3000, -5000, IntRect(20, 10, 50, 100), IntSize(10000, 20000)); + auto scroll_translation_state2 = + ref_scroll_translation_state2.GetPropertyTreeState().Unalias(); CullRect cull_rect1(IntRect(0, 0, 100, 200)); - cull_rect1.ApplyTransforms(*t1, *scroll_translation2, base::nullopt); + cull_rect1.ApplyPaintProperties(state1, state1, scroll_translation_state2, + base::nullopt); // After the first scroll: (-3960, -3965, 8070, 8180) // After t2: (-3980, -3975, 8070, 8180) // Clipped by the container rect of the second scroll: (20, 10, 50, 100) // After the second scroll offset: (3020, 5010, 50, 100) // Expanded: (-980, 1010, 8050, 8100) - EXPECT_EQ(IntRect(-980, 1010, 8050, 8100), cull_rect1.Rect()); + // Then clipped by the contents rect. + EXPECT_EQ(IntRect(0, 1010, 7070, 8100), cull_rect1.Rect()); - CullRect old_cull_rect = cull_rect1; - old_cull_rect.Move(IntSize(1, 1)); + CullRect old_cull_rect(IntRect(0, 1100, 7070, 8100)); CullRect cull_rect2(IntRect(0, 0, 100, 200)); // Use old_cull_rect if the new cull rect didn't change enough. - cull_rect2.ApplyTransforms(*t1, *scroll_translation2, old_cull_rect); + cull_rect2.ApplyPaintProperties(state1, state1, scroll_translation_state2, + old_cull_rect); EXPECT_EQ(old_cull_rect, cull_rect2); old_cull_rect.Move(IntSize(1000, 1000)); CullRect cull_rect3(IntRect(0, 0, 100, 200)); // Use the new cull rect if it changed enough. - cull_rect3.ApplyTransforms(*t1, *scroll_translation2, old_cull_rect); + cull_rect3.ApplyPaintProperties(state1, state1, scroll_translation_state2, + old_cull_rect); EXPECT_EQ(cull_rect1, cull_rect3); } +TEST_F(CullRectTest, NonCompositedTransformUnderClip) { + ScopedCullRectUpdateForTest cull_rect_update(true); + + PropertyTreeState root = PropertyTreeState::Root(); + auto c1 = CreateClip(c0(), t0(), FloatRoundedRect(100, 200, 300, 400)); + auto t1 = CreateTransform(t0(), TransformationMatrix().Translate(10, 20)); + PropertyTreeState state1(*t1, *c1, e0()); + + CullRect cull_rect1(IntRect(0, 0, 300, 500)); + cull_rect1.ApplyPaintProperties(root, root, state1, base::nullopt); + // Clip by c1, then transformed by t1. + EXPECT_EQ(IntRect(90, 180, 200, 300), cull_rect1.Rect()); + + CullRect cull_rect2(IntRect(0, 0, 300, 500)); + CullRect old_cull_rect(IntRect(133, 244, 333, 444)); + // Should ignore old_cull_rect. + cull_rect2.ApplyPaintProperties(root, root, state1, old_cull_rect); + EXPECT_EQ(cull_rect1, cull_rect2); + + CullRect cull_rect3 = CullRect::Infinite(); + cull_rect3.ApplyPaintProperties(root, root, state1, base::nullopt); + EXPECT_EQ(IntRect(90, 180, 300, 400), cull_rect3.Rect()); +} + +TEST_F(CullRectTest, CompositedTranslationUnderClip) { + ScopedCullRectUpdateForTest cull_rect_update(true); + + PropertyTreeState root = PropertyTreeState::Root(); + auto c1 = CreateClip(c0(), t0(), FloatRoundedRect(100, 200, 300, 400)); + auto t1 = CreateTransform( + t0(), TransformationMatrix().Translate(10, 20).Scale3d(2, 3, 1), + FloatPoint3D(), CompositingReason::kWillChangeTransform); + PropertyTreeState state1(*t1, *c1, e0()); + + CullRect cull_rect1(IntRect(0, 0, 300, 500)); + cull_rect1.ApplyPaintProperties(root, root, state1, base::nullopt); + // The result in NonCompositedTransformUnderClip expanded by 2000 (scaled by + // maximum of 1/2 and 1/3). + EXPECT_EQ(IntRect(-1955, -1940, 4100, 4100), cull_rect1.Rect()); + + CullRect cull_rect2(IntRect(0, 0, 300, 500)); + CullRect old_cull_rect = cull_rect1; + old_cull_rect.Move(IntSize(200, 200)); + // Use old_cull_rect if the new cull rect didn't change enough. + cull_rect2.ApplyPaintProperties(root, root, state1, old_cull_rect); + EXPECT_EQ(old_cull_rect, cull_rect2); + + CullRect cull_rect3(IntRect(0, 0, 300, 500)); + old_cull_rect.Move(IntSize(1000, 1000)); + // Use the new cull rect if it changed enough. + cull_rect3.ApplyPaintProperties(root, root, state1, old_cull_rect); + EXPECT_EQ(cull_rect1, cull_rect3); + + CullRect cull_rect4 = CullRect::Infinite(); + cull_rect4.ApplyPaintProperties(root, root, state1, base::nullopt); + EXPECT_EQ(IntRect(-1955, -1940, 4150, 4134), cull_rect4.Rect()); +} + TEST_F(CullRectTest, IntersectsVerticalRange) { CullRect cull_rect(IntRect(0, 0, 50, 100)); |