Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(780)

Side by Side Diff: cc/playback/display_item_list_unittest.cc

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/playback/display_item_list.cc ('k') | cc/playback/drawing_display_item.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_client_picture_cache.h" 23 #include "cc/test/fake_client_picture_cache.h"
24 #include "cc/test/fake_engine_picture_cache.h" 24 #include "cc/test/fake_engine_picture_cache.h"
25 #include "cc/test/fake_image_serialization_processor.h" 25 #include "cc/test/fake_image_serialization_processor.h"
26 #include "cc/test/geometry_test_utils.h" 26 #include "cc/test/geometry_test_utils.h"
27 #include "cc/test/skia_common.h" 27 #include "cc/test/skia_common.h"
28 #include "skia/ext/cdl_paint.h"
29 #include "skia/ext/cdl_picture_recorder.h"
28 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
30 #include "third_party/skia/include/core/SkBitmap.h" 32 #include "third_party/skia/include/core/SkBitmap.h"
31 #include "third_party/skia/include/core/SkCanvas.h" 33 #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 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" 36 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
37 #include "third_party/skia/include/effects/SkImageSource.h" 37 #include "third_party/skia/include/effects/SkImageSource.h"
38 #include "third_party/skia/include/utils/SkPictureUtils.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 CdlPicture> CreateRectPicture(const gfx::Rect& bounds) {
54 SkPictureRecorder recorder; 54 CdlPictureRecorder recorder;
55 SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height()); 55 CdlCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height());
56 canvas->drawRect( 56 canvas->drawRect(
57 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()), 57 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()),
58 SkPaint()); 58 CdlPaint());
59 return recorder.finishRecordingAsPicture(); 59 return recorder.finishRecordingAsPicture();
60 } 60 }
61 61
62 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, 62 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list,
63 const gfx::Size& layer_size) { 63 const gfx::Size& layer_size) {
64 gfx::PointF offset(2.f, 3.f); 64 gfx::PointF offset(2.f, 3.f);
65 SkPictureRecorder recorder; 65 CdlPictureRecorder recorder;
66 66
67 SkPaint red_paint; 67 CdlPaint red_paint;
68 red_paint.setColor(SK_ColorRED); 68 red_paint.setColor(SK_ColorRED);
69 69
70 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( 70 CdlCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH(
71 offset.x(), offset.y(), layer_size.width(), layer_size.height())); 71 offset.x(), offset.y(), layer_size.width(), layer_size.height()));
72 canvas->translate(offset.x(), offset.y()); 72 canvas->translate(offset.x(), offset.y());
73 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); 73 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint);
74 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 74 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
75 kVisualRect, recorder.finishRecordingAsPicture()); 75 kVisualRect, recorder.finishRecordingAsPicture());
76 } 76 }
77 77
78 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, 78 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list,
79 const gfx::Size& layer_size) { 79 const gfx::Size& layer_size) {
80 gfx::PointF offset(2.f, 2.f); 80 gfx::PointF offset(2.f, 2.f);
81 SkPictureRecorder recorder; 81 CdlPictureRecorder recorder;
82 82
83 SkPaint blue_paint; 83 CdlPaint blue_paint;
84 blue_paint.setColor(SK_ColorBLUE); 84 blue_paint.setColor(SK_ColorBLUE);
85 85
86 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( 86 CdlCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH(
87 offset.x(), offset.y(), layer_size.width(), layer_size.height())); 87 offset.x(), offset.y(), layer_size.width(), layer_size.height()));
88 canvas->translate(offset.x(), offset.y()); 88 canvas->translate(offset.x(), offset.y());
89 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); 89 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint);
90 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 90 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
91 kVisualRect, recorder.finishRecordingAsPicture()); 91 kVisualRect, recorder.finishRecordingAsPicture());
92 } 92 }
93 93
94 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, 94 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size,
95 scoped_refptr<DisplayItemList> list) { 95 scoped_refptr<DisplayItemList> list) {
96 list->Finalize(); 96 list->Finalize();
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 AppendSecondSerializationTestPicture(list, layer_size); 283 AppendSecondSerializationTestPicture(list, layer_size);
284 284
285 // Build the EndTransformDisplayItem. 285 // Build the EndTransformDisplayItem.
286 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); 286 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
287 287
288 ValidateDisplayItemListSerialization(layer_size, list); 288 ValidateDisplayItemListSerialization(layer_size, list);
289 } 289 }
290 290
291 TEST(DisplayItemListTest, SingleDrawingItem) { 291 TEST(DisplayItemListTest, SingleDrawingItem) {
292 gfx::Rect layer_rect(100, 100); 292 gfx::Rect layer_rect(100, 100);
293 SkPictureRecorder recorder; 293 CdlPictureRecorder recorder;
294 SkPaint blue_paint; 294 CdlPaint blue_paint;
295 blue_paint.setColor(SK_ColorBLUE); 295 blue_paint.setColor(SK_ColorBLUE);
296 SkPaint red_paint; 296 CdlPaint red_paint;
297 red_paint.setColor(SK_ColorRED); 297 red_paint.setColor(SK_ColorRED);
298 unsigned char pixels[4 * 100 * 100] = {0}; 298 unsigned char pixels[4 * 100 * 100] = {0};
299 DisplayItemListSettings settings; 299 DisplayItemListSettings settings;
300 settings.use_cached_picture = true; 300 settings.use_cached_picture = true;
301 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); 301 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
302 302
303 gfx::PointF offset(8.f, 9.f); 303 gfx::PointF offset(8.f, 9.f);
304 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); 304 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
305 SkCanvas* canvas = 305 CdlCanvas* canvas =
306 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); 306 recorder.beginRecording(gfx::RectFToSkRect(recording_rect));
307 canvas->translate(offset.x(), offset.y()); 307 canvas->translate(offset.x(), offset.y());
308 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);
309 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);
310 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 310 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
311 kVisualRect, recorder.finishRecordingAsPicture()); 311 kVisualRect, recorder.finishRecordingAsPicture());
312 list->Finalize(); 312 list->Finalize();
313 DrawDisplayList(pixels, layer_rect, list); 313 DrawDisplayList(pixels, layer_rect, list);
314 314
315 SkBitmap expected_bitmap; 315 SkBitmap expected_bitmap;
316 unsigned char expected_pixels[4 * 100 * 100] = {0}; 316 unsigned char expected_pixels[4 * 100 * 100] = {0};
317 SkImageInfo info = 317 SkImageInfo info =
318 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 318 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
319 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 319 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
320 SkCanvas expected_canvas(expected_bitmap); 320 SkCanvas expected_canvas(expected_bitmap);
321 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); 321 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect));
322 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(), 322 expected_canvas.drawRectCoords(0.f + offset.x(), 0.f + offset.y(),
323 60.f + offset.x(), 60.f + offset.y(), 323 60.f + offset.x(), 60.f + offset.y(),
324 red_paint); 324 ToSkPaint(red_paint));
325 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(), 325 expected_canvas.drawRectCoords(50.f + offset.x(), 50.f + offset.y(),
326 75.f + offset.x(), 75.f + offset.y(), 326 75.f + offset.x(), 75.f + offset.y(),
327 blue_paint); 327 ToSkPaint(blue_paint));
328 328
329 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 329 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
330 } 330 }
331 331
332 TEST(DisplayItemListTest, ClipItem) { 332 TEST(DisplayItemListTest, ClipItem) {
333 gfx::Rect layer_rect(100, 100); 333 gfx::Rect layer_rect(100, 100);
334 SkPictureRecorder recorder; 334 CdlPictureRecorder recorder;
335 SkPaint blue_paint; 335 CdlPaint blue_paint;
336 blue_paint.setColor(SK_ColorBLUE); 336 blue_paint.setColor(SK_ColorBLUE);
337 SkPaint red_paint; 337 CdlPaint red_paint;
338 red_paint.setColor(SK_ColorRED); 338 red_paint.setColor(SK_ColorRED);
339 unsigned char pixels[4 * 100 * 100] = {0}; 339 unsigned char pixels[4 * 100 * 100] = {0};
340 DisplayItemListSettings settings; 340 DisplayItemListSettings settings;
341 settings.use_cached_picture = true; 341 settings.use_cached_picture = true;
342 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); 342 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
343 343
344 gfx::PointF first_offset(8.f, 9.f); 344 gfx::PointF first_offset(8.f, 9.f);
345 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()));
346 SkCanvas* canvas = 346 CdlCanvas* canvas =
347 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); 347 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect));
348 canvas->translate(first_offset.x(), first_offset.y()); 348 canvas->translate(first_offset.x(), first_offset.y());
349 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);
350 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 350 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
351 kVisualRect, recorder.finishRecordingAsPicture()); 351 kVisualRect, recorder.finishRecordingAsPicture());
352 352
353 gfx::Rect clip_rect(60, 60, 10, 10); 353 gfx::Rect clip_rect(60, 60, 10, 10);
354 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( 354 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
355 clip_rect, std::vector<SkRRect>(), true); 355 clip_rect, std::vector<SkRRect>(), true);
356 356
(...skipping 13 matching lines...) Expand all
370 370
371 SkBitmap expected_bitmap; 371 SkBitmap expected_bitmap;
372 unsigned char expected_pixels[4 * 100 * 100] = {0}; 372 unsigned char expected_pixels[4 * 100 * 100] = {0};
373 SkImageInfo info = 373 SkImageInfo info =
374 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 374 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
375 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 375 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
376 SkCanvas expected_canvas(expected_bitmap); 376 SkCanvas expected_canvas(expected_bitmap);
377 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); 377 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect));
378 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(),
379 60.f + first_offset.x(), 379 60.f + first_offset.x(),
380 60.f + first_offset.y(), red_paint); 380 60.f + first_offset.y(), ToSkPaint(red_paint));
381 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect)); 381 expected_canvas.clipRect(gfx::RectToSkRect(clip_rect));
382 expected_canvas.drawRectCoords( 382 expected_canvas.drawRectCoords(
383 50.f + second_offset.x(), 50.f + second_offset.y(), 383 50.f + second_offset.x(), 50.f + second_offset.y(),
384 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); 384 75.f + second_offset.x(), 75.f + second_offset.y(),
385 ToSkPaint(blue_paint));
385 386
386 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 387 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
387 } 388 }
388 389
389 TEST(DisplayItemListTest, TransformItem) { 390 TEST(DisplayItemListTest, TransformItem) {
390 gfx::Rect layer_rect(100, 100); 391 gfx::Rect layer_rect(100, 100);
391 SkPictureRecorder recorder; 392 CdlPictureRecorder recorder;
392 SkPaint blue_paint; 393 CdlPaint blue_paint;
393 blue_paint.setColor(SK_ColorBLUE); 394 blue_paint.setColor(SK_ColorBLUE);
394 SkPaint red_paint; 395 CdlPaint red_paint;
395 red_paint.setColor(SK_ColorRED); 396 red_paint.setColor(SK_ColorRED);
396 unsigned char pixels[4 * 100 * 100] = {0}; 397 unsigned char pixels[4 * 100 * 100] = {0};
397 DisplayItemListSettings settings; 398 DisplayItemListSettings settings;
398 settings.use_cached_picture = true; 399 settings.use_cached_picture = true;
399 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); 400 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
400 401
401 gfx::PointF first_offset(8.f, 9.f); 402 gfx::PointF first_offset(8.f, 9.f);
402 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); 403 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
403 SkCanvas* canvas = 404 CdlCanvas* canvas =
404 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)); 405 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect));
405 canvas->translate(first_offset.x(), first_offset.y()); 406 canvas->translate(first_offset.x(), first_offset.y());
406 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 407 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
407 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 408 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
408 kVisualRect, recorder.finishRecordingAsPicture()); 409 kVisualRect, recorder.finishRecordingAsPicture());
409 410
410 gfx::Transform transform; 411 gfx::Transform transform;
411 transform.Rotate(45.0); 412 transform.Rotate(45.0);
412 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); 413 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform);
413 414
(...skipping 13 matching lines...) Expand all
427 428
428 SkBitmap expected_bitmap; 429 SkBitmap expected_bitmap;
429 unsigned char expected_pixels[4 * 100 * 100] = {0}; 430 unsigned char expected_pixels[4 * 100 * 100] = {0};
430 SkImageInfo info = 431 SkImageInfo info =
431 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 432 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
432 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 433 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
433 SkCanvas expected_canvas(expected_bitmap); 434 SkCanvas expected_canvas(expected_bitmap);
434 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); 435 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect));
435 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(), 436 expected_canvas.drawRectCoords(0.f + first_offset.x(), 0.f + first_offset.y(),
436 60.f + first_offset.x(), 437 60.f + first_offset.x(),
437 60.f + first_offset.y(), red_paint); 438 60.f + first_offset.y(), ToSkPaint(red_paint));
438 expected_canvas.setMatrix(transform.matrix()); 439 expected_canvas.setMatrix(transform.matrix());
439 expected_canvas.drawRectCoords( 440 expected_canvas.drawRectCoords(
440 50.f + second_offset.x(), 50.f + second_offset.y(), 441 50.f + second_offset.x(), 50.f + second_offset.y(),
441 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); 442 75.f + second_offset.x(), 75.f + second_offset.y(),
443 ToSkPaint(blue_paint));
442 444
443 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 445 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
444 } 446 }
445 447
446 TEST(DisplayItemListTest, FilterItem) { 448 TEST(DisplayItemListTest, FilterItem) {
447 gfx::Rect layer_rect(100, 100); 449 gfx::Rect layer_rect(100, 100);
448 FilterOperations filters; 450 FilterOperations filters;
449 unsigned char pixels[4 * 100 * 100] = {0}; 451 unsigned char pixels[4 * 100 * 100] = {0};
450 scoped_refptr<DisplayItemList> list = 452 scoped_refptr<DisplayItemList> list =
451 DisplayItemList::Create(DisplayItemListSettings()); 453 DisplayItemList::Create(DisplayItemListSettings());
(...skipping 16 matching lines...) Expand all
468 // below. 470 // below.
469 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); 471 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image);
470 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); 472 filters.Append(FilterOperation::CreateReferenceFilter(image_filter));
471 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); 473 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f));
472 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); 474 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f);
473 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>( 475 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>(
474 filters, filter_bounds, filter_bounds.origin()); 476 filters, filter_bounds, filter_bounds.origin());
475 477
476 // Include a rect drawing so that filter is actually applied to something. 478 // Include a rect drawing so that filter is actually applied to something.
477 { 479 {
478 SkPictureRecorder recorder; 480 CdlPictureRecorder recorder;
479 481
480 SkPaint red_paint; 482 CdlPaint red_paint;
481 red_paint.setColor(SK_ColorRED); 483 red_paint.setColor(SK_ColorRED);
482 484
483 SkCanvas* canvas = recorder.beginRecording( 485 CdlCanvas* canvas = recorder.beginRecording(
484 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())); 486 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height()));
485 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(), 487 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(),
486 filter_bounds.right(), filter_bounds.bottom(), 488 filter_bounds.right(), filter_bounds.bottom(),
487 red_paint); 489 red_paint);
488 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 490 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
489 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture()); 491 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture());
490 } 492 }
491 493
492 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); 494 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>();
493 list->Finalize(); 495 list->Finalize();
494 496
495 DrawDisplayList(pixels, layer_rect, list); 497 DrawDisplayList(pixels, layer_rect, list);
496 498
497 SkBitmap expected_bitmap; 499 SkBitmap expected_bitmap;
498 unsigned char expected_pixels[4 * 100 * 100] = {0}; 500 unsigned char expected_pixels[4 * 100 * 100] = {0};
499 SkPaint paint; 501 CdlPaint paint;
500 paint.setColor(SkColorSetRGB(64, 64, 64)); 502 paint.setColor(SkColorSetRGB(64, 64, 64));
501 SkImageInfo info = 503 SkImageInfo info =
502 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 504 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
503 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 505 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
504 SkCanvas expected_canvas(expected_bitmap); 506 SkCanvas expected_canvas(expected_bitmap);
505 expected_canvas.drawRect(RectFToSkRect(filter_bounds), paint); 507 expected_canvas.drawRect(RectFToSkRect(filter_bounds), ToSkPaint(paint));
506 508
507 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 509 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
508 } 510 }
509 511
510 TEST(DisplayItemListTest, CompactingItems) { 512 TEST(DisplayItemListTest, CompactingItems) {
511 gfx::Rect layer_rect(100, 100); 513 gfx::Rect layer_rect(100, 100);
512 SkPictureRecorder recorder; 514 CdlPictureRecorder recorder;
513 SkPaint blue_paint; 515 CdlPaint blue_paint;
514 blue_paint.setColor(SK_ColorBLUE); 516 blue_paint.setColor(SK_ColorBLUE);
515 SkPaint red_paint; 517 CdlPaint red_paint;
516 red_paint.setColor(SK_ColorRED); 518 red_paint.setColor(SK_ColorRED);
517 unsigned char pixels[4 * 100 * 100] = {0}; 519 unsigned char pixels[4 * 100 * 100] = {0};
518 520
519 gfx::PointF offset(8.f, 9.f); 521 gfx::PointF offset(8.f, 9.f);
520 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); 522 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
521 523
522 DisplayItemListSettings no_caching_settings; 524 DisplayItemListSettings no_caching_settings;
523 scoped_refptr<DisplayItemList> list_without_caching = 525 scoped_refptr<DisplayItemList> list_without_caching =
524 DisplayItemList::Create(no_caching_settings); 526 DisplayItemList::Create(no_caching_settings);
525 527
526 SkCanvas* canvas = 528 CdlCanvas* canvas =
527 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)); 529 recorder.beginRecording(gfx::RectFToSkRect(recording_rect));
528 canvas->translate(offset.x(), offset.y()); 530 canvas->translate(offset.x(), offset.y());
529 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 531 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
530 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 532 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
531 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 533 sk_sp<CdlPicture> picture = recorder.finishRecordingAsPicture();
532 list_without_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>( 534 list_without_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(
533 kVisualRect, picture); 535 kVisualRect, picture);
534 list_without_caching->Finalize(); 536 list_without_caching->Finalize();
535 DrawDisplayList(pixels, layer_rect, list_without_caching); 537 DrawDisplayList(pixels, layer_rect, list_without_caching);
536 538
537 unsigned char expected_pixels[4 * 100 * 100] = {0}; 539 unsigned char expected_pixels[4 * 100 * 100] = {0};
538 DisplayItemListSettings caching_settings; 540 DisplayItemListSettings caching_settings;
539 caching_settings.use_cached_picture = true; 541 caching_settings.use_cached_picture = true;
540 scoped_refptr<DisplayItemList> list_with_caching = 542 scoped_refptr<DisplayItemList> list_with_caching =
541 DisplayItemList::Create(caching_settings); 543 DisplayItemList::Create(caching_settings);
542 list_with_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, 544 list_with_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect,
543 picture); 545 picture);
544 list_with_caching->Finalize(); 546 list_with_caching->Finalize();
545 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); 547 DrawDisplayList(expected_pixels, layer_rect, list_with_caching);
546 548
547 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 549 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
548 } 550 }
549 551
550 TEST(DisplayItemListTest, ApproximateMemoryUsage) { 552 TEST(DisplayItemListTest, ApproximateMemoryUsage) {
551 const int kNumCommandsInTestSkPicture = 1000; 553 // TODO(cdl): CDL memory usage.
552 scoped_refptr<DisplayItemList> list; 554 /*
553 size_t memory_usage; 555 const int kNumCommandsInTestSkPicture = 1000;
556 scoped_refptr<DisplayItemList> list;
557 size_t memory_usage;
554 558
555 // Make an SkPicture whose size is known. 559 // Make an CdlPicture whose size is known.
556 gfx::Rect layer_rect(100, 100); 560 gfx::Rect layer_rect(100, 100);
557 SkPictureRecorder recorder; 561 CdlPictureRecorder recorder;
558 SkPaint blue_paint; 562 CdlPaint blue_paint;
559 blue_paint.setColor(SK_ColorBLUE); 563 blue_paint.setColor(SK_ColorBLUE);
560 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); 564 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect));
561 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) 565 for (int i = 0; i < kNumCommandsInTestSkPicture; i++)
562 canvas->drawPaint(blue_paint); 566 canvas->drawPaint(blue_paint);
563 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 567 sk_sp<CdlPicture> picture = recorder.finishRecordingAsPicture();
564 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); 568 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get());
565 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); 569 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint));
566 570
567 // Using a cached picture, we should get about the right size. 571 // Using a cached picture, we should get about the right size.
568 DisplayItemListSettings caching_settings; 572 DisplayItemListSettings caching_settings;
569 caching_settings.use_cached_picture = true; 573 caching_settings.use_cached_picture = true;
570 list = DisplayItemList::Create(caching_settings); 574 list = DisplayItemList::Create(caching_settings);
571 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture); 575 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture);
572 list->Finalize(); 576 list->Finalize();
573 memory_usage = list->ApproximateMemoryUsage(); 577 memory_usage = list->ApproximateMemoryUsage();
574 EXPECT_GE(memory_usage, picture_size); 578 EXPECT_GE(memory_usage, picture_size);
575 EXPECT_LE(memory_usage, 2 * picture_size); 579 EXPECT_LE(memory_usage, 2 * picture_size);
576 580
577 // Using no cached picture, we should still get the right size. 581 // Using no cached picture, we should still get the right size.
578 DisplayItemListSettings no_caching_settings; 582 DisplayItemListSettings no_caching_settings;
579 no_caching_settings.use_cached_picture = false; 583 no_caching_settings.use_cached_picture = false;
580 list = DisplayItemList::Create(no_caching_settings); 584 list = DisplayItemList::Create(no_caching_settings);
581 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture); 585 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture);
582 list->Finalize(); 586 list->Finalize();
583 memory_usage = list->ApproximateMemoryUsage(); 587 memory_usage = list->ApproximateMemoryUsage();
584 EXPECT_GE(memory_usage, picture_size); 588 EXPECT_GE(memory_usage, picture_size);
585 EXPECT_LE(memory_usage, 2 * picture_size); 589 EXPECT_LE(memory_usage, 2 * picture_size);
590 */
586 } 591 }
587 592
588 TEST(DisplayItemListTest, AsValueWithNoItems) { 593 TEST(DisplayItemListTest, AsValueWithNoItems) {
589 scoped_refptr<DisplayItemList> list = 594 scoped_refptr<DisplayItemList> list =
590 DisplayItemList::Create(DisplayItemListSettings()); 595 DisplayItemList::Create(DisplayItemListSettings());
591 list->SetRetainVisualRectsForTesting(true); 596 list->SetRetainVisualRectsForTesting(true);
592 list->Finalize(); 597 list->Finalize();
593 598
594 std::string value = list->AsValue(true)->ToString(); 599 std::string value = list->AsValue(true)->ToString();
595 EXPECT_EQ(value.find("\"layer_rect\": [0,0,0,0]"), std::string::npos); 600 EXPECT_EQ(value.find("\"layer_rect\": [0,0,0,0]"), std::string::npos);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); 949 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
945 950
946 EXPECT_EQ(4u, list->size()); 951 EXPECT_EQ(4u, list->size());
947 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); 952 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0));
948 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); 953 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1));
949 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); 954 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2));
950 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); 955 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3));
951 } 956 }
952 957
953 } // namespace cc 958 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/display_item_list.cc ('k') | cc/playback/drawing_display_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698