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