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

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

Issue 2230513005: Move visual rect unioning between paired items to cc::DisplayItemList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review feedback. Created 4 years, 4 months 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/display_item_proto_factory.cc » ('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/skia_common.h" 27 #include "cc/test/skia_common.h"
27 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 #include "third_party/skia/include/core/SkBitmap.h" 30 #include "third_party/skia/include/core/SkBitmap.h"
30 #include "third_party/skia/include/core/SkCanvas.h" 31 #include "third_party/skia/include/core/SkCanvas.h"
31 #include "third_party/skia/include/core/SkColor.h" 32 #include "third_party/skia/include/core/SkColor.h"
32 #include "third_party/skia/include/core/SkPictureRecorder.h" 33 #include "third_party/skia/include/core/SkPictureRecorder.h"
33 #include "third_party/skia/include/core/SkSurface.h" 34 #include "third_party/skia/include/core/SkSurface.h"
34 #include "third_party/skia/include/core/SkXfermode.h" 35 #include "third_party/skia/include/core/SkXfermode.h"
35 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" 36 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
36 #include "third_party/skia/include/effects/SkImageSource.h" 37 #include "third_party/skia/include/effects/SkImageSource.h"
37 #include "third_party/skia/include/utils/SkPictureUtils.h" 38 #include "third_party/skia/include/utils/SkPictureUtils.h"
38 #include "ui/gfx/geometry/rect.h" 39 #include "ui/gfx/geometry/rect.h"
39 #include "ui/gfx/geometry/rect_conversions.h" 40 #include "ui/gfx/geometry/rect_conversions.h"
40 #include "ui/gfx/skia_util.h" 41 #include "ui/gfx/skia_util.h"
41 42
42 namespace cc { 43 namespace cc {
43 44
44 namespace { 45 namespace {
45 46
46 const gfx::Rect kVisualRect(0, 0, 42, 42); 47 const gfx::Rect kVisualRect(0, 0, 42, 42);
47 48
49 scoped_refptr<DisplayItemList> CreateDefaultList() {
50 return DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings());
51 }
52
53 sk_sp<const SkPicture> CreateRectPicture(const gfx::Rect& bounds) {
54 SkPictureRecorder recorder;
55 sk_sp<SkCanvas> canvas;
56
57 canvas = sk_ref_sp(recorder.beginRecording(bounds.width(), bounds.height()));
58 canvas->drawRect(
59 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()),
60 SkPaint());
61 return recorder.finishRecordingAsPicture();
62 }
63
48 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, 64 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list,
49 const gfx::Size& layer_size) { 65 const gfx::Size& layer_size) {
50 gfx::PointF offset(2.f, 3.f); 66 gfx::PointF offset(2.f, 3.f);
51 SkPictureRecorder recorder; 67 SkPictureRecorder recorder;
52 sk_sp<SkCanvas> canvas; 68 sk_sp<SkCanvas> canvas;
53 69
54 SkPaint red_paint; 70 SkPaint red_paint;
55 red_paint.setColor(SK_ColorRED); 71 red_paint.setColor(SK_ColorRED);
56 72
57 canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH( 73 canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH(
58 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); 74 offset.x(), offset.y(), layer_size.width(), layer_size.height())));
59 canvas->translate(offset.x(), offset.y()); 75 canvas->translate(offset.x(), offset.y());
60 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); 76 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint);
61 list->CreateAndAppendItem<DrawingDisplayItem>( 77 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
62 kVisualRect, recorder.finishRecordingAsPicture()); 78 kVisualRect, recorder.finishRecordingAsPicture());
63 } 79 }
64 80
65 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list, 81 void AppendSecondSerializationTestPicture(scoped_refptr<DisplayItemList> list,
66 const gfx::Size& layer_size) { 82 const gfx::Size& layer_size) {
67 gfx::PointF offset(2.f, 2.f); 83 gfx::PointF offset(2.f, 2.f);
68 SkPictureRecorder recorder; 84 SkPictureRecorder recorder;
69 sk_sp<SkCanvas> canvas; 85 sk_sp<SkCanvas> canvas;
70 86
71 SkPaint blue_paint; 87 SkPaint blue_paint;
72 blue_paint.setColor(SK_ColorBLUE); 88 blue_paint.setColor(SK_ColorBLUE);
73 89
74 canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH( 90 canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH(
75 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); 91 offset.x(), offset.y(), layer_size.width(), layer_size.height())));
76 canvas->translate(offset.x(), offset.y()); 92 canvas->translate(offset.x(), offset.y());
77 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint); 93 canvas->drawRectCoords(3.f, 3.f, 7.f, 7.f, blue_paint);
78 list->CreateAndAppendItem<DrawingDisplayItem>( 94 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
79 kVisualRect, recorder.finishRecordingAsPicture()); 95 kVisualRect, recorder.finishRecordingAsPicture());
80 } 96 }
81 97
82 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size, 98 void ValidateDisplayItemListSerialization(const gfx::Size& layer_size,
83 scoped_refptr<DisplayItemList> list) { 99 scoped_refptr<DisplayItemList> list) {
84 list->Finalize(); 100 list->Finalize();
85 101
86 std::unique_ptr<FakeImageSerializationProcessor> 102 std::unique_ptr<FakeImageSerializationProcessor>
87 fake_image_serialization_processor = 103 fake_image_serialization_processor =
88 base::WrapUnique(new FakeImageSerializationProcessor); 104 base::WrapUnique(new FakeImageSerializationProcessor);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 scoped_refptr<DisplayItemList> list = 169 scoped_refptr<DisplayItemList> list =
154 DisplayItemList::Create(gfx::Rect(layer_size), settings); 170 DisplayItemList::Create(gfx::Rect(layer_size), settings);
155 171
156 // Build the DrawingDisplayItem. 172 // Build the DrawingDisplayItem.
157 AppendFirstSerializationTestPicture(list, layer_size); 173 AppendFirstSerializationTestPicture(list, layer_size);
158 174
159 // Build the ClipDisplayItem. 175 // Build the ClipDisplayItem.
160 gfx::Rect clip_rect(6, 6, 1, 1); 176 gfx::Rect clip_rect(6, 6, 1, 1);
161 std::vector<SkRRect> rrects; 177 std::vector<SkRRect> rrects;
162 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); 178 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f)));
163 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, rrects, 179 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(clip_rect, rrects,
164 true); 180 true);
165 181
166 // Build the second DrawingDisplayItem. 182 // Build the second DrawingDisplayItem.
167 AppendSecondSerializationTestPicture(list, layer_size); 183 AppendSecondSerializationTestPicture(list, layer_size);
168 184
169 // Build the EndClipDisplayItem. 185 // Build the EndClipDisplayItem.
170 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); 186 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
171 187
172 ValidateDisplayItemListSerialization(layer_size, list); 188 ValidateDisplayItemListSerialization(layer_size, list);
173 } 189 }
174 190
175 TEST(DisplayItemListTest, SerializeClipPathItem) { 191 TEST(DisplayItemListTest, SerializeClipPathItem) {
176 gfx::Size layer_size(10, 10); 192 gfx::Size layer_size(10, 10);
177 193
178 DisplayItemListSettings settings; 194 DisplayItemListSettings settings;
179 scoped_refptr<DisplayItemList> list = 195 scoped_refptr<DisplayItemList> list =
180 DisplayItemList::Create(gfx::Rect(layer_size), settings); 196 DisplayItemList::Create(gfx::Rect(layer_size), settings);
181 197
182 // Build the DrawingDisplayItem. 198 // Build the DrawingDisplayItem.
183 AppendFirstSerializationTestPicture(list, layer_size); 199 AppendFirstSerializationTestPicture(list, layer_size);
184 200
185 // Build the ClipPathDisplayItem. 201 // Build the ClipPathDisplayItem.
186 SkPath path; 202 SkPath path;
187 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); 203 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction);
188 list->CreateAndAppendItem<ClipPathDisplayItem>( 204 list->CreateAndAppendPairedBeginItem<ClipPathDisplayItem>(
189 kVisualRect, path, SkRegion::Op::kReplace_Op, false); 205 path, SkRegion::Op::kReplace_Op, false);
190 206
191 // Build the second DrawingDisplayItem. 207 // Build the second DrawingDisplayItem.
192 AppendSecondSerializationTestPicture(list, layer_size); 208 AppendSecondSerializationTestPicture(list, layer_size);
193 209
194 // Build the EndClipPathDisplayItem. 210 // Build the EndClipPathDisplayItem.
195 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect); 211 list->CreateAndAppendPairedEndItem<EndClipPathDisplayItem>();
196 212
197 ValidateDisplayItemListSerialization(layer_size, list); 213 ValidateDisplayItemListSerialization(layer_size, list);
198 } 214 }
199 215
200 TEST(DisplayItemListTest, SerializeCompositingItem) { 216 TEST(DisplayItemListTest, SerializeCompositingItem) {
201 gfx::Size layer_size(10, 10); 217 gfx::Size layer_size(10, 10);
202 218
203 DisplayItemListSettings settings; 219 DisplayItemListSettings settings;
204 scoped_refptr<DisplayItemList> list = 220 scoped_refptr<DisplayItemList> list =
205 DisplayItemList::Create(gfx::Rect(layer_size), settings); 221 DisplayItemList::Create(gfx::Rect(layer_size), settings);
206 222
207 // Build the DrawingDisplayItem. 223 // Build the DrawingDisplayItem.
208 AppendFirstSerializationTestPicture(list, layer_size); 224 AppendFirstSerializationTestPicture(list, layer_size);
209 225
210 // Build the CompositingDisplayItem. 226 // Build the CompositingDisplayItem.
211 list->CreateAndAppendItem<CompositingDisplayItem>( 227 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>(
212 kVisualRect, 150, SkXfermode::Mode::kDst_Mode, nullptr, 228 150, SkXfermode::Mode::kDst_Mode, nullptr,
213 SkColorMatrixFilter::MakeLightingFilter(SK_ColorRED, SK_ColorGREEN), 229 SkColorMatrixFilter::MakeLightingFilter(SK_ColorRED, SK_ColorGREEN),
214 false); 230 false);
215 231
216 // Build the second DrawingDisplayItem. 232 // Build the second DrawingDisplayItem.
217 AppendSecondSerializationTestPicture(list, layer_size); 233 AppendSecondSerializationTestPicture(list, layer_size);
218 234
219 // Build the EndCompositingDisplayItem. 235 // Build the EndCompositingDisplayItem.
220 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect); 236 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>();
221 237
222 ValidateDisplayItemListSerialization(layer_size, list); 238 ValidateDisplayItemListSerialization(layer_size, list);
223 } 239 }
224 240
225 TEST(DisplayItemListTest, SerializeFloatClipItem) { 241 TEST(DisplayItemListTest, SerializeFloatClipItem) {
226 gfx::Size layer_size(10, 10); 242 gfx::Size layer_size(10, 10);
227 243
228 DisplayItemListSettings settings; 244 DisplayItemListSettings settings;
229 scoped_refptr<DisplayItemList> list = 245 scoped_refptr<DisplayItemList> list =
230 DisplayItemList::Create(gfx::Rect(layer_size), settings); 246 DisplayItemList::Create(gfx::Rect(layer_size), settings);
231 247
232 // Build the DrawingDisplayItem. 248 // Build the DrawingDisplayItem.
233 AppendFirstSerializationTestPicture(list, layer_size); 249 AppendFirstSerializationTestPicture(list, layer_size);
234 250
235 // Build the FloatClipDisplayItem. 251 // Build the FloatClipDisplayItem.
236 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); 252 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f);
237 list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect, clip_rect); 253 list->CreateAndAppendPairedBeginItem<FloatClipDisplayItem>(clip_rect);
238 254
239 // Build the second DrawingDisplayItem. 255 // Build the second DrawingDisplayItem.
240 AppendSecondSerializationTestPicture(list, layer_size); 256 AppendSecondSerializationTestPicture(list, layer_size);
241 257
242 // Build the EndFloatClipDisplayItem. 258 // Build the EndFloatClipDisplayItem.
243 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect); 259 list->CreateAndAppendPairedEndItem<EndFloatClipDisplayItem>();
244 260
245 ValidateDisplayItemListSerialization(layer_size, list); 261 ValidateDisplayItemListSerialization(layer_size, list);
246 } 262 }
247 263
248 TEST(DisplayItemListTest, SerializeTransformItem) { 264 TEST(DisplayItemListTest, SerializeTransformItem) {
249 gfx::Size layer_size(10, 10); 265 gfx::Size layer_size(10, 10);
250 266
251 DisplayItemListSettings settings; 267 DisplayItemListSettings settings;
252 scoped_refptr<DisplayItemList> list = 268 scoped_refptr<DisplayItemList> list =
253 DisplayItemList::Create(gfx::Rect(layer_size), settings); 269 DisplayItemList::Create(gfx::Rect(layer_size), settings);
254 270
255 // Build the DrawingDisplayItem. 271 // Build the DrawingDisplayItem.
256 AppendFirstSerializationTestPicture(list, layer_size); 272 AppendFirstSerializationTestPicture(list, layer_size);
257 273
258 // Build the TransformDisplayItem. 274 // Build the TransformDisplayItem.
259 gfx::Transform transform; 275 gfx::Transform transform;
260 transform.Scale(1.25f, 1.25f); 276 transform.Scale(1.25f, 1.25f);
261 transform.Translate(-1.f, -1.f); 277 transform.Translate(-1.f, -1.f);
262 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); 278 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform);
263 279
264 // Build the second DrawingDisplayItem. 280 // Build the second DrawingDisplayItem.
265 AppendSecondSerializationTestPicture(list, layer_size); 281 AppendSecondSerializationTestPicture(list, layer_size);
266 282
267 // Build the EndTransformDisplayItem. 283 // Build the EndTransformDisplayItem.
268 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); 284 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
269 285
270 ValidateDisplayItemListSerialization(layer_size, list); 286 ValidateDisplayItemListSerialization(layer_size, list);
271 } 287 }
272 288
273 TEST(DisplayItemListTest, SingleDrawingItem) { 289 TEST(DisplayItemListTest, SingleDrawingItem) {
274 gfx::Rect layer_rect(100, 100); 290 gfx::Rect layer_rect(100, 100);
275 SkPictureRecorder recorder; 291 SkPictureRecorder recorder;
276 sk_sp<SkCanvas> canvas; 292 sk_sp<SkCanvas> canvas;
277 SkPaint blue_paint; 293 SkPaint blue_paint;
278 blue_paint.setColor(SK_ColorBLUE); 294 blue_paint.setColor(SK_ColorBLUE);
279 SkPaint red_paint; 295 SkPaint red_paint;
280 red_paint.setColor(SK_ColorRED); 296 red_paint.setColor(SK_ColorRED);
281 unsigned char pixels[4 * 100 * 100] = {0}; 297 unsigned char pixels[4 * 100 * 100] = {0};
282 DisplayItemListSettings settings; 298 DisplayItemListSettings settings;
283 scoped_refptr<DisplayItemList> list = 299 scoped_refptr<DisplayItemList> list =
284 DisplayItemList::Create(layer_rect, settings); 300 DisplayItemList::Create(layer_rect, settings);
285 301
286 gfx::PointF offset(8.f, 9.f); 302 gfx::PointF offset(8.f, 9.f);
287 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); 303 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
288 canvas = 304 canvas =
289 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 305 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
290 canvas->translate(offset.x(), offset.y()); 306 canvas->translate(offset.x(), offset.y());
291 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 307 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
292 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 308 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
293 list->CreateAndAppendItem<DrawingDisplayItem>( 309 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
294 kVisualRect, recorder.finishRecordingAsPicture()); 310 kVisualRect, recorder.finishRecordingAsPicture());
295 list->Finalize(); 311 list->Finalize();
296 DrawDisplayList(pixels, layer_rect, list); 312 DrawDisplayList(pixels, layer_rect, list);
297 313
298 SkBitmap expected_bitmap; 314 SkBitmap expected_bitmap;
299 unsigned char expected_pixels[4 * 100 * 100] = {0}; 315 unsigned char expected_pixels[4 * 100 * 100] = {0};
300 SkImageInfo info = 316 SkImageInfo info =
301 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 317 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
302 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 318 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
303 SkCanvas expected_canvas(expected_bitmap); 319 SkCanvas expected_canvas(expected_bitmap);
(...skipping 21 matching lines...) Expand all
325 settings.use_cached_picture = true; 341 settings.use_cached_picture = true;
326 scoped_refptr<DisplayItemList> list = 342 scoped_refptr<DisplayItemList> list =
327 DisplayItemList::Create(layer_rect, settings); 343 DisplayItemList::Create(layer_rect, settings);
328 344
329 gfx::PointF first_offset(8.f, 9.f); 345 gfx::PointF first_offset(8.f, 9.f);
330 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); 346 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
331 canvas = sk_ref_sp( 347 canvas = sk_ref_sp(
332 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); 348 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
333 canvas->translate(first_offset.x(), first_offset.y()); 349 canvas->translate(first_offset.x(), first_offset.y());
334 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 350 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
335 list->CreateAndAppendItem<DrawingDisplayItem>( 351 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
336 kVisualRect, recorder.finishRecordingAsPicture()); 352 kVisualRect, recorder.finishRecordingAsPicture());
337 353
338 gfx::Rect clip_rect(60, 60, 10, 10); 354 gfx::Rect clip_rect(60, 60, 10, 10);
339 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, 355 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
340 std::vector<SkRRect>(), true); 356 clip_rect, std::vector<SkRRect>(), true);
341 357
342 gfx::PointF second_offset(2.f, 3.f); 358 gfx::PointF second_offset(2.f, 3.f);
343 gfx::RectF second_recording_rect(second_offset, 359 gfx::RectF second_recording_rect(second_offset,
344 gfx::SizeF(layer_rect.size())); 360 gfx::SizeF(layer_rect.size()));
345 canvas = sk_ref_sp( 361 canvas = sk_ref_sp(
346 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); 362 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)));
347 canvas->translate(second_offset.x(), second_offset.y()); 363 canvas->translate(second_offset.x(), second_offset.y());
348 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 364 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
349 list->CreateAndAppendItem<DrawingDisplayItem>( 365 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
350 kVisualRect, recorder.finishRecordingAsPicture()); 366 kVisualRect, recorder.finishRecordingAsPicture());
351 367
352 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); 368 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
353 list->Finalize(); 369 list->Finalize();
354 370
355 DrawDisplayList(pixels, layer_rect, list); 371 DrawDisplayList(pixels, layer_rect, list);
356 372
357 SkBitmap expected_bitmap; 373 SkBitmap expected_bitmap;
358 unsigned char expected_pixels[4 * 100 * 100] = {0}; 374 unsigned char expected_pixels[4 * 100 * 100] = {0};
359 SkImageInfo info = 375 SkImageInfo info =
360 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 376 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
361 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 377 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
362 SkCanvas expected_canvas(expected_bitmap); 378 SkCanvas expected_canvas(expected_bitmap);
(...skipping 22 matching lines...) Expand all
385 settings.use_cached_picture = true; 401 settings.use_cached_picture = true;
386 scoped_refptr<DisplayItemList> list = 402 scoped_refptr<DisplayItemList> list =
387 DisplayItemList::Create(layer_rect, settings); 403 DisplayItemList::Create(layer_rect, settings);
388 404
389 gfx::PointF first_offset(8.f, 9.f); 405 gfx::PointF first_offset(8.f, 9.f);
390 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); 406 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
391 canvas = sk_ref_sp( 407 canvas = sk_ref_sp(
392 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); 408 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
393 canvas->translate(first_offset.x(), first_offset.y()); 409 canvas->translate(first_offset.x(), first_offset.y());
394 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 410 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
395 list->CreateAndAppendItem<DrawingDisplayItem>( 411 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
396 kVisualRect, recorder.finishRecordingAsPicture()); 412 kVisualRect, recorder.finishRecordingAsPicture());
397 413
398 gfx::Transform transform; 414 gfx::Transform transform;
399 transform.Rotate(45.0); 415 transform.Rotate(45.0);
400 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); 416 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform);
401 417
402 gfx::PointF second_offset(2.f, 3.f); 418 gfx::PointF second_offset(2.f, 3.f);
403 gfx::RectF second_recording_rect(second_offset, 419 gfx::RectF second_recording_rect(second_offset,
404 gfx::SizeF(layer_rect.size())); 420 gfx::SizeF(layer_rect.size()));
405 canvas = sk_ref_sp( 421 canvas = sk_ref_sp(
406 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); 422 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)));
407 canvas->translate(second_offset.x(), second_offset.y()); 423 canvas->translate(second_offset.x(), second_offset.y());
408 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 424 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
409 list->CreateAndAppendItem<DrawingDisplayItem>( 425 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
410 kVisualRect, recorder.finishRecordingAsPicture()); 426 kVisualRect, recorder.finishRecordingAsPicture());
411 427
412 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); 428 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
413 list->Finalize(); 429 list->Finalize();
414 430
415 DrawDisplayList(pixels, layer_rect, list); 431 DrawDisplayList(pixels, layer_rect, list);
416 432
417 SkBitmap expected_bitmap; 433 SkBitmap expected_bitmap;
418 unsigned char expected_pixels[4 * 100 * 100] = {0}; 434 unsigned char expected_pixels[4 * 100 * 100] = {0};
419 SkImageInfo info = 435 SkImageInfo info =
420 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 436 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
421 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 437 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
422 SkCanvas expected_canvas(expected_bitmap); 438 SkCanvas expected_canvas(expected_bitmap);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by 470 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by
455 // translating |dst| after it is computed by computeFastBounds, rather than 471 // translating |dst| after it is computed by computeFastBounds, rather than
456 // translating |src| before it provided to computedFastBounds) can cause 472 // translating |src| before it provided to computedFastBounds) can cause
457 // incorrect clipping of filter output. To test for this, we include an 473 // incorrect clipping of filter output. To test for this, we include an
458 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined 474 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined
459 // below. 475 // below.
460 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); 476 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image);
461 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); 477 filters.Append(FilterOperation::CreateReferenceFilter(image_filter));
462 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); 478 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f));
463 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); 479 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f);
464 list->CreateAndAppendItem<FilterDisplayItem>(kVisualRect, filters, 480 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>(filters,
465 filter_bounds); 481 filter_bounds);
466 list->CreateAndAppendItem<EndFilterDisplayItem>(kVisualRect); 482 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>();
467 list->Finalize(); 483 list->Finalize();
468 484
469 DrawDisplayList(pixels, layer_rect, list); 485 DrawDisplayList(pixels, layer_rect, list);
470 486
471 SkBitmap expected_bitmap; 487 SkBitmap expected_bitmap;
472 unsigned char expected_pixels[4 * 100 * 100] = {0}; 488 unsigned char expected_pixels[4 * 100 * 100] = {0};
473 SkPaint paint; 489 SkPaint paint;
474 paint.setColor(SkColorSetRGB(64, 64, 64)); 490 paint.setColor(SkColorSetRGB(64, 64, 64));
475 SkImageInfo info = 491 SkImageInfo info =
476 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 492 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
(...skipping 21 matching lines...) Expand all
498 no_caching_settings.use_cached_picture = false; 514 no_caching_settings.use_cached_picture = false;
499 scoped_refptr<DisplayItemList> list_without_caching = 515 scoped_refptr<DisplayItemList> list_without_caching =
500 DisplayItemList::Create(layer_rect, no_caching_settings); 516 DisplayItemList::Create(layer_rect, no_caching_settings);
501 517
502 canvas = 518 canvas =
503 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 519 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
504 canvas->translate(offset.x(), offset.y()); 520 canvas->translate(offset.x(), offset.y());
505 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 521 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
506 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 522 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
507 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 523 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
508 list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, 524 list_without_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(
509 picture); 525 kVisualRect, picture);
510 list_without_caching->Finalize(); 526 list_without_caching->Finalize();
511 DrawDisplayList(pixels, layer_rect, list_without_caching); 527 DrawDisplayList(pixels, layer_rect, list_without_caching);
512 528
513 unsigned char expected_pixels[4 * 100 * 100] = {0}; 529 unsigned char expected_pixels[4 * 100 * 100] = {0};
514 DisplayItemListSettings caching_settings; 530 DisplayItemListSettings caching_settings;
515 caching_settings.use_cached_picture = true; 531 caching_settings.use_cached_picture = true;
516 scoped_refptr<DisplayItemList> list_with_caching = 532 scoped_refptr<DisplayItemList> list_with_caching =
517 DisplayItemList::Create(layer_rect, caching_settings); 533 DisplayItemList::Create(layer_rect, caching_settings);
518 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, 534 list_with_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect,
519 picture); 535 picture);
520 list_with_caching->Finalize(); 536 list_with_caching->Finalize();
521 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); 537 DrawDisplayList(expected_pixels, layer_rect, list_with_caching);
522 538
523 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 539 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
524 } 540 }
525 541
526 TEST(DisplayItemListTest, ApproximateMemoryUsage) { 542 TEST(DisplayItemListTest, ApproximateMemoryUsage) {
527 const int kNumCommandsInTestSkPicture = 1000; 543 const int kNumCommandsInTestSkPicture = 1000;
528 scoped_refptr<DisplayItemList> list; 544 scoped_refptr<DisplayItemList> list;
529 size_t memory_usage; 545 size_t memory_usage;
530 546
531 // Make an SkPicture whose size is known. 547 // Make an SkPicture whose size is known.
532 gfx::Rect layer_rect(100, 100); 548 gfx::Rect layer_rect(100, 100);
533 SkPictureRecorder recorder; 549 SkPictureRecorder recorder;
534 SkPaint blue_paint; 550 SkPaint blue_paint;
535 blue_paint.setColor(SK_ColorBLUE); 551 blue_paint.setColor(SK_ColorBLUE);
536 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); 552 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect));
537 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) 553 for (int i = 0; i < kNumCommandsInTestSkPicture; i++)
538 canvas->drawPaint(blue_paint); 554 canvas->drawPaint(blue_paint);
539 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 555 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
540 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); 556 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get());
541 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); 557 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint));
542 558
543 // Using a cached picture, we should get about the right size. 559 // Using a cached picture, we should get about the right size.
544 DisplayItemListSettings caching_settings; 560 DisplayItemListSettings caching_settings;
545 caching_settings.use_cached_picture = true; 561 caching_settings.use_cached_picture = true;
546 list = DisplayItemList::Create(layer_rect, caching_settings); 562 list = DisplayItemList::Create(layer_rect, caching_settings);
547 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); 563 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture);
548 list->Finalize(); 564 list->Finalize();
549 memory_usage = list->ApproximateMemoryUsage(); 565 memory_usage = list->ApproximateMemoryUsage();
550 EXPECT_GE(memory_usage, picture_size); 566 EXPECT_GE(memory_usage, picture_size);
551 EXPECT_LE(memory_usage, 2 * picture_size); 567 EXPECT_LE(memory_usage, 2 * picture_size);
552 568
553 // Using no cached picture, we should still get the right size. 569 // Using no cached picture, we should still get the right size.
554 DisplayItemListSettings no_caching_settings; 570 DisplayItemListSettings no_caching_settings;
555 no_caching_settings.use_cached_picture = false; 571 no_caching_settings.use_cached_picture = false;
556 list = DisplayItemList::Create(layer_rect, no_caching_settings); 572 list = DisplayItemList::Create(layer_rect, no_caching_settings);
557 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); 573 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture);
558 list->Finalize(); 574 list->Finalize();
559 memory_usage = list->ApproximateMemoryUsage(); 575 memory_usage = list->ApproximateMemoryUsage();
560 EXPECT_GE(memory_usage, picture_size); 576 EXPECT_GE(memory_usage, picture_size);
561 EXPECT_LE(memory_usage, 2 * picture_size); 577 EXPECT_LE(memory_usage, 2 * picture_size);
562 578
563 // To avoid double counting, we expect zero size to be computed if both the 579 // To avoid double counting, we expect zero size to be computed if both the
564 // picture and items are retained (currently this only happens due to certain 580 // picture and items are retained (currently this only happens due to certain
565 // categories being traced). 581 // categories being traced).
566 list = new DisplayItemList(layer_rect, caching_settings, true); 582 list = new DisplayItemList(layer_rect, caching_settings, true);
567 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); 583 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture);
568 list->Finalize(); 584 list->Finalize();
569 memory_usage = list->ApproximateMemoryUsage(); 585 memory_usage = list->ApproximateMemoryUsage();
570 EXPECT_EQ(static_cast<size_t>(0), memory_usage); 586 EXPECT_EQ(static_cast<size_t>(0), memory_usage);
571 } 587 }
572 588
573 TEST(DisplayItemListTest, AsValueWithRectAndNoItems) { 589 TEST(DisplayItemListTest, AsValueWithRectAndNoItems) {
574 scoped_refptr<DisplayItemList> list = 590 scoped_refptr<DisplayItemList> list =
575 DisplayItemList::Create(gfx::Rect(1, 2, 8, 9), DisplayItemListSettings()); 591 DisplayItemList::Create(gfx::Rect(1, 2, 8, 9), DisplayItemListSettings());
576 list->Finalize(); 592 list->Finalize();
577 593
578 std::string value = list->AsValue(true)->ToString(); 594 std::string value = list->AsValue(true)->ToString();
579 EXPECT_NE(value.find("\"items\":[]"), std::string::npos); 595 EXPECT_NE(value.find("\"items\":[]"), std::string::npos);
580 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 596 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos);
581 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 597 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
582 598
583 value = list->AsValue(false)->ToString(); 599 value = list->AsValue(false)->ToString();
584 EXPECT_EQ(value.find("\"items\":"), std::string::npos); 600 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
585 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 601 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos);
586 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 602 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
587 } 603 }
588 604
589 TEST(DisplayItemListTest, AsValueWithRectAndItems) { 605 TEST(DisplayItemListTest, AsValueWithRectAndItems) {
590 gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9); 606 gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9);
591 scoped_refptr<DisplayItemList> list = 607 scoped_refptr<DisplayItemList> list =
592 DisplayItemList::Create(layer_rect, DisplayItemListSettings()); 608 DisplayItemList::Create(layer_rect, DisplayItemListSettings());
593 gfx::Transform transform; 609 gfx::Transform transform;
594 transform.Translate(6.f, 7.f); 610 transform.Translate(6.f, 7.f);
595 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); 611 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform);
596 AppendFirstSerializationTestPicture(list, layer_rect.size()); 612 AppendFirstSerializationTestPicture(list, layer_rect.size());
597 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); 613 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
598 list->Finalize(); 614 list->Finalize();
599 615
600 std::string value = list->AsValue(true)->ToString(); 616 std::string value = list->AsValue(true)->ToString();
601 EXPECT_NE(value.find("{\"items\":[\"TransformDisplayItem"), 617 EXPECT_NE(value.find("{\"items\":[\"TransformDisplayItem"),
602 std::string::npos); 618 std::string::npos);
603 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 619 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos);
604 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 620 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
605 621
606 value = list->AsValue(false)->ToString(); 622 value = list->AsValue(false)->ToString();
607 EXPECT_EQ(value.find("{\"items\":[\"TransformDisplayItem"), 623 EXPECT_EQ(value.find("{\"items\":[\"TransformDisplayItem"),
608 std::string::npos); 624 std::string::npos);
609 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 625 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos);
610 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 626 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
611 } 627 }
612 628
613 TEST(DisplayItemListTest, AsValueWithEmptyRectAndNoItems) { 629 TEST(DisplayItemListTest, AsValueWithEmptyRectAndNoItems) {
614 scoped_refptr<DisplayItemList> list = 630 scoped_refptr<DisplayItemList> list = CreateDefaultList();
615 DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings());
616 list->Finalize(); 631 list->Finalize();
617 632
618 std::string value = list->AsValue(true)->ToString(); 633 std::string value = list->AsValue(true)->ToString();
619 EXPECT_NE(value.find("\"items\":[]"), std::string::npos); 634 EXPECT_NE(value.find("\"items\":[]"), std::string::npos);
620 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos); 635 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
621 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos); 636 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
622 637
623 value = list->AsValue(false)->ToString(); 638 value = list->AsValue(false)->ToString();
624 EXPECT_EQ(value.find("\"items\":"), std::string::npos); 639 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
625 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos); 640 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
626 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos); 641 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
627 } 642 }
628 643
629 TEST(DisplayItemListTest, AsValueWithEmptyRectAndItems) { 644 TEST(DisplayItemListTest, AsValueWithEmptyRectAndItems) {
630 scoped_refptr<DisplayItemList> list = 645 scoped_refptr<DisplayItemList> list = CreateDefaultList();
631 DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings());
632 gfx::Transform transform; 646 gfx::Transform transform;
633 transform.Translate(6.f, 7.f); 647 transform.Translate(6.f, 7.f);
634 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); 648 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform);
635 AppendFirstSerializationTestPicture(list, gfx::Size()); 649 AppendFirstSerializationTestPicture(list, gfx::Size());
636 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); 650 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
637 list->Finalize(); 651 list->Finalize();
638 652
639 std::string value = list->AsValue(true)->ToString(); 653 std::string value = list->AsValue(true)->ToString();
640 EXPECT_NE(value.find("\"items\":[\"TransformDisplayItem"), std::string::npos); 654 EXPECT_NE(value.find("\"items\":[\"TransformDisplayItem"), std::string::npos);
641 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos); 655 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
642 // There should be one skp64 entry present associated with the test picture 656 // There should be one skp64 entry present associated with the test picture
643 // item, though the overall list has no skp64 as the layer rect is empty. 657 // item, though the overall list has no skp64 as the layer rect is empty.
644 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 658 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
645 659
646 value = list->AsValue(false)->ToString(); 660 value = list->AsValue(false)->ToString();
647 EXPECT_EQ(value.find("\"items\":"), std::string::npos); 661 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
648 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos); 662 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
649 // There should be no skp64 entry present as the items aren't included and the 663 // There should be no skp64 entry present as the items aren't included and the
650 // layer rect is empty. 664 // layer rect is empty.
651 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos); 665 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
652 } 666 }
653 667
668 TEST(DisplayItemListTest, SizeEmpty) {
669 scoped_refptr<DisplayItemList> list = CreateDefaultList();
670 EXPECT_EQ(0u, list->size());
671 }
672
673 TEST(DisplayItemListTest, SizeOne) {
674 scoped_refptr<DisplayItemList> list = CreateDefaultList();
675 gfx::Rect drawing_bounds(5, 6, 1, 1);
676 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
677 drawing_bounds, CreateRectPicture(drawing_bounds));
678 EXPECT_EQ(1u, list->size());
679 }
680
681 TEST(DisplayItemListTest, SizeMultiple) {
682 scoped_refptr<DisplayItemList> list = CreateDefaultList();
683 gfx::Rect clip_bounds(5, 6, 7, 8);
684 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
685 clip_bounds, std::vector<SkRRect>(), true);
686 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
687 EXPECT_EQ(2u, list->size());
688 }
689
690 TEST(DisplayItemListTest, AppendVisualRectSimple) {
691 scoped_refptr<DisplayItemList> list = CreateDefaultList();
692
693 // One drawing: D.
694
695 gfx::Rect drawing_bounds(5, 6, 7, 8);
696 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
697 drawing_bounds, CreateRectPicture(drawing_bounds));
698
699 EXPECT_EQ(1u, list->size());
700 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0));
701 }
702
703 TEST(DisplayItemListTest, AppendVisualRectEmptyBlock) {
704 scoped_refptr<DisplayItemList> list = CreateDefaultList();
705
706 // One block: B1, E1.
707
708 gfx::Rect clip_bounds(5, 6, 7, 8);
709 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
710 clip_bounds, std::vector<SkRRect>(), true);
711
712 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
713
714 EXPECT_EQ(2u, list->size());
715 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(0));
716 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(1));
717 }
718
719 TEST(DisplayItemListTest, AppendVisualRectEmptyBlockContainingEmptyBlock) {
720 scoped_refptr<DisplayItemList> list = CreateDefaultList();
721
722 // Two nested blocks: B1, B2, E2, E1.
723
724 gfx::Rect clip_bounds(5, 6, 7, 8);
725 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
726 clip_bounds, std::vector<SkRRect>(), true);
727 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform());
728 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
729 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
730
731 EXPECT_EQ(4u, list->size());
732 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(0));
733 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(1));
734 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(2));
735 EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(3));
736 }
737
738 TEST(DisplayItemListTest, AppendVisualRectBlockContainingDrawing) {
739 scoped_refptr<DisplayItemList> list = CreateDefaultList();
740
741 // One block with one drawing: B1, Da, E1.
742
743 gfx::Rect clip_bounds(5, 6, 7, 8);
744 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
745 clip_bounds, std::vector<SkRRect>(), true);
746
747 gfx::Rect drawing_bounds(5, 6, 1, 1);
748 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
749 drawing_bounds, CreateRectPicture(drawing_bounds));
750
751 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
752
753 EXPECT_EQ(3u, list->size());
754 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0));
755 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(1));
756 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(2));
757 }
758
759 TEST(DisplayItemListTest, AppendVisualRectBlockContainingEscapedDrawing) {
760 scoped_refptr<DisplayItemList> list = CreateDefaultList();
761
762 // One block with one drawing: B1, Da (escapes), E1.
763
764 gfx::Rect clip_bounds(5, 6, 7, 8);
765 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
766 clip_bounds, std::vector<SkRRect>(), true);
767
768 gfx::Rect drawing_bounds(1, 2, 3, 4);
769 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
770 drawing_bounds, CreateRectPicture(drawing_bounds));
771
772 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
773
774 EXPECT_EQ(3u, list->size());
775 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0));
776 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(1));
777 EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(2));
778 }
779
780 TEST(DisplayItemListTest,
781 AppendVisualRectDrawingFollowedByBlockContainingEscapedDrawing) {
782 scoped_refptr<DisplayItemList> list = CreateDefaultList();
783
784 // One drawing followed by one block with one drawing: Da, B1, Db (escapes),
785 // E1.
786
787 gfx::Rect drawing_a_bounds(1, 2, 3, 4);
788 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
789 drawing_a_bounds, CreateRectPicture(drawing_a_bounds));
790
791 gfx::Rect clip_bounds(5, 6, 7, 8);
792 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
793 clip_bounds, std::vector<SkRRect>(), true);
794
795 gfx::Rect drawing_b_bounds(13, 14, 1, 1);
796 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
797 drawing_b_bounds, CreateRectPicture(drawing_b_bounds));
798
799 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
800
801 EXPECT_EQ(4u, list->size());
802 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(0));
803 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(1));
804 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2));
805 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3));
806 }
807
808 TEST(DisplayItemListTest, AppendVisualRectTwoBlocksTwoDrawings) {
809 scoped_refptr<DisplayItemList> list = CreateDefaultList();
810
811 // Multiple nested blocks with drawings amidst: B1, Da, B2, Db, E2, E1.
812
813 gfx::Rect clip_bounds(5, 6, 7, 8);
814 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
815 clip_bounds, std::vector<SkRRect>(), true);
816
817 gfx::Rect drawing_a_bounds(5, 6, 1, 1);
818 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
819 drawing_a_bounds, CreateRectPicture(drawing_a_bounds));
820
821 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform());
822
823 gfx::Rect drawing_b_bounds(7, 8, 1, 1);
824 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
825 drawing_b_bounds, CreateRectPicture(drawing_b_bounds));
826
827 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
828 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
829
830 EXPECT_EQ(6u, list->size());
831 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds);
832 merged_drawing_bounds.Union(drawing_b_bounds);
833 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0));
834 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1));
835 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2));
836 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3));
837 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4));
838 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5));
839 }
840
841 TEST(DisplayItemListTest,
842 AppendVisualRectTwoBlocksTwoDrawingsInnerDrawingEscaped) {
843 scoped_refptr<DisplayItemList> list = CreateDefaultList();
844
845 // Multiple nested blocks with drawings amidst: B1, Da, B2, Db (escapes), E2,
846 // E1.
847
848 gfx::Rect clip_bounds(5, 6, 7, 8);
849 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
850 clip_bounds, std::vector<SkRRect>(), true);
851
852 gfx::Rect drawing_a_bounds(5, 6, 1, 1);
853 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
854 drawing_a_bounds, CreateRectPicture(drawing_a_bounds));
855
856 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform());
857
858 gfx::Rect drawing_b_bounds(1, 2, 3, 4);
859 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
860 drawing_b_bounds, CreateRectPicture(drawing_b_bounds));
861
862 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
863 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
864
865 EXPECT_EQ(6u, list->size());
866 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds);
867 merged_drawing_bounds.Union(drawing_b_bounds);
868 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0));
869 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1));
870 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2));
871 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3));
872 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4));
873 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5));
874 }
875
876 TEST(DisplayItemListTest,
877 AppendVisualRectTwoBlocksTwoDrawingsOuterDrawingEscaped) {
878 scoped_refptr<DisplayItemList> list = CreateDefaultList();
879
880 // Multiple nested blocks with drawings amidst: B1, Da (escapes), B2, Db, E2,
881 // E1.
882
883 gfx::Rect clip_bounds(5, 6, 7, 8);
884 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
885 clip_bounds, std::vector<SkRRect>(), true);
886
887 gfx::Rect drawing_a_bounds(1, 2, 3, 4);
888 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
889 drawing_a_bounds, CreateRectPicture(drawing_a_bounds));
890
891 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform());
892
893 gfx::Rect drawing_b_bounds(7, 8, 1, 1);
894 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
895 drawing_b_bounds, CreateRectPicture(drawing_b_bounds));
896
897 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
898 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
899
900 EXPECT_EQ(6u, list->size());
901 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds);
902 merged_drawing_bounds.Union(drawing_b_bounds);
903 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0));
904 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1));
905 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2));
906 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3));
907 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4));
908 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5));
909 }
910
911 TEST(DisplayItemListTest,
912 AppendVisualRectTwoBlocksTwoDrawingsBothDrawingsEscaped) {
913 scoped_refptr<DisplayItemList> list = CreateDefaultList();
914
915 // Multiple nested blocks with drawings amidst:
916 // B1, Da (escapes to the right), B2, Db (escapes to the left), E2, E1.
917
918 gfx::Rect clip_bounds(5, 6, 7, 8);
919 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(
920 clip_bounds, std::vector<SkRRect>(), true);
921
922 gfx::Rect drawing_a_bounds(13, 14, 1, 1);
923 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
924 drawing_a_bounds, CreateRectPicture(drawing_a_bounds));
925
926 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(gfx::Transform());
927
928 gfx::Rect drawing_b_bounds(1, 2, 3, 4);
929 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
930 drawing_b_bounds, CreateRectPicture(drawing_b_bounds));
931
932 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
933 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
934
935 EXPECT_EQ(6u, list->size());
936 gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds);
937 merged_drawing_bounds.Union(drawing_b_bounds);
938 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0));
939 EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(1));
940 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2));
941 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(3));
942 EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(4));
943 EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(5));
944 }
945
654 } // namespace cc 946 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/display_item_list.cc ('k') | cc/playback/display_item_proto_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698