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