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

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

Issue 2457023002: Replace coversExtraPixels with simpler logic (Closed)
Patch Set: Rebaseline 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/HTMLNames.h" 5 #include "core/HTMLNames.h"
6 #include "core/frame/FrameView.h" 6 #include "core/frame/FrameView.h"
7 #include "core/layout/LayoutTestHelper.h" 7 #include "core/layout/LayoutTestHelper.h"
8 #include "core/layout/LayoutView.h" 8 #include "core/layout/LayoutView.h"
9 #include "core/paint/PaintLayer.h" 9 #include "core/paint/PaintLayer.h"
10 #include "platform/graphics/GraphicsLayer.h" 10 #include "platform/graphics/GraphicsLayer.h"
(...skipping 18 matching lines...) Expand all
29 enableCompositing(); 29 enableCompositing();
30 setBodyInnerHTML( 30 setBodyInnerHTML(
31 "<style>" 31 "<style>"
32 " body { margin: 0 }" 32 " body { margin: 0 }"
33 " #target {" 33 " #target {"
34 " width: 50px;" 34 " width: 50px;"
35 " height: 100px;" 35 " height: 100px;"
36 " border-width: 20px 10px;" 36 " border-width: 20px 10px;"
37 " border-style: solid;" 37 " border-style: solid;"
38 " border-color: red;" 38 " border-color: red;"
39 " transform-origin: 0 0"
39 " }" 40 " }"
40 "</style>" 41 "</style>"
41 "<div id='target'></div>"); 42 "<div id='target'></div>");
42 } 43 }
43 }; 44 };
44 45
45 TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationExpand) { 46 TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationExpand) {
46 document().view()->setTracksPaintInvalidations(true); 47 document().view()->setTracksPaintInvalidations(true);
47 Element* target = document().getElementById("target"); 48 Element* target = document().getElementById("target");
48 target->setAttribute(HTMLNames::styleAttr, "width: 100px; height: 200px"); 49 target->setAttribute(HTMLNames::styleAttr, "width: 100px; height: 200px");
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason); 85 EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason);
85 EXPECT_EQ(IntRect(0, 100, 70, 40), rasterInvalidations[1].rect); 86 EXPECT_EQ(IntRect(0, 100, 70, 40), rasterInvalidations[1].rect);
86 EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[1].reason); 87 EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[1].reason);
87 document().view()->setTracksPaintInvalidations(false); 88 document().view()->setTracksPaintInvalidations(false);
88 } 89 }
89 90
90 TEST_F(BoxPaintInvalidatorTest, SubpixelVisualRectChagne) { 91 TEST_F(BoxPaintInvalidatorTest, SubpixelVisualRectChagne) {
91 ScopedSlimmingPaintInvalidationForTest scopedSlimmingPaintInvalidation(true); 92 ScopedSlimmingPaintInvalidationForTest scopedSlimmingPaintInvalidation(true);
92 93
93 Element* target = document().getElementById("target"); 94 Element* target = document().getElementById("target");
94 LayoutObject* targetObject = target->layoutObject();
95 EXPECT_FALSE(targetObject->previousPaintInvalidationRectCoversExtraPixels());
96 95
97 // Should do full invalidation if new geometry has subpixels. 96 // Should do full invalidation if new geometry has subpixels.
98 document().view()->setTracksPaintInvalidations(true); 97 document().view()->setTracksPaintInvalidations(true);
99 target->setAttribute(HTMLNames::styleAttr, "width: 100.6px; height: 70.3px"); 98 target->setAttribute(HTMLNames::styleAttr, "width: 100.6px; height: 70.3px");
100 document().view()->updateAllLifecyclePhases(); 99 document().view()->updateAllLifecyclePhases();
101 EXPECT_TRUE(targetObject->previousPaintInvalidationRectCoversExtraPixels());
102 const auto* rasterInvalidations = 100 const auto* rasterInvalidations =
103 &getRasterInvalidationTracking()->trackedRasterInvalidations; 101 &getRasterInvalidationTracking()->trackedRasterInvalidations;
104 EXPECT_EQ(2u, rasterInvalidations->size()); 102 EXPECT_EQ(2u, rasterInvalidations->size());
105 EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[0].rect); 103 EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[0].rect);
106 EXPECT_EQ(PaintInvalidationBoundsChange, (*rasterInvalidations)[0].reason); 104 EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[0].reason);
107 EXPECT_EQ(IntRect(0, 0, 121, 111), (*rasterInvalidations)[1].rect); 105 EXPECT_EQ(IntRect(0, 0, 121, 111), (*rasterInvalidations)[1].rect);
108 EXPECT_EQ(PaintInvalidationBoundsChange, (*rasterInvalidations)[1].reason); 106 EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[1].reason);
109 document().view()->setTracksPaintInvalidations(false); 107 document().view()->setTracksPaintInvalidations(false);
110 108
111 // Should do full invalidation if old geometry has subpixels. 109 // Should do full invalidation if old geometry has subpixels.
112 document().view()->setTracksPaintInvalidations(true); 110 document().view()->setTracksPaintInvalidations(true);
113 target->setAttribute(HTMLNames::styleAttr, "width: 50px; height: 100px"); 111 target->setAttribute(HTMLNames::styleAttr, "width: 50px; height: 100px");
114 document().view()->updateAllLifecyclePhases(); 112 document().view()->updateAllLifecyclePhases();
115 EXPECT_FALSE(targetObject->previousPaintInvalidationRectCoversExtraPixels());
116 rasterInvalidations = 113 rasterInvalidations =
117 &getRasterInvalidationTracking()->trackedRasterInvalidations; 114 &getRasterInvalidationTracking()->trackedRasterInvalidations;
118 EXPECT_EQ(2u, rasterInvalidations->size()); 115 EXPECT_EQ(2u, rasterInvalidations->size());
119 EXPECT_EQ(IntRect(0, 0, 121, 111), (*rasterInvalidations)[0].rect); 116 EXPECT_EQ(IntRect(0, 0, 121, 111), (*rasterInvalidations)[0].rect);
120 EXPECT_EQ(PaintInvalidationBoundsChange, (*rasterInvalidations)[0].reason); 117 EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[0].reason);
121 EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[1].rect); 118 EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[1].rect);
122 EXPECT_EQ(PaintInvalidationBoundsChange, (*rasterInvalidations)[1].reason); 119 EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[1].reason);
123 document().view()->setTracksPaintInvalidations(false); 120 document().view()->setTracksPaintInvalidations(false);
124 } 121 }
125 122
126 TEST_F(BoxPaintInvalidatorTest, SubpixelChangeWithoutVisualRectChange) { 123 TEST_F(BoxPaintInvalidatorTest, SubpixelChangeWithoutVisualRectChange) {
127 ScopedSlimmingPaintInvalidationForTest scopedSlimmingPaintInvalidation(true); 124 ScopedSlimmingPaintInvalidationForTest scopedSlimmingPaintInvalidation(true);
128 125
129 Element* target = document().getElementById("target"); 126 Element* target = document().getElementById("target");
130 LayoutObject* targetObject = target->layoutObject(); 127 LayoutObject* targetObject = target->layoutObject();
131 EXPECT_EQ(LayoutRect(0, 0, 70, 140), 128 EXPECT_EQ(LayoutRect(0, 0, 70, 140),
132 targetObject->previousPaintInvalidationRect()); 129 targetObject->previousPaintInvalidationRect());
133 EXPECT_FALSE(targetObject->previousPaintInvalidationRectCoversExtraPixels());
134 130
135 // Should do full invalidation if new geometry has subpixels even if the paint 131 // Should do full invalidation if new geometry has subpixels even if the paint
136 // invalidation rect doesn't change. 132 // invalidation rect doesn't change.
137 document().view()->setTracksPaintInvalidations(true); 133 document().view()->setTracksPaintInvalidations(true);
138 target->setAttribute(HTMLNames::styleAttr, 134 target->setAttribute(HTMLNames::styleAttr,
139 "margin-top: 0.6px; width: 50px; height: 99.3px"); 135 "margin-top: 0.6px; width: 50px; height: 99.3px");
140 document().view()->updateAllLifecyclePhases(); 136 document().view()->updateAllLifecyclePhases();
141 EXPECT_EQ(LayoutRect(0, 0, 70, 140), 137 EXPECT_EQ(LayoutRect(0, 0, 70, 140),
142 targetObject->previousPaintInvalidationRect()); 138 targetObject->previousPaintInvalidationRect());
143 EXPECT_TRUE(targetObject->previousPaintInvalidationRectCoversExtraPixels());
144 const auto* rasterInvalidations = 139 const auto* rasterInvalidations =
145 &getRasterInvalidationTracking()->trackedRasterInvalidations; 140 &getRasterInvalidationTracking()->trackedRasterInvalidations;
146 EXPECT_EQ(1u, rasterInvalidations->size()); 141 EXPECT_EQ(1u, rasterInvalidations->size());
147 EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[0].rect); 142 EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[0].rect);
148 EXPECT_EQ(PaintInvalidationLocationChange, (*rasterInvalidations)[0].reason); 143 EXPECT_EQ(PaintInvalidationLocationChange, (*rasterInvalidations)[0].reason);
149 document().view()->setTracksPaintInvalidations(false); 144 document().view()->setTracksPaintInvalidations(false);
150 145
151 // When changing size in subpixels keeping the paint invalidation rect
152 // unchanged, incremental incremental should cover all the changed pixels.
153 document().view()->setTracksPaintInvalidations(true); 146 document().view()->setTracksPaintInvalidations(true);
154 target->setAttribute(HTMLNames::styleAttr, 147 target->setAttribute(HTMLNames::styleAttr,
155 "margin-top: 0.6px; width: 49.3px; height: 98.5px"); 148 "margin-top: 0.6px; width: 49.3px; height: 98.5px");
156 document().view()->updateAllLifecyclePhases(); 149 document().view()->updateAllLifecyclePhases();
157 EXPECT_EQ(LayoutRect(0, 0, 70, 140), 150 EXPECT_EQ(LayoutRect(0, 0, 70, 140),
158 targetObject->previousPaintInvalidationRect()); 151 targetObject->previousPaintInvalidationRect());
159 EXPECT_TRUE(targetObject->previousPaintInvalidationRectCoversExtraPixels());
160 rasterInvalidations = 152 rasterInvalidations =
161 &getRasterInvalidationTracking()->trackedRasterInvalidations; 153 &getRasterInvalidationTracking()->trackedRasterInvalidations;
162 EXPECT_EQ(2u, rasterInvalidations->size()); 154 EXPECT_EQ(1u, rasterInvalidations->size());
163 EXPECT_EQ(IntRect(59, 0, 11, 140), (*rasterInvalidations)[0].rect); 155 EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[0].rect);
164 EXPECT_EQ(PaintInvalidationIncremental, (*rasterInvalidations)[0].reason); 156 EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[0].reason);
165 EXPECT_EQ(IntRect(0, 119, 70, 21), (*rasterInvalidations)[1].rect);
166 EXPECT_EQ(PaintInvalidationIncremental, (*rasterInvalidations)[1].reason);
167 document().view()->setTracksPaintInvalidations(false); 157 document().view()->setTracksPaintInvalidations(false);
168 } 158 }
169 159
160 TEST_F(BoxPaintInvalidatorTest, ResizeRotated) {
161 ScopedSlimmingPaintInvalidationForTest scopedSlimmingPaintInvalidation(true);
162
163 Element* target = document().getElementById("target");
164 target->setAttribute(HTMLNames::styleAttr, "transform: rotate(45deg)");
165 document().view()->updateAllLifecyclePhases();
166
167 // Should do full invalidation a rotated object is resized.
168 document().view()->setTracksPaintInvalidations(true);
169 target->setAttribute(HTMLNames::styleAttr,
170 "transform: rotate(45deg); width: 200px");
171 document().view()->updateAllLifecyclePhases();
172 const auto* rasterInvalidations =
173 &getRasterInvalidationTracking()->trackedRasterInvalidations;
174 EXPECT_EQ(1u, rasterInvalidations->size());
175 EXPECT_EQ(IntRect(-99, 0, 255, 255), (*rasterInvalidations)[0].rect);
176 EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[0].reason);
177 document().view()->setTracksPaintInvalidations(false);
178 }
179
180 TEST_F(BoxPaintInvalidatorTest, ResizeRotatedChild) {
181 ScopedSlimmingPaintInvalidationForTest scopedSlimmingPaintInvalidation(true);
182
183 Element* target = document().getElementById("target");
184 target->setAttribute(HTMLNames::styleAttr,
185 "transform: rotate(45deg); width: 200px");
186 target->setInnerHTML(
187 "<div id=child style='width: 50px; height: 50px; background: red'></div>",
188 ASSERT_NO_EXCEPTION);
189 document().view()->updateAllLifecyclePhases();
190 Element* child = document().getElementById("child");
191
192 // Should do full invalidation a rotated object is resized.
193 document().view()->setTracksPaintInvalidations(true);
194 child->setAttribute(HTMLNames::styleAttr,
195 "width: 100px; height: 50px; background: red");
196 document().view()->updateAllLifecyclePhases();
197 const auto* rasterInvalidations =
198 &getRasterInvalidationTracking()->trackedRasterInvalidations;
199 EXPECT_EQ(1u, rasterInvalidations->size());
200 EXPECT_EQ(IntRect(-43, 21, 107, 107), (*rasterInvalidations)[0].rect);
201 EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[0].reason);
202 document().view()->setTracksPaintInvalidations(false);
203 }
204
170 } // namespace blink 205 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698