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/playback/clip_display_item.h" | 14 #include "cc/playback/clip_display_item.h" |
15 #include "cc/playback/clip_path_display_item.h" | 15 #include "cc/playback/clip_path_display_item.h" |
16 #include "cc/playback/compositing_display_item.h" | 16 #include "cc/playback/compositing_display_item.h" |
17 #include "cc/playback/display_item_list_settings.h" | 17 #include "cc/playback/display_item_list_settings.h" |
18 #include "cc/playback/drawing_display_item.h" | 18 #include "cc/playback/drawing_display_item.h" |
19 #include "cc/playback/filter_display_item.h" | 19 #include "cc/playback/filter_display_item.h" |
20 #include "cc/playback/float_clip_display_item.h" | 20 #include "cc/playback/float_clip_display_item.h" |
21 #include "cc/playback/transform_display_item.h" | 21 #include "cc/playback/transform_display_item.h" |
22 #include "cc/proto/display_item.pb.h" | 22 #include "cc/proto/display_item.pb.h" |
23 #include "cc/test/fake_image_serialization_processor.h" | 23 #include "cc/test/fake_image_serialization_processor.h" |
24 #include "cc/test/skia_common.h" | 24 #include "cc/test/skia_common.h" |
25 #include "skia/ext/refptr.h" | |
26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
28 #include "third_party/skia/include/core/SkCanvas.h" | 27 #include "third_party/skia/include/core/SkCanvas.h" |
29 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
30 #include "third_party/skia/include/core/SkPictureRecorder.h" | 29 #include "third_party/skia/include/core/SkPictureRecorder.h" |
31 #include "third_party/skia/include/core/SkSurface.h" | 30 #include "third_party/skia/include/core/SkSurface.h" |
32 #include "third_party/skia/include/core/SkXfermode.h" | 31 #include "third_party/skia/include/core/SkXfermode.h" |
33 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" | 32 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" |
34 #include "third_party/skia/include/effects/SkImageSource.h" | 33 #include "third_party/skia/include/effects/SkImageSource.h" |
35 #include "third_party/skia/include/utils/SkPictureUtils.h" | 34 #include "third_party/skia/include/utils/SkPictureUtils.h" |
36 #include "ui/gfx/geometry/rect.h" | 35 #include "ui/gfx/geometry/rect.h" |
37 #include "ui/gfx/geometry/rect_conversions.h" | 36 #include "ui/gfx/geometry/rect_conversions.h" |
38 #include "ui/gfx/skia_util.h" | 37 #include "ui/gfx/skia_util.h" |
39 | 38 |
40 namespace cc { | 39 namespace cc { |
41 | 40 |
42 namespace { | 41 namespace { |
43 | 42 |
44 const gfx::Rect kVisualRect(0, 0, 42, 42); | 43 const gfx::Rect kVisualRect(0, 0, 42, 42); |
45 | 44 |
46 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 45 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
47 const gfx::Size& layer_size) { | 46 const gfx::Size& layer_size) { |
48 gfx::PointF offset(2.f, 3.f); | 47 gfx::PointF offset(2.f, 3.f); |
49 SkPictureRecorder recorder; | 48 SkPictureRecorder recorder; |
50 skia::RefPtr<SkCanvas> canvas; | 49 sk_sp<SkCanvas> canvas; |
51 | 50 |
52 SkPaint red_paint; | 51 SkPaint red_paint; |
53 red_paint.setColor(SK_ColorRED); | 52 red_paint.setColor(SK_ColorRED); |
54 | 53 |
55 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( | 54 canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH( |
56 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); | 55 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
57 canvas->translate(offset.x(), offset.y()); | 56 canvas->translate(offset.x(), offset.y()); |
58 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); | 57 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
59 list->CreateAndAppendItem<DrawingDisplayItem>( | 58 list->CreateAndAppendItem<DrawingDisplayItem>( |
60 kVisualRect, recorder.finishRecordingAsPicture()); | 59 kVisualRect, recorder.finishRecordingAsPicture()); |
61 } | 60 } |
62 | 61 |
63 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, | 62 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, |
64 const gfx::Size& layer_size) { | 63 const gfx::Size& layer_size) { |
65 gfx::PointF offset(2.f, 2.f); | 64 gfx::PointF offset(2.f, 2.f); |
66 SkPictureRecorder recorder; | 65 SkPictureRecorder recorder; |
67 skia::RefPtr<SkCanvas> canvas; | 66 sk_sp<SkCanvas> canvas; |
68 | 67 |
69 SkPaint blue_paint; | 68 SkPaint blue_paint; |
70 blue_paint.setColor(SK_ColorBLUE); | 69 blue_paint.setColor(SK_ColorBLUE); |
71 | 70 |
72 canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( | 71 canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH( |
73 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); | 72 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
74 canvas->translate(offset.x(), offset.y()); | 73 canvas->translate(offset.x(), offset.y()); |
75 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); | 74 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
76 list->CreateAndAppendItem<DrawingDisplayItem>( | 75 list->CreateAndAppendItem<DrawingDisplayItem>( |
77 kVisualRect, recorder.finishRecordingAsPicture()); | 76 kVisualRect, recorder.finishRecordingAsPicture()); |
78 } | 77 } |
79 | 78 |
80 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, | 79 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, |
81 scoped_refptr<DisplayItemList> list) { | 80 scoped_refptr<DisplayItemList> list) { |
82 list->Finalize(); | 81 list->Finalize(); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 248 |
250 // Build the EndTransformDisplayItem. | 249 // Build the EndTransformDisplayItem. |
251 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); | 250 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); |
252 | 251 |
253 ValidateDisplayItemListSerialization(layer_size, list); | 252 ValidateDisplayItemListSerialization(layer_size, list); |
254 } | 253 } |
255 | 254 |
256 TEST(DisplayItemListTest, SingleDrawingItem) { | 255 TEST(DisplayItemListTest, SingleDrawingItem) { |
257 gfx::Rect layer_rect(100, 100); | 256 gfx::Rect layer_rect(100, 100); |
258 SkPictureRecorder recorder; | 257 SkPictureRecorder recorder; |
259 skia::RefPtr<SkCanvas> canvas; | 258 sk_sp<SkCanvas> canvas; |
260 SkPaint blue_paint; | 259 SkPaint blue_paint; |
261 blue_paint.setColor(SK_ColorBLUE); | 260 blue_paint.setColor(SK_ColorBLUE); |
262 SkPaint red_paint; | 261 SkPaint red_paint; |
263 red_paint.setColor(SK_ColorRED); | 262 red_paint.setColor(SK_ColorRED); |
264 unsigned char pixels[4 * 100 * 100] = {0}; | 263 unsigned char pixels[4 * 100 * 100] = {0}; |
265 DisplayItemListSettings settings; | 264 DisplayItemListSettings settings; |
266 scoped_refptr<DisplayItemList> list = | 265 scoped_refptr<DisplayItemList> list = |
267 DisplayItemList::Create(layer_rect, settings); | 266 DisplayItemList::Create(layer_rect, settings); |
268 | 267 |
269 gfx::PointF offset(8.f, 9.f); | 268 gfx::PointF offset(8.f, 9.f); |
270 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 269 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
271 canvas = skia::SharePtr( | 270 canvas = |
272 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 271 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); |
273 canvas->translate(offset.x(), offset.y()); | 272 canvas->translate(offset.x(), offset.y()); |
274 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 273 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
275 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 274 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
276 list->CreateAndAppendItem<DrawingDisplayItem>( | 275 list->CreateAndAppendItem<DrawingDisplayItem>( |
277 kVisualRect, recorder.finishRecordingAsPicture()); | 276 kVisualRect, recorder.finishRecordingAsPicture()); |
278 list->Finalize(); | 277 list->Finalize(); |
279 DrawDisplayList(pixels, layer_rect, list); | 278 DrawDisplayList(pixels, layer_rect, list); |
280 | 279 |
281 SkBitmap expected_bitmap; | 280 SkBitmap expected_bitmap; |
282 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 281 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
283 SkImageInfo info = | 282 SkImageInfo info = |
284 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 283 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
285 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 284 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
286 SkCanvas expected_canvas(expected_bitmap); | 285 SkCanvas expected_canvas(expected_bitmap); |
287 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 286 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
288 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), | 287 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), |
289 60.f + offset.x(), 60.f + offset.y(), | 288 60.f + offset.x(), 60.f + offset.y(), |
290 red_paint); | 289 red_paint); |
291 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), | 290 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), |
292 75.f + offset.x(), 75.f + offset.y(), | 291 75.f + offset.x(), 75.f + offset.y(), |
293 blue_paint); | 292 blue_paint); |
294 | 293 |
295 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 294 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
296 } | 295 } |
297 | 296 |
298 TEST(DisplayItemListTest, ClipItem) { | 297 TEST(DisplayItemListTest, ClipItem) { |
299 gfx::Rect layer_rect(100, 100); | 298 gfx::Rect layer_rect(100, 100); |
300 SkPictureRecorder recorder; | 299 SkPictureRecorder recorder; |
301 skia::RefPtr<SkCanvas> canvas; | 300 sk_sp<SkCanvas> canvas; |
302 SkPaint blue_paint; | 301 SkPaint blue_paint; |
303 blue_paint.setColor(SK_ColorBLUE); | 302 blue_paint.setColor(SK_ColorBLUE); |
304 SkPaint red_paint; | 303 SkPaint red_paint; |
305 red_paint.setColor(SK_ColorRED); | 304 red_paint.setColor(SK_ColorRED); |
306 unsigned char pixels[4 * 100 * 100] = {0}; | 305 unsigned char pixels[4 * 100 * 100] = {0}; |
307 DisplayItemListSettings settings; | 306 DisplayItemListSettings settings; |
308 settings.use_cached_picture = true; | 307 settings.use_cached_picture = true; |
309 scoped_refptr<DisplayItemList> list = | 308 scoped_refptr<DisplayItemList> list = |
310 DisplayItemList::Create(layer_rect, settings); | 309 DisplayItemList::Create(layer_rect, settings); |
311 | 310 |
312 gfx::PointF first_offset(8.f, 9.f); | 311 gfx::PointF first_offset(8.f, 9.f); |
313 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 312 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
314 canvas = skia::SharePtr( | 313 canvas = sk_ref_sp( |
315 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 314 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
316 canvas->translate(first_offset.x(), first_offset.y()); | 315 canvas->translate(first_offset.x(), first_offset.y()); |
317 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 316 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
318 list->CreateAndAppendItem<DrawingDisplayItem>( | 317 list->CreateAndAppendItem<DrawingDisplayItem>( |
319 kVisualRect, recorder.finishRecordingAsPicture()); | 318 kVisualRect, recorder.finishRecordingAsPicture()); |
320 | 319 |
321 gfx::Rect clip_rect(60, 60, 10, 10); | 320 gfx::Rect clip_rect(60, 60, 10, 10); |
322 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, | 321 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, |
323 std::vector<SkRRect>()); | 322 std::vector<SkRRect>()); |
324 | 323 |
325 gfx::PointF second_offset(2.f, 3.f); | 324 gfx::PointF second_offset(2.f, 3.f); |
326 gfx::RectF second_recording_rect(second_offset, | 325 gfx::RectF second_recording_rect(second_offset, |
327 gfx::SizeF(layer_rect.size())); | 326 gfx::SizeF(layer_rect.size())); |
328 canvas = skia::SharePtr( | 327 canvas = sk_ref_sp( |
329 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); | 328 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); |
330 canvas->translate(second_offset.x(), second_offset.y()); | 329 canvas->translate(second_offset.x(), second_offset.y()); |
331 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 330 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
332 list->CreateAndAppendItem<DrawingDisplayItem>( | 331 list->CreateAndAppendItem<DrawingDisplayItem>( |
333 kVisualRect, recorder.finishRecordingAsPicture()); | 332 kVisualRect, recorder.finishRecordingAsPicture()); |
334 | 333 |
335 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); | 334 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); |
336 list->Finalize(); | 335 list->Finalize(); |
337 | 336 |
338 DrawDisplayList(pixels, layer_rect, list); | 337 DrawDisplayList(pixels, layer_rect, list); |
(...skipping 12 matching lines...) Expand all Loading... |
351 expected_canvas.drawRectCoords( | 350 expected_canvas.drawRectCoords( |
352 50.f + second_offset.x(), 50.f + second_offset.y(), | 351 50.f + second_offset.x(), 50.f + second_offset.y(), |
353 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); | 352 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); |
354 | 353 |
355 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 354 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
356 } | 355 } |
357 | 356 |
358 TEST(DisplayItemListTest, TransformItem) { | 357 TEST(DisplayItemListTest, TransformItem) { |
359 gfx::Rect layer_rect(100, 100); | 358 gfx::Rect layer_rect(100, 100); |
360 SkPictureRecorder recorder; | 359 SkPictureRecorder recorder; |
361 skia::RefPtr<SkCanvas> canvas; | 360 sk_sp<SkCanvas> canvas; |
362 SkPaint blue_paint; | 361 SkPaint blue_paint; |
363 blue_paint.setColor(SK_ColorBLUE); | 362 blue_paint.setColor(SK_ColorBLUE); |
364 SkPaint red_paint; | 363 SkPaint red_paint; |
365 red_paint.setColor(SK_ColorRED); | 364 red_paint.setColor(SK_ColorRED); |
366 unsigned char pixels[4 * 100 * 100] = {0}; | 365 unsigned char pixels[4 * 100 * 100] = {0}; |
367 DisplayItemListSettings settings; | 366 DisplayItemListSettings settings; |
368 settings.use_cached_picture = true; | 367 settings.use_cached_picture = true; |
369 scoped_refptr<DisplayItemList> list = | 368 scoped_refptr<DisplayItemList> list = |
370 DisplayItemList::Create(layer_rect, settings); | 369 DisplayItemList::Create(layer_rect, settings); |
371 | 370 |
372 gfx::PointF first_offset(8.f, 9.f); | 371 gfx::PointF first_offset(8.f, 9.f); |
373 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); | 372 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); |
374 canvas = skia::SharePtr( | 373 canvas = sk_ref_sp( |
375 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); | 374 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); |
376 canvas->translate(first_offset.x(), first_offset.y()); | 375 canvas->translate(first_offset.x(), first_offset.y()); |
377 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 376 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
378 list->CreateAndAppendItem<DrawingDisplayItem>( | 377 list->CreateAndAppendItem<DrawingDisplayItem>( |
379 kVisualRect, recorder.finishRecordingAsPicture()); | 378 kVisualRect, recorder.finishRecordingAsPicture()); |
380 | 379 |
381 gfx::Transform transform; | 380 gfx::Transform transform; |
382 transform.Rotate(45.0); | 381 transform.Rotate(45.0); |
383 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); | 382 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); |
384 | 383 |
385 gfx::PointF second_offset(2.f, 3.f); | 384 gfx::PointF second_offset(2.f, 3.f); |
386 gfx::RectF second_recording_rect(second_offset, | 385 gfx::RectF second_recording_rect(second_offset, |
387 gfx::SizeF(layer_rect.size())); | 386 gfx::SizeF(layer_rect.size())); |
388 canvas = skia::SharePtr( | 387 canvas = sk_ref_sp( |
389 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); | 388 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); |
390 canvas->translate(second_offset.x(), second_offset.y()); | 389 canvas->translate(second_offset.x(), second_offset.y()); |
391 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 390 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
392 list->CreateAndAppendItem<DrawingDisplayItem>( | 391 list->CreateAndAppendItem<DrawingDisplayItem>( |
393 kVisualRect, recorder.finishRecordingAsPicture()); | 392 kVisualRect, recorder.finishRecordingAsPicture()); |
394 | 393 |
395 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); | 394 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); |
396 list->Finalize(); | 395 list->Finalize(); |
397 | 396 |
398 DrawDisplayList(pixels, layer_rect, list); | 397 DrawDisplayList(pixels, layer_rect, list); |
(...skipping 21 matching lines...) Expand all Loading... |
420 FilterOperations filters; | 419 FilterOperations filters; |
421 unsigned char pixels[4 * 100 * 100] = {0}; | 420 unsigned char pixels[4 * 100 * 100] = {0}; |
422 DisplayItemListSettings settings; | 421 DisplayItemListSettings settings; |
423 settings.use_cached_picture = true; | 422 settings.use_cached_picture = true; |
424 scoped_refptr<DisplayItemList> list = | 423 scoped_refptr<DisplayItemList> list = |
425 DisplayItemList::Create(layer_rect, settings); | 424 DisplayItemList::Create(layer_rect, settings); |
426 | 425 |
427 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50); | 426 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50); |
428 SkCanvas* source_canvas = source_surface->getCanvas(); | 427 SkCanvas* source_canvas = source_surface->getCanvas(); |
429 source_canvas->clear(SkColorSetRGB(128, 128, 128)); | 428 source_canvas->clear(SkColorSetRGB(128, 128, 128)); |
430 skia::RefPtr<SkImage> source_image = | 429 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot(); |
431 skia::AdoptRef(source_surface->newImageSnapshot()); | |
432 | 430 |
433 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are | 431 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are |
434 // dependent on the provided |src| bounds. This means, for example, that | 432 // dependent on the provided |src| bounds. This means, for example, that |
435 // translating |src| results in a corresponding translation of |dst|. But this | 433 // translating |src| results in a corresponding translation of |dst|. But this |
436 // is not the case for all SkImageFilters; for some of them (e.g. | 434 // is not the case for all SkImageFilters; for some of them (e.g. |
437 // SkImageSource), the computation of |dst| in computeFastBounds doesn't | 435 // SkImageSource), the computation of |dst| in computeFastBounds doesn't |
438 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by | 436 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by |
439 // translating |dst| after it is computed by computeFastBounds, rather than | 437 // translating |dst| after it is computed by computeFastBounds, rather than |
440 // translating |src| before it provided to computedFastBounds) can cause | 438 // translating |src| before it provided to computedFastBounds) can cause |
441 // incorrect clipping of filter output. To test for this, we include an | 439 // incorrect clipping of filter output. To test for this, we include an |
442 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined | 440 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined |
443 // below. | 441 // below. |
444 skia::RefPtr<SkImageFilter> image_filter = | 442 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); |
445 skia::AdoptRef(SkImageSource::Create(source_image.get())); | |
446 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); | 443 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); |
447 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); | 444 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); |
448 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); | 445 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); |
449 list->CreateAndAppendItem<FilterDisplayItem>(kVisualRect, filters, | 446 list->CreateAndAppendItem<FilterDisplayItem>(kVisualRect, filters, |
450 filter_bounds); | 447 filter_bounds); |
451 list->CreateAndAppendItem<EndFilterDisplayItem>(kVisualRect); | 448 list->CreateAndAppendItem<EndFilterDisplayItem>(kVisualRect); |
452 list->Finalize(); | 449 list->Finalize(); |
453 | 450 |
454 DrawDisplayList(pixels, layer_rect, list); | 451 DrawDisplayList(pixels, layer_rect, list); |
455 | 452 |
456 SkBitmap expected_bitmap; | 453 SkBitmap expected_bitmap; |
457 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 454 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
458 SkPaint paint; | 455 SkPaint paint; |
459 paint.setColor(SkColorSetRGB(64, 64, 64)); | 456 paint.setColor(SkColorSetRGB(64, 64, 64)); |
460 SkImageInfo info = | 457 SkImageInfo info = |
461 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); | 458 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); |
462 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); | 459 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); |
463 SkCanvas expected_canvas(expected_bitmap); | 460 SkCanvas expected_canvas(expected_bitmap); |
464 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); | 461 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); |
465 | 462 |
466 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 463 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
467 } | 464 } |
468 | 465 |
469 TEST(DisplayItemListTest, CompactingItems) { | 466 TEST(DisplayItemListTest, CompactingItems) { |
470 gfx::Rect layer_rect(100, 100); | 467 gfx::Rect layer_rect(100, 100); |
471 SkPictureRecorder recorder; | 468 SkPictureRecorder recorder; |
472 skia::RefPtr<SkCanvas> canvas; | 469 sk_sp<SkCanvas> canvas; |
473 SkPaint blue_paint; | 470 SkPaint blue_paint; |
474 blue_paint.setColor(SK_ColorBLUE); | 471 blue_paint.setColor(SK_ColorBLUE); |
475 SkPaint red_paint; | 472 SkPaint red_paint; |
476 red_paint.setColor(SK_ColorRED); | 473 red_paint.setColor(SK_ColorRED); |
477 unsigned char pixels[4 * 100 * 100] = {0}; | 474 unsigned char pixels[4 * 100 * 100] = {0}; |
478 | 475 |
479 gfx::PointF offset(8.f, 9.f); | 476 gfx::PointF offset(8.f, 9.f); |
480 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); | 477 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); |
481 | 478 |
482 DisplayItemListSettings no_caching_settings; | 479 DisplayItemListSettings no_caching_settings; |
483 no_caching_settings.use_cached_picture = false; | 480 no_caching_settings.use_cached_picture = false; |
484 scoped_refptr<DisplayItemList> list_without_caching = | 481 scoped_refptr<DisplayItemList> list_without_caching = |
485 DisplayItemList::Create(layer_rect, no_caching_settings); | 482 DisplayItemList::Create(layer_rect, no_caching_settings); |
486 | 483 |
487 canvas = skia::SharePtr( | 484 canvas = |
488 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); | 485 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); |
489 canvas->translate(offset.x(), offset.y()); | 486 canvas->translate(offset.x(), offset.y()); |
490 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); | 487 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); |
491 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); | 488 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); |
492 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | 489 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); |
493 list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, | 490 list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, |
494 picture); | 491 picture); |
495 list_without_caching->Finalize(); | 492 list_without_caching->Finalize(); |
496 DrawDisplayList(pixels, layer_rect, list_without_caching); | 493 DrawDisplayList(pixels, layer_rect, list_without_caching); |
497 | 494 |
498 unsigned char expected_pixels[4 * 100 * 100] = {0}; | 495 unsigned char expected_pixels[4 * 100 * 100] = {0}; |
499 DisplayItemListSettings caching_settings; | 496 DisplayItemListSettings caching_settings; |
500 caching_settings.use_cached_picture = true; | 497 caching_settings.use_cached_picture = true; |
501 scoped_refptr<DisplayItemList> list_with_caching = | 498 scoped_refptr<DisplayItemList> list_with_caching = |
502 DisplayItemList::Create(layer_rect, caching_settings); | 499 DisplayItemList::Create(layer_rect, caching_settings); |
503 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, | 500 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, |
504 picture); | 501 picture); |
505 list_with_caching->Finalize(); | 502 list_with_caching->Finalize(); |
506 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); | 503 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); |
507 | 504 |
508 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); | 505 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); |
509 } | 506 } |
510 | 507 |
511 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithCachedPicture) { | 508 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithCachedPicture) { |
512 gfx::Rect layer_rect(1000, 1000); | 509 gfx::Rect layer_rect(1000, 1000); |
513 SkPictureRecorder recorder; | 510 SkPictureRecorder recorder; |
514 skia::RefPtr<SkCanvas> canvas; | 511 sk_sp<SkCanvas> canvas; |
515 | 512 |
516 DisplayItemListSettings settings; | 513 DisplayItemListSettings settings; |
517 settings.use_cached_picture = true; | 514 settings.use_cached_picture = true; |
518 scoped_refptr<DisplayItemList> list = | 515 scoped_refptr<DisplayItemList> list = |
519 DisplayItemList::Create(layer_rect, settings); | 516 DisplayItemList::Create(layer_rect, settings); |
520 canvas = | 517 canvas = sk_ref_sp(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
521 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | |
522 | 518 |
523 SkPath path; | 519 SkPath path; |
524 path.moveTo(0, 0); | 520 path.moveTo(0, 0); |
525 path.lineTo(0, 100); | 521 path.lineTo(0, 100); |
526 path.lineTo(50, 50); | 522 path.lineTo(50, 50); |
527 path.lineTo(100, 100); | 523 path.lineTo(100, 100); |
528 path.lineTo(100, 0); | 524 path.lineTo(100, 0); |
529 path.close(); | 525 path.close(); |
530 | 526 |
531 SkPaint paint; | 527 SkPaint paint; |
532 paint.setAntiAlias(true); | 528 paint.setAntiAlias(true); |
533 canvas->drawPath(path, paint); | 529 canvas->drawPath(path, paint); |
534 | 530 |
535 sk_sp<SkPicture> suitable_picture = recorder.finishRecordingAsPicture(); | 531 sk_sp<SkPicture> suitable_picture = recorder.finishRecordingAsPicture(); |
536 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, suitable_picture); | 532 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, suitable_picture); |
537 list->Finalize(); | 533 list->Finalize(); |
538 | 534 |
539 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger | 535 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger |
540 // a veto. | 536 // a veto. |
541 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 537 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
542 | 538 |
543 // Now check the RasterIntoCanvas path. | 539 // Now check the RasterIntoCanvas path. |
544 list = DisplayItemList::Create(layer_rect, settings); | 540 list = DisplayItemList::Create(layer_rect, settings); |
545 DrawingDisplayItem suitable_item(suitable_picture); | 541 DrawingDisplayItem suitable_item(suitable_picture); |
546 list->RasterIntoCanvas(suitable_item); | 542 list->RasterIntoCanvas(suitable_item); |
547 list->Finalize(); | 543 list->Finalize(); |
548 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 544 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
549 | 545 |
550 list = DisplayItemList::Create(layer_rect, settings); | 546 list = DisplayItemList::Create(layer_rect, settings); |
551 canvas = | 547 canvas = sk_ref_sp(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
552 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | |
553 for (int i = 0; i < 10; ++i) | 548 for (int i = 0; i < 10; ++i) |
554 canvas->drawPath(path, paint); | 549 canvas->drawPath(path, paint); |
555 sk_sp<SkPicture> unsuitable_picture = recorder.finishRecordingAsPicture(); | 550 sk_sp<SkPicture> unsuitable_picture = recorder.finishRecordingAsPicture(); |
556 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, | 551 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, |
557 unsuitable_picture); | 552 unsuitable_picture); |
558 list->Finalize(); | 553 list->Finalize(); |
559 | 554 |
560 // A single DrawingDisplayItem with several large AA concave paths should | 555 // A single DrawingDisplayItem with several large AA concave paths should |
561 // trigger a veto. | 556 // trigger a veto. |
562 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | 557 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
563 | 558 |
564 // Now check the RasterIntoCanvas path. | 559 // Now check the RasterIntoCanvas path. |
565 list = DisplayItemList::Create(layer_rect, settings); | 560 list = DisplayItemList::Create(layer_rect, settings); |
566 DrawingDisplayItem unsuitable_item(unsuitable_picture); | 561 DrawingDisplayItem unsuitable_item(unsuitable_picture); |
567 list->RasterIntoCanvas(unsuitable_item); | 562 list->RasterIntoCanvas(unsuitable_item); |
568 list->Finalize(); | 563 list->Finalize(); |
569 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | 564 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
570 } | 565 } |
571 | 566 |
572 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) { | 567 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) { |
573 gfx::Rect layer_rect(1000, 1000); | 568 gfx::Rect layer_rect(1000, 1000); |
574 SkPictureRecorder recorder; | 569 SkPictureRecorder recorder; |
575 skia::RefPtr<SkCanvas> canvas; | 570 sk_sp<SkCanvas> canvas; |
576 skia::RefPtr<SkPicture> picture; | 571 sk_sp<SkPicture> picture; |
577 | 572 |
578 DisplayItemListSettings settings; | 573 DisplayItemListSettings settings; |
579 settings.use_cached_picture = false; | 574 settings.use_cached_picture = false; |
580 scoped_refptr<DisplayItemList> list = | 575 scoped_refptr<DisplayItemList> list = |
581 DisplayItemList::Create(layer_rect, settings); | 576 DisplayItemList::Create(layer_rect, settings); |
582 canvas = | 577 canvas = sk_ref_sp(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
583 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | |
584 | 578 |
585 SkPath path; | 579 SkPath path; |
586 path.moveTo(0, 0); | 580 path.moveTo(0, 0); |
587 path.lineTo(0, 100); | 581 path.lineTo(0, 100); |
588 path.lineTo(50, 50); | 582 path.lineTo(50, 50); |
589 path.lineTo(100, 100); | 583 path.lineTo(100, 100); |
590 path.lineTo(100, 0); | 584 path.lineTo(100, 0); |
591 path.close(); | 585 path.close(); |
592 | 586 |
593 SkPaint paint; | 587 SkPaint paint; |
594 paint.setAntiAlias(true); | 588 paint.setAntiAlias(true); |
595 canvas->drawPath(path, paint); | 589 canvas->drawPath(path, paint); |
596 | 590 |
597 list->CreateAndAppendItem<DrawingDisplayItem>( | 591 list->CreateAndAppendItem<DrawingDisplayItem>( |
598 kVisualRect, recorder.finishRecordingAsPicture()); | 592 kVisualRect, recorder.finishRecordingAsPicture()); |
599 list->Finalize(); | 593 list->Finalize(); |
600 | 594 |
601 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger | 595 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger |
602 // a veto. | 596 // a veto. |
603 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 597 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
604 | 598 |
605 list = DisplayItemList::Create(layer_rect, settings); | 599 list = DisplayItemList::Create(layer_rect, settings); |
606 canvas = | 600 canvas = sk_ref_sp(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
607 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | |
608 for (int i = 0; i < 10; ++i) | 601 for (int i = 0; i < 10; ++i) |
609 canvas->drawPath(path, paint); | 602 canvas->drawPath(path, paint); |
610 list->CreateAndAppendItem<DrawingDisplayItem>( | 603 list->CreateAndAppendItem<DrawingDisplayItem>( |
611 kVisualRect, recorder.finishRecordingAsPicture()); | 604 kVisualRect, recorder.finishRecordingAsPicture()); |
612 list->Finalize(); | 605 list->Finalize(); |
613 | 606 |
614 // A single DrawingDisplayItem with several large AA concave paths should | 607 // A single DrawingDisplayItem with several large AA concave paths should |
615 // trigger a veto. | 608 // trigger a veto. |
616 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); | 609 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); |
617 | 610 |
618 list = DisplayItemList::Create(layer_rect, settings); | 611 list = DisplayItemList::Create(layer_rect, settings); |
619 for (int i = 0; i < 10; ++i) { | 612 for (int i = 0; i < 10; ++i) { |
620 canvas = | 613 canvas = sk_ref_sp(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); |
621 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); | |
622 canvas->drawPath(path, paint); | 614 canvas->drawPath(path, paint); |
623 list->CreateAndAppendItem<DrawingDisplayItem>( | 615 list->CreateAndAppendItem<DrawingDisplayItem>( |
624 kVisualRect, recorder.finishRecordingAsPicture()); | 616 kVisualRect, recorder.finishRecordingAsPicture()); |
625 } | 617 } |
626 list->Finalize(); | 618 list->Finalize(); |
627 | 619 |
628 // Without a cached picture, having several DrawingDisplayItems that each | 620 // Without a cached picture, having several DrawingDisplayItems that each |
629 // contain a single large AA concave will not trigger a veto, since each item | 621 // contain a single large AA concave will not trigger a veto, since each item |
630 // is individually suitable for GPU rasterization. | 622 // is individually suitable for GPU rasterization. |
631 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); | 623 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 | 745 |
754 value = list->AsValue(false)->ToString(); | 746 value = list->AsValue(false)->ToString(); |
755 EXPECT_EQ(value.find("\"items\":"), std::string::npos); | 747 EXPECT_EQ(value.find("\"items\":"), std::string::npos); |
756 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos); | 748 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos); |
757 // There should be no skp64 entry present as the items aren't included and the | 749 // There should be no skp64 entry present as the items aren't included and the |
758 // layer rect is empty. | 750 // layer rect is empty. |
759 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos); | 751 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos); |
760 } | 752 } |
761 | 753 |
762 } // namespace cc | 754 } // namespace cc |
OLD | NEW |