| 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" | |
| 23 #include "cc/test/fake_client_picture_cache.h" | |
| 24 #include "cc/test/fake_engine_picture_cache.h" | |
| 25 #include "cc/test/fake_image_serialization_processor.h" | |
| 26 #include "cc/test/geometry_test_utils.h" | 22 #include "cc/test/geometry_test_utils.h" |
| 27 #include "cc/test/skia_common.h" | 23 #include "cc/test/skia_common.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
| 31 #include "third_party/skia/include/core/SkCanvas.h" | 27 #include "third_party/skia/include/core/SkCanvas.h" |
| 32 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
| 33 #include "third_party/skia/include/core/SkPictureRecorder.h" | 29 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 34 #include "third_party/skia/include/core/SkSurface.h" | 30 #include "third_party/skia/include/core/SkSurface.h" |
| 35 | 31 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 red_paint.setColor(SK_ColorRED); | 64 red_paint.setColor(SK_ColorRED); |
| 69 | 65 |
| 70 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( | 66 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( |
| 71 offset.x(), offset.y(), layer_size.width(), layer_size.height())); | 67 offset.x(), offset.y(), layer_size.width(), layer_size.height())); |
| 72 canvas->translate(offset.x(), offset.y()); | 68 canvas->translate(offset.x(), offset.y()); |
| 73 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); | 69 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
| 74 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 70 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
| 75 kVisualRect, recorder.finishRecordingAsPicture()); | 71 kVisualRect, recorder.finishRecordingAsPicture()); |
| 76 } | 72 } |
| 77 | 73 |
| 78 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, | |
| 79 const gfx::Size& layer_size) { | |
| 80 gfx::PointF offset(2.f, 2.f); | |
| 81 SkPictureRecorder recorder; | |
| 82 | |
| 83 SkPaint blue_paint; | |
| 84 blue_paint.setColor(SK_ColorBLUE); | |
| 85 | |
| 86 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( | |
| 87 offset.x(), offset.y(), layer_size.width(), layer_size.height())); | |
| 88 canvas->translate(offset.x(), offset.y()); | |
| 89 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); | |
| 90 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | |
| 91 kVisualRect, recorder.finishRecordingAsPicture()); | |
| 92 } | |
| 93 | |
| 94 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, | |
| 95 scoped_refptr<DisplayItemList> list) { | |
| 96 list->Finalize(); | |
| 97 | |
| 98 std::unique_ptr<FakeImageSerializationProcessor> | |
| 99 fake_image_serialization_processor = | |
| 100 base::WrapUnique(new FakeImageSerializationProcessor); | |
| 101 std::unique_ptr<EnginePictureCache> fake_engine_picture_cache = | |
| 102 fake_image_serialization_processor->CreateEnginePictureCache(); | |
| 103 FakeEnginePictureCache* fake_engine_picture_cache_ptr = | |
| 104 static_cast<FakeEnginePictureCache*>(fake_engine_picture_cache.get()); | |
| 105 std::unique_ptr<ClientPictureCache> fake_client_picture_cache = | |
| 106 fake_image_serialization_processor->CreateClientPictureCache(); | |
| 107 | |
| 108 fake_engine_picture_cache_ptr->MarkAllSkPicturesAsUsed(list.get()); | |
| 109 | |
| 110 // Serialize and deserialize the DisplayItemList. | |
| 111 proto::DisplayItemList proto; | |
| 112 list->ToProtobuf(&proto); | |
| 113 | |
| 114 std::vector<uint32_t> actual_picture_ids; | |
| 115 scoped_refptr<DisplayItemList> new_list = DisplayItemList::CreateFromProto( | |
| 116 proto, fake_client_picture_cache.get(), &actual_picture_ids); | |
| 117 | |
| 118 EXPECT_THAT(actual_picture_ids, | |
| 119 testing::UnorderedElementsAreArray( | |
| 120 fake_engine_picture_cache_ptr->GetAllUsedPictureIds())); | |
| 121 | |
| 122 EXPECT_TRUE(AreDisplayListDrawingResultsSame(gfx::Rect(layer_size), | |
| 123 list.get(), new_list.get())); | |
| 124 } | |
| 125 | |
| 126 } // namespace | 74 } // namespace |
| 127 | 75 |
| 128 TEST(DisplayItemListTest, SerializeDisplayItemListSettings) { | |
| 129 DisplayItemListSettings settings; | |
| 130 settings.use_cached_picture = false; | |
| 131 | |
| 132 { | |
| 133 proto::DisplayItemListSettings proto; | |
| 134 settings.ToProtobuf(&proto); | |
| 135 DisplayItemListSettings deserialized(proto); | |
| 136 EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture); | |
| 137 } | |
| 138 | |
| 139 settings.use_cached_picture = true; | |
| 140 { | |
| 141 proto::DisplayItemListSettings proto; | |
| 142 settings.ToProtobuf(&proto); | |
| 143 DisplayItemListSettings deserialized(proto); | |
| 144 EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture); | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 TEST(DisplayItemListTest, SerializeSingleDrawingItem) { | |
| 149 gfx::Size layer_size(10, 10); | |
| 150 | |
| 151 DisplayItemListSettings settings; | |
| 152 settings.use_cached_picture = true; | |
| 153 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | |
| 154 list->SetRetainVisualRectsForTesting(true); | |
| 155 | |
| 156 // Build the DrawingDisplayItem. | |
| 157 AppendFirstSerializationTestPicture(list, layer_size); | |
| 158 | |
| 159 ValidateDisplayItemListSerialization(layer_size, list); | |
| 160 } | |
| 161 | |
| 162 TEST(DisplayItemListTest, SerializeClipItem) { | |
| 163 gfx::Size layer_size(10, 10); | |
| 164 | |
| 165 DisplayItemListSettings settings; | |
| 166 settings.use_cached_picture = true; | |
| 167 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | |
| 168 list->SetRetainVisualRectsForTesting(true); | |
| 169 | |
| 170 // Build the DrawingDisplayItem. | |
| 171 AppendFirstSerializationTestPicture(list, layer_size); | |
| 172 | |
| 173 // Build the ClipDisplayItem. | |
| 174 gfx::Rect clip_rect(6, 6, 1, 1); | |
| 175 std::vector<SkRRect> rrects; | |
| 176 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); | |
| 177 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(clip_rect, rrects, | |
| 178 true); | |
| 179 | |
| 180 // Build the second DrawingDisplayItem. | |
| 181 AppendSecondSerializationTestPicture(list, layer_size); | |
| 182 | |
| 183 // Build the EndClipDisplayItem. | |
| 184 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | |
| 185 | |
| 186 ValidateDisplayItemListSerialization(layer_size, list); | |
| 187 } | |
| 188 | |
| 189 TEST(DisplayItemListTest, SerializeClipPathItem) { | |
| 190 gfx::Size layer_size(10, 10); | |
| 191 | |
| 192 DisplayItemListSettings settings; | |
| 193 settings.use_cached_picture = true; | |
| 194 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | |
| 195 list->SetRetainVisualRectsForTesting(true); | |
| 196 | |
| 197 // Build the DrawingDisplayItem. | |
| 198 AppendFirstSerializationTestPicture(list, layer_size); | |
| 199 | |
| 200 // Build the ClipPathDisplayItem. | |
| 201 SkPath path; | |
| 202 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); | |
| 203 list->CreateAndAppendPairedBeginItem<ClipPathDisplayItem>(path, false); | |
| 204 | |
| 205 // Build the second DrawingDisplayItem. | |
| 206 AppendSecondSerializationTestPicture(list, layer_size); | |
| 207 | |
| 208 // Build the EndClipPathDisplayItem. | |
| 209 list->CreateAndAppendPairedEndItem<EndClipPathDisplayItem>(); | |
| 210 | |
| 211 ValidateDisplayItemListSerialization(layer_size, list); | |
| 212 } | |
| 213 | |
| 214 TEST(DisplayItemListTest, SerializeCompositingItem) { | |
| 215 gfx::Size layer_size(10, 10); | |
| 216 | |
| 217 DisplayItemListSettings settings; | |
| 218 settings.use_cached_picture = true; | |
| 219 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | |
| 220 list->SetRetainVisualRectsForTesting(true); | |
| 221 | |
| 222 // Build the DrawingDisplayItem. | |
| 223 AppendFirstSerializationTestPicture(list, layer_size); | |
| 224 | |
| 225 // Build the CompositingDisplayItem. | |
| 226 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>( | |
| 227 150, SkBlendMode::kDst, nullptr, | |
| 228 SkColorMatrixFilter::MakeLightingFilter(SK_ColorRED, SK_ColorGREEN), | |
| 229 false); | |
| 230 | |
| 231 // Build the second DrawingDisplayItem. | |
| 232 AppendSecondSerializationTestPicture(list, layer_size); | |
| 233 | |
| 234 // Build the EndCompositingDisplayItem. | |
| 235 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>(); | |
| 236 | |
| 237 ValidateDisplayItemListSerialization(layer_size, list); | |
| 238 } | |
| 239 | |
| 240 TEST(DisplayItemListTest, SerializeFloatClipItem) { | |
| 241 gfx::Size layer_size(10, 10); | |
| 242 | |
| 243 DisplayItemListSettings settings; | |
| 244 settings.use_cached_picture = true; | |
| 245 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | |
| 246 list->SetRetainVisualRectsForTesting(true); | |
| 247 | |
| 248 // Build the DrawingDisplayItem. | |
| 249 AppendFirstSerializationTestPicture(list, layer_size); | |
| 250 | |
| 251 // Build the FloatClipDisplayItem. | |
| 252 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); | |
| 253 list->CreateAndAppendPairedBeginItem<FloatClipDisplayItem>(clip_rect); | |
| 254 | |
| 255 // Build the second DrawingDisplayItem. | |
| 256 AppendSecondSerializationTestPicture(list, layer_size); | |
| 257 | |
| 258 // Build the EndFloatClipDisplayItem. | |
| 259 list->CreateAndAppendPairedEndItem<EndFloatClipDisplayItem>(); | |
| 260 | |
| 261 ValidateDisplayItemListSerialization(layer_size, list); | |
| 262 } | |
| 263 | |
| 264 TEST(DisplayItemListTest, SerializeTransformItem) { | |
| 265 gfx::Size layer_size(10, 10); | |
| 266 | |
| 267 DisplayItemListSettings settings; | |
| 268 settings.use_cached_picture = true; | |
| 269 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings); | |
| 270 list->SetRetainVisualRectsForTesting(true); | |
| 271 | |
| 272 // Build the DrawingDisplayItem. | |
| 273 AppendFirstSerializationTestPicture(list, layer_size); | |
| 274 | |
| 275 // Build the TransformDisplayItem. | |
| 276 gfx::Transform transform; | |
| 277 transform.Scale(1.25f, 1.25f); | |
| 278 transform.Translate(-1.f, -1.f); | |
| 279 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); | |
| 280 | |
| 281 // Build the second DrawingDisplayItem. | |
| 282 AppendSecondSerializationTestPicture(list, layer_size); | |
| 283 | |
| 284 // Build the EndTransformDisplayItem. | |
| 285 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); | |
| 286 | |
| 287 ValidateDisplayItemListSerialization(layer_size, list); | |
| 288 } | |
| 289 | |
| 290 TEST(DisplayItemListTest, SingleDrawingItem) { | 76 TEST(DisplayItemListTest, SingleDrawingItem) { |
| 291 gfx::Rect layer_rect(100, 100); | 77 gfx::Rect layer_rect(100, 100); |
| 292 SkPictureRecorder recorder; | 78 SkPictureRecorder recorder; |
| 293 SkPaint blue_paint; | 79 SkPaint blue_paint; |
| 294 blue_paint.setColor(SK_ColorBLUE); | 80 blue_paint.setColor(SK_ColorBLUE); |
| 295 SkPaint red_paint; | 81 SkPaint red_paint; |
| 296 red_paint.setColor(SK_ColorRED); | 82 red_paint.setColor(SK_ColorRED); |
| 297 unsigned char pixels[4 * 100 * 100] = {0}; | 83 unsigned char pixels[4 * 100 * 100] = {0}; |
| 298 DisplayItemListSettings settings; | 84 DisplayItemListSettings settings; |
| 299 settings.use_cached_picture = true; | 85 settings.use_cached_picture = true; |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 729 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
| 944 | 730 |
| 945 EXPECT_EQ(4u, list->size()); | 731 EXPECT_EQ(4u, list->size()); |
| 946 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); | 732 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); |
| 947 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); | 733 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); |
| 948 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); | 734 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); |
| 949 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); | 735 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); |
| 950 } | 736 } |
| 951 | 737 |
| 952 } // namespace cc | 738 } // namespace cc |
| OLD | NEW |