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

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

Issue 2621243002: Fix paint offset and clips in SPv2 (Closed)
Patch Set: none Created 3 years, 11 months 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/paint/PaintLayerClipper.h" 5 #include "core/paint/PaintLayerClipper.h"
6 6
7 #include "core/layout/LayoutBoxModelObject.h" 7 #include "core/layout/LayoutBoxModelObject.h"
8 #include "core/layout/LayoutTestHelper.h" 8 #include "core/layout/LayoutTestHelper.h"
9 #include "core/layout/LayoutView.h" 9 #include "core/layout/LayoutView.h"
10 #include "core/paint/PaintLayer.h" 10 #include "core/paint/PaintLayer.h"
11 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
12 #include "platform/testing/UnitTestHelpers.h"
11 13
12 namespace blink { 14 namespace blink {
13 15
14 class PaintLayerClipperTest : public RenderingTest { 16 class PaintLayerClipperTest : public ::testing::WithParamInterface<bool>,
17 private ScopedSlimmingPaintV2ForTest,
18 public RenderingTest {
15 public: 19 public:
16 PaintLayerClipperTest() : RenderingTest(EmptyFrameLoaderClient::create()) {} 20 PaintLayerClipperTest()
21 : ScopedSlimmingPaintV2ForTest(GetParam()),
22 RenderingTest(EmptyFrameLoaderClient::create()) {}
23
24 bool geometryMapperCacheEmpty(const PaintLayerClipper& clipper) {
25 return clipper.m_geometryMapper->m_data.isEmpty();
26 }
17 }; 27 };
18 28
19 TEST_F(PaintLayerClipperTest, LayoutSVGRoot) { 29 INSTANTIATE_TEST_CASE_P(All,
30 PaintLayerClipperTest,
31 ::testing::ValuesIn({false, true}));
32
33 TEST_P(PaintLayerClipperTest, LayoutSVGRoot) {
20 setBodyInnerHTML( 34 setBodyInnerHTML(
21 "<!DOCTYPE html>" 35 "<!DOCTYPE html>"
22 "<svg id=target width=200 height=300 style='position: relative'>" 36 "<svg id=target width=200 height=300 style='position: relative'>"
23 " <rect width=400 height=500 fill='blue'/>" 37 " <rect width=400 height=500 fill='blue'/>"
24 "</svg>"); 38 "</svg>");
25 39
26 Element* target = document().getElementById("target"); 40 Element* target = document().getElementById("target");
27 PaintLayer* targetPaintLayer = 41 PaintLayer* targetPaintLayer =
28 toLayoutBoxModelObject(target->layoutObject())->layer(); 42 toLayoutBoxModelObject(target->layoutObject())->layer();
29 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); 43 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects);
30 // When RLS is enabled, the LayoutView will have a composited scrolling layer, 44 // When RLS is enabled, the LayoutView will have a composited scrolling layer,
31 // so don't apply an overflow clip. 45 // so don't apply an overflow clip.
32 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) 46 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled())
33 context.setIgnoreOverflowClip(); 47 context.setIgnoreOverflowClip();
34 LayoutRect layerBounds; 48 LayoutRect layerBounds;
35 ClipRect backgroundRect, foregroundRect; 49 ClipRect backgroundRect, foregroundRect;
36 targetPaintLayer->clipper().calculateRects( 50 targetPaintLayer->clipper().calculateRects(
37 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, 51 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds,
38 backgroundRect, foregroundRect); 52 backgroundRect, foregroundRect);
39 EXPECT_EQ(LayoutRect(LayoutRect::infiniteIntRect()), backgroundRect.rect()); 53 EXPECT_EQ(LayoutRect(LayoutRect::infiniteIntRect()), backgroundRect.rect());
40 EXPECT_EQ(LayoutRect(LayoutRect::infiniteIntRect()), foregroundRect.rect()); 54 // TODO(chrishtr): the behavior for SPv2 is actually correct, since the
55 // svg root clip should be applied to the foreground rect. See
56 // crbug.com/680325.
57 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled())
58 EXPECT_EQ(LayoutRect(LayoutRect::infiniteIntRect()), foregroundRect.rect());
41 EXPECT_EQ(LayoutRect(8, 8, 200, 300), layerBounds); 59 EXPECT_EQ(LayoutRect(8, 8, 200, 300), layerBounds);
42 } 60 }
43 61
44 TEST_F(PaintLayerClipperTest, LayoutSVGRootChild) { 62 TEST_P(PaintLayerClipperTest, LayoutSVGRootChild) {
45 setBodyInnerHTML( 63 setBodyInnerHTML(
46 "<svg width=200 height=300 style='position: relative'>" 64 "<svg width=200 height=300 style='position: relative'>"
47 " <foreignObject width=400 height=500>" 65 " <foreignObject width=400 height=500>"
48 " <div id=target xmlns='http://www.w3.org/1999/xhtml' " 66 " <div id=target xmlns='http://www.w3.org/1999/xhtml' "
49 "style='position: relative'></div>" 67 "style='position: relative'></div>"
50 " </foreignObject>" 68 " </foreignObject>"
51 "</svg>"); 69 "</svg>");
52 70
53 Element* target = document().getElementById("target"); 71 Element* target = document().getElementById("target");
54 PaintLayer* targetPaintLayer = 72 PaintLayer* targetPaintLayer =
55 toLayoutBoxModelObject(target->layoutObject())->layer(); 73 toLayoutBoxModelObject(target->layoutObject())->layer();
56 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects); 74 ClipRectsContext context(document().layoutView()->layer(), UncachedClipRects);
57 LayoutRect layerBounds; 75 LayoutRect layerBounds;
58 ClipRect backgroundRect, foregroundRect; 76 ClipRect backgroundRect, foregroundRect;
59 targetPaintLayer->clipper().calculateRects( 77 targetPaintLayer->clipper().calculateRects(
60 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds, 78 context, LayoutRect(LayoutRect::infiniteIntRect()), layerBounds,
61 backgroundRect, foregroundRect); 79 backgroundRect, foregroundRect);
62 EXPECT_EQ(LayoutRect(8, 8, 200, 300), backgroundRect.rect()); 80 EXPECT_EQ(LayoutRect(8, 8, 200, 300), backgroundRect.rect());
63 EXPECT_EQ(LayoutRect(8, 8, 200, 300), foregroundRect.rect()); 81 EXPECT_EQ(LayoutRect(8, 8, 200, 300), foregroundRect.rect());
64 EXPECT_EQ(LayoutRect(8, 8, 400, 0), layerBounds); 82 EXPECT_EQ(LayoutRect(8, 8, 400, 0), layerBounds);
65 } 83 }
66 84
67 TEST_F(PaintLayerClipperTest, ContainPaintClip) { 85 TEST_P(PaintLayerClipperTest, ContainPaintClip) {
68 setBodyInnerHTML( 86 setBodyInnerHTML(
69 "<div id='target'" 87 "<div id='target'"
70 " style='contain: paint; width: 200px; height: 200px; overflow: auto'>" 88 " style='contain: paint; width: 200px; height: 200px; overflow: auto'>"
71 " <div style='height: 400px'></div>" 89 " <div style='height: 400px'></div>"
72 "</div>"); 90 "</div>");
73 91
74 LayoutRect infiniteRect(LayoutRect::infiniteIntRect()); 92 LayoutRect infiniteRect(LayoutRect::infiniteIntRect());
75 PaintLayer* layer = 93 PaintLayer* layer =
76 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 94 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
77 ClipRectsContext context(layer, PaintingClipRectsIgnoringOverflowClip); 95 ClipRectsContext context(layer, PaintingClipRectsIgnoringOverflowClip);
78 LayoutRect layerBounds; 96 LayoutRect layerBounds;
79 ClipRect backgroundRect, foregroundRect; 97 ClipRect backgroundRect, foregroundRect;
80 layer->clipper().calculateRects(context, infiniteRect, layerBounds, 98 layer->clipper().calculateRects(context, infiniteRect, layerBounds,
81 backgroundRect, foregroundRect); 99 backgroundRect, foregroundRect);
82 EXPECT_EQ(infiniteRect, backgroundRect.rect()); 100 EXPECT_GE(backgroundRect.rect().size().width().toInt(), 33554422);
83 EXPECT_EQ(infiniteRect, foregroundRect.rect()); 101 EXPECT_GE(backgroundRect.rect().size().height().toInt(), 33554422);
102 EXPECT_EQ(backgroundRect.rect(), foregroundRect.rect());
84 EXPECT_EQ(LayoutRect(0, 0, 200, 200), layerBounds); 103 EXPECT_EQ(LayoutRect(0, 0, 200, 200), layerBounds);
85 104
86 ClipRectsContext contextClip(layer, PaintingClipRects); 105 ClipRectsContext contextClip(layer, PaintingClipRects);
87 layer->clipper().calculateRects(contextClip, infiniteRect, layerBounds, 106 layer->clipper().calculateRects(contextClip, infiniteRect, layerBounds,
88 backgroundRect, foregroundRect); 107 backgroundRect, foregroundRect);
89 EXPECT_EQ(LayoutRect(0, 0, 200, 200), backgroundRect.rect()); 108 EXPECT_EQ(LayoutRect(0, 0, 200, 200), backgroundRect.rect());
90 EXPECT_EQ(LayoutRect(0, 0, 200, 200), foregroundRect.rect()); 109 EXPECT_EQ(LayoutRect(0, 0, 200, 200), foregroundRect.rect());
91 EXPECT_EQ(LayoutRect(0, 0, 200, 200), layerBounds); 110 EXPECT_EQ(LayoutRect(0, 0, 200, 200), layerBounds);
92 } 111 }
93 112
94 TEST_F(PaintLayerClipperTest, NestedContainPaintClip) { 113 TEST_P(PaintLayerClipperTest, NestedContainPaintClip) {
95 setBodyInnerHTML( 114 setBodyInnerHTML(
96 "<div style='contain: paint; width: 200px; height: 200px; overflow: " 115 "<div style='contain: paint; width: 200px; height: 200px; overflow: "
97 "auto'>" 116 "auto'>"
98 " <div id='target' style='contain: paint; height: 400px'>" 117 " <div id='target' style='contain: paint; height: 400px'>"
99 " </div>" 118 " </div>"
100 "</div>"); 119 "</div>");
101 120
102 LayoutRect infiniteRect(LayoutRect::infiniteIntRect()); 121 LayoutRect infiniteRect(LayoutRect::infiniteIntRect());
103 PaintLayer* layer = 122 PaintLayer* layer =
104 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer(); 123 toLayoutBoxModelObject(getLayoutObjectByElementId("target"))->layer();
105 ClipRectsContext context(layer->parent(), 124 ClipRectsContext context(layer->parent(),
106 PaintingClipRectsIgnoringOverflowClip); 125 PaintingClipRectsIgnoringOverflowClip);
107 LayoutRect layerBounds; 126 LayoutRect layerBounds;
108 ClipRect backgroundRect, foregroundRect; 127 ClipRect backgroundRect, foregroundRect;
109 layer->clipper().calculateRects(context, infiniteRect, layerBounds, 128 layer->clipper().calculateRects(context, infiniteRect, layerBounds,
110 backgroundRect, foregroundRect); 129 backgroundRect, foregroundRect);
111 EXPECT_EQ(LayoutRect(0, 0, 200, 400), backgroundRect.rect()); 130 EXPECT_EQ(LayoutRect(0, 0, 200, 400), backgroundRect.rect());
112 EXPECT_EQ(LayoutRect(0, 0, 200, 400), foregroundRect.rect()); 131 EXPECT_EQ(LayoutRect(0, 0, 200, 400), foregroundRect.rect());
113 EXPECT_EQ(LayoutRect(0, 0, 200, 400), layerBounds); 132 EXPECT_EQ(LayoutRect(0, 0, 200, 400), layerBounds);
114 133
115 ClipRectsContext contextClip(layer->parent(), PaintingClipRects); 134 ClipRectsContext contextClip(layer->parent(), PaintingClipRects);
116 layer->clipper().calculateRects(contextClip, infiniteRect, layerBounds, 135 layer->clipper().calculateRects(contextClip, infiniteRect, layerBounds,
117 backgroundRect, foregroundRect); 136 backgroundRect, foregroundRect);
118 EXPECT_EQ(LayoutRect(0, 0, 200, 200), backgroundRect.rect()); 137 EXPECT_EQ(LayoutRect(0, 0, 200, 200), backgroundRect.rect());
119 EXPECT_EQ(LayoutRect(0, 0, 200, 200), foregroundRect.rect()); 138 EXPECT_EQ(LayoutRect(0, 0, 200, 200), foregroundRect.rect());
120 EXPECT_EQ(LayoutRect(0, 0, 200, 400), layerBounds); 139 EXPECT_EQ(LayoutRect(0, 0, 200, 400), layerBounds);
121 } 140 }
122 141
123 TEST_F(PaintLayerClipperTest, LocalClipRectFixedUnderTransform) { 142 TEST_P(PaintLayerClipperTest, LocalClipRectFixedUnderTransform) {
124 setBodyInnerHTML( 143 setBodyInnerHTML(
125 "<div id='transformed'" 144 "<div id='transformed'"
126 " style='will-change: transform; width: 100px; height: 100px;" 145 " style='will-change: transform; width: 100px; height: 100px;"
127 " overflow: hidden'>" 146 " overflow: hidden'>"
128 " <div id='fixed' " 147 " <div id='fixed' "
129 " style='position: fixed; width: 100px; height: 100px;" 148 " style='position: fixed; width: 100px; height: 100px;"
130 " top: -50px'>" 149 " top: -50px'>"
131 " </div>" 150 " </div>"
132 "</div>"); 151 "</div>");
133 152
134 LayoutRect infiniteRect(LayoutRect::infiniteIntRect()); 153 LayoutRect infiniteRect(LayoutRect::infiniteIntRect());
135 PaintLayer* transformed = 154 PaintLayer* transformed =
136 toLayoutBoxModelObject(getLayoutObjectByElementId("transformed")) 155 toLayoutBoxModelObject(getLayoutObjectByElementId("transformed"))
137 ->layer(); 156 ->layer();
138 PaintLayer* fixed = 157 PaintLayer* fixed =
139 toLayoutBoxModelObject(getLayoutObjectByElementId("fixed"))->layer(); 158 toLayoutBoxModelObject(getLayoutObjectByElementId("fixed"))->layer();
140 159
141 EXPECT_EQ(LayoutRect(0, 0, 100, 100), 160 EXPECT_EQ(LayoutRect(0, 0, 100, 100),
142 transformed->clipper().localClipRect(transformed)); 161 transformed->clipper().localClipRect(transformed));
143 EXPECT_EQ(LayoutRect(0, 50, 100, 100), 162 EXPECT_EQ(LayoutRect(0, 50, 100, 100),
144 fixed->clipper().localClipRect(transformed)); 163 fixed->clipper().localClipRect(transformed));
145 } 164 }
146 165
147 TEST_F(PaintLayerClipperTest, ClearClipRectsRecursive) { 166 TEST_P(PaintLayerClipperTest, ClearClipRectsRecursive) {
167 // SPv2 will re-use a global GeometryMapper, so this
168 // logic does not apply.
169 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
170 return;
171
148 setBodyInnerHTML( 172 setBodyInnerHTML(
149 "<style>" 173 "<style>"
150 "div { " 174 "div { "
151 " width: 5px; height: 5px; background: blue;" 175 " width: 5px; height: 5px; background: blue; overflow: hidden;"
152 " position: relative;" 176 " position: relative;"
153 "}" 177 "}"
154 "</style>" 178 "</style>"
155 "<div id='parent'>" 179 "<div id='parent'>"
156 " <div id='child'>" 180 " <div id='child'>"
157 " <div id='grandchild'></div>" 181 " <div id='grandchild'></div>"
158 " </div>" 182 " </div>"
159 "</div>"); 183 "</div>");
160 184
161 PaintLayer* parent = 185 PaintLayer* parent =
162 toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer(); 186 toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer();
163 PaintLayer* child = 187 PaintLayer* child =
164 toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer(); 188 toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer();
165 189
166 EXPECT_TRUE(parent->clipRectsCache()); 190 EXPECT_TRUE(parent->clipRectsCache());
167 EXPECT_TRUE(child->clipRectsCache()); 191 EXPECT_TRUE(child->clipRectsCache());
168 192
169 parent->clipper().clearClipRectsIncludingDescendants(); 193 parent->clipper().clearClipRectsIncludingDescendants();
170 194
171 EXPECT_FALSE(parent->clipRectsCache()); 195 EXPECT_FALSE(parent->clipRectsCache());
172 EXPECT_FALSE(child->clipRectsCache()); 196 EXPECT_FALSE(child->clipRectsCache());
173 } 197 }
174 198
175 TEST_F(PaintLayerClipperTest, ClearClipRectsRecursiveChild) { 199 TEST_P(PaintLayerClipperTest, ClearClipRectsRecursiveChild) {
200 // SPv2 will re-use a global GeometryMapper, so this
201 // logic does not apply.
202 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
203 return;
204
176 setBodyInnerHTML( 205 setBodyInnerHTML(
177 "<style>" 206 "<style>"
178 "div { " 207 "div { "
179 " width: 5px; height: 5px; background: blue;" 208 " width: 5px; height: 5px; background: blue;"
180 " position: relative;" 209 " position: relative;"
181 "}" 210 "}"
182 "</style>" 211 "</style>"
183 "<div id='parent'>" 212 "<div id='parent'>"
184 " <div id='child'>" 213 " <div id='child'>"
185 " <div id='grandchild'></div>" 214 " <div id='grandchild'></div>"
186 " </div>" 215 " </div>"
187 "</div>"); 216 "</div>");
188 217
189 PaintLayer* parent = 218 PaintLayer* parent =
190 toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer(); 219 toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer();
191 PaintLayer* child = 220 PaintLayer* child =
192 toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer(); 221 toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer();
193 222
194 EXPECT_TRUE(parent->clipRectsCache()); 223 EXPECT_TRUE(parent->clipRectsCache());
195 EXPECT_TRUE(child->clipRectsCache()); 224 EXPECT_TRUE(child->clipRectsCache());
196 225
197 child->clipper().clearClipRectsIncludingDescendants(); 226 child->clipper().clearClipRectsIncludingDescendants();
198 227
199 EXPECT_TRUE(parent->clipRectsCache()); 228 EXPECT_TRUE(parent->clipRectsCache());
200 EXPECT_FALSE(child->clipRectsCache()); 229 EXPECT_FALSE(child->clipRectsCache());
201 } 230 }
202 231
203 TEST_F(PaintLayerClipperTest, ClearClipRectsRecursiveOneType) { 232 TEST_P(PaintLayerClipperTest, ClearClipRectsRecursiveOneType) {
233 // SPv2 will re-use a global GeometryMapper, so this
234 // logic does not apply.
235 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
236 return;
237
204 setBodyInnerHTML( 238 setBodyInnerHTML(
205 "<style>" 239 "<style>"
206 "div { " 240 "div { "
207 " width: 5px; height: 5px; background: blue;" 241 " width: 5px; height: 5px; background: blue;"
208 " position: relative;" 242 " position: relative;"
209 "}" 243 "}"
210 "</style>" 244 "</style>"
211 "<div id='parent'>" 245 "<div id='parent'>"
212 " <div id='child'>" 246 " <div id='child'>"
213 " <div id='grandchild'></div>" 247 " <div id='grandchild'></div>"
(...skipping 12 matching lines...) Expand all
226 260
227 parent->clipper().clearClipRectsIncludingDescendants(AbsoluteClipRects); 261 parent->clipper().clearClipRectsIncludingDescendants(AbsoluteClipRects);
228 262
229 EXPECT_TRUE(parent->clipRectsCache()); 263 EXPECT_TRUE(parent->clipRectsCache());
230 EXPECT_TRUE(child->clipRectsCache()); 264 EXPECT_TRUE(child->clipRectsCache());
231 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root); 265 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root);
232 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root); 266 EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root);
233 } 267 }
234 268
235 } // namespace blink 269 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/PaintLayerClipper.cpp ('k') | third_party/WebKit/Source/core/paint/PaintLayerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698