OLD | NEW |
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 "platform/graphics/paint/DisplayItemList.h" | 5 #include "platform/graphics/paint/DisplayItemList.h" |
6 | 6 |
7 #include "SkPictureRecorder.h" | 7 #include "SkPictureRecorder.h" |
8 #include "SkTypes.h" | 8 #include "SkTypes.h" |
9 #include "platform/graphics/paint/DrawingDisplayItem.h" | 9 #include "platform/graphics/paint/DrawingDisplayItem.h" |
10 #include "platform/graphics/paint/SubsequenceDisplayItem.h" | 10 #include "platform/graphics/paint/SubsequenceDisplayItem.h" |
11 #include "platform/graphics/paint/TransformDisplayItem.h" | |
12 #include "platform/graphics/skia/SkiaUtils.h" | 11 #include "platform/graphics/skia/SkiaUtils.h" |
13 #include "platform/testing/FakeDisplayItemClient.h" | 12 #include "platform/testing/FakeDisplayItemClient.h" |
14 #include "platform/transforms/AffineTransform.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
16 | 14 |
17 namespace blink { | 15 namespace blink { |
18 namespace { | 16 namespace { |
19 | 17 |
20 #define EXPECT_RECT_EQ(expected, actual) \ | 18 #define EXPECT_RECT_EQ(expected, actual) \ |
21 do { \ | 19 do { \ |
22 const IntRect& actualRect = actual; \ | 20 const IntRect& actualRect = actual; \ |
23 EXPECT_EQ(expected.x(), actualRect.x()); \ | 21 EXPECT_EQ(expected.x(), actualRect.x()); \ |
24 EXPECT_EQ(expected.y(), actualRect.y()); \ | 22 EXPECT_EQ(expected.y(), actualRect.y()); \ |
(...skipping 16 matching lines...) Expand all Loading... |
41 { | 39 { |
42 SkPictureRecorder recorder; | 40 SkPictureRecorder recorder; |
43 SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height()); | 41 SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height()); |
44 canvas->drawRect(SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bo
unds.height()), | 42 canvas->drawRect(SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bo
unds.height()), |
45 SkPaint()); | 43 SkPaint()); |
46 return fromSkSp(recorder.finishRecordingAsPicture()); | 44 return fromSkSp(recorder.finishRecordingAsPicture()); |
47 } | 45 } |
48 | 46 |
49 TEST_F(DisplayItemListTest, AppendVisualRect_Simple) | 47 TEST_F(DisplayItemListTest, AppendVisualRect_Simple) |
50 { | 48 { |
51 // One drawing: D. | |
52 | |
53 IntRect drawingBounds(5, 6, 7, 8); | 49 IntRect drawingBounds(5, 6, 7, 8); |
54 m_list.allocateAndConstruct<DrawingDisplayItem>( | 50 m_list.allocateAndConstruct<DrawingDisplayItem>( |
55 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngBounds), true); | 51 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngBounds), true); |
56 m_list.appendVisualRect(drawingBounds); | 52 m_list.appendVisualRect(drawingBounds); |
57 | 53 |
58 EXPECT_EQ(static_cast<size_t>(1), m_list.size()); | 54 EXPECT_EQ(static_cast<size_t>(1), m_list.size()); |
59 EXPECT_RECT_EQ(drawingBounds, m_list.visualRect(0)); | 55 EXPECT_RECT_EQ(drawingBounds, m_list.visualRect(0)); |
60 } | 56 } |
61 | 57 |
62 TEST_F(DisplayItemListTest, AppendVisualRect_EmptyBlock) | |
63 { | |
64 // One block: B1, E1. | |
65 | |
66 IntRect subsequenceBounds(5, 6, 7, 8); | |
67 m_list.allocateAndConstruct<BeginSubsequenceDisplayItem>(m_client); | |
68 m_list.appendVisualRect(subsequenceBounds); | |
69 | |
70 m_list.allocateAndConstruct<EndSubsequenceDisplayItem>(m_client); | |
71 m_list.appendVisualRect(subsequenceBounds); | |
72 | |
73 EXPECT_EQ(static_cast<size_t>(2), m_list.size()); | |
74 EXPECT_RECT_EQ(subsequenceBounds, m_list.visualRect(0)); | |
75 EXPECT_RECT_EQ(subsequenceBounds, m_list.visualRect(1)); | |
76 } | |
77 | |
78 TEST_F(DisplayItemListTest, AppendVisualRect_EmptyBlockContainingEmptyBlock) | |
79 { | |
80 // Two nested blocks: B1, B2, E2, E1. | |
81 | |
82 IntRect subsequenceBounds(5, 6, 7, 8); | |
83 m_list.allocateAndConstruct<BeginSubsequenceDisplayItem>(m_client); | |
84 m_list.appendVisualRect(subsequenceBounds); | |
85 | |
86 IntRect transformBounds(5, 6, 1, 1); | |
87 AffineTransform transform; | |
88 m_list.allocateAndConstruct<BeginTransformDisplayItem>(m_client, transform); | |
89 m_list.appendVisualRect(transformBounds); | |
90 | |
91 m_list.allocateAndConstruct<EndTransformDisplayItem>(m_client); | |
92 m_list.appendVisualRect(transformBounds); | |
93 | |
94 m_list.allocateAndConstruct<EndSubsequenceDisplayItem>(m_client); | |
95 m_list.appendVisualRect(subsequenceBounds); | |
96 | |
97 EXPECT_EQ(static_cast<size_t>(4), m_list.size()); | |
98 EXPECT_RECT_EQ(subsequenceBounds, m_list.visualRect(0)); | |
99 EXPECT_RECT_EQ(transformBounds, m_list.visualRect(1)); | |
100 EXPECT_RECT_EQ(transformBounds, m_list.visualRect(2)); | |
101 EXPECT_RECT_EQ(subsequenceBounds, m_list.visualRect(3)); | |
102 } | |
103 | |
104 TEST_F(DisplayItemListTest, AppendVisualRect_EmptyBlockContainingEscapedEmptyBlo
ck) | |
105 { | |
106 // Two nested blocks with the inner block escaping: | |
107 // B1, B2 (escapes), E2, E1. | |
108 | |
109 IntRect subsequenceBounds(5, 6, 7, 8); | |
110 m_list.allocateAndConstruct<BeginSubsequenceDisplayItem>(m_client); | |
111 m_list.appendVisualRect(subsequenceBounds); | |
112 | |
113 IntRect transformBounds(1, 2, 3, 4); | |
114 AffineTransform transform; | |
115 m_list.allocateAndConstruct<BeginTransformDisplayItem>(m_client, transform); | |
116 m_list.appendVisualRect(transformBounds); | |
117 | |
118 m_list.allocateAndConstruct<EndTransformDisplayItem>(m_client); | |
119 m_list.appendVisualRect(transformBounds); | |
120 | |
121 m_list.allocateAndConstruct<EndSubsequenceDisplayItem>(m_client); | |
122 m_list.appendVisualRect(subsequenceBounds); | |
123 | |
124 EXPECT_EQ(static_cast<size_t>(4), m_list.size()); | |
125 IntRect mergedSubsequenceBounds(1, 2, 11, 12); | |
126 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(0)); | |
127 EXPECT_RECT_EQ(transformBounds, m_list.visualRect(1)); | |
128 EXPECT_RECT_EQ(transformBounds, m_list.visualRect(2)); | |
129 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(3)); | |
130 } | |
131 | |
132 TEST_F(DisplayItemListTest, AppendVisualRect_BlockContainingDrawing) | 58 TEST_F(DisplayItemListTest, AppendVisualRect_BlockContainingDrawing) |
133 { | 59 { |
134 // One block with one drawing: B1, Da, E1. | 60 // TODO(wkorman): Note the visual rects for the paired begin/end are now |
| 61 // irrelevant as they're overwritten in cc::DisplayItemList when rebuilt to |
| 62 // represent the union of all drawing display item visual rects between the |
| 63 // pair. We should consider revising Blink's display item list in some form |
| 64 // so as to only store visual rects for drawing display items. |
135 | 65 |
136 IntRect subsequenceBounds(5, 6, 7, 8); | 66 IntRect subsequenceBounds(5, 6, 7, 8); |
137 m_list.allocateAndConstruct<BeginSubsequenceDisplayItem>(m_client); | 67 m_list.allocateAndConstruct<BeginSubsequenceDisplayItem>(m_client); |
138 m_list.appendVisualRect(subsequenceBounds); | 68 m_list.appendVisualRect(subsequenceBounds); |
139 | 69 |
140 IntRect drawingBounds(5, 6, 1, 1); | 70 IntRect drawingBounds(5, 6, 1, 1); |
141 m_list.allocateAndConstruct<DrawingDisplayItem>( | 71 m_list.allocateAndConstruct<DrawingDisplayItem>( |
142 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngBounds), true); | 72 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngBounds), true); |
143 m_list.appendVisualRect(drawingBounds); | 73 m_list.appendVisualRect(drawingBounds); |
144 | 74 |
145 m_list.allocateAndConstruct<EndSubsequenceDisplayItem>(m_client); | 75 m_list.allocateAndConstruct<EndSubsequenceDisplayItem>(m_client); |
146 m_list.appendVisualRect(subsequenceBounds); | 76 m_list.appendVisualRect(subsequenceBounds); |
147 | 77 |
148 EXPECT_EQ(static_cast<size_t>(3), m_list.size()); | 78 EXPECT_EQ(static_cast<size_t>(3), m_list.size()); |
149 EXPECT_RECT_EQ(subsequenceBounds, m_list.visualRect(0)); | 79 EXPECT_RECT_EQ(subsequenceBounds, m_list.visualRect(0)); |
150 EXPECT_RECT_EQ(drawingBounds, m_list.visualRect(1)); | 80 EXPECT_RECT_EQ(drawingBounds, m_list.visualRect(1)); |
151 EXPECT_RECT_EQ(subsequenceBounds, m_list.visualRect(2)); | 81 EXPECT_RECT_EQ(subsequenceBounds, m_list.visualRect(2)); |
152 } | 82 } |
153 | |
154 TEST_F(DisplayItemListTest, AppendVisualRect_BlockContainingEscapedDrawing) | |
155 { | |
156 // One block with one drawing: B1, Da (escapes), E1. | |
157 | |
158 IntRect subsequenceBounds(5, 6, 7, 8); | |
159 m_list.allocateAndConstruct<BeginSubsequenceDisplayItem>(m_client); | |
160 m_list.appendVisualRect(subsequenceBounds); | |
161 | |
162 IntRect drawingBounds(1, 2, 3, 4); | |
163 m_list.allocateAndConstruct<DrawingDisplayItem>( | |
164 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngBounds), true); | |
165 m_list.appendVisualRect(drawingBounds); | |
166 | |
167 m_list.allocateAndConstruct<EndSubsequenceDisplayItem>(m_client); | |
168 m_list.appendVisualRect(subsequenceBounds); | |
169 | |
170 EXPECT_EQ(static_cast<size_t>(3), m_list.size()); | |
171 IntRect mergedSubsequenceBounds(1, 2, 11, 12); | |
172 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(0)); | |
173 EXPECT_RECT_EQ(drawingBounds, m_list.visualRect(1)); | |
174 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(2)); | |
175 } | |
176 | |
177 TEST_F(DisplayItemListTest, AppendVisualRect_DrawingFollowedByBlockContainingEsc
apedDrawing) | |
178 { | |
179 // One drawing followed by one block with one drawing: Da, B1, Db (escapes),
E1. | |
180 | |
181 IntRect drawingABounds(1, 2, 3, 4); | |
182 m_list.allocateAndConstruct<DrawingDisplayItem>( | |
183 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngABounds), true); | |
184 m_list.appendVisualRect(drawingABounds); | |
185 | |
186 IntRect subsequenceBounds(5, 6, 7, 8); | |
187 m_list.allocateAndConstruct<BeginSubsequenceDisplayItem>(m_client); | |
188 m_list.appendVisualRect(subsequenceBounds); | |
189 | |
190 IntRect drawingBBounds(13, 14, 1, 1); | |
191 m_list.allocateAndConstruct<DrawingDisplayItem>( | |
192 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngBBounds), true); | |
193 m_list.appendVisualRect(drawingBBounds); | |
194 | |
195 m_list.allocateAndConstruct<EndSubsequenceDisplayItem>(m_client); | |
196 m_list.appendVisualRect(subsequenceBounds); | |
197 | |
198 EXPECT_EQ(static_cast<size_t>(4), m_list.size()); | |
199 EXPECT_RECT_EQ(drawingABounds, m_list.visualRect(0)); | |
200 IntRect mergedSubsequenceBounds(5, 6, 9, 9); | |
201 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(1)); | |
202 EXPECT_RECT_EQ(drawingBBounds, m_list.visualRect(2)); | |
203 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(3)); | |
204 } | |
205 | |
206 TEST_F(DisplayItemListTest, AppendVisualRect_TwoBlocksTwoDrawings) | |
207 { | |
208 // Multiple nested blocks with drawings amidst: B1, Da, B2, Db, E2, E1. | |
209 | |
210 IntRect subsequenceBounds(5, 6, 7, 8); | |
211 m_list.allocateAndConstruct<BeginSubsequenceDisplayItem>(m_client); | |
212 m_list.appendVisualRect(subsequenceBounds); | |
213 | |
214 IntRect drawingABounds(5, 6, 1, 1); | |
215 m_list.allocateAndConstruct<DrawingDisplayItem>( | |
216 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngABounds), true); | |
217 m_list.appendVisualRect(drawingABounds); | |
218 | |
219 IntRect transformBounds(7, 8, 2, 2); | |
220 AffineTransform transform; | |
221 m_list.allocateAndConstruct<BeginTransformDisplayItem>(m_client, transform); | |
222 m_list.appendVisualRect(transformBounds); | |
223 | |
224 IntRect drawingBBounds(7, 8, 1, 1); | |
225 m_list.allocateAndConstruct<DrawingDisplayItem>( | |
226 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngBBounds), true); | |
227 m_list.appendVisualRect(drawingBBounds); | |
228 | |
229 m_list.allocateAndConstruct<EndTransformDisplayItem>(m_client); | |
230 m_list.appendVisualRect(transformBounds); | |
231 | |
232 m_list.allocateAndConstruct<EndSubsequenceDisplayItem>(m_client); | |
233 m_list.appendVisualRect(subsequenceBounds); | |
234 | |
235 EXPECT_EQ(static_cast<size_t>(6), m_list.size()); | |
236 EXPECT_RECT_EQ(subsequenceBounds, m_list.visualRect(0)); | |
237 EXPECT_RECT_EQ(drawingABounds, m_list.visualRect(1)); | |
238 EXPECT_RECT_EQ(transformBounds, m_list.visualRect(2)); | |
239 EXPECT_RECT_EQ(drawingBBounds, m_list.visualRect(3)); | |
240 EXPECT_RECT_EQ(transformBounds, m_list.visualRect(4)); | |
241 EXPECT_RECT_EQ(subsequenceBounds, m_list.visualRect(5)); | |
242 } | |
243 | |
244 TEST_F(DisplayItemListTest, AppendVisualRect_TwoBlocksTwoDrawingsInnerDrawingEsc
aped) | |
245 { | |
246 // Multiple nested blocks with drawings amidst: B1, Da, B2, Db (escapes), E2
, E1. | |
247 | |
248 IntRect subsequenceBounds(5, 6, 7, 8); | |
249 m_list.allocateAndConstruct<BeginSubsequenceDisplayItem>(m_client); | |
250 m_list.appendVisualRect(subsequenceBounds); | |
251 | |
252 IntRect drawingABounds(5, 6, 1, 1); | |
253 m_list.allocateAndConstruct<DrawingDisplayItem>( | |
254 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngABounds), true); | |
255 m_list.appendVisualRect(drawingABounds); | |
256 | |
257 IntRect transformBounds(7, 8, 2, 2); | |
258 AffineTransform transform; | |
259 m_list.allocateAndConstruct<BeginTransformDisplayItem>(m_client, transform); | |
260 m_list.appendVisualRect(transformBounds); | |
261 | |
262 IntRect drawingBBounds(1, 2, 3, 4); | |
263 m_list.allocateAndConstruct<DrawingDisplayItem>( | |
264 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngBBounds), true); | |
265 m_list.appendVisualRect(drawingBBounds); | |
266 | |
267 m_list.allocateAndConstruct<EndTransformDisplayItem>(m_client); | |
268 m_list.appendVisualRect(transformBounds); | |
269 | |
270 m_list.allocateAndConstruct<EndSubsequenceDisplayItem>(m_client); | |
271 m_list.appendVisualRect(subsequenceBounds); | |
272 | |
273 EXPECT_EQ(static_cast<size_t>(6), m_list.size()); | |
274 IntRect mergedSubsequenceBounds(1, 2, 11, 12); | |
275 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(0)); | |
276 EXPECT_RECT_EQ(drawingABounds, m_list.visualRect(1)); | |
277 IntRect mergedTransformBounds(1, 2, 8, 8); | |
278 EXPECT_RECT_EQ(mergedTransformBounds, m_list.visualRect(2)); | |
279 EXPECT_RECT_EQ(drawingBBounds, m_list.visualRect(3)); | |
280 EXPECT_RECT_EQ(mergedTransformBounds, m_list.visualRect(4)); | |
281 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(5)); | |
282 } | |
283 | |
284 TEST_F(DisplayItemListTest, AppendVisualRect_TwoBlocksTwoDrawingsOuterDrawingEsc
aped) | |
285 { | |
286 // Multiple nested blocks with drawings amidst: B1, Da (escapes), B2, Db, E2
, E1. | |
287 | |
288 IntRect subsequenceBounds(5, 6, 7, 8); | |
289 m_list.allocateAndConstruct<BeginSubsequenceDisplayItem>(m_client); | |
290 m_list.appendVisualRect(subsequenceBounds); | |
291 | |
292 IntRect drawingABounds(1, 2, 3, 4); | |
293 m_list.allocateAndConstruct<DrawingDisplayItem>( | |
294 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngABounds), true); | |
295 m_list.appendVisualRect(drawingABounds); | |
296 | |
297 IntRect transformBounds(7, 8, 2, 2); | |
298 AffineTransform transform; | |
299 m_list.allocateAndConstruct<BeginTransformDisplayItem>(m_client, transform); | |
300 m_list.appendVisualRect(transformBounds); | |
301 | |
302 IntRect drawingBBounds(7, 8, 1, 1); | |
303 m_list.allocateAndConstruct<DrawingDisplayItem>( | |
304 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngBBounds), true); | |
305 m_list.appendVisualRect(drawingBBounds); | |
306 | |
307 m_list.allocateAndConstruct<EndTransformDisplayItem>(m_client); | |
308 m_list.appendVisualRect(transformBounds); | |
309 | |
310 m_list.allocateAndConstruct<EndSubsequenceDisplayItem>(m_client); | |
311 m_list.appendVisualRect(subsequenceBounds); | |
312 | |
313 EXPECT_EQ(static_cast<size_t>(6), m_list.size()); | |
314 IntRect mergedSubsequenceBounds(1, 2, 11, 12); | |
315 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(0)); | |
316 EXPECT_RECT_EQ(drawingABounds, m_list.visualRect(1)); | |
317 EXPECT_RECT_EQ(transformBounds, m_list.visualRect(2)); | |
318 EXPECT_RECT_EQ(drawingBBounds, m_list.visualRect(3)); | |
319 EXPECT_RECT_EQ(transformBounds, m_list.visualRect(4)); | |
320 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(5)); | |
321 } | |
322 | |
323 TEST_F(DisplayItemListTest, AppendVisualRect_TwoBlocksTwoDrawingsBothDrawingsEsc
aped) | |
324 { | |
325 // Multiple nested blocks with drawings amidst: | |
326 // B1, Da (escapes to the right), B2, Db (escapes to the left), E2, E1. | |
327 | |
328 IntRect subsequenceBounds(5, 6, 7, 8); | |
329 m_list.allocateAndConstruct<BeginSubsequenceDisplayItem>(m_client); | |
330 m_list.appendVisualRect(subsequenceBounds); | |
331 | |
332 IntRect drawingABounds(13, 14, 1, 1); | |
333 m_list.allocateAndConstruct<DrawingDisplayItem>( | |
334 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngABounds), true); | |
335 m_list.appendVisualRect(drawingABounds); | |
336 | |
337 IntRect transformBounds(7, 8, 2, 2); | |
338 AffineTransform transform; | |
339 m_list.allocateAndConstruct<BeginTransformDisplayItem>(m_client, transform); | |
340 m_list.appendVisualRect(transformBounds); | |
341 | |
342 IntRect drawingBBounds(1, 2, 3, 4); | |
343 m_list.allocateAndConstruct<DrawingDisplayItem>( | |
344 m_client, DisplayItem::Type::DocumentBackground, createRectPicture(drawi
ngBBounds), true); | |
345 m_list.appendVisualRect(drawingBBounds); | |
346 | |
347 m_list.allocateAndConstruct<EndTransformDisplayItem>(m_client); | |
348 m_list.appendVisualRect(transformBounds); | |
349 | |
350 m_list.allocateAndConstruct<EndSubsequenceDisplayItem>(m_client); | |
351 m_list.appendVisualRect(subsequenceBounds); | |
352 | |
353 EXPECT_EQ(static_cast<size_t>(6), m_list.size()); | |
354 IntRect mergedSubsequenceBounds(1, 2, 13, 13); | |
355 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(0)); | |
356 EXPECT_RECT_EQ(drawingABounds, m_list.visualRect(1)); | |
357 IntRect mergedTransformBounds(1, 2, 8, 8); | |
358 EXPECT_RECT_EQ(mergedTransformBounds, m_list.visualRect(2)); | |
359 EXPECT_RECT_EQ(drawingBBounds, m_list.visualRect(3)); | |
360 EXPECT_RECT_EQ(mergedTransformBounds, m_list.visualRect(4)); | |
361 EXPECT_RECT_EQ(mergedSubsequenceBounds, m_list.visualRect(5)); | |
362 } | |
363 | |
364 } // namespace | 83 } // namespace |
365 } // namespace blink | 84 } // namespace blink |
OLD | NEW |