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/playback/display_item_list.h" | 5 #include "cc/playback/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 namespace { | 45 namespace { |
46 | 46 |
47 const gfx::Rect kVisualRect(0, 0, 42, 42); | 47 const gfx::Rect kVisualRect(0, 0, 42, 42); |
48 | 48 |
49 scoped_refptr<DisplayItemList> CreateDefaultList() { | 49 scoped_refptr<DisplayItemList> CreateDefaultList() { |
50 return DisplayItemList::Create(DisplayItemListSettings()); | 50 return DisplayItemList::Create(DisplayItemListSettings()); |
51 } | 51 } |
52 | 52 |
53 sk_sp<const SkPicture> CreateRectPicture(const gfx::Rect& bounds) { | 53 sk_sp<const SkPicture> CreateRectPicture(const gfx::Rect& bounds) { |
54 SkPictureRecorder recorder; | 54 SkPictureRecorder recorder; |
55 sk_sp<SkCanvas> canvas; | 55 SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height()); |
56 | |
57 canvas = sk_ref_sp(recorder.beginRecording(bounds.width(), bounds.height())); | |
58 canvas->drawRect( | 56 canvas->drawRect( |
59 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()), | 57 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()), |
60 SkPaint()); | 58 SkPaint()); |
61 return recorder.finishRecordingAsPicture(); | 59 return recorder.finishRecordingAsPicture(); |
62 } | 60 } |
63 | 61 |
64 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 62 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
65 const gfx::Size& layer_size) { | 63 const gfx::Size& layer_size) { |
66 gfx::PointF offset(2.f, 3.f); | 64 gfx::PointF offset(2.f, 3.f); |
67 SkPictureRecorder recorder; | 65 SkPictureRecorder recorder; |
68 sk_sp<SkCanvas> canvas; | |
69 | 66 |
70 SkPaint red_paint; | 67 SkPaint red_paint; |
71 red_paint.setColor(SK_ColorRED); | 68 red_paint.setColor(SK_ColorRED); |
72 | 69 |
73 canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH( | 70 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( |
74 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); | 71 offset.x(), offset.y(), layer_size.width(), layer_size.height())); |
75 canvas->translate(offset.x(), offset.y()); | 72 canvas->translate(offset.x(), offset.y()); |
76 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); | 73 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
77 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 74 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
78 kVisualRect, recorder.finishRecordingAsPicture()); | 75 kVisualRect, recorder.finishRecordingAsPicture()); |
79 } | 76 } |
80 | 77 |
81 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 78 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
82 const gfx::Size& layer_size) { | 79 const gfx::Size& layer_size) { |
83 gfx::PointF offset(2.f, 2.f); | 80 gfx::PointF offset(2.f, 2.f); |
84 SkPictureRecorder recorder; | 81 SkPictureRecorder recorder; |
85 sk_sp<SkCanvas> canvas; | |
86 | 82 |
87 SkPaint blue_paint; | 83 SkPaint blue_paint; |
88 blue_paint.setColor(SK_ColorBLUE); | 84 blue_paint.setColor(SK_ColorBLUE); |
89 | 85 |
90 canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH( | 86 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( |
91 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); | 87 offset.x(), offset.y(), layer_size.width(), layer_size.height())); |
92 canvas->translate(offset.x(), offset.y()); | 88 canvas->translate(offset.x(), offset.y()); |
93 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); | 89 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
94 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 90 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
95 kVisualRect, recorder.finishRecordingAsPicture()); | 91 kVisualRect, recorder.finishRecordingAsPicture()); |
96 } | 92 } |
97 | 93 |
98 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, | 94 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, |
99 scoped_refptr<DisplayItemList> list) { | 95 scoped_refptr<DisplayItemList> list) { |
100 list->Finalize(); | 96 list->Finalize(); |
101 | 97 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 284 |
289 // Build the EndTransformDisplayItem. | 285 // Build the EndTransformDisplayItem. |
290 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | 286 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); |
291 | 287 |
292 ValidateDisplayItemListSerialization(layer_size, list); | 288 ValidateDisplayItemListSerialization(layer_size, list); |
293 } | 289 } |
294 | 290 |
295 TEST(DisplayItemListTest, SingleDrawingItem) { | 291 TEST(DisplayItemListTest, SingleDrawingItem) { |
296 gfx::Rect layer_rect(100, 100); | 292 gfx::Rect layer_rect(100, 100); |
297 SkPictureRecorder recorder; | 293 SkPictureRecorder recorder; |
298 sk_sp<SkCanvas> canvas; | |
299 SkPaint blue_paint; | 294 SkPaint blue_paint; |
300 blue_paint.setColor(SK_ColorBLUE); | 295 blue_paint.setColor(SK_ColorBLUE); |
301 SkPaint red_paint; | 296 SkPaint red_paint; |
302 red_paint.setColor(SK_ColorRED); | 297 red_paint.setColor(SK_ColorRED); |
303 unsigned char pixels[4 * 100 * 100] = {0}; | 298 unsigned char pixels[4 * 100 * 100] = {0}; |
304 DisplayItemListSettings settings; | 299 DisplayItemListSettings settings; |
305 settings.use_cached_picture = true; | 300 settings.use_cached_picture = true; |
306 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | 301 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
307 | 302 |
308 gfx::PointF offset(8.f, 9.f); | 303 gfx::PointF offset(8.f, 9.f); |
309 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 304 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
310 canvas = | 305 SkCanvas* canvas = |
311 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 306 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); |
312 canvas->translate(offset.x(), offset.y()); | 307 canvas->translate(offset.x(), offset.y()); |
313 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 308 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
314 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 309 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
315 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 310 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
316 kVisualRect, recorder.finishRecordingAsPicture()); | 311 kVisualRect, recorder.finishRecordingAsPicture()); |
317 list->Finalize(); | 312 list->Finalize(); |
318 DrawDisplayList(pixels, layer_rect, list); | 313 DrawDisplayList(pixels, layer_rect, list); |
319 | 314 |
320 SkBitmap expected_bitmap; | 315 SkBitmap expected_bitmap; |
321 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 316 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
322 SkImageInfo info = | 317 SkImageInfo info = |
323 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 318 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
324 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 319 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
325 SkCanvas expected_canvas(expected_bitmap); | 320 SkCanvas expected_canvas(expected_bitmap); |
326 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 321 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
327 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), | 322 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), |
328 60.f + offset.x(), 60.f + offset.y(), | 323 60.f + offset.x(), 60.f + offset.y(), |
329 red_paint); | 324 red_paint); |
330 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), | 325 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), |
331 75.f + offset.x(), 75.f + offset.y(), | 326 75.f + offset.x(), 75.f + offset.y(), |
332 blue_paint); | 327 blue_paint); |
333 | 328 |
334 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 329 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
335 } | 330 } |
336 | 331 |
337 TEST(DisplayItemListTest, ClipItem) { | 332 TEST(DisplayItemListTest, ClipItem) { |
338 gfx::Rect layer_rect(100, 100); | 333 gfx::Rect layer_rect(100, 100); |
339 SkPictureRecorder recorder; | 334 SkPictureRecorder recorder; |
340 sk_sp<SkCanvas> canvas; | |
341 SkPaint blue_paint; | 335 SkPaint blue_paint; |
342 blue_paint.setColor(SK_ColorBLUE); | 336 blue_paint.setColor(SK_ColorBLUE); |
343 SkPaint red_paint; | 337 SkPaint red_paint; |
344 red_paint.setColor(SK_ColorRED); | 338 red_paint.setColor(SK_ColorRED); |
345 unsigned char pixels[4 * 100 * 100] = {0}; | 339 unsigned char pixels[4 * 100 * 100] = {0}; |
346 DisplayItemListSettings settings; | 340 DisplayItemListSettings settings; |
347 settings.use_cached_picture = true; | 341 settings.use_cached_picture = true; |
348 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | 342 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
349 | 343 |
350 gfx::PointF first_offset(8.f, 9.f); | 344 gfx::PointF first_offset(8.f, 9.f); |
351 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 345 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
352 canvas = sk_ref_sp( | 346 SkCanvas* canvas = |
353 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 347 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); |
354 canvas->translate(first_offset.x(), first_offset.y()); | 348 canvas->translate(first_offset.x(), first_offset.y()); |
355 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 349 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
356 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 350 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
357 kVisualRect, recorder.finishRecordingAsPicture()); | 351 kVisualRect, recorder.finishRecordingAsPicture()); |
358 | 352 |
359 gfx::Rect clip_rect(60, 60, 10, 10); | 353 gfx::Rect clip_rect(60, 60, 10, 10); |
360 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 354 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
361 clip_rect, std::vector<SkRRect>(), true); | 355 clip_rect, std::vector<SkRRect>(), true); |
362 | 356 |
363 gfx::PointF second_offset(2.f, 3.f); | 357 gfx::PointF second_offset(2.f, 3.f); |
364 gfx::RectF second_recording_rect(second_offset, | 358 gfx::RectF second_recording_rect(second_offset, |
365 gfx::SizeF(layer_rect.size())); | 359 gfx::SizeF(layer_rect.size())); |
366 canvas = sk_ref_sp( | 360 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); |
367 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); | |
368 canvas->translate(second_offset.x(), second_offset.y()); | 361 canvas->translate(second_offset.x(), second_offset.y()); |
369 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 362 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
370 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 363 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
371 kVisualRect, recorder.finishRecordingAsPicture()); | 364 kVisualRect, recorder.finishRecordingAsPicture()); |
372 | 365 |
373 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 366 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
374 list->Finalize(); | 367 list->Finalize(); |
375 | 368 |
376 DrawDisplayList(pixels, layer_rect, list); | 369 DrawDisplayList(pixels, layer_rect, list); |
377 | 370 |
(...skipping 11 matching lines...) Expand all Loading... |
389 expected_canvas.drawRectCoords( | 382 expected_canvas.drawRectCoords( |
390 50.f + second_offset.x(), 50.f + second_offset.y(), | 383 50.f + second_offset.x(), 50.f + second_offset.y(), |
391 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); | 384 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); |
392 | 385 |
393 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 386 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
394 } | 387 } |
395 | 388 |
396 TEST(DisplayItemListTest, TransformItem) { | 389 TEST(DisplayItemListTest, TransformItem) { |
397 gfx::Rect layer_rect(100, 100); | 390 gfx::Rect layer_rect(100, 100); |
398 SkPictureRecorder recorder; | 391 SkPictureRecorder recorder; |
399 sk_sp<SkCanvas> canvas; | |
400 SkPaint blue_paint; | 392 SkPaint blue_paint; |
401 blue_paint.setColor(SK_ColorBLUE); | 393 blue_paint.setColor(SK_ColorBLUE); |
402 SkPaint red_paint; | 394 SkPaint red_paint; |
403 red_paint.setColor(SK_ColorRED); | 395 red_paint.setColor(SK_ColorRED); |
404 unsigned char pixels[4 * 100 * 100] = {0}; | 396 unsigned char pixels[4 * 100 * 100] = {0}; |
405 DisplayItemListSettings settings; | 397 DisplayItemListSettings settings; |
406 settings.use_cached_picture = true; | 398 settings.use_cached_picture = true; |
407 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | 399 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
408 | 400 |
409 gfx::PointF first_offset(8.f, 9.f); | 401 gfx::PointF first_offset(8.f, 9.f); |
410 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 402 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
411 canvas = sk_ref_sp( | 403 SkCanvas* canvas = |
412 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 404 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); |
413 canvas->translate(first_offset.x(), first_offset.y()); | 405 canvas->translate(first_offset.x(), first_offset.y()); |
414 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 406 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
415 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 407 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
416 kVisualRect, recorder.finishRecordingAsPicture()); | 408 kVisualRect, recorder.finishRecordingAsPicture()); |
417 | 409 |
418 gfx::Transform transform; | 410 gfx::Transform transform; |
419 transform.Rotate(45.0); | 411 transform.Rotate(45.0); |
420 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); | 412 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); |
421 | 413 |
422 gfx::PointF second_offset(2.f, 3.f); | 414 gfx::PointF second_offset(2.f, 3.f); |
423 gfx::RectF second_recording_rect(second_offset, | 415 gfx::RectF second_recording_rect(second_offset, |
424 gfx::SizeF(layer_rect.size())); | 416 gfx::SizeF(layer_rect.size())); |
425 canvas = sk_ref_sp( | 417 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); |
426 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); | |
427 canvas->translate(second_offset.x(), second_offset.y()); | 418 canvas->translate(second_offset.x(), second_offset.y()); |
428 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 419 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
429 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 420 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
430 kVisualRect, recorder.finishRecordingAsPicture()); | 421 kVisualRect, recorder.finishRecordingAsPicture()); |
431 | 422 |
432 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | 423 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); |
433 list->Finalize(); | 424 list->Finalize(); |
434 | 425 |
435 DrawDisplayList(pixels, layer_rect, list); | 426 DrawDisplayList(pixels, layer_rect, list); |
436 | 427 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); | 469 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); |
479 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); | 470 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); |
480 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); | 471 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); |
481 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); | 472 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); |
482 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>( | 473 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>( |
483 filters, filter_bounds, filter_bounds.origin()); | 474 filters, filter_bounds, filter_bounds.origin()); |
484 | 475 |
485 // Include a rect drawing so that filter is actually applied to something. | 476 // Include a rect drawing so that filter is actually applied to something. |
486 { | 477 { |
487 SkPictureRecorder recorder; | 478 SkPictureRecorder recorder; |
488 sk_sp<SkCanvas> canvas; | |
489 | 479 |
490 SkPaint red_paint; | 480 SkPaint red_paint; |
491 red_paint.setColor(SK_ColorRED); | 481 red_paint.setColor(SK_ColorRED); |
492 | 482 |
493 canvas = sk_ref_sp(recorder.beginRecording( | 483 SkCanvas* canvas = recorder.beginRecording( |
494 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height()))); | 484 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())); |
495 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(), | 485 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(), |
496 filter_bounds.right(), filter_bounds.bottom(), | 486 filter_bounds.right(), filter_bounds.bottom(), |
497 red_paint); | 487 red_paint); |
498 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 488 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
499 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); | 489 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); |
500 } | 490 } |
501 | 491 |
502 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); | 492 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); |
503 list->Finalize(); | 493 list->Finalize(); |
504 | 494 |
505 DrawDisplayList(pixels, layer_rect, list); | 495 DrawDisplayList(pixels, layer_rect, list); |
506 | 496 |
507 SkBitmap expected_bitmap; | 497 SkBitmap expected_bitmap; |
508 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 498 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
509 SkPaint paint; | 499 SkPaint paint; |
510 paint.setColor(SkColorSetRGB(64, 64, 64)); | 500 paint.setColor(SkColorSetRGB(64, 64, 64)); |
511 SkImageInfo info = | 501 SkImageInfo info = |
512 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 502 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
513 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 503 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
514 SkCanvas expected_canvas(expected_bitmap); | 504 SkCanvas expected_canvas(expected_bitmap); |
515 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); | 505 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); |
516 | 506 |
517 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 507 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
518 } | 508 } |
519 | 509 |
520 TEST(DisplayItemListTest, CompactingItems) { | 510 TEST(DisplayItemListTest, CompactingItems) { |
521 gfx::Rect layer_rect(100, 100); | 511 gfx::Rect layer_rect(100, 100); |
522 SkPictureRecorder recorder; | 512 SkPictureRecorder recorder; |
523 sk_sp<SkCanvas> canvas; | |
524 SkPaint blue_paint; | 513 SkPaint blue_paint; |
525 blue_paint.setColor(SK_ColorBLUE); | 514 blue_paint.setColor(SK_ColorBLUE); |
526 SkPaint red_paint; | 515 SkPaint red_paint; |
527 red_paint.setColor(SK_ColorRED); | 516 red_paint.setColor(SK_ColorRED); |
528 unsigned char pixels[4 * 100 * 100] = {0}; | 517 unsigned char pixels[4 * 100 * 100] = {0}; |
529 | 518 |
530 gfx::PointF offset(8.f, 9.f); | 519 gfx::PointF offset(8.f, 9.f); |
531 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 520 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
532 | 521 |
533 DisplayItemListSettings no_caching_settings; | 522 DisplayItemListSettings no_caching_settings; |
534 scoped_refptr<DisplayItemList> list_without_caching = | 523 scoped_refptr<DisplayItemList> list_without_caching = |
535 DisplayItemList::Create(no_caching_settings); | 524 DisplayItemList::Create(no_caching_settings); |
536 | 525 |
537 canvas = | 526 SkCanvas* canvas = |
538 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 527 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); |
539 canvas->translate(offset.x(), offset.y()); | 528 canvas->translate(offset.x(), offset.y()); |
540 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 529 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
541 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 530 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
542 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | 531 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); |
543 list_without_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 532 list_without_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
544 kVisualRect, picture); | 533 kVisualRect, picture); |
545 list_without_caching->Finalize(); | 534 list_without_caching->Finalize(); |
546 DrawDisplayList(pixels, layer_rect, list_without_caching); | 535 DrawDisplayList(pixels, layer_rect, list_without_caching); |
547 | 536 |
548 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 537 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 944 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
956 | 945 |
957 EXPECT_EQ(4u, list->size()); | 946 EXPECT_EQ(4u, list->size()); |
958 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); | 947 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); |
959 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); | 948 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); |
960 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); | 949 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); |
961 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); | 950 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); |
962 } | 951 } |
963 | 952 |
964 } // namespace cc | 953 } // namespace cc |
OLD | NEW |