Chromium Code Reviews| Index: cc/playback/display_item_list_unittest.cc |
| diff --git a/cc/playback/display_item_list_unittest.cc b/cc/playback/display_item_list_unittest.cc |
| index c490bbfab73fe405b70d72e216a03b026c4ea3b6..894fbc3b0fd11a224f69f5a19a26e86867aa2a5c 100644 |
| --- a/cc/playback/display_item_list_unittest.cc |
| +++ b/cc/playback/display_item_list_unittest.cc |
| @@ -9,10 +9,14 @@ |
| #include "cc/output/filter_operation.h" |
| #include "cc/output/filter_operations.h" |
| #include "cc/playback/clip_display_item.h" |
| +#include "cc/playback/clip_path_display_item.h" |
| +#include "cc/playback/compositing_display_item.h" |
| #include "cc/playback/display_item_list_settings.h" |
| #include "cc/playback/drawing_display_item.h" |
| #include "cc/playback/filter_display_item.h" |
| +#include "cc/playback/float_clip_display_item.h" |
| #include "cc/playback/transform_display_item.h" |
| +#include "cc/proto/display_item.pb.h" |
| #include "cc/test/skia_common.h" |
| #include "skia/ext/refptr.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -21,6 +25,7 @@ |
| #include "third_party/skia/include/core/SkColor.h" |
| #include "third_party/skia/include/core/SkPictureRecorder.h" |
| #include "third_party/skia/include/core/SkSurface.h" |
| +#include "third_party/skia/include/core/SkXfermode.h" |
| #include "third_party/skia/include/effects/SkImageSource.h" |
| #include "third_party/skia/include/utils/SkPictureUtils.h" |
| #include "ui/gfx/geometry/rect_conversions.h" |
| @@ -28,6 +33,321 @@ |
| namespace cc { |
| +namespace { |
| + |
| +void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, |
| + scoped_refptr<DisplayItemList> list) { |
| + // Serialize and deserialize the DisplayItemList. |
| + proto::DisplayItemList proto; |
| + list->ToProtobuf(&proto); |
| + scoped_refptr<DisplayItemList> new_list = DisplayItemList::Create(proto); |
| + |
| + // Finalize the DisplayItemLists to perform raster. |
| + list->Finalize(); |
| + new_list->Finalize(); |
| + |
| + const int pixel_size = 4 * layer_size.GetArea(); |
| + |
| + // Get the rendered contents of the old DisplayItemList. |
| + scoped_ptr<unsigned char[]> pixels(new unsigned char[pixel_size]); |
| + memset(pixels.get(), 0, pixel_size); |
| + DrawDisplayList(pixels.get(), gfx::Rect(layer_size), list); |
| + |
| + // Get the rendered contents of the new DisplayItemList. |
| + scoped_ptr<unsigned char[]> new_pixels(new unsigned char[pixel_size]); |
| + memset(new_pixels.get(), 0, pixel_size); |
| + DrawDisplayList(new_pixels.get(), gfx::Rect(layer_size), new_list); |
| + |
| + EXPECT_EQ(0, memcmp(pixels.get(), new_pixels.get(), pixel_size)); |
| +} |
| + |
| +} // namespace |
| + |
| +TEST(DisplayItemListTest, SerializeDisplayItemListSettings) { |
| + DisplayItemListSettings settings; |
| + settings.use_cached_picture = false; |
| + |
| + { |
| + proto::DisplayItemListSettings proto; |
| + settings.ToProtobuf(&proto); |
| + DisplayItemListSettings deserialized(proto); |
| + EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture); |
| + } |
| + |
| + settings.use_cached_picture = true; |
| + { |
| + proto::DisplayItemListSettings proto; |
| + settings.ToProtobuf(&proto); |
| + DisplayItemListSettings deserialized(proto); |
| + EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture); |
| + } |
| +} |
| + |
| +TEST(DisplayItemListTest, SerializeSingleDrawingItem) { |
| + gfx::Size layer_size(10, 10); |
| + gfx::PointF offset(2.f, 3.f); |
| + |
| + DisplayItemListSettings settings; |
| + settings.use_cached_picture = true; |
| + scoped_refptr<DisplayItemList> list = |
| + DisplayItemList::Create(gfx::Rect(layer_size), settings); |
| + |
| + // Build the DrawingDisplayItem. |
| + SkPaint blue_paint; |
| + blue_paint.setColor(SK_ColorBLUE); |
| + SkPaint red_paint; |
| + red_paint.setColor(SK_ColorRED); |
| + SkPictureRecorder recorder; |
| + skia::RefPtr<SkCanvas> canvas; |
| + skia::RefPtr<SkPicture> picture; |
| + canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| + offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| + canvas->translate(offset.x(), offset.y()); |
| + canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
| + canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
| + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| + auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(); |
| + item->SetNew(picture); |
| + |
| + ValidateDisplayItemListSerialization(layer_size, list); |
| +} |
| + |
| +TEST(DisplayItemListTest, SerializeClipItem) { |
| + gfx::Size layer_size(10, 10); |
| + gfx::PointF offset(2.f, 3.f); |
| + |
| + DisplayItemListSettings settings; |
| + settings.use_cached_picture = true; |
| + scoped_refptr<DisplayItemList> list = |
| + DisplayItemList::Create(gfx::Rect(layer_size), settings); |
| + |
| + // Build the DrawingDisplayItem. |
|
David Trainor- moved to gerrit
2015/10/14 23:09:28
TODO(me): Pull out the common code for these unit
David Trainor- moved to gerrit
2015/10/20 20:26:49
Done.
|
| + SkPaint blue_paint; |
| + blue_paint.setColor(SK_ColorBLUE); |
| + SkPaint red_paint; |
| + red_paint.setColor(SK_ColorRED); |
| + SkPictureRecorder recorder; |
| + skia::RefPtr<SkCanvas> canvas; |
| + skia::RefPtr<SkPicture> picture; |
| + canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| + offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| + canvas->translate(offset.x(), offset.y()); |
| + canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
| + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| + auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(); |
| + item1->SetNew(picture); |
| + |
| + // Build the ClipDisplayItem. |
| + gfx::Rect clip_rect(6, 6, 1, 1); |
| + std::vector<SkRRect> rrects; |
| + rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); |
| + auto* item2 = list->CreateAndAppendItem<ClipDisplayItem>(); |
| + item2->SetNew(clip_rect, rrects); |
| + |
| + // Build the second DrawingDisplayItem. |
| + offset.SetPoint(2.f, 2.f); |
| + canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| + offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| + canvas->translate(offset.x(), offset.y()); |
| + canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
| + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| + auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(); |
| + item3->SetNew(picture); |
| + |
| + // Build the EndClipDisplayItem. |
| + list->CreateAndAppendItem<EndClipDisplayItem>(); |
| + |
| + ValidateDisplayItemListSerialization(layer_size, list); |
| +} |
| + |
| +TEST(DisplayItemListTest, SerializeClipPathItem) { |
| + gfx::Size layer_size(10, 10); |
| + gfx::PointF offset(2.f, 3.f); |
| + |
| + DisplayItemListSettings settings; |
| + settings.use_cached_picture = true; |
| + scoped_refptr<DisplayItemList> list = |
| + DisplayItemList::Create(gfx::Rect(layer_size), settings); |
| + |
| + // Build the DrawingDisplayItem. |
| + SkPaint blue_paint; |
| + blue_paint.setColor(SK_ColorBLUE); |
| + SkPaint red_paint; |
| + red_paint.setColor(SK_ColorRED); |
| + SkPictureRecorder recorder; |
| + skia::RefPtr<SkCanvas> canvas; |
| + skia::RefPtr<SkPicture> picture; |
| + canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| + offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| + canvas->translate(offset.x(), offset.y()); |
| + canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
| + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| + auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(); |
| + item1->SetNew(picture); |
| + |
| + // Build the ClipPathDisplayItem. |
| + SkPath path; |
| + path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); |
| + auto* item2 = list->CreateAndAppendItem<ClipPathDisplayItem>(); |
| + item2->SetNew(path, SkRegion::Op::kReplace_Op, false); |
| + |
| + // Build the second DrawingDisplayItem. |
| + offset.SetPoint(2.f, 2.f); |
| + canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| + offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| + canvas->translate(offset.x(), offset.y()); |
| + canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
| + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| + auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(); |
| + item3->SetNew(picture); |
| + |
| + // Build the EndClipPathDisplayItem. |
| + list->CreateAndAppendItem<EndClipPathDisplayItem>(); |
| + |
| + ValidateDisplayItemListSerialization(layer_size, list); |
| +} |
| + |
| +TEST(DisplayItemListTest, SerializeCompositingItem) { |
| + gfx::Size layer_size(10, 10); |
| + gfx::PointF offset(2.f, 3.f); |
| + |
| + DisplayItemListSettings settings; |
| + settings.use_cached_picture = true; |
| + scoped_refptr<DisplayItemList> list = |
| + DisplayItemList::Create(gfx::Rect(layer_size), settings); |
| + |
| + // Build the DrawingDisplayItem. |
| + SkPaint blue_paint; |
| + blue_paint.setColor(SK_ColorBLUE); |
| + SkPaint red_paint; |
| + red_paint.setColor(SK_ColorRED); |
| + SkPictureRecorder recorder; |
| + skia::RefPtr<SkCanvas> canvas; |
| + skia::RefPtr<SkPicture> picture; |
| + canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| + offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| + canvas->translate(offset.x(), offset.y()); |
| + canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
| + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| + auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(); |
| + item1->SetNew(picture); |
| + |
| + // Build the CompositingDisplayItem. |
| + skia::RefPtr<SkColorFilter> filter = skia::AdoptRef( |
| + SkColorFilter::CreateLightingFilter(SK_ColorRED, SK_ColorGREEN)); |
| + auto* item2 = list->CreateAndAppendItem<CompositingDisplayItem>(); |
| + item2->SetNew(150, SkXfermode::Mode::kDst_Mode, nullptr, filter); |
| + |
| + // Build the second DrawingDisplayItem. |
| + offset.SetPoint(2.f, 2.f); |
| + canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| + offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| + canvas->translate(offset.x(), offset.y()); |
| + canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
| + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| + auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(); |
| + item3->SetNew(picture); |
| + |
| + // Build the EndCompositingDisplayItem. |
| + list->CreateAndAppendItem<EndCompositingDisplayItem>(); |
| + |
| + ValidateDisplayItemListSerialization(layer_size, list); |
| +} |
| + |
| +TEST(DisplayItemListTest, SerializeFloatClipItem) { |
| + gfx::Size layer_size(10, 10); |
| + gfx::PointF offset(2.f, 3.f); |
| + |
| + DisplayItemListSettings settings; |
| + settings.use_cached_picture = true; |
| + scoped_refptr<DisplayItemList> list = |
| + DisplayItemList::Create(gfx::Rect(layer_size), settings); |
| + |
| + // Build the DrawingDisplayItem. |
| + SkPaint blue_paint; |
| + blue_paint.setColor(SK_ColorBLUE); |
| + SkPaint red_paint; |
| + red_paint.setColor(SK_ColorRED); |
| + SkPictureRecorder recorder; |
| + skia::RefPtr<SkCanvas> canvas; |
| + skia::RefPtr<SkPicture> picture; |
| + canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| + offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| + canvas->translate(offset.x(), offset.y()); |
| + canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
| + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| + auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(); |
| + item1->SetNew(picture); |
| + |
| + // Build the FloatClipDisplayItem. |
| + gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); |
| + auto* item2 = list->CreateAndAppendItem<FloatClipDisplayItem>(); |
| + item2->SetNew(clip_rect); |
| + |
| + // Build the second DrawingDisplayItem. |
| + offset.SetPoint(2.f, 2.f); |
| + canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| + offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| + canvas->translate(offset.x(), offset.y()); |
| + canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
| + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| + auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(); |
| + item3->SetNew(picture); |
| + |
| + // Build the EndFloatClipDisplayItem. |
| + list->CreateAndAppendItem<EndFloatClipDisplayItem>(); |
| + |
| + ValidateDisplayItemListSerialization(layer_size, list); |
| +} |
| + |
| +TEST(DisplayItemListTest, SerializeTransformItem) { |
| + gfx::Size layer_size(10, 10); |
| + gfx::PointF offset(2.f, 3.f); |
| + |
| + DisplayItemListSettings settings; |
| + settings.use_cached_picture = true; |
| + scoped_refptr<DisplayItemList> list = |
| + DisplayItemList::Create(gfx::Rect(layer_size), settings); |
| + |
| + // Build the DrawingDisplayItem. |
| + SkPaint blue_paint; |
| + blue_paint.setColor(SK_ColorBLUE); |
| + SkPaint red_paint; |
| + red_paint.setColor(SK_ColorRED); |
| + SkPictureRecorder recorder; |
| + skia::RefPtr<SkCanvas> canvas; |
| + skia::RefPtr<SkPicture> picture; |
| + canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| + offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| + canvas->translate(offset.x(), offset.y()); |
| + canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
| + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| + auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>(); |
| + item1->SetNew(picture); |
| + |
| + // Build the TransformDisplayItem. |
| + gfx::Transform transform; |
| + transform.Scale(1.25f, 1.25f); |
| + transform.Translate(-1.f, -1.f); |
| + auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>(); |
| + item2->SetNew(transform); |
| + |
| + // Build the second DrawingDisplayItem. |
| + offset.SetPoint(2.f, 2.f); |
| + canvas = skia::SharePtr(recorder.beginRecording(SkRect::MakeXYWH( |
| + offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| + canvas->translate(offset.x(), offset.y()); |
| + canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); |
| + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); |
| + auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>(); |
| + item3->SetNew(picture); |
| + |
| + // Build the EndTransformDisplayItem. |
| + list->CreateAndAppendItem<EndTransformDisplayItem>(); |
| + |
| + ValidateDisplayItemListSerialization(layer_size, list); |
| +} |
| + |
| TEST(DisplayItemListTest, SingleDrawingItem) { |
| gfx::Rect layer_rect(100, 100); |
| SkPictureRecorder recorder; |