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

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

Issue 1484163002: Raster display item lists via a visual rect RTree. (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
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 settings.ToProtobuf(&proto); 130 settings.ToProtobuf(&proto);
131 DisplayItemListSettings deserialized(proto); 131 DisplayItemListSettings deserialized(proto);
132 EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture); 132 EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture);
133 } 133 }
134 } 134 }
135 135
136 TEST(DisplayItemListTest, SerializeSingleDrawingItem) { 136 TEST(DisplayItemListTest, SerializeSingleDrawingItem) {
137 gfx::Size layer_size(10, 10); 137 gfx::Size layer_size(10, 10);
138 138
139 DisplayItemListSettings settings; 139 DisplayItemListSettings settings;
140 scoped_refptr<DisplayItemList> list = 140 settings.use_cached_picture = true;
141 DisplayItemList::Create(gfx::Rect(layer_size), settings); 141 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
142 list->SetRetainVisualRectsForTesting(true);
142 143
143 // Build the DrawingDisplayItem. 144 // Build the DrawingDisplayItem.
144 AppendFirstSerializationTestPicture(list, layer_size); 145 AppendFirstSerializationTestPicture(list, layer_size);
145 146
146 ValidateDisplayItemListSerialization(layer_size, list); 147 ValidateDisplayItemListSerialization(layer_size, list);
147 } 148 }
148 149
149 TEST(DisplayItemListTest, SerializeClipItem) { 150 TEST(DisplayItemListTest, SerializeClipItem) {
150 gfx::Size layer_size(10, 10); 151 gfx::Size layer_size(10, 10);
151 152
152 DisplayItemListSettings settings; 153 DisplayItemListSettings settings;
153 scoped_refptr<DisplayItemList> list = 154 settings.use_cached_picture = true;
154 DisplayItemList::Create(gfx::Rect(layer_size), settings); 155 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
156 list->SetRetainVisualRectsForTesting(true);
155 157
156 // Build the DrawingDisplayItem. 158 // Build the DrawingDisplayItem.
157 AppendFirstSerializationTestPicture(list, layer_size); 159 AppendFirstSerializationTestPicture(list, layer_size);
158 160
159 // Build the ClipDisplayItem. 161 // Build the ClipDisplayItem.
160 gfx::Rect clip_rect(6, 6, 1, 1); 162 gfx::Rect clip_rect(6, 6, 1, 1);
161 std::vector<SkRRect> rrects; 163 std::vector<SkRRect> rrects;
162 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); 164 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f)));
163 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, rrects, 165 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, rrects,
164 true); 166 true);
165 167
166 // Build the second DrawingDisplayItem. 168 // Build the second DrawingDisplayItem.
167 AppendSecondSerializationTestPicture(list, layer_size); 169 AppendSecondSerializationTestPicture(list, layer_size);
168 170
169 // Build the EndClipDisplayItem. 171 // Build the EndClipDisplayItem.
170 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); 172 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect);
171 173
172 ValidateDisplayItemListSerialization(layer_size, list); 174 ValidateDisplayItemListSerialization(layer_size, list);
173 } 175 }
174 176
175 TEST(DisplayItemListTest, SerializeClipPathItem) { 177 TEST(DisplayItemListTest, SerializeClipPathItem) {
176 gfx::Size layer_size(10, 10); 178 gfx::Size layer_size(10, 10);
177 179
178 DisplayItemListSettings settings; 180 DisplayItemListSettings settings;
179 scoped_refptr<DisplayItemList> list = 181 settings.use_cached_picture = true;
180 DisplayItemList::Create(gfx::Rect(layer_size), settings); 182 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
183 list->SetRetainVisualRectsForTesting(true);
181 184
182 // Build the DrawingDisplayItem. 185 // Build the DrawingDisplayItem.
183 AppendFirstSerializationTestPicture(list, layer_size); 186 AppendFirstSerializationTestPicture(list, layer_size);
184 187
185 // Build the ClipPathDisplayItem. 188 // Build the ClipPathDisplayItem.
186 SkPath path; 189 SkPath path;
187 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); 190 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction);
188 list->CreateAndAppendItem<ClipPathDisplayItem>( 191 list->CreateAndAppendItem<ClipPathDisplayItem>(
189 kVisualRect, path, SkRegion::Op::kReplace_Op, false); 192 kVisualRect, path, SkRegion::Op::kReplace_Op, false);
190 193
191 // Build the second DrawingDisplayItem. 194 // Build the second DrawingDisplayItem.
192 AppendSecondSerializationTestPicture(list, layer_size); 195 AppendSecondSerializationTestPicture(list, layer_size);
193 196
194 // Build the EndClipPathDisplayItem. 197 // Build the EndClipPathDisplayItem.
195 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect); 198 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect);
196 199
197 ValidateDisplayItemListSerialization(layer_size, list); 200 ValidateDisplayItemListSerialization(layer_size, list);
198 } 201 }
199 202
200 TEST(DisplayItemListTest, SerializeCompositingItem) { 203 TEST(DisplayItemListTest, SerializeCompositingItem) {
201 gfx::Size layer_size(10, 10); 204 gfx::Size layer_size(10, 10);
202 205
203 DisplayItemListSettings settings; 206 DisplayItemListSettings settings;
204 scoped_refptr<DisplayItemList> list = 207 settings.use_cached_picture = true;
205 DisplayItemList::Create(gfx::Rect(layer_size), settings); 208 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
209 list->SetRetainVisualRectsForTesting(true);
206 210
207 // Build the DrawingDisplayItem. 211 // Build the DrawingDisplayItem.
208 AppendFirstSerializationTestPicture(list, layer_size); 212 AppendFirstSerializationTestPicture(list, layer_size);
209 213
210 // Build the CompositingDisplayItem. 214 // Build the CompositingDisplayItem.
211 list->CreateAndAppendItem<CompositingDisplayItem>( 215 list->CreateAndAppendItem<CompositingDisplayItem>(
212 kVisualRect, 150, SkXfermode::Mode::kDst_Mode, nullptr, 216 kVisualRect, 150, SkXfermode::Mode::kDst_Mode, nullptr,
213 SkColorMatrixFilter::MakeLightingFilter(SK_ColorRED, SK_ColorGREEN), 217 SkColorMatrixFilter::MakeLightingFilter(SK_ColorRED, SK_ColorGREEN),
214 false); 218 false);
215 219
216 // Build the second DrawingDisplayItem. 220 // Build the second DrawingDisplayItem.
217 AppendSecondSerializationTestPicture(list, layer_size); 221 AppendSecondSerializationTestPicture(list, layer_size);
218 222
219 // Build the EndCompositingDisplayItem. 223 // Build the EndCompositingDisplayItem.
220 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect); 224 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect);
221 225
222 ValidateDisplayItemListSerialization(layer_size, list); 226 ValidateDisplayItemListSerialization(layer_size, list);
223 } 227 }
224 228
225 TEST(DisplayItemListTest, SerializeFloatClipItem) { 229 TEST(DisplayItemListTest, SerializeFloatClipItem) {
226 gfx::Size layer_size(10, 10); 230 gfx::Size layer_size(10, 10);
227 231
228 DisplayItemListSettings settings; 232 DisplayItemListSettings settings;
229 scoped_refptr<DisplayItemList> list = 233 settings.use_cached_picture = true;
230 DisplayItemList::Create(gfx::Rect(layer_size), settings); 234 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
235 list->SetRetainVisualRectsForTesting(true);
231 236
232 // Build the DrawingDisplayItem. 237 // Build the DrawingDisplayItem.
233 AppendFirstSerializationTestPicture(list, layer_size); 238 AppendFirstSerializationTestPicture(list, layer_size);
234 239
235 // Build the FloatClipDisplayItem. 240 // Build the FloatClipDisplayItem.
236 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); 241 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f);
237 list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect, clip_rect); 242 list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect, clip_rect);
238 243
239 // Build the second DrawingDisplayItem. 244 // Build the second DrawingDisplayItem.
240 AppendSecondSerializationTestPicture(list, layer_size); 245 AppendSecondSerializationTestPicture(list, layer_size);
241 246
242 // Build the EndFloatClipDisplayItem. 247 // Build the EndFloatClipDisplayItem.
243 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect); 248 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect);
244 249
245 ValidateDisplayItemListSerialization(layer_size, list); 250 ValidateDisplayItemListSerialization(layer_size, list);
246 } 251 }
247 252
248 TEST(DisplayItemListTest, SerializeTransformItem) { 253 TEST(DisplayItemListTest, SerializeTransformItem) {
249 gfx::Size layer_size(10, 10); 254 gfx::Size layer_size(10, 10);
250 255
251 DisplayItemListSettings settings; 256 DisplayItemListSettings settings;
252 scoped_refptr<DisplayItemList> list = 257 settings.use_cached_picture = true;
253 DisplayItemList::Create(gfx::Rect(layer_size), settings); 258 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
259 list->SetRetainVisualRectsForTesting(true);
254 260
255 // Build the DrawingDisplayItem. 261 // Build the DrawingDisplayItem.
256 AppendFirstSerializationTestPicture(list, layer_size); 262 AppendFirstSerializationTestPicture(list, layer_size);
257 263
258 // Build the TransformDisplayItem. 264 // Build the TransformDisplayItem.
259 gfx::Transform transform; 265 gfx::Transform transform;
260 transform.Scale(1.25f, 1.25f); 266 transform.Scale(1.25f, 1.25f);
261 transform.Translate(-1.f, -1.f); 267 transform.Translate(-1.f, -1.f);
262 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); 268 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform);
263 269
264 // Build the second DrawingDisplayItem. 270 // Build the second DrawingDisplayItem.
265 AppendSecondSerializationTestPicture(list, layer_size); 271 AppendSecondSerializationTestPicture(list, layer_size);
266 272
267 // Build the EndTransformDisplayItem. 273 // Build the EndTransformDisplayItem.
268 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); 274 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect);
269 275
270 ValidateDisplayItemListSerialization(layer_size, list); 276 ValidateDisplayItemListSerialization(layer_size, list);
271 } 277 }
272 278
273 TEST(DisplayItemListTest, SingleDrawingItem) { 279 TEST(DisplayItemListTest, SingleDrawingItem) {
274 gfx::Rect layer_rect(100, 100); 280 gfx::Rect layer_rect(100, 100);
275 SkPictureRecorder recorder; 281 SkPictureRecorder recorder;
276 sk_sp<SkCanvas> canvas; 282 sk_sp<SkCanvas> canvas;
277 SkPaint blue_paint; 283 SkPaint blue_paint;
278 blue_paint.setColor(SK_ColorBLUE); 284 blue_paint.setColor(SK_ColorBLUE);
279 SkPaint red_paint; 285 SkPaint red_paint;
280 red_paint.setColor(SK_ColorRED); 286 red_paint.setColor(SK_ColorRED);
281 unsigned char pixels[4 * 100 * 100] = {0}; 287 unsigned char pixels[4 * 100 * 100] = {0};
282 DisplayItemListSettings settings; 288 DisplayItemListSettings settings;
283 scoped_refptr<DisplayItemList> list = 289 settings.use_cached_picture = true;
284 DisplayItemList::Create(layer_rect, settings); 290 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
285 291
286 gfx::PointF offset(8.f, 9.f); 292 gfx::PointF offset(8.f, 9.f);
287 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); 293 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
288 canvas = 294 canvas =
289 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 295 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
290 canvas->translate(offset.x(), offset.y()); 296 canvas->translate(offset.x(), offset.y());
291 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 297 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); 298 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
293 list->CreateAndAppendItem<DrawingDisplayItem>( 299 list->CreateAndAppendItem<DrawingDisplayItem>(
294 kVisualRect, recorder.finishRecordingAsPicture()); 300 kVisualRect, recorder.finishRecordingAsPicture());
(...skipping 21 matching lines...) Expand all
316 gfx::Rect layer_rect(100, 100); 322 gfx::Rect layer_rect(100, 100);
317 SkPictureRecorder recorder; 323 SkPictureRecorder recorder;
318 sk_sp<SkCanvas> canvas; 324 sk_sp<SkCanvas> canvas;
319 SkPaint blue_paint; 325 SkPaint blue_paint;
320 blue_paint.setColor(SK_ColorBLUE); 326 blue_paint.setColor(SK_ColorBLUE);
321 SkPaint red_paint; 327 SkPaint red_paint;
322 red_paint.setColor(SK_ColorRED); 328 red_paint.setColor(SK_ColorRED);
323 unsigned char pixels[4 * 100 * 100] = {0}; 329 unsigned char pixels[4 * 100 * 100] = {0};
324 DisplayItemListSettings settings; 330 DisplayItemListSettings settings;
325 settings.use_cached_picture = true; 331 settings.use_cached_picture = true;
326 scoped_refptr<DisplayItemList> list = 332 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
327 DisplayItemList::Create(layer_rect, settings);
328 333
329 gfx::PointF first_offset(8.f, 9.f); 334 gfx::PointF first_offset(8.f, 9.f);
330 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); 335 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
331 canvas = sk_ref_sp( 336 canvas = sk_ref_sp(
332 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); 337 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
333 canvas->translate(first_offset.x(), first_offset.y()); 338 canvas->translate(first_offset.x(), first_offset.y());
334 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 339 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
335 list->CreateAndAppendItem<DrawingDisplayItem>( 340 list->CreateAndAppendItem<DrawingDisplayItem>(
336 kVisualRect, recorder.finishRecordingAsPicture()); 341 kVisualRect, recorder.finishRecordingAsPicture());
337 342
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 gfx::Rect layer_rect(100, 100); 381 gfx::Rect layer_rect(100, 100);
377 SkPictureRecorder recorder; 382 SkPictureRecorder recorder;
378 sk_sp<SkCanvas> canvas; 383 sk_sp<SkCanvas> canvas;
379 SkPaint blue_paint; 384 SkPaint blue_paint;
380 blue_paint.setColor(SK_ColorBLUE); 385 blue_paint.setColor(SK_ColorBLUE);
381 SkPaint red_paint; 386 SkPaint red_paint;
382 red_paint.setColor(SK_ColorRED); 387 red_paint.setColor(SK_ColorRED);
383 unsigned char pixels[4 * 100 * 100] = {0}; 388 unsigned char pixels[4 * 100 * 100] = {0};
384 DisplayItemListSettings settings; 389 DisplayItemListSettings settings;
385 settings.use_cached_picture = true; 390 settings.use_cached_picture = true;
386 scoped_refptr<DisplayItemList> list = 391 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
387 DisplayItemList::Create(layer_rect, settings);
388 392
389 gfx::PointF first_offset(8.f, 9.f); 393 gfx::PointF first_offset(8.f, 9.f);
390 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); 394 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
391 canvas = sk_ref_sp( 395 canvas = sk_ref_sp(
392 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); 396 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
393 canvas->translate(first_offset.x(), first_offset.y()); 397 canvas->translate(first_offset.x(), first_offset.y());
394 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 398 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
395 list->CreateAndAppendItem<DrawingDisplayItem>( 399 list->CreateAndAppendItem<DrawingDisplayItem>(
396 kVisualRect, recorder.finishRecordingAsPicture()); 400 kVisualRect, recorder.finishRecordingAsPicture());
397 401
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 50.f + second_offset.x(), 50.f + second_offset.y(), 433 50.f + second_offset.x(), 50.f + second_offset.y(),
430 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); 434 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint);
431 435
432 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 436 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
433 } 437 }
434 438
435 TEST(DisplayItemListTest, FilterItem) { 439 TEST(DisplayItemListTest, FilterItem) {
436 gfx::Rect layer_rect(100, 100); 440 gfx::Rect layer_rect(100, 100);
437 FilterOperations filters; 441 FilterOperations filters;
438 unsigned char pixels[4 * 100 * 100] = {0}; 442 unsigned char pixels[4 * 100 * 100] = {0};
439 DisplayItemListSettings settings;
440 settings.use_cached_picture = true;
441 scoped_refptr<DisplayItemList> list = 443 scoped_refptr<DisplayItemList> list =
442 DisplayItemList::Create(layer_rect, settings); 444 DisplayItemList::Create(DisplayItemListSettings());
443 445
444 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50); 446 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50);
445 SkCanvas* source_canvas = source_surface->getCanvas(); 447 SkCanvas* source_canvas = source_surface->getCanvas();
446 source_canvas->clear(SkColorSetRGB(128, 128, 128)); 448 source_canvas->clear(SkColorSetRGB(128, 128, 128));
447 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot(); 449 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot();
448 450
449 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are 451 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are
450 // dependent on the provided |src| bounds. This means, for example, that 452 // dependent on the provided |src| bounds. This means, for example, that
451 // translating |src| results in a corresponding translation of |dst|. But this 453 // translating |src| results in a corresponding translation of |dst|. But this
452 // is not the case for all SkImageFilters; for some of them (e.g. 454 // is not the case for all SkImageFilters; for some of them (e.g.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 SkPaint blue_paint; 490 SkPaint blue_paint;
489 blue_paint.setColor(SK_ColorBLUE); 491 blue_paint.setColor(SK_ColorBLUE);
490 SkPaint red_paint; 492 SkPaint red_paint;
491 red_paint.setColor(SK_ColorRED); 493 red_paint.setColor(SK_ColorRED);
492 unsigned char pixels[4 * 100 * 100] = {0}; 494 unsigned char pixels[4 * 100 * 100] = {0};
493 495
494 gfx::PointF offset(8.f, 9.f); 496 gfx::PointF offset(8.f, 9.f);
495 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); 497 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
496 498
497 DisplayItemListSettings no_caching_settings; 499 DisplayItemListSettings no_caching_settings;
498 no_caching_settings.use_cached_picture = false;
499 scoped_refptr<DisplayItemList> list_without_caching = 500 scoped_refptr<DisplayItemList> list_without_caching =
500 DisplayItemList::Create(layer_rect, no_caching_settings); 501 DisplayItemList::Create(no_caching_settings);
501 502
502 canvas = 503 canvas =
503 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 504 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
504 canvas->translate(offset.x(), offset.y()); 505 canvas->translate(offset.x(), offset.y());
505 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 506 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); 507 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
507 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 508 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
508 list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, 509 list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect,
509 picture); 510 picture);
510 list_without_caching->Finalize(); 511 list_without_caching->Finalize();
511 DrawDisplayList(pixels, layer_rect, list_without_caching); 512 DrawDisplayList(pixels, layer_rect, list_without_caching);
512 513
513 unsigned char expected_pixels[4 * 100 * 100] = {0}; 514 unsigned char expected_pixels[4 * 100 * 100] = {0};
514 DisplayItemListSettings caching_settings; 515 DisplayItemListSettings caching_settings;
515 caching_settings.use_cached_picture = true; 516 caching_settings.use_cached_picture = true;
516 scoped_refptr<DisplayItemList> list_with_caching = 517 scoped_refptr<DisplayItemList> list_with_caching =
517 DisplayItemList::Create(layer_rect, caching_settings); 518 DisplayItemList::Create(caching_settings);
518 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, 519 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect,
519 picture); 520 picture);
520 list_with_caching->Finalize(); 521 list_with_caching->Finalize();
521 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); 522 DrawDisplayList(expected_pixels, layer_rect, list_with_caching);
522 523
523 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 524 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
524 } 525 }
525 526
526 TEST(DisplayItemListTest, ApproximateMemoryUsage) { 527 TEST(DisplayItemListTest, ApproximateMemoryUsage) {
527 const int kNumCommandsInTestSkPicture = 1000; 528 const int kNumCommandsInTestSkPicture = 1000;
528 scoped_refptr<DisplayItemList> list; 529 scoped_refptr<DisplayItemList> list;
529 size_t memory_usage; 530 size_t memory_usage;
530 531
531 // Make an SkPicture whose size is known. 532 // Make an SkPicture whose size is known.
532 gfx::Rect layer_rect(100, 100); 533 gfx::Rect layer_rect(100, 100);
533 SkPictureRecorder recorder; 534 SkPictureRecorder recorder;
534 SkPaint blue_paint; 535 SkPaint blue_paint;
535 blue_paint.setColor(SK_ColorBLUE); 536 blue_paint.setColor(SK_ColorBLUE);
536 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); 537 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect));
537 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) 538 for (int i = 0; i < kNumCommandsInTestSkPicture; i++)
538 canvas->drawPaint(blue_paint); 539 canvas->drawPaint(blue_paint);
539 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 540 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
540 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); 541 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get());
541 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); 542 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint));
542 543
543 // Using a cached picture, we should get about the right size. 544 // Using a cached picture, we should get about the right size.
544 DisplayItemListSettings caching_settings; 545 DisplayItemListSettings caching_settings;
545 caching_settings.use_cached_picture = true; 546 caching_settings.use_cached_picture = true;
546 list = DisplayItemList::Create(layer_rect, caching_settings); 547 list = DisplayItemList::Create(caching_settings);
547 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); 548 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture);
548 list->Finalize(); 549 list->Finalize();
549 memory_usage = list->ApproximateMemoryUsage(); 550 memory_usage = list->ApproximateMemoryUsage();
550 EXPECT_GE(memory_usage, picture_size); 551 EXPECT_GE(memory_usage, picture_size);
551 EXPECT_LE(memory_usage, 2 * picture_size); 552 EXPECT_LE(memory_usage, 2 * picture_size);
552 553
553 // Using no cached picture, we should still get the right size. 554 // Using no cached picture, we should still get the right size.
554 DisplayItemListSettings no_caching_settings; 555 DisplayItemListSettings no_caching_settings;
555 no_caching_settings.use_cached_picture = false; 556 no_caching_settings.use_cached_picture = false;
556 list = DisplayItemList::Create(layer_rect, no_caching_settings); 557 list = DisplayItemList::Create(no_caching_settings);
557 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); 558 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture);
558 list->Finalize(); 559 list->Finalize();
559 memory_usage = list->ApproximateMemoryUsage(); 560 memory_usage = list->ApproximateMemoryUsage();
560 EXPECT_GE(memory_usage, picture_size); 561 EXPECT_GE(memory_usage, picture_size);
561 EXPECT_LE(memory_usage, 2 * picture_size); 562 EXPECT_LE(memory_usage, 2 * picture_size);
562
563 // 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
565 // categories being traced).
566 list = new DisplayItemList(layer_rect, caching_settings, true);
567 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture);
568 list->Finalize();
569 memory_usage = list->ApproximateMemoryUsage();
570 EXPECT_EQ(static_cast<size_t>(0), memory_usage);
571 } 563 }
572 564
573 TEST(DisplayItemListTest, AsValueWithRectAndNoItems) { 565 TEST(DisplayItemListTest, AsValueWithNoItems) {
574 scoped_refptr<DisplayItemList> list = 566 scoped_refptr<DisplayItemList> list =
575 DisplayItemList::Create(gfx::Rect(1, 2, 8, 9), DisplayItemListSettings()); 567 DisplayItemList::Create(DisplayItemListSettings());
568 list->SetRetainVisualRectsForTesting(true);
576 list->Finalize(); 569 list->Finalize();
577 570
578 std::string value = list->AsValue(true)->ToString(); 571 std::string value = list->AsValue(true)->ToString();
579 EXPECT_NE(value.find("\"items\":[]"), std::string::npos); 572 EXPECT_NE(value.find("\"items\":[]"), std::string::npos);
580 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 573 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
581 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 574 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
582 575
583 value = list->AsValue(false)->ToString(); 576 value = list->AsValue(false)->ToString();
584 EXPECT_EQ(value.find("\"items\":"), std::string::npos); 577 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
585 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 578 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
586 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 579 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
587 } 580 }
588 581
589 TEST(DisplayItemListTest, AsValueWithRectAndItems) { 582 TEST(DisplayItemListTest, AsValueWithItems) {
590 gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9); 583 gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9);
591 scoped_refptr<DisplayItemList> list = 584 scoped_refptr<DisplayItemList> list =
592 DisplayItemList::Create(layer_rect, DisplayItemListSettings()); 585 DisplayItemList::Create(DisplayItemListSettings());
586 list->SetRetainVisualRectsForTesting(true);
593 gfx::Transform transform; 587 gfx::Transform transform;
594 transform.Translate(6.f, 7.f); 588 transform.Translate(6.f, 7.f);
595 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); 589 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform);
596 AppendFirstSerializationTestPicture(list, layer_rect.size()); 590 AppendFirstSerializationTestPicture(list, layer_rect.size());
597 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); 591 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect);
598 list->Finalize(); 592 list->Finalize();
599 593
600 std::string value = list->AsValue(true)->ToString(); 594 std::string value = list->AsValue(true)->ToString();
601 EXPECT_NE(value.find("{\"items\":[\"TransformDisplayItem"), 595 EXPECT_NE(value.find("{\"items\":[\"TransformDisplayItem"),
602 std::string::npos); 596 std::string::npos);
603 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 597 EXPECT_NE(value.find("visualRect: [0,0 42x42]"), std::string::npos);
604 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 598 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
605 599
606 value = list->AsValue(false)->ToString(); 600 value = list->AsValue(false)->ToString();
607 EXPECT_EQ(value.find("{\"items\":[\"TransformDisplayItem"), 601 EXPECT_EQ(value.find("{\"items\":[\"TransformDisplayItem"),
608 std::string::npos); 602 std::string::npos);
609 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 603 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
610 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 604 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
611 } 605 }
612 606
613 TEST(DisplayItemListTest, AsValueWithEmptyRectAndNoItems) {
614 scoped_refptr<DisplayItemList> list =
615 DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings());
616 list->Finalize();
617
618 std::string value = list->AsValue(true)->ToString();
619 EXPECT_NE(value.find("\"items\":[]"), std::string::npos);
620 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
621 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
622
623 value = list->AsValue(false)->ToString();
624 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
625 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
626 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
627 }
628
629 TEST(DisplayItemListTest, AsValueWithEmptyRectAndItems) {
630 scoped_refptr<DisplayItemList> list =
631 DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings());
632 gfx::Transform transform;
633 transform.Translate(6.f, 7.f);
634 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform);
635 AppendFirstSerializationTestPicture(list, gfx::Size());
636 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect);
637 list->Finalize();
638
639 std::string value = list->AsValue(true)->ToString();
640 EXPECT_NE(value.find("\"items\":[\"TransformDisplayItem"), std::string::npos);
641 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
643 // item, though the overall list has no skp64 as the layer rect is empty.
644 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
645
646 value = list->AsValue(false)->ToString();
647 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
648 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
650 // layer rect is empty.
651 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
652 }
653
654 } // namespace cc 607 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698