OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 "cc/playback/display_item_list.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include <vector> | |
10 | |
11 #include "base/memory/ptr_util.h" | |
12 #include "base/trace_event/trace_event_argument.h" | |
13 #include "cc/output/filter_operation.h" | |
14 #include "cc/output/filter_operations.h" | |
15 #include "cc/paint/paint_canvas.h" | |
16 #include "cc/paint/paint_flags.h" | |
17 #include "cc/paint/paint_record.h" | |
18 #include "cc/paint/paint_recorder.h" | |
19 #include "cc/paint/paint_surface.h" | |
20 #include "cc/playback/clip_display_item.h" | |
21 #include "cc/playback/clip_path_display_item.h" | |
22 #include "cc/playback/compositing_display_item.h" | |
23 #include "cc/playback/drawing_display_item.h" | |
24 #include "cc/playback/filter_display_item.h" | |
25 #include "cc/playback/float_clip_display_item.h" | |
26 #include "cc/playback/transform_display_item.h" | |
27 #include "cc/test/geometry_test_utils.h" | |
28 #include "cc/test/skia_common.h" | |
29 #include "testing/gmock/include/gmock/gmock.h" | |
30 #include "testing/gtest/include/gtest/gtest.h" | |
31 #include "third_party/skia/include/core/SkBitmap.h" | |
32 #include "third_party/skia/include/core/SkColor.h" | |
33 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | |
34 #include "third_party/skia/include/effects/SkImageSource.h" | |
35 #include "ui/gfx/geometry/rect.h" | |
36 #include "ui/gfx/geometry/rect_conversions.h" | |
37 #include "ui/gfx/skia_util.h" | |
38 | |
39 namespace cc { | |
40 | |
41 namespace { | |
42 | |
43 const gfx::Rect kVisualRect(0, 0, 42, 42); | |
44 | |
45 sk_sp<const PaintRecord> CreateRectPicture(const gfx::Rect& bounds) { | |
46 PaintRecorder recorder; | |
47 PaintCanvas* canvas = | |
48 recorder.beginRecording(bounds.width(), bounds.height()); | |
49 canvas->drawRect( | |
50 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()), | |
51 PaintFlags()); | |
52 return recorder.finishRecordingAsPicture(); | |
53 } | |
54 | |
55 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, | |
56 const gfx::Size& layer_size) { | |
57 gfx::PointF offset(2.f, 3.f); | |
58 PaintRecorder recorder; | |
59 | |
60 PaintFlags red_paint; | |
61 red_paint.setColor(SK_ColorRED); | |
62 | |
63 PaintCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( | |
64 offset.x(), offset.y(), layer_size.width(), layer_size.height())); | |
65 canvas->translate(offset.x(), offset.y()); | |
66 canvas->drawRect(SkRect::MakeWH(4, 4), red_paint); | |
67 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
68 kVisualRect, recorder.finishRecordingAsPicture()); | |
69 } | |
70 | |
71 } // namespace | |
72 | |
73 TEST(DisplayItemListTest, SingleDrawingItem) { | |
74 gfx::Rect layer_rect(100, 100); | |
75 PaintRecorder recorder; | |
76 PaintFlags blue_flags; | |
77 blue_flags.setColor(SK_ColorBLUE); | |
78 PaintFlags red_paint; | |
79 red_paint.setColor(SK_ColorRED); | |
80 unsigned char pixels[4 * 100 * 100] = {0}; | |
81 auto list = make_scoped_refptr(new DisplayItemList); | |
82 | |
83 gfx::PointF offset(8.f, 9.f); | |
84 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | |
85 PaintCanvas* canvas = | |
86 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); | |
87 canvas->translate(offset.x(), offset.y()); | |
88 canvas->drawRect(SkRect::MakeLTRB(0.f, 0.f, 60.f, 60.f), red_paint); | |
89 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); | |
90 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
91 kVisualRect, recorder.finishRecordingAsPicture()); | |
92 list->Finalize(); | |
93 DrawDisplayList(pixels, layer_rect, list); | |
94 | |
95 SkBitmap expected_bitmap; | |
96 unsigned char expected_pixels[4 * 100 * 100] = {0}; | |
97 SkImageInfo info = | |
98 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | |
99 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | |
100 SkiaPaintCanvas expected_canvas(expected_bitmap); | |
101 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | |
102 expected_canvas.drawRect( | |
103 SkRect::MakeLTRB(0.f + offset.x(), 0.f + offset.y(), 60.f + offset.x(), | |
104 60.f + offset.y()), | |
105 red_paint); | |
106 expected_canvas.drawRect( | |
107 SkRect::MakeLTRB(50.f + offset.x(), 50.f + offset.y(), 75.f + offset.x(), | |
108 75.f + offset.y()), | |
109 blue_flags); | |
110 | |
111 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | |
112 } | |
113 | |
114 TEST(DisplayItemListTest, ClipItem) { | |
115 gfx::Rect layer_rect(100, 100); | |
116 PaintRecorder recorder; | |
117 PaintFlags blue_flags; | |
118 blue_flags.setColor(SK_ColorBLUE); | |
119 PaintFlags red_paint; | |
120 red_paint.setColor(SK_ColorRED); | |
121 unsigned char pixels[4 * 100 * 100] = {0}; | |
122 auto list = make_scoped_refptr(new DisplayItemList); | |
123 | |
124 gfx::PointF first_offset(8.f, 9.f); | |
125 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | |
126 PaintCanvas* canvas = | |
127 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); | |
128 canvas->translate(first_offset.x(), first_offset.y()); | |
129 canvas->drawRect(SkRect::MakeWH(60, 60), red_paint); | |
130 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
131 kVisualRect, recorder.finishRecordingAsPicture()); | |
132 | |
133 gfx::Rect clip_rect(60, 60, 10, 10); | |
134 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
135 clip_rect, std::vector<SkRRect>(), true); | |
136 | |
137 gfx::PointF second_offset(2.f, 3.f); | |
138 gfx::RectF second_recording_rect(second_offset, | |
139 gfx::SizeF(layer_rect.size())); | |
140 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); | |
141 canvas->translate(second_offset.x(), second_offset.y()); | |
142 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); | |
143 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
144 kVisualRect, recorder.finishRecordingAsPicture()); | |
145 | |
146 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
147 list->Finalize(); | |
148 | |
149 DrawDisplayList(pixels, layer_rect, list); | |
150 | |
151 SkBitmap expected_bitmap; | |
152 unsigned char expected_pixels[4 * 100 * 100] = {0}; | |
153 SkImageInfo info = | |
154 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | |
155 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | |
156 SkiaPaintCanvas expected_canvas(expected_bitmap); | |
157 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | |
158 expected_canvas.drawRect( | |
159 SkRect::MakeLTRB(0.f + first_offset.x(), 0.f + first_offset.y(), | |
160 60.f + first_offset.x(), 60.f + first_offset.y()), | |
161 red_paint); | |
162 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); | |
163 expected_canvas.drawRect( | |
164 SkRect::MakeLTRB(50.f + second_offset.x(), 50.f + second_offset.y(), | |
165 75.f + second_offset.x(), 75.f + second_offset.y()), | |
166 blue_flags); | |
167 | |
168 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | |
169 } | |
170 | |
171 TEST(DisplayItemListTest, TransformItem) { | |
172 gfx::Rect layer_rect(100, 100); | |
173 PaintRecorder recorder; | |
174 PaintFlags blue_flags; | |
175 blue_flags.setColor(SK_ColorBLUE); | |
176 PaintFlags red_paint; | |
177 red_paint.setColor(SK_ColorRED); | |
178 unsigned char pixels[4 * 100 * 100] = {0}; | |
179 auto list = make_scoped_refptr(new DisplayItemList); | |
180 | |
181 gfx::PointF first_offset(8.f, 9.f); | |
182 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | |
183 PaintCanvas* canvas = | |
184 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); | |
185 canvas->translate(first_offset.x(), first_offset.y()); | |
186 canvas->drawRect(SkRect::MakeWH(60, 60), red_paint); | |
187 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
188 kVisualRect, recorder.finishRecordingAsPicture()); | |
189 | |
190 gfx::Transform transform; | |
191 transform.Rotate(45.0); | |
192 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); | |
193 | |
194 gfx::PointF second_offset(2.f, 3.f); | |
195 gfx::RectF second_recording_rect(second_offset, | |
196 gfx::SizeF(layer_rect.size())); | |
197 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); | |
198 canvas->translate(second_offset.x(), second_offset.y()); | |
199 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); | |
200 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
201 kVisualRect, recorder.finishRecordingAsPicture()); | |
202 | |
203 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | |
204 list->Finalize(); | |
205 | |
206 DrawDisplayList(pixels, layer_rect, list); | |
207 | |
208 SkBitmap expected_bitmap; | |
209 unsigned char expected_pixels[4 * 100 * 100] = {0}; | |
210 SkImageInfo info = | |
211 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | |
212 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | |
213 SkiaPaintCanvas expected_canvas(expected_bitmap); | |
214 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | |
215 expected_canvas.drawRect( | |
216 SkRect::MakeLTRB(0.f + first_offset.x(), 0.f + first_offset.y(), | |
217 60.f + first_offset.x(), 60.f + first_offset.y()), | |
218 red_paint); | |
219 expected_canvas.setMatrix(transform.matrix()); | |
220 expected_canvas.drawRect( | |
221 SkRect::MakeLTRB(50.f + second_offset.x(), 50.f + second_offset.y(), | |
222 75.f + second_offset.x(), 75.f + second_offset.y()), | |
223 blue_flags); | |
224 | |
225 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | |
226 } | |
227 | |
228 TEST(DisplayItemListTest, FilterItem) { | |
229 gfx::Rect layer_rect(100, 100); | |
230 FilterOperations filters; | |
231 unsigned char pixels[4 * 100 * 100] = {0}; | |
232 auto list = make_scoped_refptr(new DisplayItemList); | |
233 | |
234 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50); | |
235 SkCanvas* source_canvas = source_surface->getCanvas(); | |
236 source_canvas->clear(SkColorSetRGB(128, 128, 128)); | |
237 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot(); | |
238 | |
239 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are | |
240 // dependent on the provided |src| bounds. This means, for example, that | |
241 // translating |src| results in a corresponding translation of |dst|. But this | |
242 // is not the case for all SkImageFilters; for some of them (e.g. | |
243 // SkImageSource), the computation of |dst| in computeFastBounds doesn't | |
244 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by | |
245 // translating |dst| after it is computed by computeFastBounds, rather than | |
246 // translating |src| before it provided to computedFastBounds) can cause | |
247 // incorrect clipping of filter output. To test for this, we include an | |
248 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined | |
249 // below. | |
250 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); | |
251 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); | |
252 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); | |
253 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); | |
254 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>( | |
255 filters, filter_bounds, filter_bounds.origin()); | |
256 | |
257 // Include a rect drawing so that filter is actually applied to something. | |
258 { | |
259 PaintRecorder recorder; | |
260 | |
261 PaintFlags red_paint; | |
262 red_paint.setColor(SK_ColorRED); | |
263 | |
264 PaintCanvas* canvas = recorder.beginRecording( | |
265 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())); | |
266 canvas->drawRect( | |
267 SkRect::MakeLTRB(filter_bounds.x(), filter_bounds.y(), | |
268 filter_bounds.right(), filter_bounds.bottom()), | |
269 red_paint); | |
270 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
271 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); | |
272 } | |
273 | |
274 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); | |
275 list->Finalize(); | |
276 | |
277 DrawDisplayList(pixels, layer_rect, list); | |
278 | |
279 SkBitmap expected_bitmap; | |
280 unsigned char expected_pixels[4 * 100 * 100] = {0}; | |
281 PaintFlags paint; | |
282 paint.setColor(SkColorSetRGB(64, 64, 64)); | |
283 SkImageInfo info = | |
284 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | |
285 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | |
286 SkiaPaintCanvas expected_canvas(expected_bitmap); | |
287 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); | |
288 | |
289 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | |
290 } | |
291 | |
292 TEST(DisplayItemListTest, ApproximateMemoryUsage) { | |
293 const int kNumCommandsInTestSkPicture = 1000; | |
294 size_t memory_usage; | |
295 | |
296 // Make an PaintRecord whose size is known. | |
297 gfx::Rect layer_rect(100, 100); | |
298 PaintRecorder recorder; | |
299 PaintFlags blue_flags; | |
300 blue_flags.setColor(SK_ColorBLUE); | |
301 PaintCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); | |
302 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) | |
303 canvas->drawRect(SkRect(), blue_flags); | |
304 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); | |
305 size_t record_size = record->approximateBytesUsed(); | |
306 ASSERT_GE(record_size, kNumCommandsInTestSkPicture * sizeof(SkRect)); | |
307 | |
308 auto list = make_scoped_refptr(new DisplayItemList); | |
309 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, record); | |
310 list->Finalize(); | |
311 memory_usage = list->ApproximateMemoryUsage(); | |
312 EXPECT_GE(memory_usage, record_size); | |
313 EXPECT_LE(memory_usage, 2 * record_size); | |
314 } | |
315 | |
316 TEST(DisplayItemListTest, AsValueWithNoItems) { | |
317 auto list = make_scoped_refptr(new DisplayItemList); | |
318 list->SetRetainVisualRectsForTesting(true); | |
319 list->Finalize(); | |
320 | |
321 std::string value = list->CreateTracedValue(true)->ToString(); | |
322 EXPECT_EQ(value.find("\"layer_rect\": [0,0,0,0]"), std::string::npos); | |
323 EXPECT_NE(value.find("\"items\":[]"), std::string::npos); | |
324 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos); | |
325 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); | |
326 | |
327 value = list->CreateTracedValue(false)->ToString(); | |
328 EXPECT_EQ(value.find("\"layer_rect\": [0,0,0,0]"), std::string::npos); | |
329 EXPECT_EQ(value.find("\"items\":"), std::string::npos); | |
330 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos); | |
331 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); | |
332 } | |
333 | |
334 TEST(DisplayItemListTest, AsValueWithItems) { | |
335 gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9); | |
336 auto list = make_scoped_refptr(new DisplayItemList); | |
337 list->SetRetainVisualRectsForTesting(true); | |
338 gfx::Transform transform; | |
339 transform.Translate(6.f, 7.f); | |
340 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); | |
341 AppendFirstSerializationTestPicture(list, layer_rect.size()); | |
342 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | |
343 list->Finalize(); | |
344 | |
345 std::string value = list->CreateTracedValue(true)->ToString(); | |
346 EXPECT_EQ(value.find("\"layer_rect\": [0,0,42,42]"), std::string::npos); | |
347 EXPECT_NE(value.find("{\"items\":[\"TransformDisplayItem"), | |
348 std::string::npos); | |
349 EXPECT_NE(value.find("visualRect: [0,0 42x42]"), std::string::npos); | |
350 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); | |
351 | |
352 value = list->CreateTracedValue(false)->ToString(); | |
353 EXPECT_EQ(value.find("\"layer_rect\": [0,0,42,42]"), std::string::npos); | |
354 EXPECT_EQ(value.find("{\"items\":[\"TransformDisplayItem"), | |
355 std::string::npos); | |
356 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos); | |
357 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); | |
358 } | |
359 | |
360 TEST(DisplayItemListTest, SizeEmpty) { | |
361 auto list = make_scoped_refptr(new DisplayItemList); | |
362 EXPECT_EQ(0u, list->size()); | |
363 } | |
364 | |
365 TEST(DisplayItemListTest, SizeOne) { | |
366 auto list = make_scoped_refptr(new DisplayItemList); | |
367 gfx::Rect drawing_bounds(5, 6, 1, 1); | |
368 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
369 drawing_bounds, CreateRectPicture(drawing_bounds)); | |
370 EXPECT_EQ(1u, list->size()); | |
371 } | |
372 | |
373 TEST(DisplayItemListTest, SizeMultiple) { | |
374 auto list = make_scoped_refptr(new DisplayItemList); | |
375 gfx::Rect clip_bounds(5, 6, 7, 8); | |
376 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
377 clip_bounds, std::vector<SkRRect>(), true); | |
378 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
379 EXPECT_EQ(2u, list->size()); | |
380 } | |
381 | |
382 TEST(DisplayItemListTest, AppendVisualRectSimple) { | |
383 auto list = make_scoped_refptr(new DisplayItemList); | |
384 | |
385 // One drawing: D. | |
386 | |
387 gfx::Rect drawing_bounds(5, 6, 7, 8); | |
388 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
389 drawing_bounds, CreateRectPicture(drawing_bounds)); | |
390 | |
391 EXPECT_EQ(1u, list->size()); | |
392 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0)); | |
393 } | |
394 | |
395 TEST(DisplayItemListTest, AppendVisualRectEmptyBlock) { | |
396 auto list = make_scoped_refptr(new DisplayItemList); | |
397 | |
398 // One block: B1, E1. | |
399 | |
400 gfx::Rect clip_bounds(5, 6, 7, 8); | |
401 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
402 clip_bounds, std::vector<SkRRect>(), true); | |
403 | |
404 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
405 | |
406 EXPECT_EQ(2u, list->size()); | |
407 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(0)); | |
408 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(1)); | |
409 } | |
410 | |
411 TEST(DisplayItemListTest, AppendVisualRectEmptyBlockContainingEmptyBlock) { | |
412 auto list = make_scoped_refptr(new DisplayItemList); | |
413 | |
414 // Two nested blocks: B1, B2, E2, E1. | |
415 | |
416 gfx::Rect clip_bounds(5, 6, 7, 8); | |
417 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
418 clip_bounds, std::vector<SkRRect>(), true); | |
419 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); | |
420 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | |
421 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
422 | |
423 EXPECT_EQ(4u, list->size()); | |
424 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(0)); | |
425 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(1)); | |
426 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(2)); | |
427 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(3)); | |
428 } | |
429 | |
430 TEST(DisplayItemListTest, AppendVisualRectBlockContainingDrawing) { | |
431 auto list = make_scoped_refptr(new DisplayItemList); | |
432 | |
433 // One block with one drawing: B1, Da, E1. | |
434 | |
435 gfx::Rect clip_bounds(5, 6, 7, 8); | |
436 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
437 clip_bounds, std::vector<SkRRect>(), true); | |
438 | |
439 gfx::Rect drawing_bounds(5, 6, 1, 1); | |
440 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
441 drawing_bounds, CreateRectPicture(drawing_bounds)); | |
442 | |
443 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
444 | |
445 EXPECT_EQ(3u, list->size()); | |
446 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0)); | |
447 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(1)); | |
448 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(2)); | |
449 } | |
450 | |
451 TEST(DisplayItemListTest, AppendVisualRectBlockContainingEscapedDrawing) { | |
452 auto list = make_scoped_refptr(new DisplayItemList); | |
453 | |
454 // One block with one drawing: B1, Da (escapes), E1. | |
455 | |
456 gfx::Rect clip_bounds(5, 6, 7, 8); | |
457 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
458 clip_bounds, std::vector<SkRRect>(), true); | |
459 | |
460 gfx::Rect drawing_bounds(1, 2, 3, 4); | |
461 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
462 drawing_bounds, CreateRectPicture(drawing_bounds)); | |
463 | |
464 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
465 | |
466 EXPECT_EQ(3u, list->size()); | |
467 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0)); | |
468 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(1)); | |
469 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(2)); | |
470 } | |
471 | |
472 TEST(DisplayItemListTest, | |
473 AppendVisualRectDrawingFollowedByBlockContainingEscapedDrawing) { | |
474 auto list = make_scoped_refptr(new DisplayItemList); | |
475 | |
476 // One drawing followed by one block with one drawing: Da, B1, Db (escapes), | |
477 // E1. | |
478 | |
479 gfx::Rect drawing_a_bounds(1, 2, 3, 4); | |
480 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
481 drawing_a_bounds, CreateRectPicture(drawing_a_bounds)); | |
482 | |
483 gfx::Rect clip_bounds(5, 6, 7, 8); | |
484 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
485 clip_bounds, std::vector<SkRRect>(), true); | |
486 | |
487 gfx::Rect drawing_b_bounds(13, 14, 1, 1); | |
488 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
489 drawing_b_bounds, CreateRectPicture(drawing_b_bounds)); | |
490 | |
491 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
492 | |
493 EXPECT_EQ(4u, list->size()); | |
494 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(0)); | |
495 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(1)); | |
496 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); | |
497 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); | |
498 } | |
499 | |
500 TEST(DisplayItemListTest, AppendVisualRectTwoBlocksTwoDrawings) { | |
501 auto list = make_scoped_refptr(new DisplayItemList); | |
502 | |
503 // Multiple nested blocks with drawings amidst: B1, Da, B2, Db, E2, E1. | |
504 | |
505 gfx::Rect clip_bounds(5, 6, 7, 8); | |
506 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
507 clip_bounds, std::vector<SkRRect>(), true); | |
508 | |
509 gfx::Rect drawing_a_bounds(5, 6, 1, 1); | |
510 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
511 drawing_a_bounds, CreateRectPicture(drawing_a_bounds)); | |
512 | |
513 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); | |
514 | |
515 gfx::Rect drawing_b_bounds(7, 8, 1, 1); | |
516 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
517 drawing_b_bounds, CreateRectPicture(drawing_b_bounds)); | |
518 | |
519 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | |
520 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
521 | |
522 EXPECT_EQ(6u, list->size()); | |
523 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); | |
524 merged_drawing_bounds.Union(drawing_b_bounds); | |
525 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); | |
526 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); | |
527 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); | |
528 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); | |
529 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4)); | |
530 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5)); | |
531 } | |
532 | |
533 TEST(DisplayItemListTest, | |
534 AppendVisualRectTwoBlocksTwoDrawingsInnerDrawingEscaped) { | |
535 auto list = make_scoped_refptr(new DisplayItemList); | |
536 | |
537 // Multiple nested blocks with drawings amidst: B1, Da, B2, Db (escapes), E2, | |
538 // E1. | |
539 | |
540 gfx::Rect clip_bounds(5, 6, 7, 8); | |
541 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
542 clip_bounds, std::vector<SkRRect>(), true); | |
543 | |
544 gfx::Rect drawing_a_bounds(5, 6, 1, 1); | |
545 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
546 drawing_a_bounds, CreateRectPicture(drawing_a_bounds)); | |
547 | |
548 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); | |
549 | |
550 gfx::Rect drawing_b_bounds(1, 2, 3, 4); | |
551 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
552 drawing_b_bounds, CreateRectPicture(drawing_b_bounds)); | |
553 | |
554 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | |
555 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
556 | |
557 EXPECT_EQ(6u, list->size()); | |
558 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); | |
559 merged_drawing_bounds.Union(drawing_b_bounds); | |
560 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); | |
561 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); | |
562 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); | |
563 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); | |
564 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4)); | |
565 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5)); | |
566 } | |
567 | |
568 TEST(DisplayItemListTest, | |
569 AppendVisualRectTwoBlocksTwoDrawingsOuterDrawingEscaped) { | |
570 auto list = make_scoped_refptr(new DisplayItemList); | |
571 | |
572 // Multiple nested blocks with drawings amidst: B1, Da (escapes), B2, Db, E2, | |
573 // E1. | |
574 | |
575 gfx::Rect clip_bounds(5, 6, 7, 8); | |
576 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
577 clip_bounds, std::vector<SkRRect>(), true); | |
578 | |
579 gfx::Rect drawing_a_bounds(1, 2, 3, 4); | |
580 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
581 drawing_a_bounds, CreateRectPicture(drawing_a_bounds)); | |
582 | |
583 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); | |
584 | |
585 gfx::Rect drawing_b_bounds(7, 8, 1, 1); | |
586 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
587 drawing_b_bounds, CreateRectPicture(drawing_b_bounds)); | |
588 | |
589 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | |
590 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
591 | |
592 EXPECT_EQ(6u, list->size()); | |
593 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); | |
594 merged_drawing_bounds.Union(drawing_b_bounds); | |
595 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); | |
596 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); | |
597 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); | |
598 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); | |
599 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4)); | |
600 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5)); | |
601 } | |
602 | |
603 TEST(DisplayItemListTest, | |
604 AppendVisualRectTwoBlocksTwoDrawingsBothDrawingsEscaped) { | |
605 auto list = make_scoped_refptr(new DisplayItemList); | |
606 | |
607 // Multiple nested blocks with drawings amidst: | |
608 // B1, Da (escapes to the right), B2, Db (escapes to the left), E2, E1. | |
609 | |
610 gfx::Rect clip_bounds(5, 6, 7, 8); | |
611 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
612 clip_bounds, std::vector<SkRRect>(), true); | |
613 | |
614 gfx::Rect drawing_a_bounds(13, 14, 1, 1); | |
615 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
616 drawing_a_bounds, CreateRectPicture(drawing_a_bounds)); | |
617 | |
618 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); | |
619 | |
620 gfx::Rect drawing_b_bounds(1, 2, 3, 4); | |
621 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
622 drawing_b_bounds, CreateRectPicture(drawing_b_bounds)); | |
623 | |
624 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | |
625 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
626 | |
627 EXPECT_EQ(6u, list->size()); | |
628 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); | |
629 merged_drawing_bounds.Union(drawing_b_bounds); | |
630 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); | |
631 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); | |
632 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); | |
633 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); | |
634 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4)); | |
635 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5)); | |
636 } | |
637 | |
638 TEST(DisplayItemListTest, AppendVisualRectOneFilterNoDrawings) { | |
639 auto list = make_scoped_refptr(new DisplayItemList); | |
640 | |
641 // One filter containing no drawings: Bf, Ef | |
642 | |
643 gfx::Rect filter_bounds(5, 6, 1, 1); | |
644 list->CreateAndAppendPairedBeginItemWithVisualRect<FilterDisplayItem>( | |
645 filter_bounds, FilterOperations(), gfx::RectF(filter_bounds), | |
646 gfx::PointF(filter_bounds.origin())); | |
647 | |
648 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); | |
649 | |
650 EXPECT_EQ(2u, list->size()); | |
651 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); | |
652 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); | |
653 } | |
654 | |
655 TEST(DisplayItemListTest, AppendVisualRectBlockContainingFilterNoDrawings) { | |
656 auto list = make_scoped_refptr(new DisplayItemList); | |
657 | |
658 // One block containing one filter and no drawings: B1, Bf, Ef, E1. | |
659 | |
660 gfx::Rect clip_bounds(5, 6, 7, 8); | |
661 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | |
662 clip_bounds, std::vector<SkRRect>(), true); | |
663 | |
664 gfx::Rect filter_bounds(5, 6, 1, 1); | |
665 list->CreateAndAppendPairedBeginItemWithVisualRect<FilterDisplayItem>( | |
666 filter_bounds, FilterOperations(), gfx::RectF(filter_bounds), | |
667 gfx::PointF(filter_bounds.origin())); | |
668 | |
669 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); | |
670 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
671 | |
672 EXPECT_EQ(4u, list->size()); | |
673 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); | |
674 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); | |
675 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); | |
676 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); | |
677 } | |
678 | |
679 } // namespace cc | |
OLD | NEW |