OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "cc/paint/display_item_list.h" | 5 #include "cc/paint/display_item_list.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 | 96 |
97 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 97 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
98 const gfx::Size& layer_size) { | 98 const gfx::Size& layer_size) { |
99 gfx::PointF offset(2.f, 3.f); | 99 gfx::PointF offset(2.f, 3.f); |
100 PaintRecorder recorder; | 100 PaintRecorder recorder; |
101 | 101 |
102 PaintFlags red_paint; | 102 PaintFlags red_paint; |
103 red_paint.setColor(SK_ColorRED); | 103 red_paint.setColor(SK_ColorRED); |
104 | 104 |
105 SkRect bounds = SkRect::MakeXYWH(offset.x(), offset.y(), layer_size.width(), | 105 PaintCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( |
106 layer_size.height()); | 106 offset.x(), offset.y(), layer_size.width(), layer_size.height())); |
107 PaintCanvas* canvas = recorder.beginRecording(bounds); | |
108 canvas->translate(offset.x(), offset.y()); | 107 canvas->translate(offset.x(), offset.y()); |
109 canvas->drawRect(SkRect::MakeWH(4, 4), red_paint); | 108 canvas->drawRect(SkRect::MakeWH(4, 4), red_paint); |
110 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 109 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
111 kVisualRect, recorder.finishRecordingAsPicture(), bounds); | 110 kVisualRect, recorder.finishRecordingAsPicture()); |
112 } | 111 } |
113 | 112 |
114 } // namespace | 113 } // namespace |
115 | 114 |
116 TEST(DisplayItemListTest, SingleDrawingItem) { | 115 TEST(DisplayItemListTest, SingleDrawingItem) { |
117 gfx::Rect layer_rect(100, 100); | 116 gfx::Rect layer_rect(100, 100); |
118 PaintRecorder recorder; | 117 PaintRecorder recorder; |
119 PaintFlags blue_flags; | 118 PaintFlags blue_flags; |
120 blue_flags.setColor(SK_ColorBLUE); | 119 blue_flags.setColor(SK_ColorBLUE); |
121 PaintFlags red_paint; | 120 PaintFlags red_paint; |
122 red_paint.setColor(SK_ColorRED); | 121 red_paint.setColor(SK_ColorRED); |
123 unsigned char pixels[4 * 100 * 100] = {0}; | 122 unsigned char pixels[4 * 100 * 100] = {0}; |
124 auto list = make_scoped_refptr(new DisplayItemList); | 123 auto list = make_scoped_refptr(new DisplayItemList); |
125 | 124 |
126 gfx::PointF offset(8.f, 9.f); | 125 gfx::PointF offset(8.f, 9.f); |
127 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 126 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
128 PaintCanvas* canvas = | 127 PaintCanvas* canvas = |
129 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); | 128 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); |
130 canvas->translate(offset.x(), offset.y()); | 129 canvas->translate(offset.x(), offset.y()); |
131 canvas->drawRect(SkRect::MakeLTRB(0.f, 0.f, 60.f, 60.f), red_paint); | 130 canvas->drawRect(SkRect::MakeLTRB(0.f, 0.f, 60.f, 60.f), red_paint); |
132 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); | 131 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); |
133 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 132 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
134 kVisualRect, recorder.finishRecordingAsPicture(), | 133 kVisualRect, recorder.finishRecordingAsPicture()); |
135 gfx::RectFToSkRect(recording_rect)); | |
136 list->Finalize(); | 134 list->Finalize(); |
137 DrawDisplayList(pixels, layer_rect, list); | 135 DrawDisplayList(pixels, layer_rect, list); |
138 | 136 |
139 SkBitmap expected_bitmap; | 137 SkBitmap expected_bitmap; |
140 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 138 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
141 SkImageInfo info = | 139 SkImageInfo info = |
142 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 140 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
143 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 141 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
144 SkiaPaintCanvas expected_canvas(expected_bitmap); | 142 SkiaPaintCanvas expected_canvas(expected_bitmap); |
145 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 143 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
(...skipping 19 matching lines...) Expand all Loading... |
165 unsigned char pixels[4 * 100 * 100] = {0}; | 163 unsigned char pixels[4 * 100 * 100] = {0}; |
166 auto list = make_scoped_refptr(new DisplayItemList); | 164 auto list = make_scoped_refptr(new DisplayItemList); |
167 | 165 |
168 gfx::PointF first_offset(8.f, 9.f); | 166 gfx::PointF first_offset(8.f, 9.f); |
169 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 167 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
170 PaintCanvas* canvas = | 168 PaintCanvas* canvas = |
171 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); | 169 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); |
172 canvas->translate(first_offset.x(), first_offset.y()); | 170 canvas->translate(first_offset.x(), first_offset.y()); |
173 canvas->drawRect(SkRect::MakeWH(60, 60), red_paint); | 171 canvas->drawRect(SkRect::MakeWH(60, 60), red_paint); |
174 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 172 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
175 kVisualRect, recorder.finishRecordingAsPicture(), | 173 kVisualRect, recorder.finishRecordingAsPicture()); |
176 gfx::RectFToSkRect(first_recording_rect)); | |
177 | 174 |
178 gfx::Rect clip_rect(60, 60, 10, 10); | 175 gfx::Rect clip_rect(60, 60, 10, 10); |
179 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 176 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
180 clip_rect, std::vector<SkRRect>(), true); | 177 clip_rect, std::vector<SkRRect>(), true); |
181 | 178 |
182 gfx::PointF second_offset(2.f, 3.f); | 179 gfx::PointF second_offset(2.f, 3.f); |
183 gfx::RectF second_recording_rect(second_offset, | 180 gfx::RectF second_recording_rect(second_offset, |
184 gfx::SizeF(layer_rect.size())); | 181 gfx::SizeF(layer_rect.size())); |
185 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); | 182 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); |
186 canvas->translate(second_offset.x(), second_offset.y()); | 183 canvas->translate(second_offset.x(), second_offset.y()); |
187 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); | 184 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); |
188 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 185 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
189 kVisualRect, recorder.finishRecordingAsPicture(), | 186 kVisualRect, recorder.finishRecordingAsPicture()); |
190 gfx::RectFToSkRect(second_recording_rect)); | |
191 | 187 |
192 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 188 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
193 list->Finalize(); | 189 list->Finalize(); |
194 | 190 |
195 DrawDisplayList(pixels, layer_rect, list); | 191 DrawDisplayList(pixels, layer_rect, list); |
196 | 192 |
197 SkBitmap expected_bitmap; | 193 SkBitmap expected_bitmap; |
198 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 194 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
199 SkImageInfo info = | 195 SkImageInfo info = |
200 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 196 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
(...skipping 23 matching lines...) Expand all Loading... |
224 unsigned char pixels[4 * 100 * 100] = {0}; | 220 unsigned char pixels[4 * 100 * 100] = {0}; |
225 auto list = make_scoped_refptr(new DisplayItemList); | 221 auto list = make_scoped_refptr(new DisplayItemList); |
226 | 222 |
227 gfx::PointF first_offset(8.f, 9.f); | 223 gfx::PointF first_offset(8.f, 9.f); |
228 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 224 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
229 PaintCanvas* canvas = | 225 PaintCanvas* canvas = |
230 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); | 226 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); |
231 canvas->translate(first_offset.x(), first_offset.y()); | 227 canvas->translate(first_offset.x(), first_offset.y()); |
232 canvas->drawRect(SkRect::MakeWH(60, 60), red_paint); | 228 canvas->drawRect(SkRect::MakeWH(60, 60), red_paint); |
233 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 229 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
234 kVisualRect, recorder.finishRecordingAsPicture(), | 230 kVisualRect, recorder.finishRecordingAsPicture()); |
235 gfx::RectFToSkRect(first_recording_rect)); | |
236 | 231 |
237 gfx::Transform transform; | 232 gfx::Transform transform; |
238 transform.Rotate(45.0); | 233 transform.Rotate(45.0); |
239 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); | 234 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); |
240 | 235 |
241 gfx::PointF second_offset(2.f, 3.f); | 236 gfx::PointF second_offset(2.f, 3.f); |
242 gfx::RectF second_recording_rect(second_offset, | 237 gfx::RectF second_recording_rect(second_offset, |
243 gfx::SizeF(layer_rect.size())); | 238 gfx::SizeF(layer_rect.size())); |
244 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); | 239 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); |
245 canvas->translate(second_offset.x(), second_offset.y()); | 240 canvas->translate(second_offset.x(), second_offset.y()); |
246 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); | 241 canvas->drawRect(SkRect::MakeLTRB(50.f, 50.f, 75.f, 75.f), blue_flags); |
247 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 242 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
248 kVisualRect, recorder.finishRecordingAsPicture(), | 243 kVisualRect, recorder.finishRecordingAsPicture()); |
249 gfx::RectFToSkRect(second_recording_rect)); | |
250 | 244 |
251 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | 245 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); |
252 list->Finalize(); | 246 list->Finalize(); |
253 | 247 |
254 DrawDisplayList(pixels, layer_rect, list); | 248 DrawDisplayList(pixels, layer_rect, list); |
255 | 249 |
256 SkBitmap expected_bitmap; | 250 SkBitmap expected_bitmap; |
257 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 251 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
258 SkImageInfo info = | 252 SkImageInfo info = |
259 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 253 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>( | 296 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>( |
303 filters, filter_bounds, filter_bounds.origin()); | 297 filters, filter_bounds, filter_bounds.origin()); |
304 | 298 |
305 // Include a rect drawing so that filter is actually applied to something. | 299 // Include a rect drawing so that filter is actually applied to something. |
306 { | 300 { |
307 PaintRecorder recorder; | 301 PaintRecorder recorder; |
308 | 302 |
309 PaintFlags red_paint; | 303 PaintFlags red_paint; |
310 red_paint.setColor(SK_ColorRED); | 304 red_paint.setColor(SK_ColorRED); |
311 | 305 |
312 SkRect bounds = | 306 PaintCanvas* canvas = recorder.beginRecording( |
313 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height()); | 307 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())); |
314 PaintCanvas* canvas = recorder.beginRecording(bounds); | |
315 canvas->drawRect( | 308 canvas->drawRect( |
316 SkRect::MakeLTRB(filter_bounds.x(), filter_bounds.y(), | 309 SkRect::MakeLTRB(filter_bounds.x(), filter_bounds.y(), |
317 filter_bounds.right(), filter_bounds.bottom()), | 310 filter_bounds.right(), filter_bounds.bottom()), |
318 red_paint); | 311 red_paint); |
319 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 312 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
320 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture(), | 313 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); |
321 bounds); | |
322 } | 314 } |
323 | 315 |
324 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); | 316 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); |
325 list->Finalize(); | 317 list->Finalize(); |
326 | 318 |
327 DrawDisplayList(pixels, layer_rect, list); | 319 DrawDisplayList(pixels, layer_rect, list); |
328 | 320 |
329 SkBitmap expected_bitmap; | 321 SkBitmap expected_bitmap; |
330 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 322 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
331 PaintFlags paint; | 323 PaintFlags paint; |
(...skipping 17 matching lines...) Expand all Loading... |
349 PaintFlags blue_flags; | 341 PaintFlags blue_flags; |
350 blue_flags.setColor(SK_ColorBLUE); | 342 blue_flags.setColor(SK_ColorBLUE); |
351 PaintCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); | 343 PaintCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); |
352 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) | 344 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) |
353 canvas->drawRect(SkRect(), blue_flags); | 345 canvas->drawRect(SkRect(), blue_flags); |
354 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); | 346 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); |
355 size_t record_size = record->bytes_used(); | 347 size_t record_size = record->bytes_used(); |
356 ASSERT_GE(record_size, kNumCommandsInTestSkPicture * sizeof(SkRect)); | 348 ASSERT_GE(record_size, kNumCommandsInTestSkPicture * sizeof(SkRect)); |
357 | 349 |
358 auto list = make_scoped_refptr(new DisplayItemList); | 350 auto list = make_scoped_refptr(new DisplayItemList); |
359 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 351 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, record); |
360 kVisualRect, record, gfx::RectToSkRect(layer_rect)); | |
361 list->Finalize(); | 352 list->Finalize(); |
362 memory_usage = list->ApproximateMemoryUsage(); | 353 memory_usage = list->ApproximateMemoryUsage(); |
363 EXPECT_GE(memory_usage, record_size); | 354 EXPECT_GE(memory_usage, record_size); |
364 EXPECT_LE(memory_usage, 2 * record_size); | 355 EXPECT_LE(memory_usage, 2 * record_size); |
365 } | 356 } |
366 | 357 |
367 TEST(DisplayItemListTest, AsValueWithNoItems) { | 358 TEST(DisplayItemListTest, AsValueWithNoItems) { |
368 auto list = make_scoped_refptr(new DisplayItemList); | 359 auto list = make_scoped_refptr(new DisplayItemList); |
369 list->SetRetainVisualRectsForTesting(true); | 360 list->SetRetainVisualRectsForTesting(true); |
370 list->Finalize(); | 361 list->Finalize(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 | 401 |
411 TEST(DisplayItemListTest, SizeEmpty) { | 402 TEST(DisplayItemListTest, SizeEmpty) { |
412 auto list = make_scoped_refptr(new DisplayItemList); | 403 auto list = make_scoped_refptr(new DisplayItemList); |
413 EXPECT_EQ(0u, list->size()); | 404 EXPECT_EQ(0u, list->size()); |
414 } | 405 } |
415 | 406 |
416 TEST(DisplayItemListTest, SizeOne) { | 407 TEST(DisplayItemListTest, SizeOne) { |
417 auto list = make_scoped_refptr(new DisplayItemList); | 408 auto list = make_scoped_refptr(new DisplayItemList); |
418 gfx::Rect drawing_bounds(5, 6, 1, 1); | 409 gfx::Rect drawing_bounds(5, 6, 1, 1); |
419 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 410 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
420 drawing_bounds, CreateRectPicture(drawing_bounds), | 411 drawing_bounds, CreateRectPicture(drawing_bounds)); |
421 gfx::RectToSkRect(drawing_bounds)); | |
422 EXPECT_EQ(1u, list->size()); | 412 EXPECT_EQ(1u, list->size()); |
423 } | 413 } |
424 | 414 |
425 TEST(DisplayItemListTest, SizeMultiple) { | 415 TEST(DisplayItemListTest, SizeMultiple) { |
426 auto list = make_scoped_refptr(new DisplayItemList); | 416 auto list = make_scoped_refptr(new DisplayItemList); |
427 gfx::Rect clip_bounds(5, 6, 7, 8); | 417 gfx::Rect clip_bounds(5, 6, 7, 8); |
428 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 418 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
429 clip_bounds, std::vector<SkRRect>(), true); | 419 clip_bounds, std::vector<SkRRect>(), true); |
430 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 420 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
431 EXPECT_EQ(2u, list->size()); | 421 EXPECT_EQ(2u, list->size()); |
432 } | 422 } |
433 | 423 |
434 TEST(DisplayItemListTest, AppendVisualRectSimple) { | 424 TEST(DisplayItemListTest, AppendVisualRectSimple) { |
435 auto list = make_scoped_refptr(new DisplayItemList); | 425 auto list = make_scoped_refptr(new DisplayItemList); |
436 | 426 |
437 // One drawing: D. | 427 // One drawing: D. |
438 | 428 |
439 gfx::Rect drawing_bounds(5, 6, 7, 8); | 429 gfx::Rect drawing_bounds(5, 6, 7, 8); |
440 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 430 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
441 drawing_bounds, CreateRectPicture(drawing_bounds), | 431 drawing_bounds, CreateRectPicture(drawing_bounds)); |
442 gfx::RectToSkRect(drawing_bounds)); | |
443 | 432 |
444 EXPECT_EQ(1u, list->size()); | 433 EXPECT_EQ(1u, list->size()); |
445 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0)); | 434 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0)); |
446 } | 435 } |
447 | 436 |
448 TEST(DisplayItemListTest, AppendVisualRectEmptyBlock) { | 437 TEST(DisplayItemListTest, AppendVisualRectEmptyBlock) { |
449 auto list = make_scoped_refptr(new DisplayItemList); | 438 auto list = make_scoped_refptr(new DisplayItemList); |
450 | 439 |
451 // One block: B1, E1. | 440 // One block: B1, E1. |
452 | 441 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 auto list = make_scoped_refptr(new DisplayItemList); | 473 auto list = make_scoped_refptr(new DisplayItemList); |
485 | 474 |
486 // One block with one drawing: B1, Da, E1. | 475 // One block with one drawing: B1, Da, E1. |
487 | 476 |
488 gfx::Rect clip_bounds(5, 6, 7, 8); | 477 gfx::Rect clip_bounds(5, 6, 7, 8); |
489 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 478 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
490 clip_bounds, std::vector<SkRRect>(), true); | 479 clip_bounds, std::vector<SkRRect>(), true); |
491 | 480 |
492 gfx::Rect drawing_bounds(5, 6, 1, 1); | 481 gfx::Rect drawing_bounds(5, 6, 1, 1); |
493 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 482 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
494 drawing_bounds, CreateRectPicture(drawing_bounds), | 483 drawing_bounds, CreateRectPicture(drawing_bounds)); |
495 gfx::RectToSkRect(drawing_bounds)); | |
496 | 484 |
497 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 485 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
498 | 486 |
499 EXPECT_EQ(3u, list->size()); | 487 EXPECT_EQ(3u, list->size()); |
500 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0)); | 488 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0)); |
501 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(1)); | 489 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(1)); |
502 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(2)); | 490 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(2)); |
503 } | 491 } |
504 | 492 |
505 TEST(DisplayItemListTest, AppendVisualRectBlockContainingEscapedDrawing) { | 493 TEST(DisplayItemListTest, AppendVisualRectBlockContainingEscapedDrawing) { |
506 auto list = make_scoped_refptr(new DisplayItemList); | 494 auto list = make_scoped_refptr(new DisplayItemList); |
507 | 495 |
508 // One block with one drawing: B1, Da (escapes), E1. | 496 // One block with one drawing: B1, Da (escapes), E1. |
509 | 497 |
510 gfx::Rect clip_bounds(5, 6, 7, 8); | 498 gfx::Rect clip_bounds(5, 6, 7, 8); |
511 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 499 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
512 clip_bounds, std::vector<SkRRect>(), true); | 500 clip_bounds, std::vector<SkRRect>(), true); |
513 | 501 |
514 gfx::Rect drawing_bounds(1, 2, 3, 4); | 502 gfx::Rect drawing_bounds(1, 2, 3, 4); |
515 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 503 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
516 drawing_bounds, CreateRectPicture(drawing_bounds), | 504 drawing_bounds, CreateRectPicture(drawing_bounds)); |
517 gfx::RectToSkRect(drawing_bounds)); | |
518 | 505 |
519 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 506 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
520 | 507 |
521 EXPECT_EQ(3u, list->size()); | 508 EXPECT_EQ(3u, list->size()); |
522 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0)); | 509 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0)); |
523 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(1)); | 510 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(1)); |
524 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(2)); | 511 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(2)); |
525 } | 512 } |
526 | 513 |
527 TEST(DisplayItemListTest, | 514 TEST(DisplayItemListTest, |
528 AppendVisualRectDrawingFollowedByBlockContainingEscapedDrawing) { | 515 AppendVisualRectDrawingFollowedByBlockContainingEscapedDrawing) { |
529 auto list = make_scoped_refptr(new DisplayItemList); | 516 auto list = make_scoped_refptr(new DisplayItemList); |
530 | 517 |
531 // One drawing followed by one block with one drawing: Da, B1, Db (escapes), | 518 // One drawing followed by one block with one drawing: Da, B1, Db (escapes), |
532 // E1. | 519 // E1. |
533 | 520 |
534 gfx::Rect drawing_a_bounds(1, 2, 3, 4); | 521 gfx::Rect drawing_a_bounds(1, 2, 3, 4); |
535 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 522 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
536 drawing_a_bounds, CreateRectPicture(drawing_a_bounds), | 523 drawing_a_bounds, CreateRectPicture(drawing_a_bounds)); |
537 gfx::RectToSkRect(drawing_a_bounds)); | |
538 | 524 |
539 gfx::Rect clip_bounds(5, 6, 7, 8); | 525 gfx::Rect clip_bounds(5, 6, 7, 8); |
540 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 526 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
541 clip_bounds, std::vector<SkRRect>(), true); | 527 clip_bounds, std::vector<SkRRect>(), true); |
542 | 528 |
543 gfx::Rect drawing_b_bounds(13, 14, 1, 1); | 529 gfx::Rect drawing_b_bounds(13, 14, 1, 1); |
544 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 530 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
545 drawing_b_bounds, CreateRectPicture(drawing_b_bounds), | 531 drawing_b_bounds, CreateRectPicture(drawing_b_bounds)); |
546 gfx::RectToSkRect(drawing_b_bounds)); | |
547 | 532 |
548 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 533 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
549 | 534 |
550 EXPECT_EQ(4u, list->size()); | 535 EXPECT_EQ(4u, list->size()); |
551 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(0)); | 536 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(0)); |
552 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(1)); | 537 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(1)); |
553 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); | 538 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); |
554 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); | 539 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); |
555 } | 540 } |
556 | 541 |
557 TEST(DisplayItemListTest, AppendVisualRectTwoBlocksTwoDrawings) { | 542 TEST(DisplayItemListTest, AppendVisualRectTwoBlocksTwoDrawings) { |
558 auto list = make_scoped_refptr(new DisplayItemList); | 543 auto list = make_scoped_refptr(new DisplayItemList); |
559 | 544 |
560 // Multiple nested blocks with drawings amidst: B1, Da, B2, Db, E2, E1. | 545 // Multiple nested blocks with drawings amidst: B1, Da, B2, Db, E2, E1. |
561 | 546 |
562 gfx::Rect clip_bounds(5, 6, 7, 8); | 547 gfx::Rect clip_bounds(5, 6, 7, 8); |
563 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 548 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
564 clip_bounds, std::vector<SkRRect>(), true); | 549 clip_bounds, std::vector<SkRRect>(), true); |
565 | 550 |
566 gfx::Rect drawing_a_bounds(5, 6, 1, 1); | 551 gfx::Rect drawing_a_bounds(5, 6, 1, 1); |
567 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 552 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
568 drawing_a_bounds, CreateRectPicture(drawing_a_bounds), | 553 drawing_a_bounds, CreateRectPicture(drawing_a_bounds)); |
569 gfx::RectToSkRect(drawing_a_bounds)); | |
570 | 554 |
571 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); | 555 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); |
572 | 556 |
573 gfx::Rect drawing_b_bounds(7, 8, 1, 1); | 557 gfx::Rect drawing_b_bounds(7, 8, 1, 1); |
574 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 558 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
575 drawing_b_bounds, CreateRectPicture(drawing_b_bounds), | 559 drawing_b_bounds, CreateRectPicture(drawing_b_bounds)); |
576 gfx::RectToSkRect(drawing_b_bounds)); | |
577 | 560 |
578 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | 561 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); |
579 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 562 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
580 | 563 |
581 EXPECT_EQ(6u, list->size()); | 564 EXPECT_EQ(6u, list->size()); |
582 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); | 565 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); |
583 merged_drawing_bounds.Union(drawing_b_bounds); | 566 merged_drawing_bounds.Union(drawing_b_bounds); |
584 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); | 567 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); |
585 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); | 568 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); |
586 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); | 569 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); |
587 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); | 570 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); |
588 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4)); | 571 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4)); |
589 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5)); | 572 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5)); |
590 } | 573 } |
591 | 574 |
592 TEST(DisplayItemListTest, | 575 TEST(DisplayItemListTest, |
593 AppendVisualRectTwoBlocksTwoDrawingsInnerDrawingEscaped) { | 576 AppendVisualRectTwoBlocksTwoDrawingsInnerDrawingEscaped) { |
594 auto list = make_scoped_refptr(new DisplayItemList); | 577 auto list = make_scoped_refptr(new DisplayItemList); |
595 | 578 |
596 // Multiple nested blocks with drawings amidst: B1, Da, B2, Db (escapes), E2, | 579 // Multiple nested blocks with drawings amidst: B1, Da, B2, Db (escapes), E2, |
597 // E1. | 580 // E1. |
598 | 581 |
599 gfx::Rect clip_bounds(5, 6, 7, 8); | 582 gfx::Rect clip_bounds(5, 6, 7, 8); |
600 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 583 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
601 clip_bounds, std::vector<SkRRect>(), true); | 584 clip_bounds, std::vector<SkRRect>(), true); |
602 | 585 |
603 gfx::Rect drawing_a_bounds(5, 6, 1, 1); | 586 gfx::Rect drawing_a_bounds(5, 6, 1, 1); |
604 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 587 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
605 drawing_a_bounds, CreateRectPicture(drawing_a_bounds), | 588 drawing_a_bounds, CreateRectPicture(drawing_a_bounds)); |
606 gfx::RectToSkRect(drawing_a_bounds)); | |
607 | 589 |
608 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); | 590 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); |
609 | 591 |
610 gfx::Rect drawing_b_bounds(1, 2, 3, 4); | 592 gfx::Rect drawing_b_bounds(1, 2, 3, 4); |
611 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 593 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
612 drawing_b_bounds, CreateRectPicture(drawing_b_bounds), | 594 drawing_b_bounds, CreateRectPicture(drawing_b_bounds)); |
613 gfx::RectToSkRect(drawing_b_bounds)); | |
614 | 595 |
615 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | 596 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); |
616 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 597 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
617 | 598 |
618 EXPECT_EQ(6u, list->size()); | 599 EXPECT_EQ(6u, list->size()); |
619 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); | 600 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); |
620 merged_drawing_bounds.Union(drawing_b_bounds); | 601 merged_drawing_bounds.Union(drawing_b_bounds); |
621 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); | 602 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); |
622 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); | 603 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); |
623 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); | 604 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); |
624 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); | 605 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); |
625 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4)); | 606 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4)); |
626 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5)); | 607 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5)); |
627 } | 608 } |
628 | 609 |
629 TEST(DisplayItemListTest, | 610 TEST(DisplayItemListTest, |
630 AppendVisualRectTwoBlocksTwoDrawingsOuterDrawingEscaped) { | 611 AppendVisualRectTwoBlocksTwoDrawingsOuterDrawingEscaped) { |
631 auto list = make_scoped_refptr(new DisplayItemList); | 612 auto list = make_scoped_refptr(new DisplayItemList); |
632 | 613 |
633 // Multiple nested blocks with drawings amidst: B1, Da (escapes), B2, Db, E2, | 614 // Multiple nested blocks with drawings amidst: B1, Da (escapes), B2, Db, E2, |
634 // E1. | 615 // E1. |
635 | 616 |
636 gfx::Rect clip_bounds(5, 6, 7, 8); | 617 gfx::Rect clip_bounds(5, 6, 7, 8); |
637 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 618 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
638 clip_bounds, std::vector<SkRRect>(), true); | 619 clip_bounds, std::vector<SkRRect>(), true); |
639 | 620 |
640 gfx::Rect drawing_a_bounds(1, 2, 3, 4); | 621 gfx::Rect drawing_a_bounds(1, 2, 3, 4); |
641 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 622 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
642 drawing_a_bounds, CreateRectPicture(drawing_a_bounds), | 623 drawing_a_bounds, CreateRectPicture(drawing_a_bounds)); |
643 gfx::RectToSkRect(drawing_a_bounds)); | |
644 | 624 |
645 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); | 625 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); |
646 | 626 |
647 gfx::Rect drawing_b_bounds(7, 8, 1, 1); | 627 gfx::Rect drawing_b_bounds(7, 8, 1, 1); |
648 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 628 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
649 drawing_b_bounds, CreateRectPicture(drawing_b_bounds), | 629 drawing_b_bounds, CreateRectPicture(drawing_b_bounds)); |
650 gfx::RectToSkRect(drawing_b_bounds)); | |
651 | 630 |
652 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | 631 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); |
653 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 632 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
654 | 633 |
655 EXPECT_EQ(6u, list->size()); | 634 EXPECT_EQ(6u, list->size()); |
656 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); | 635 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); |
657 merged_drawing_bounds.Union(drawing_b_bounds); | 636 merged_drawing_bounds.Union(drawing_b_bounds); |
658 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); | 637 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); |
659 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); | 638 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); |
660 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); | 639 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); |
661 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); | 640 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3)); |
662 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4)); | 641 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4)); |
663 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5)); | 642 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5)); |
664 } | 643 } |
665 | 644 |
666 TEST(DisplayItemListTest, | 645 TEST(DisplayItemListTest, |
667 AppendVisualRectTwoBlocksTwoDrawingsBothDrawingsEscaped) { | 646 AppendVisualRectTwoBlocksTwoDrawingsBothDrawingsEscaped) { |
668 auto list = make_scoped_refptr(new DisplayItemList); | 647 auto list = make_scoped_refptr(new DisplayItemList); |
669 | 648 |
670 // Multiple nested blocks with drawings amidst: | 649 // Multiple nested blocks with drawings amidst: |
671 // B1, Da (escapes to the right), B2, Db (escapes to the left), E2, E1. | 650 // B1, Da (escapes to the right), B2, Db (escapes to the left), E2, E1. |
672 | 651 |
673 gfx::Rect clip_bounds(5, 6, 7, 8); | 652 gfx::Rect clip_bounds(5, 6, 7, 8); |
674 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 653 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
675 clip_bounds, std::vector<SkRRect>(), true); | 654 clip_bounds, std::vector<SkRRect>(), true); |
676 | 655 |
677 gfx::Rect drawing_a_bounds(13, 14, 1, 1); | 656 gfx::Rect drawing_a_bounds(13, 14, 1, 1); |
678 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 657 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
679 drawing_a_bounds, CreateRectPicture(drawing_a_bounds), | 658 drawing_a_bounds, CreateRectPicture(drawing_a_bounds)); |
680 gfx::RectToSkRect(drawing_a_bounds)); | |
681 | 659 |
682 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); | 660 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform()); |
683 | 661 |
684 gfx::Rect drawing_b_bounds(1, 2, 3, 4); | 662 gfx::Rect drawing_b_bounds(1, 2, 3, 4); |
685 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 663 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
686 drawing_b_bounds, CreateRectPicture(drawing_b_bounds), | 664 drawing_b_bounds, CreateRectPicture(drawing_b_bounds)); |
687 gfx::RectToSkRect(drawing_b_bounds)); | |
688 | 665 |
689 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | 666 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); |
690 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 667 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
691 | 668 |
692 EXPECT_EQ(6u, list->size()); | 669 EXPECT_EQ(6u, list->size()); |
693 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); | 670 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds); |
694 merged_drawing_bounds.Union(drawing_b_bounds); | 671 merged_drawing_bounds.Union(drawing_b_bounds); |
695 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); | 672 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0)); |
696 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); | 673 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1)); |
697 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); | 674 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 | 720 |
744 // Verify that raster time optimizations for compositing item / draw single op / | 721 // Verify that raster time optimizations for compositing item / draw single op / |
745 // end compositing item can be collapsed together into a single draw op | 722 // end compositing item can be collapsed together into a single draw op |
746 // with the opacity from the compositing item folded in. | 723 // with the opacity from the compositing item folded in. |
747 TEST(DisplayItemListTest, SaveDrawRestore) { | 724 TEST(DisplayItemListTest, SaveDrawRestore) { |
748 auto list = make_scoped_refptr(new DisplayItemList); | 725 auto list = make_scoped_refptr(new DisplayItemList); |
749 | 726 |
750 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>( | 727 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>( |
751 80, SkBlendMode::kSrcOver, nullptr, nullptr, false); | 728 80, SkBlendMode::kSrcOver, nullptr, nullptr, false); |
752 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 729 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
753 kVisualRect, CreateRectPictureWithAlpha(kVisualRect, 40), | 730 kVisualRect, CreateRectPictureWithAlpha(kVisualRect, 40)); |
754 gfx::RectToSkRect(kVisualRect)); | |
755 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>(); | 731 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>(); |
756 list->Finalize(); | 732 list->Finalize(); |
757 | 733 |
758 SaveCountingCanvas canvas; | 734 SaveCountingCanvas canvas; |
759 list->Raster(&canvas); | 735 list->Raster(&canvas); |
760 | 736 |
761 EXPECT_EQ(0, canvas.save_count_); | 737 EXPECT_EQ(0, canvas.save_count_); |
762 EXPECT_EQ(0, canvas.restore_count_); | 738 EXPECT_EQ(0, canvas.restore_count_); |
763 EXPECT_EQ(gfx::RectToSkRect(kVisualRect), canvas.draw_rect_); | 739 EXPECT_EQ(gfx::RectToSkRect(kVisualRect), canvas.draw_rect_); |
764 | 740 |
(...skipping 29 matching lines...) Expand all Loading... |
794 // The same as SaveDrawRestore, but with save flags that prevent the | 770 // The same as SaveDrawRestore, but with save flags that prevent the |
795 // optimization. | 771 // optimization. |
796 TEST(DisplayItemListTest, SaveDrawRestoreFail_BadSaveFlags) { | 772 TEST(DisplayItemListTest, SaveDrawRestoreFail_BadSaveFlags) { |
797 auto list = make_scoped_refptr(new DisplayItemList); | 773 auto list = make_scoped_refptr(new DisplayItemList); |
798 | 774 |
799 // Use a blend mode that's not compatible with the SaveDrawRestore | 775 // Use a blend mode that's not compatible with the SaveDrawRestore |
800 // optimization. | 776 // optimization. |
801 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>( | 777 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>( |
802 80, SkBlendMode::kSrc, nullptr, nullptr, false); | 778 80, SkBlendMode::kSrc, nullptr, nullptr, false); |
803 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 779 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
804 kVisualRect, CreateRectPictureWithAlpha(kVisualRect, 40), | 780 kVisualRect, CreateRectPictureWithAlpha(kVisualRect, 40)); |
805 gfx::RectToSkRect(kVisualRect)); | |
806 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>(); | 781 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>(); |
807 list->Finalize(); | 782 list->Finalize(); |
808 | 783 |
809 SaveCountingCanvas canvas; | 784 SaveCountingCanvas canvas; |
810 list->Raster(&canvas); | 785 list->Raster(&canvas); |
811 | 786 |
812 EXPECT_EQ(1, canvas.save_count_); | 787 EXPECT_EQ(1, canvas.save_count_); |
813 EXPECT_EQ(1, canvas.restore_count_); | 788 EXPECT_EQ(1, canvas.restore_count_); |
814 EXPECT_EQ(gfx::RectToSkRect(kVisualRect), canvas.draw_rect_); | 789 EXPECT_EQ(gfx::RectToSkRect(kVisualRect), canvas.draw_rect_); |
815 EXPECT_LE(40, canvas.paint_.getAlpha()); | 790 EXPECT_LE(40, canvas.paint_.getAlpha()); |
816 } | 791 } |
817 | 792 |
818 // The same as SaveDrawRestore, but with too many ops in the PaintRecord. | 793 // The same as SaveDrawRestore, but with too many ops in the PaintRecord. |
819 TEST(DisplayItemListTest, SaveDrawRestoreFail_TooManyOps) { | 794 TEST(DisplayItemListTest, SaveDrawRestoreFail_TooManyOps) { |
820 sk_sp<const PaintRecord> record; | 795 sk_sp<const PaintRecord> record; |
821 SkRect bounds = SkRect::MakeWH(kVisualRect.width(), kVisualRect.height()); | |
822 { | 796 { |
823 PaintRecorder recorder; | 797 PaintRecorder recorder; |
824 PaintCanvas* canvas = recorder.beginRecording(bounds); | 798 PaintCanvas* canvas = |
| 799 recorder.beginRecording(kVisualRect.width(), kVisualRect.height()); |
825 PaintFlags flags; | 800 PaintFlags flags; |
826 flags.setAlpha(40); | 801 flags.setAlpha(40); |
827 canvas->drawRect(gfx::RectToSkRect(kVisualRect), flags); | 802 canvas->drawRect(gfx::RectToSkRect(kVisualRect), flags); |
828 // Add an extra op here. | 803 // Add an extra op here. |
829 canvas->drawRect(gfx::RectToSkRect(kVisualRect), flags); | 804 canvas->drawRect(gfx::RectToSkRect(kVisualRect), flags); |
830 record = recorder.finishRecordingAsPicture(); | 805 record = recorder.finishRecordingAsPicture(); |
831 } | 806 } |
832 EXPECT_GT(record->size(), 1u); | 807 EXPECT_GT(record->size(), 1u); |
833 | 808 |
834 auto list = make_scoped_refptr(new DisplayItemList); | 809 auto list = make_scoped_refptr(new DisplayItemList); |
835 | 810 |
836 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>( | 811 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>( |
837 80, SkBlendMode::kSrcOver, nullptr, nullptr, false); | 812 80, SkBlendMode::kSrcOver, nullptr, nullptr, false); |
838 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 813 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, |
839 kVisualRect, std::move(record), bounds); | 814 std::move(record)); |
840 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>(); | 815 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>(); |
841 list->Finalize(); | 816 list->Finalize(); |
842 | 817 |
843 SaveCountingCanvas canvas; | 818 SaveCountingCanvas canvas; |
844 list->Raster(&canvas); | 819 list->Raster(&canvas); |
845 | 820 |
846 EXPECT_EQ(1, canvas.save_count_); | 821 EXPECT_EQ(1, canvas.save_count_); |
847 EXPECT_EQ(1, canvas.restore_count_); | 822 EXPECT_EQ(1, canvas.restore_count_); |
848 EXPECT_EQ(gfx::RectToSkRect(kVisualRect), canvas.draw_rect_); | 823 EXPECT_EQ(gfx::RectToSkRect(kVisualRect), canvas.draw_rect_); |
849 EXPECT_LE(40, canvas.paint_.getAlpha()); | 824 EXPECT_LE(40, canvas.paint_.getAlpha()); |
850 } | 825 } |
851 | 826 |
852 } // namespace cc | 827 } // namespace cc |
OLD | NEW |