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

Side by Side Diff: third_party/WebKit/Source/core/paint/PrePaintTreeWalkTest.cpp

Issue 2495893002: Implement incremental paint property tree rebuilding (Closed)
Patch Set: Suppress main thread scrolling invalidation failures Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/layout/LayoutTestHelper.h"
6 #include "core/layout/LayoutTreeAsText.h"
7 #include "core/layout/api/LayoutViewItem.h"
8 #include "core/paint/ObjectPaintProperties.h"
9 #include "core/paint/PaintPropertyTreePrinter.h"
10 #include "platform/graphics/paint/GeometryMapper.h"
11 #include "platform/graphics/paint/ScrollPaintPropertyNode.h"
12 #include "platform/graphics/paint/TransformPaintPropertyNode.h"
13 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
14 #include "platform/testing/UnitTestHelpers.h"
15 #include "platform/text/TextStream.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "wtf/HashMap.h"
18 #include "wtf/Vector.h"
19
20 namespace blink {
21
22 typedef bool TestParamRootLayerScrolling;
23 class PrePaintTreeWalkTest
24 : public ::testing::WithParamInterface<TestParamRootLayerScrolling>,
25 private ScopedSlimmingPaintV2ForTest,
26 private ScopedRootLayerScrollingForTest,
27 public RenderingTest {
28 public:
29 PrePaintTreeWalkTest()
30 : ScopedSlimmingPaintV2ForTest(true),
31 ScopedRootLayerScrollingForTest(GetParam()),
32 RenderingTest(SingleChildFrameLoaderClient::create()) {}
33
34 const TransformPaintPropertyNode* framePreTranslation() {
35 FrameView* frameView = document().view();
36 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
37 return frameView->layoutView()
38 ->paintProperties()
39 ->paintOffsetTranslation();
40 }
41 return frameView->preTranslation();
42 }
43
44 const TransformPaintPropertyNode* frameScrollTranslation() {
45 FrameView* frameView = document().view();
46 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
47 return frameView->layoutView()->paintProperties()->scrollTranslation();
48 }
49 return frameView->scrollTranslation();
50 }
51
52 private:
53 void SetUp() override {
54 Settings::setMockScrollbarsEnabled(true);
55
56 RenderingTest::SetUp();
57 enableCompositing();
58 }
59
60 void TearDown() override {
61 RenderingTest::TearDown();
62
63 Settings::setMockScrollbarsEnabled(false);
64 }
65 };
66
67 INSTANTIATE_TEST_CASE_P(All, PrePaintTreeWalkTest, ::testing::Bool());
68
69 TEST_P(PrePaintTreeWalkTest, PropertyTreesRebuiltWithBorderInvalidation) {
70 setBodyInnerHTML(
71 "<style>"
72 " body { margin: 0; }"
73 " #transformed { transform: translate(100px, 100px); }"
74 " .border { border: 10px solid black; }"
75 "</style>"
76 "<div id='transformed'></div>");
77
78 auto* transformedElement = document().getElementById("transformed");
79 const auto* transformedProperties =
80 transformedElement->layoutObject()->paintProperties();
81 EXPECT_EQ(TransformationMatrix().translate(100, 100),
82 transformedProperties->transform()->matrix());
83
84 // Artifically change the transform node.
85 const_cast<ObjectPaintProperties*>(transformedProperties)->clearTransform();
86 EXPECT_EQ(nullptr, transformedProperties->transform());
87
88 // Cause a paint invalidation.
89 transformedElement->setAttribute(HTMLNames::classAttr, "border");
90 document().view()->updateAllLifecyclePhases();
91
92 // Should have changed back.
93 EXPECT_EQ(TransformationMatrix().translate(100, 100),
94 transformedProperties->transform()->matrix());
95 }
96
97 TEST_P(PrePaintTreeWalkTest, PropertyTreesRebuiltWithFrameScroll) {
98 setBodyInnerHTML("<style> body { height: 10000px; } </style>");
99 EXPECT_EQ(TransformationMatrix().translate(0, 0),
100 frameScrollTranslation()->matrix());
101
102 // Cause a scroll invalidation and ensure the translation is updated.
103 document().domWindow()->scrollTo(0, 100);
104 document().view()->updateAllLifecyclePhases();
105
106 EXPECT_EQ(TransformationMatrix().translate(0, -100),
107 frameScrollTranslation()->matrix());
108 }
109
110 TEST_P(PrePaintTreeWalkTest, PropertyTreesRebuiltWithCSSTransformInvalidation) {
111 setBodyInnerHTML(
112 "<style>"
113 " .transformA { transform: translate(100px, 100px); }"
114 " .transformB { transform: translate(200px, 200px); }"
115 " #transformed { will-change: transform; }"
116 "</style>"
117 "<div id='transformed' class='transformA'></div>");
118
119 auto* transformedElement = document().getElementById("transformed");
120 const auto* transformedProperties =
121 transformedElement->layoutObject()->paintProperties();
122 EXPECT_EQ(TransformationMatrix().translate(100, 100),
123 transformedProperties->transform()->matrix());
124
125 // Invalidate the CSS transform property.
126 transformedElement->setAttribute(HTMLNames::classAttr, "transformB");
127 document().view()->updateAllLifecyclePhases();
128
129 // The transform should have changed.
130 EXPECT_EQ(TransformationMatrix().translate(200, 200),
131 transformedProperties->transform()->matrix());
132 }
133
134 TEST_P(PrePaintTreeWalkTest, PropertyTreesRebuiltWithOpacityInvalidation) {
135 setBodyInnerHTML(
136 "<style>"
137 " .opacityA { opacity: 0.9; }"
138 " .opacityB { opacity: 0.4; }"
139 "</style>"
140 "<div id='transparent' class='opacityA'></div>");
141
142 auto* transparentElement = document().getElementById("transparent");
143 const auto* transparentProperties =
144 transparentElement->layoutObject()->paintProperties();
145 EXPECT_EQ(0.9f, transparentProperties->effect()->opacity());
146
147 // Invalidate the opacity property.
148 transparentElement->setAttribute(HTMLNames::classAttr, "opacityB");
149 document().view()->updateAllLifecyclePhases();
150
151 // The opacity should have changed.
152 EXPECT_EQ(0.4f, transparentProperties->effect()->opacity());
153 }
154
155 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698