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 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "cc/output/filter_operation.h" | 12 #include "cc/output/filter_operation.h" |
13 #include "cc/output/filter_operations.h" | 13 #include "cc/output/filter_operations.h" |
14 #include "cc/paint/paint_canvas.h" | |
15 #include "cc/paint/paint_flags.h" | |
16 #include "cc/paint/paint_recorder.h" | |
14 #include "cc/playback/clip_display_item.h" | 17 #include "cc/playback/clip_display_item.h" |
15 #include "cc/playback/clip_path_display_item.h" | 18 #include "cc/playback/clip_path_display_item.h" |
16 #include "cc/playback/compositing_display_item.h" | 19 #include "cc/playback/compositing_display_item.h" |
17 #include "cc/playback/display_item_list_settings.h" | 20 #include "cc/playback/display_item_list_settings.h" |
18 #include "cc/playback/drawing_display_item.h" | 21 #include "cc/playback/drawing_display_item.h" |
19 #include "cc/playback/filter_display_item.h" | 22 #include "cc/playback/filter_display_item.h" |
20 #include "cc/playback/float_clip_display_item.h" | 23 #include "cc/playback/float_clip_display_item.h" |
21 #include "cc/playback/transform_display_item.h" | 24 #include "cc/playback/transform_display_item.h" |
22 #include "cc/proto/display_item.pb.h" | 25 #include "cc/proto/display_item.pb.h" |
23 #include "cc/test/fake_client_picture_cache.h" | 26 #include "cc/test/fake_client_picture_cache.h" |
24 #include "cc/test/fake_engine_picture_cache.h" | 27 #include "cc/test/fake_engine_picture_cache.h" |
25 #include "cc/test/fake_image_serialization_processor.h" | 28 #include "cc/test/fake_image_serialization_processor.h" |
26 #include "cc/test/geometry_test_utils.h" | 29 #include "cc/test/geometry_test_utils.h" |
27 #include "cc/test/skia_common.h" | 30 #include "cc/test/skia_common.h" |
28 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
31 #include "third_party/skia/include/core/SkCanvas.h" | |
32 #include "third_party/skia/include/core/SkColor.h" | 34 #include "third_party/skia/include/core/SkColor.h" |
33 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
34 #include "third_party/skia/include/core/SkSurface.h" | 35 #include "third_party/skia/include/core/SkSurface.h" |
35 | 36 |
36 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | 37 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" |
37 #include "third_party/skia/include/effects/SkImageSource.h" | 38 #include "third_party/skia/include/effects/SkImageSource.h" |
38 #include "third_party/skia/include/utils/SkPictureUtils.h" | |
39 #include "ui/gfx/geometry/rect.h" | 39 #include "ui/gfx/geometry/rect.h" |
40 #include "ui/gfx/geometry/rect_conversions.h" | 40 #include "ui/gfx/geometry/rect_conversions.h" |
41 #include "ui/gfx/skia_util.h" | 41 #include "ui/gfx/skia_util.h" |
42 | 42 |
43 namespace cc { | 43 namespace cc { |
44 | 44 |
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 PaintRecord> CreateRectPicture(const gfx::Rect& bounds) { |
54 SkPictureRecorder recorder; | 54 PaintRecorder recorder; |
55 SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height()); | 55 PaintCanvas* canvas = |
56 recorder.beginRecording(bounds.width(), bounds.height()); | |
56 canvas->drawRect( | 57 canvas->drawRect( |
57 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()), | 58 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()), |
58 SkPaint()); | 59 PaintFlags()); |
59 return recorder.finishRecordingAsPicture(); | 60 return recorder.finishRecordingAsPicture(); |
60 } | 61 } |
61 | 62 |
62 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 63 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
63 const gfx::Size& layer_size) { | 64 const gfx::Size& layer_size) { |
64 gfx::PointF offset(2.f, 3.f); | 65 gfx::PointF offset(2.f, 3.f); |
65 SkPictureRecorder recorder; | 66 PaintRecorder recorder; |
66 | 67 |
67 SkPaint red_paint; | 68 PaintFlags red_paint; |
68 red_paint.setColor(SK_ColorRED); | 69 red_paint.setColor(SK_ColorRED); |
69 | 70 |
70 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( | 71 PaintCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( |
71 offset.x(), offset.y(), layer_size.width(), layer_size.height())); | 72 offset.x(), offset.y(), layer_size.width(), layer_size.height())); |
72 canvas->translate(offset.x(), offset.y()); | 73 canvas->translate(offset.x(), offset.y()); |
73 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); | 74 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
74 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 75 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
75 kVisualRect, recorder.finishRecordingAsPicture()); | 76 kVisualRect, recorder.finishRecordingAsPicture()); |
76 } | 77 } |
77 | 78 |
78 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 79 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
79 const gfx::Size& layer_size) { | 80 const gfx::Size& layer_size) { |
80 gfx::PointF offset(2.f, 2.f); | 81 gfx::PointF offset(2.f, 2.f); |
81 SkPictureRecorder recorder; | 82 PaintRecorder recorder; |
82 | 83 |
83 SkPaint blue_paint; | 84 PaintFlags blue_paint; |
84 blue_paint.setColor(SK_ColorBLUE); | 85 blue_paint.setColor(SK_ColorBLUE); |
85 | 86 |
86 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( | 87 PaintCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( |
87 offset.x(), offset.y(), layer_size.width(), layer_size.height())); | 88 offset.x(), offset.y(), layer_size.width(), layer_size.height())); |
88 canvas->translate(offset.x(), offset.y()); | 89 canvas->translate(offset.x(), offset.y()); |
89 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); | 90 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
90 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 91 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
91 kVisualRect, recorder.finishRecordingAsPicture()); | 92 kVisualRect, recorder.finishRecordingAsPicture()); |
92 } | 93 } |
93 | 94 |
94 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, | 95 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, |
95 scoped_refptr<DisplayItemList> list) { | 96 scoped_refptr<DisplayItemList> list) { |
96 list->Finalize(); | 97 list->Finalize(); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 AppendSecondSerializationTestPicture(list, layer_size); | 283 AppendSecondSerializationTestPicture(list, layer_size); |
283 | 284 |
284 // Build the EndTransformDisplayItem. | 285 // Build the EndTransformDisplayItem. |
285 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | 286 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); |
286 | 287 |
287 ValidateDisplayItemListSerialization(layer_size, list); | 288 ValidateDisplayItemListSerialization(layer_size, list); |
288 } | 289 } |
289 | 290 |
290 TEST(DisplayItemListTest, SingleDrawingItem) { | 291 TEST(DisplayItemListTest, SingleDrawingItem) { |
291 gfx::Rect layer_rect(100, 100); | 292 gfx::Rect layer_rect(100, 100); |
292 SkPictureRecorder recorder; | 293 PaintRecorder recorder; |
293 SkPaint blue_paint; | 294 PaintFlags blue_paint; |
294 blue_paint.setColor(SK_ColorBLUE); | 295 blue_paint.setColor(SK_ColorBLUE); |
295 SkPaint red_paint; | 296 PaintFlags red_paint; |
296 red_paint.setColor(SK_ColorRED); | 297 red_paint.setColor(SK_ColorRED); |
297 unsigned char pixels[4 * 100 * 100] = {0}; | 298 unsigned char pixels[4 * 100 * 100] = {0}; |
298 DisplayItemListSettings settings; | 299 DisplayItemListSettings settings; |
299 settings.use_cached_picture = true; | 300 settings.use_cached_picture = true; |
300 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | 301 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
301 | 302 |
302 gfx::PointF offset(8.f, 9.f); | 303 gfx::PointF offset(8.f, 9.f); |
303 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 304 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
304 SkCanvas* canvas = | 305 PaintCanvas* canvas = |
305 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); | 306 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); |
306 canvas->translate(offset.x(), offset.y()); | 307 canvas->translate(offset.x(), offset.y()); |
307 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); |
308 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); |
309 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 310 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
310 kVisualRect, recorder.finishRecordingAsPicture()); | 311 kVisualRect, recorder.finishRecordingAsPicture()); |
311 list->Finalize(); | 312 list->Finalize(); |
312 DrawDisplayList(pixels, layer_rect, list); | 313 DrawDisplayList(pixels, layer_rect, list); |
313 | 314 |
314 SkBitmap expected_bitmap; | 315 SkBitmap expected_bitmap; |
315 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 316 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
316 SkImageInfo info = | 317 SkImageInfo info = |
317 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 318 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
318 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 319 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
319 SkCanvas expected_canvas(expected_bitmap); | 320 PaintCanvas expected_canvas(expected_bitmap); |
danakj
2017/01/20 23:34:13
This should stay SkCanvas right
enne (OOO)
2017/01/24 01:51:27
Good catch, thanks.
| |
320 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 321 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
321 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), | 322 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), |
322 60.f + offset.x(), 60.f + offset.y(), | 323 60.f + offset.x(), 60.f + offset.y(), |
323 red_paint); | 324 red_paint); |
324 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), | 325 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), |
325 75.f + offset.x(), 75.f + offset.y(), | 326 75.f + offset.x(), 75.f + offset.y(), |
326 blue_paint); | 327 blue_paint); |
327 | 328 |
328 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 329 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
329 } | 330 } |
330 | 331 |
331 TEST(DisplayItemListTest, ClipItem) { | 332 TEST(DisplayItemListTest, ClipItem) { |
332 gfx::Rect layer_rect(100, 100); | 333 gfx::Rect layer_rect(100, 100); |
333 SkPictureRecorder recorder; | 334 PaintRecorder recorder; |
334 SkPaint blue_paint; | 335 PaintFlags blue_paint; |
335 blue_paint.setColor(SK_ColorBLUE); | 336 blue_paint.setColor(SK_ColorBLUE); |
336 SkPaint red_paint; | 337 PaintFlags red_paint; |
337 red_paint.setColor(SK_ColorRED); | 338 red_paint.setColor(SK_ColorRED); |
338 unsigned char pixels[4 * 100 * 100] = {0}; | 339 unsigned char pixels[4 * 100 * 100] = {0}; |
339 DisplayItemListSettings settings; | 340 DisplayItemListSettings settings; |
340 settings.use_cached_picture = true; | 341 settings.use_cached_picture = true; |
341 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | 342 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
342 | 343 |
343 gfx::PointF first_offset(8.f, 9.f); | 344 gfx::PointF first_offset(8.f, 9.f); |
344 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())); |
345 SkCanvas* canvas = | 346 PaintCanvas* canvas = |
346 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); | 347 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); |
347 canvas->translate(first_offset.x(), first_offset.y()); | 348 canvas->translate(first_offset.x(), first_offset.y()); |
348 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); |
349 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 350 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
350 kVisualRect, recorder.finishRecordingAsPicture()); | 351 kVisualRect, recorder.finishRecordingAsPicture()); |
351 | 352 |
352 gfx::Rect clip_rect(60, 60, 10, 10); | 353 gfx::Rect clip_rect(60, 60, 10, 10); |
353 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 354 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
354 clip_rect, std::vector<SkRRect>(), true); | 355 clip_rect, std::vector<SkRRect>(), true); |
355 | 356 |
356 gfx::PointF second_offset(2.f, 3.f); | 357 gfx::PointF second_offset(2.f, 3.f); |
357 gfx::RectF second_recording_rect(second_offset, | 358 gfx::RectF second_recording_rect(second_offset, |
358 gfx::SizeF(layer_rect.size())); | 359 gfx::SizeF(layer_rect.size())); |
359 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); | 360 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); |
360 canvas->translate(second_offset.x(), second_offset.y()); | 361 canvas->translate(second_offset.x(), second_offset.y()); |
361 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); |
362 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 363 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
363 kVisualRect, recorder.finishRecordingAsPicture()); | 364 kVisualRect, recorder.finishRecordingAsPicture()); |
364 | 365 |
365 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 366 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
366 list->Finalize(); | 367 list->Finalize(); |
367 | 368 |
368 DrawDisplayList(pixels, layer_rect, list); | 369 DrawDisplayList(pixels, layer_rect, list); |
369 | 370 |
370 SkBitmap expected_bitmap; | 371 SkBitmap expected_bitmap; |
371 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 372 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
372 SkImageInfo info = | 373 SkImageInfo info = |
373 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 374 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
374 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 375 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
375 SkCanvas expected_canvas(expected_bitmap); | 376 PaintCanvas expected_canvas(expected_bitmap); |
danakj
2017/01/20 23:34:13
same
| |
376 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 377 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
377 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), | 378 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), |
378 60.f + first_offset.x(), | 379 60.f + first_offset.x(), |
379 60.f + first_offset.y(), red_paint); | 380 60.f + first_offset.y(), red_paint); |
380 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); | 381 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); |
381 expected_canvas.drawRectCoords( | 382 expected_canvas.drawRectCoords( |
382 50.f + second_offset.x(), 50.f + second_offset.y(), | 383 50.f + second_offset.x(), 50.f + second_offset.y(), |
383 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); |
384 | 385 |
385 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 386 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
386 } | 387 } |
387 | 388 |
388 TEST(DisplayItemListTest, TransformItem) { | 389 TEST(DisplayItemListTest, TransformItem) { |
389 gfx::Rect layer_rect(100, 100); | 390 gfx::Rect layer_rect(100, 100); |
390 SkPictureRecorder recorder; | 391 PaintRecorder recorder; |
391 SkPaint blue_paint; | 392 PaintFlags blue_paint; |
392 blue_paint.setColor(SK_ColorBLUE); | 393 blue_paint.setColor(SK_ColorBLUE); |
393 SkPaint red_paint; | 394 PaintFlags red_paint; |
394 red_paint.setColor(SK_ColorRED); | 395 red_paint.setColor(SK_ColorRED); |
395 unsigned char pixels[4 * 100 * 100] = {0}; | 396 unsigned char pixels[4 * 100 * 100] = {0}; |
396 DisplayItemListSettings settings; | 397 DisplayItemListSettings settings; |
397 settings.use_cached_picture = true; | 398 settings.use_cached_picture = true; |
398 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | 399 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); |
399 | 400 |
400 gfx::PointF first_offset(8.f, 9.f); | 401 gfx::PointF first_offset(8.f, 9.f); |
401 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())); |
402 SkCanvas* canvas = | 403 PaintCanvas* canvas = |
403 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); | 404 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); |
404 canvas->translate(first_offset.x(), first_offset.y()); | 405 canvas->translate(first_offset.x(), first_offset.y()); |
405 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); |
406 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 407 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
407 kVisualRect, recorder.finishRecordingAsPicture()); | 408 kVisualRect, recorder.finishRecordingAsPicture()); |
408 | 409 |
409 gfx::Transform transform; | 410 gfx::Transform transform; |
410 transform.Rotate(45.0); | 411 transform.Rotate(45.0); |
411 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); | 412 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); |
412 | 413 |
413 gfx::PointF second_offset(2.f, 3.f); | 414 gfx::PointF second_offset(2.f, 3.f); |
414 gfx::RectF second_recording_rect(second_offset, | 415 gfx::RectF second_recording_rect(second_offset, |
415 gfx::SizeF(layer_rect.size())); | 416 gfx::SizeF(layer_rect.size())); |
416 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); | 417 canvas = recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)); |
417 canvas->translate(second_offset.x(), second_offset.y()); | 418 canvas->translate(second_offset.x(), second_offset.y()); |
418 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); |
419 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 420 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
420 kVisualRect, recorder.finishRecordingAsPicture()); | 421 kVisualRect, recorder.finishRecordingAsPicture()); |
421 | 422 |
422 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | 423 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); |
423 list->Finalize(); | 424 list->Finalize(); |
424 | 425 |
425 DrawDisplayList(pixels, layer_rect, list); | 426 DrawDisplayList(pixels, layer_rect, list); |
426 | 427 |
427 SkBitmap expected_bitmap; | 428 SkBitmap expected_bitmap; |
428 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 429 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
429 SkImageInfo info = | 430 SkImageInfo info = |
430 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 431 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
431 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 432 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
432 SkCanvas expected_canvas(expected_bitmap); | 433 PaintCanvas expected_canvas(expected_bitmap); |
danakj
2017/01/20 23:34:13
same
| |
433 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 434 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
434 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), | 435 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), |
435 60.f + first_offset.x(), | 436 60.f + first_offset.x(), |
436 60.f + first_offset.y(), red_paint); | 437 60.f + first_offset.y(), red_paint); |
437 expected_canvas.setMatrix(transform.matrix()); | 438 expected_canvas.setMatrix(transform.matrix()); |
438 expected_canvas.drawRectCoords( | 439 expected_canvas.drawRectCoords( |
439 50.f + second_offset.x(), 50.f + second_offset.y(), | 440 50.f + second_offset.x(), 50.f + second_offset.y(), |
440 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); | 441 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); |
441 | 442 |
442 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 443 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
443 } | 444 } |
444 | 445 |
445 TEST(DisplayItemListTest, FilterItem) { | 446 TEST(DisplayItemListTest, FilterItem) { |
446 gfx::Rect layer_rect(100, 100); | 447 gfx::Rect layer_rect(100, 100); |
447 FilterOperations filters; | 448 FilterOperations filters; |
448 unsigned char pixels[4 * 100 * 100] = {0}; | 449 unsigned char pixels[4 * 100 * 100] = {0}; |
449 scoped_refptr<DisplayItemList> list = | 450 scoped_refptr<DisplayItemList> list = |
450 DisplayItemList::Create(DisplayItemListSettings()); | 451 DisplayItemList::Create(DisplayItemListSettings()); |
451 | 452 |
452 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50); | 453 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50); |
453 SkCanvas* source_canvas = source_surface->getCanvas(); | 454 PaintCanvas* source_canvas = source_surface->getCanvas(); |
454 source_canvas->clear(SkColorSetRGB(128, 128, 128)); | 455 source_canvas->clear(SkColorSetRGB(128, 128, 128)); |
455 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot(); | 456 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot(); |
456 | 457 |
457 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are | 458 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are |
458 // dependent on the provided |src| bounds. This means, for example, that | 459 // dependent on the provided |src| bounds. This means, for example, that |
459 // translating |src| results in a corresponding translation of |dst|. But this | 460 // translating |src| results in a corresponding translation of |dst|. But this |
460 // is not the case for all SkImageFilters; for some of them (e.g. | 461 // is not the case for all SkImageFilters; for some of them (e.g. |
461 // SkImageSource), the computation of |dst| in computeFastBounds doesn't | 462 // SkImageSource), the computation of |dst| in computeFastBounds doesn't |
462 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by | 463 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by |
463 // translating |dst| after it is computed by computeFastBounds, rather than | 464 // translating |dst| after it is computed by computeFastBounds, rather than |
464 // translating |src| before it provided to computedFastBounds) can cause | 465 // translating |src| before it provided to computedFastBounds) can cause |
465 // incorrect clipping of filter output. To test for this, we include an | 466 // incorrect clipping of filter output. To test for this, we include an |
466 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined | 467 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined |
467 // below. | 468 // below. |
468 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); | 469 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); |
469 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); | 470 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); |
470 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); | 471 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); |
471 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); |
472 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>( | 473 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>( |
473 filters, filter_bounds, filter_bounds.origin()); | 474 filters, filter_bounds, filter_bounds.origin()); |
474 | 475 |
475 // 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. |
476 { | 477 { |
477 SkPictureRecorder recorder; | 478 PaintRecorder recorder; |
478 | 479 |
479 SkPaint red_paint; | 480 PaintFlags red_paint; |
480 red_paint.setColor(SK_ColorRED); | 481 red_paint.setColor(SK_ColorRED); |
481 | 482 |
482 SkCanvas* canvas = recorder.beginRecording( | 483 PaintCanvas* canvas = recorder.beginRecording( |
483 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())); | 484 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())); |
484 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(), | 485 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(), |
485 filter_bounds.right(), filter_bounds.bottom(), | 486 filter_bounds.right(), filter_bounds.bottom(), |
486 red_paint); | 487 red_paint); |
487 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 488 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
488 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); | 489 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); |
489 } | 490 } |
490 | 491 |
491 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); | 492 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); |
492 list->Finalize(); | 493 list->Finalize(); |
493 | 494 |
494 DrawDisplayList(pixels, layer_rect, list); | 495 DrawDisplayList(pixels, layer_rect, list); |
495 | 496 |
496 SkBitmap expected_bitmap; | 497 SkBitmap expected_bitmap; |
497 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 498 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
498 SkPaint paint; | 499 PaintFlags paint; |
499 paint.setColor(SkColorSetRGB(64, 64, 64)); | 500 paint.setColor(SkColorSetRGB(64, 64, 64)); |
500 SkImageInfo info = | 501 SkImageInfo info = |
501 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 502 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
502 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 503 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
503 SkCanvas expected_canvas(expected_bitmap); | 504 PaintCanvas expected_canvas(expected_bitmap); |
danakj
2017/01/20 23:34:13
same
| |
504 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); | 505 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); |
505 | 506 |
506 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 507 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
507 } | 508 } |
508 | 509 |
509 TEST(DisplayItemListTest, CompactingItems) { | 510 TEST(DisplayItemListTest, CompactingItems) { |
510 gfx::Rect layer_rect(100, 100); | 511 gfx::Rect layer_rect(100, 100); |
511 SkPictureRecorder recorder; | 512 PaintRecorder recorder; |
512 SkPaint blue_paint; | 513 PaintFlags blue_paint; |
513 blue_paint.setColor(SK_ColorBLUE); | 514 blue_paint.setColor(SK_ColorBLUE); |
514 SkPaint red_paint; | 515 PaintFlags red_paint; |
515 red_paint.setColor(SK_ColorRED); | 516 red_paint.setColor(SK_ColorRED); |
516 unsigned char pixels[4 * 100 * 100] = {0}; | 517 unsigned char pixels[4 * 100 * 100] = {0}; |
517 | 518 |
518 gfx::PointF offset(8.f, 9.f); | 519 gfx::PointF offset(8.f, 9.f); |
519 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 520 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
520 | 521 |
521 DisplayItemListSettings no_caching_settings; | 522 DisplayItemListSettings no_caching_settings; |
522 scoped_refptr<DisplayItemList> list_without_caching = | 523 scoped_refptr<DisplayItemList> list_without_caching = |
523 DisplayItemList::Create(no_caching_settings); | 524 DisplayItemList::Create(no_caching_settings); |
524 | 525 |
525 SkCanvas* canvas = | 526 PaintCanvas* canvas = |
526 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); | 527 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); |
527 canvas->translate(offset.x(), offset.y()); | 528 canvas->translate(offset.x(), offset.y()); |
528 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); |
529 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); |
530 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | 531 sk_sp<PaintRecord> picture = recorder.finishRecordingAsPicture(); |
531 list_without_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 532 list_without_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
532 kVisualRect, picture); | 533 kVisualRect, picture); |
533 list_without_caching->Finalize(); | 534 list_without_caching->Finalize(); |
534 DrawDisplayList(pixels, layer_rect, list_without_caching); | 535 DrawDisplayList(pixels, layer_rect, list_without_caching); |
535 | 536 |
536 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 537 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
537 DisplayItemListSettings caching_settings; | 538 DisplayItemListSettings caching_settings; |
538 caching_settings.use_cached_picture = true; | 539 caching_settings.use_cached_picture = true; |
539 scoped_refptr<DisplayItemList> list_with_caching = | 540 scoped_refptr<DisplayItemList> list_with_caching = |
540 DisplayItemList::Create(caching_settings); | 541 DisplayItemList::Create(caching_settings); |
541 list_with_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, | 542 list_with_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, |
542 picture); | 543 picture); |
543 list_with_caching->Finalize(); | 544 list_with_caching->Finalize(); |
544 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); | 545 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); |
545 | 546 |
546 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 547 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
547 } | 548 } |
548 | 549 |
549 TEST(DisplayItemListTest, ApproximateMemoryUsage) { | 550 TEST(DisplayItemListTest, ApproximateMemoryUsage) { |
550 const int kNumCommandsInTestSkPicture = 1000; | 551 const int kNumCommandsInTestPaintRecord = 1000; |
551 scoped_refptr<DisplayItemList> list; | 552 scoped_refptr<DisplayItemList> list; |
552 size_t memory_usage; | 553 size_t memory_usage; |
553 | 554 |
554 // Make an SkPicture whose size is known. | 555 // Make an PaintRecord whose size is known. |
danakj
2017/01/20 23:34:13
a
| |
555 gfx::Rect layer_rect(100, 100); | 556 gfx::Rect layer_rect(100, 100); |
556 SkPictureRecorder recorder; | 557 PaintRecorder recorder; |
557 SkPaint blue_paint; | 558 PaintFlags blue_paint; |
558 blue_paint.setColor(SK_ColorBLUE); | 559 blue_paint.setColor(SK_ColorBLUE); |
559 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); | 560 PaintCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); |
560 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) | 561 for (int i = 0; i < kNumCommandsInTestPaintRecord; i++) |
561 canvas->drawPaint(blue_paint); | 562 canvas->drawPaint(blue_paint); |
562 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | 563 sk_sp<PaintRecord> picture = recorder.finishRecordingAsPicture(); |
563 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); | 564 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); |
564 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); | 565 ASSERT_GE(picture_size, kNumCommandsInTestPaintRecord * sizeof(blue_paint)); |
565 | 566 |
566 // Using a cached picture, we should get about the right size. | 567 // Using a cached picture, we should get about the right size. |
567 DisplayItemListSettings caching_settings; | 568 DisplayItemListSettings caching_settings; |
568 caching_settings.use_cached_picture = true; | 569 caching_settings.use_cached_picture = true; |
569 list = DisplayItemList::Create(caching_settings); | 570 list = DisplayItemList::Create(caching_settings); |
570 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture); | 571 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture); |
571 list->Finalize(); | 572 list->Finalize(); |
572 memory_usage = list->ApproximateMemoryUsage(); | 573 memory_usage = list->ApproximateMemoryUsage(); |
573 EXPECT_GE(memory_usage, picture_size); | 574 EXPECT_GE(memory_usage, picture_size); |
574 EXPECT_LE(memory_usage, 2 * picture_size); | 575 EXPECT_LE(memory_usage, 2 * picture_size); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 944 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
944 | 945 |
945 EXPECT_EQ(4u, list->size()); | 946 EXPECT_EQ(4u, list->size()); |
946 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); | 947 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); |
947 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); | 948 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); |
948 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); | 949 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); |
949 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); | 950 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); |
950 } | 951 } |
951 | 952 |
952 } // namespace cc | 953 } // namespace cc |
OLD | NEW |