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

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

Powered by Google App Engine
This is Rietveld 408576698