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

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: Sync to head and flip for LayoutInline. Created 4 years, 6 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 settings.ToProtobuf(&proto); 113 settings.ToProtobuf(&proto);
114 DisplayItemListSettings deserialized(proto); 114 DisplayItemListSettings deserialized(proto);
115 EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture); 115 EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture);
116 } 116 }
117 } 117 }
118 118
119 TEST(DisplayItemListTest, SerializeSingleDrawingItem) { 119 TEST(DisplayItemListTest, SerializeSingleDrawingItem) {
120 gfx::Size layer_size(10, 10); 120 gfx::Size layer_size(10, 10);
121 121
122 DisplayItemListSettings settings; 122 DisplayItemListSettings settings;
123 scoped_refptr<DisplayItemList> list = 123 settings.use_cached_picture = true;
124 DisplayItemList::Create(gfx::Rect(layer_size), settings); 124 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
125 list->SetRetainVisualRectsForTesting(true);
125 126
126 // Build the DrawingDisplayItem. 127 // Build the DrawingDisplayItem.
127 AppendFirstSerializationTestPicture(list, layer_size); 128 AppendFirstSerializationTestPicture(list, layer_size);
128 129
129 ValidateDisplayItemListSerialization(layer_size, list); 130 ValidateDisplayItemListSerialization(layer_size, list);
130 } 131 }
131 132
132 TEST(DisplayItemListTest, SerializeClipItem) { 133 TEST(DisplayItemListTest, SerializeClipItem) {
133 gfx::Size layer_size(10, 10); 134 gfx::Size layer_size(10, 10);
134 135
135 DisplayItemListSettings settings; 136 DisplayItemListSettings settings;
136 scoped_refptr<DisplayItemList> list = 137 settings.use_cached_picture = true;
137 DisplayItemList::Create(gfx::Rect(layer_size), settings); 138 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
139 list->SetRetainVisualRectsForTesting(true);
138 140
139 // Build the DrawingDisplayItem. 141 // Build the DrawingDisplayItem.
140 AppendFirstSerializationTestPicture(list, layer_size); 142 AppendFirstSerializationTestPicture(list, layer_size);
141 143
142 // Build the ClipDisplayItem. 144 // Build the ClipDisplayItem.
143 gfx::Rect clip_rect(6, 6, 1, 1); 145 gfx::Rect clip_rect(6, 6, 1, 1);
144 std::vector<SkRRect> rrects; 146 std::vector<SkRRect> rrects;
145 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); 147 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f)));
146 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, rrects); 148 list->CreateAndAppendItem<ClipDisplayItem>(kVisualRect, clip_rect, rrects);
147 149
148 // Build the second DrawingDisplayItem. 150 // Build the second DrawingDisplayItem.
149 AppendSecondSerializationTestPicture(list, layer_size); 151 AppendSecondSerializationTestPicture(list, layer_size);
150 152
151 // Build the EndClipDisplayItem. 153 // Build the EndClipDisplayItem.
152 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect); 154 list->CreateAndAppendItem<EndClipDisplayItem>(kVisualRect);
153 155
154 ValidateDisplayItemListSerialization(layer_size, list); 156 ValidateDisplayItemListSerialization(layer_size, list);
155 } 157 }
156 158
157 TEST(DisplayItemListTest, SerializeClipPathItem) { 159 TEST(DisplayItemListTest, SerializeClipPathItem) {
158 gfx::Size layer_size(10, 10); 160 gfx::Size layer_size(10, 10);
159 161
160 DisplayItemListSettings settings; 162 DisplayItemListSettings settings;
161 scoped_refptr<DisplayItemList> list = 163 settings.use_cached_picture = true;
162 DisplayItemList::Create(gfx::Rect(layer_size), settings); 164 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
165 list->SetRetainVisualRectsForTesting(true);
163 166
164 // Build the DrawingDisplayItem. 167 // Build the DrawingDisplayItem.
165 AppendFirstSerializationTestPicture(list, layer_size); 168 AppendFirstSerializationTestPicture(list, layer_size);
166 169
167 // Build the ClipPathDisplayItem. 170 // Build the ClipPathDisplayItem.
168 SkPath path; 171 SkPath path;
169 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); 172 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction);
170 list->CreateAndAppendItem<ClipPathDisplayItem>( 173 list->CreateAndAppendItem<ClipPathDisplayItem>(
171 kVisualRect, path, SkRegion::Op::kReplace_Op, false); 174 kVisualRect, path, SkRegion::Op::kReplace_Op, false);
172 175
173 // Build the second DrawingDisplayItem. 176 // Build the second DrawingDisplayItem.
174 AppendSecondSerializationTestPicture(list, layer_size); 177 AppendSecondSerializationTestPicture(list, layer_size);
175 178
176 // Build the EndClipPathDisplayItem. 179 // Build the EndClipPathDisplayItem.
177 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect); 180 list->CreateAndAppendItem<EndClipPathDisplayItem>(kVisualRect);
178 181
179 ValidateDisplayItemListSerialization(layer_size, list); 182 ValidateDisplayItemListSerialization(layer_size, list);
180 } 183 }
181 184
182 TEST(DisplayItemListTest, SerializeCompositingItem) { 185 TEST(DisplayItemListTest, SerializeCompositingItem) {
183 gfx::Size layer_size(10, 10); 186 gfx::Size layer_size(10, 10);
184 187
185 DisplayItemListSettings settings; 188 DisplayItemListSettings settings;
186 scoped_refptr<DisplayItemList> list = 189 settings.use_cached_picture = true;
187 DisplayItemList::Create(gfx::Rect(layer_size), settings); 190 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
191 list->SetRetainVisualRectsForTesting(true);
188 192
189 // Build the DrawingDisplayItem. 193 // Build the DrawingDisplayItem.
190 AppendFirstSerializationTestPicture(list, layer_size); 194 AppendFirstSerializationTestPicture(list, layer_size);
191 195
192 // Build the CompositingDisplayItem. 196 // Build the CompositingDisplayItem.
193 list->CreateAndAppendItem<CompositingDisplayItem>( 197 list->CreateAndAppendItem<CompositingDisplayItem>(
194 kVisualRect, 150, SkXfermode::Mode::kDst_Mode, nullptr, 198 kVisualRect, 150, SkXfermode::Mode::kDst_Mode, nullptr,
195 SkColorMatrixFilter::MakeLightingFilter(SK_ColorRED, SK_ColorGREEN), 199 SkColorMatrixFilter::MakeLightingFilter(SK_ColorRED, SK_ColorGREEN),
196 false); 200 false);
197 201
198 // Build the second DrawingDisplayItem. 202 // Build the second DrawingDisplayItem.
199 AppendSecondSerializationTestPicture(list, layer_size); 203 AppendSecondSerializationTestPicture(list, layer_size);
200 204
201 // Build the EndCompositingDisplayItem. 205 // Build the EndCompositingDisplayItem.
202 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect); 206 list->CreateAndAppendItem<EndCompositingDisplayItem>(kVisualRect);
203 207
204 ValidateDisplayItemListSerialization(layer_size, list); 208 ValidateDisplayItemListSerialization(layer_size, list);
205 } 209 }
206 210
207 TEST(DisplayItemListTest, SerializeFloatClipItem) { 211 TEST(DisplayItemListTest, SerializeFloatClipItem) {
208 gfx::Size layer_size(10, 10); 212 gfx::Size layer_size(10, 10);
209 213
210 DisplayItemListSettings settings; 214 DisplayItemListSettings settings;
211 scoped_refptr<DisplayItemList> list = 215 settings.use_cached_picture = true;
212 DisplayItemList::Create(gfx::Rect(layer_size), settings); 216 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
217 list->SetRetainVisualRectsForTesting(true);
213 218
214 // Build the DrawingDisplayItem. 219 // Build the DrawingDisplayItem.
215 AppendFirstSerializationTestPicture(list, layer_size); 220 AppendFirstSerializationTestPicture(list, layer_size);
216 221
217 // Build the FloatClipDisplayItem. 222 // Build the FloatClipDisplayItem.
218 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); 223 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f);
219 list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect, clip_rect); 224 list->CreateAndAppendItem<FloatClipDisplayItem>(kVisualRect, clip_rect);
220 225
221 // Build the second DrawingDisplayItem. 226 // Build the second DrawingDisplayItem.
222 AppendSecondSerializationTestPicture(list, layer_size); 227 AppendSecondSerializationTestPicture(list, layer_size);
223 228
224 // Build the EndFloatClipDisplayItem. 229 // Build the EndFloatClipDisplayItem.
225 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect); 230 list->CreateAndAppendItem<EndFloatClipDisplayItem>(kVisualRect);
226 231
227 ValidateDisplayItemListSerialization(layer_size, list); 232 ValidateDisplayItemListSerialization(layer_size, list);
228 } 233 }
229 234
230 TEST(DisplayItemListTest, SerializeTransformItem) { 235 TEST(DisplayItemListTest, SerializeTransformItem) {
231 gfx::Size layer_size(10, 10); 236 gfx::Size layer_size(10, 10);
232 237
233 DisplayItemListSettings settings; 238 DisplayItemListSettings settings;
234 scoped_refptr<DisplayItemList> list = 239 settings.use_cached_picture = true;
235 DisplayItemList::Create(gfx::Rect(layer_size), settings); 240 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
241 list->SetRetainVisualRectsForTesting(true);
236 242
237 // Build the DrawingDisplayItem. 243 // Build the DrawingDisplayItem.
238 AppendFirstSerializationTestPicture(list, layer_size); 244 AppendFirstSerializationTestPicture(list, layer_size);
239 245
240 // Build the TransformDisplayItem. 246 // Build the TransformDisplayItem.
241 gfx::Transform transform; 247 gfx::Transform transform;
242 transform.Scale(1.25f, 1.25f); 248 transform.Scale(1.25f, 1.25f);
243 transform.Translate(-1.f, -1.f); 249 transform.Translate(-1.f, -1.f);
244 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); 250 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform);
245 251
246 // Build the second DrawingDisplayItem. 252 // Build the second DrawingDisplayItem.
247 AppendSecondSerializationTestPicture(list, layer_size); 253 AppendSecondSerializationTestPicture(list, layer_size);
248 254
249 // Build the EndTransformDisplayItem. 255 // Build the EndTransformDisplayItem.
250 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); 256 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect);
251 257
252 ValidateDisplayItemListSerialization(layer_size, list); 258 ValidateDisplayItemListSerialization(layer_size, list);
253 } 259 }
254 260
255 TEST(DisplayItemListTest, SingleDrawingItem) { 261 TEST(DisplayItemListTest, SingleDrawingItem) {
256 gfx::Rect layer_rect(100, 100); 262 gfx::Rect layer_rect(100, 100);
257 SkPictureRecorder recorder; 263 SkPictureRecorder recorder;
258 sk_sp<SkCanvas> canvas; 264 sk_sp<SkCanvas> canvas;
259 SkPaint blue_paint; 265 SkPaint blue_paint;
260 blue_paint.setColor(SK_ColorBLUE); 266 blue_paint.setColor(SK_ColorBLUE);
261 SkPaint red_paint; 267 SkPaint red_paint;
262 red_paint.setColor(SK_ColorRED); 268 red_paint.setColor(SK_ColorRED);
263 unsigned char pixels[4 * 100 * 100] = {0}; 269 unsigned char pixels[4 * 100 * 100] = {0};
264 DisplayItemListSettings settings; 270 DisplayItemListSettings settings;
265 scoped_refptr<DisplayItemList> list = 271 settings.use_cached_picture = true;
266 DisplayItemList::Create(layer_rect, settings); 272 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
267 273
268 gfx::PointF offset(8.f, 9.f); 274 gfx::PointF offset(8.f, 9.f);
269 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); 275 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
270 canvas = 276 canvas =
271 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 277 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
272 canvas->translate(offset.x(), offset.y()); 278 canvas->translate(offset.x(), offset.y());
273 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 279 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
274 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 280 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
275 list->CreateAndAppendItem<DrawingDisplayItem>( 281 list->CreateAndAppendItem<DrawingDisplayItem>(
276 kVisualRect, recorder.finishRecordingAsPicture()); 282 kVisualRect, recorder.finishRecordingAsPicture());
(...skipping 21 matching lines...) Expand all
298 gfx::Rect layer_rect(100, 100); 304 gfx::Rect layer_rect(100, 100);
299 SkPictureRecorder recorder; 305 SkPictureRecorder recorder;
300 sk_sp<SkCanvas> canvas; 306 sk_sp<SkCanvas> canvas;
301 SkPaint blue_paint; 307 SkPaint blue_paint;
302 blue_paint.setColor(SK_ColorBLUE); 308 blue_paint.setColor(SK_ColorBLUE);
303 SkPaint red_paint; 309 SkPaint red_paint;
304 red_paint.setColor(SK_ColorRED); 310 red_paint.setColor(SK_ColorRED);
305 unsigned char pixels[4 * 100 * 100] = {0}; 311 unsigned char pixels[4 * 100 * 100] = {0};
306 DisplayItemListSettings settings; 312 DisplayItemListSettings settings;
307 settings.use_cached_picture = true; 313 settings.use_cached_picture = true;
308 scoped_refptr<DisplayItemList> list = 314 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
309 DisplayItemList::Create(layer_rect, settings);
310 315
311 gfx::PointF first_offset(8.f, 9.f); 316 gfx::PointF first_offset(8.f, 9.f);
312 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); 317 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
313 canvas = sk_ref_sp( 318 canvas = sk_ref_sp(
314 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); 319 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
315 canvas->translate(first_offset.x(), first_offset.y()); 320 canvas->translate(first_offset.x(), first_offset.y());
316 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 321 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
317 list->CreateAndAppendItem<DrawingDisplayItem>( 322 list->CreateAndAppendItem<DrawingDisplayItem>(
318 kVisualRect, recorder.finishRecordingAsPicture()); 323 kVisualRect, recorder.finishRecordingAsPicture());
319 324
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 gfx::Rect layer_rect(100, 100); 363 gfx::Rect layer_rect(100, 100);
359 SkPictureRecorder recorder; 364 SkPictureRecorder recorder;
360 sk_sp<SkCanvas> canvas; 365 sk_sp<SkCanvas> canvas;
361 SkPaint blue_paint; 366 SkPaint blue_paint;
362 blue_paint.setColor(SK_ColorBLUE); 367 blue_paint.setColor(SK_ColorBLUE);
363 SkPaint red_paint; 368 SkPaint red_paint;
364 red_paint.setColor(SK_ColorRED); 369 red_paint.setColor(SK_ColorRED);
365 unsigned char pixels[4 * 100 * 100] = {0}; 370 unsigned char pixels[4 * 100 * 100] = {0};
366 DisplayItemListSettings settings; 371 DisplayItemListSettings settings;
367 settings.use_cached_picture = true; 372 settings.use_cached_picture = true;
368 scoped_refptr<DisplayItemList> list = 373 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
369 DisplayItemList::Create(layer_rect, settings);
370 374
371 gfx::PointF first_offset(8.f, 9.f); 375 gfx::PointF first_offset(8.f, 9.f);
372 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); 376 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
373 canvas = sk_ref_sp( 377 canvas = sk_ref_sp(
374 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); 378 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
375 canvas->translate(first_offset.x(), first_offset.y()); 379 canvas->translate(first_offset.x(), first_offset.y());
376 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 380 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
377 list->CreateAndAppendItem<DrawingDisplayItem>( 381 list->CreateAndAppendItem<DrawingDisplayItem>(
378 kVisualRect, recorder.finishRecordingAsPicture()); 382 kVisualRect, recorder.finishRecordingAsPicture());
379 383
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 50.f + second_offset.x(), 50.f + second_offset.y(), 415 50.f + second_offset.x(), 50.f + second_offset.y(),
412 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); 416 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint);
413 417
414 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 418 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
415 } 419 }
416 420
417 TEST(DisplayItemListTest, FilterItem) { 421 TEST(DisplayItemListTest, FilterItem) {
418 gfx::Rect layer_rect(100, 100); 422 gfx::Rect layer_rect(100, 100);
419 FilterOperations filters; 423 FilterOperations filters;
420 unsigned char pixels[4 * 100 * 100] = {0}; 424 unsigned char pixels[4 * 100 * 100] = {0};
421 DisplayItemListSettings settings;
422 settings.use_cached_picture = true;
423 scoped_refptr<DisplayItemList> list = 425 scoped_refptr<DisplayItemList> list =
424 DisplayItemList::Create(layer_rect, settings); 426 DisplayItemList::Create(DisplayItemListSettings());
425 427
426 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50); 428 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50);
427 SkCanvas* source_canvas = source_surface->getCanvas(); 429 SkCanvas* source_canvas = source_surface->getCanvas();
428 source_canvas->clear(SkColorSetRGB(128, 128, 128)); 430 source_canvas->clear(SkColorSetRGB(128, 128, 128));
429 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot(); 431 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot();
430 432
431 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are 433 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are
432 // dependent on the provided |src| bounds. This means, for example, that 434 // dependent on the provided |src| bounds. This means, for example, that
433 // translating |src| results in a corresponding translation of |dst|. But this 435 // translating |src| results in a corresponding translation of |dst|. But this
434 // is not the case for all SkImageFilters; for some of them (e.g. 436 // 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
470 SkPaint blue_paint; 472 SkPaint blue_paint;
471 blue_paint.setColor(SK_ColorBLUE); 473 blue_paint.setColor(SK_ColorBLUE);
472 SkPaint red_paint; 474 SkPaint red_paint;
473 red_paint.setColor(SK_ColorRED); 475 red_paint.setColor(SK_ColorRED);
474 unsigned char pixels[4 * 100 * 100] = {0}; 476 unsigned char pixels[4 * 100 * 100] = {0};
475 477
476 gfx::PointF offset(8.f, 9.f); 478 gfx::PointF offset(8.f, 9.f);
477 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); 479 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
478 480
479 DisplayItemListSettings no_caching_settings; 481 DisplayItemListSettings no_caching_settings;
480 no_caching_settings.use_cached_picture = false;
481 scoped_refptr<DisplayItemList> list_without_caching = 482 scoped_refptr<DisplayItemList> list_without_caching =
482 DisplayItemList::Create(layer_rect, no_caching_settings); 483 DisplayItemList::Create(no_caching_settings);
483 484
484 canvas = 485 canvas =
485 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 486 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
486 canvas->translate(offset.x(), offset.y()); 487 canvas->translate(offset.x(), offset.y());
487 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 488 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
488 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 489 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
489 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 490 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
490 list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, 491 list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect,
491 picture); 492 picture);
492 list_without_caching->Finalize(); 493 list_without_caching->Finalize();
493 DrawDisplayList(pixels, layer_rect, list_without_caching); 494 DrawDisplayList(pixels, layer_rect, list_without_caching);
494 495
495 unsigned char expected_pixels[4 * 100 * 100] = {0}; 496 unsigned char expected_pixels[4 * 100 * 100] = {0};
496 DisplayItemListSettings caching_settings; 497 DisplayItemListSettings caching_settings;
497 caching_settings.use_cached_picture = true; 498 caching_settings.use_cached_picture = true;
498 scoped_refptr<DisplayItemList> list_with_caching = 499 scoped_refptr<DisplayItemList> list_with_caching =
499 DisplayItemList::Create(layer_rect, caching_settings); 500 DisplayItemList::Create(caching_settings);
500 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, 501 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect,
501 picture); 502 picture);
502 list_with_caching->Finalize(); 503 list_with_caching->Finalize();
503 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); 504 DrawDisplayList(expected_pixels, layer_rect, list_with_caching);
504 505
505 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 506 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
506 } 507 }
507 508
508 TEST(DisplayItemListTest, ApproximateMemoryUsage) { 509 TEST(DisplayItemListTest, ApproximateMemoryUsage) {
509 const int kNumCommandsInTestSkPicture = 1000; 510 const int kNumCommandsInTestSkPicture = 1000;
510 scoped_refptr<DisplayItemList> list; 511 scoped_refptr<DisplayItemList> list;
511 size_t memory_usage; 512 size_t memory_usage;
512 513
513 // Make an SkPicture whose size is known. 514 // Make an SkPicture whose size is known.
514 gfx::Rect layer_rect(100, 100); 515 gfx::Rect layer_rect(100, 100);
515 SkPictureRecorder recorder; 516 SkPictureRecorder recorder;
516 SkPaint blue_paint; 517 SkPaint blue_paint;
517 blue_paint.setColor(SK_ColorBLUE); 518 blue_paint.setColor(SK_ColorBLUE);
518 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); 519 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect));
519 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) 520 for (int i = 0; i < kNumCommandsInTestSkPicture; i++)
520 canvas->drawPaint(blue_paint); 521 canvas->drawPaint(blue_paint);
521 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 522 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
522 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); 523 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get());
523 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); 524 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint));
524 525
525 // Using a cached picture, we should get about the right size. 526 // Using a cached picture, we should get about the right size.
526 DisplayItemListSettings caching_settings; 527 DisplayItemListSettings caching_settings;
527 caching_settings.use_cached_picture = true; 528 caching_settings.use_cached_picture = true;
528 list = DisplayItemList::Create(layer_rect, caching_settings); 529 list = DisplayItemList::Create(caching_settings);
529 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); 530 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture);
530 list->Finalize(); 531 list->Finalize();
531 memory_usage = list->ApproximateMemoryUsage(); 532 memory_usage = list->ApproximateMemoryUsage();
532 EXPECT_GE(memory_usage, picture_size); 533 EXPECT_GE(memory_usage, picture_size);
533 EXPECT_LE(memory_usage, 2 * picture_size); 534 EXPECT_LE(memory_usage, 2 * picture_size);
534 535
535 // Using no cached picture, we should still get the right size. 536 // Using no cached picture, we should still get the right size.
536 DisplayItemListSettings no_caching_settings; 537 DisplayItemListSettings no_caching_settings;
537 no_caching_settings.use_cached_picture = false; 538 no_caching_settings.use_cached_picture = false;
538 list = DisplayItemList::Create(layer_rect, no_caching_settings); 539 list = DisplayItemList::Create(no_caching_settings);
539 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); 540 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture);
540 list->Finalize(); 541 list->Finalize();
541 memory_usage = list->ApproximateMemoryUsage(); 542 memory_usage = list->ApproximateMemoryUsage();
542 EXPECT_GE(memory_usage, picture_size); 543 EXPECT_GE(memory_usage, picture_size);
543 EXPECT_LE(memory_usage, 2 * picture_size); 544 EXPECT_LE(memory_usage, 2 * picture_size);
544
545 // To avoid double counting, we expect zero size to be computed if both the
546 // picture and items are retained (currently this only happens due to certain
547 // categories being traced).
548 list = new DisplayItemList(layer_rect, caching_settings, true);
549 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture);
550 list->Finalize();
551 memory_usage = list->ApproximateMemoryUsage();
552 EXPECT_EQ(static_cast<size_t>(0), memory_usage);
553 } 545 }
554 546
555 TEST(DisplayItemListTest, AsValueWithRectAndNoItems) { 547 TEST(DisplayItemListTest, AsValueWithNoItems) {
556 scoped_refptr<DisplayItemList> list = 548 scoped_refptr<DisplayItemList> list =
557 DisplayItemList::Create(gfx::Rect(1, 2, 8, 9), DisplayItemListSettings()); 549 DisplayItemList::Create(DisplayItemListSettings());
550 list->SetRetainVisualRectsForTesting(true);
558 list->Finalize(); 551 list->Finalize();
559 552
560 std::string value = list->AsValue(true)->ToString(); 553 std::string value = list->AsValue(true)->ToString();
561 EXPECT_NE(value.find("\"items\":[]"), std::string::npos); 554 EXPECT_NE(value.find("\"items\":[]"), std::string::npos);
562 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 555 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
563 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 556 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
564 557
565 value = list->AsValue(false)->ToString(); 558 value = list->AsValue(false)->ToString();
566 EXPECT_EQ(value.find("\"items\":"), std::string::npos); 559 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
567 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 560 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
568 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 561 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
569 } 562 }
570 563
571 TEST(DisplayItemListTest, AsValueWithRectAndItems) { 564 TEST(DisplayItemListTest, AsValueWithItems) {
572 gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9); 565 gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9);
573 scoped_refptr<DisplayItemList> list = 566 scoped_refptr<DisplayItemList> list =
574 DisplayItemList::Create(layer_rect, DisplayItemListSettings()); 567 DisplayItemList::Create(DisplayItemListSettings());
568 list->SetRetainVisualRectsForTesting(true);
575 gfx::Transform transform; 569 gfx::Transform transform;
576 transform.Translate(6.f, 7.f); 570 transform.Translate(6.f, 7.f);
577 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); 571 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform);
578 AppendFirstSerializationTestPicture(list, layer_rect.size()); 572 AppendFirstSerializationTestPicture(list, layer_rect.size());
579 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); 573 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect);
580 list->Finalize(); 574 list->Finalize();
581 575
582 std::string value = list->AsValue(true)->ToString(); 576 std::string value = list->AsValue(true)->ToString();
583 EXPECT_NE(value.find("{\"items\":[\"TransformDisplayItem"), 577 EXPECT_NE(value.find("{\"items\":[\"TransformDisplayItem"),
584 std::string::npos); 578 std::string::npos);
585 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 579 EXPECT_NE(value.find("visualRect: [0,0 42x42]"), std::string::npos);
586 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 580 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
587 581
588 value = list->AsValue(false)->ToString(); 582 value = list->AsValue(false)->ToString();
589 EXPECT_EQ(value.find("{\"items\":[\"TransformDisplayItem"), 583 EXPECT_EQ(value.find("{\"items\":[\"TransformDisplayItem"),
590 std::string::npos); 584 std::string::npos);
591 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 585 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
592 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 586 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
593 } 587 }
594 588
595 TEST(DisplayItemListTest, AsValueWithEmptyRectAndNoItems) {
596 scoped_refptr<DisplayItemList> list =
597 DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings());
598 list->Finalize();
599
600 std::string value = list->AsValue(true)->ToString();
601 EXPECT_NE(value.find("\"items\":[]"), std::string::npos);
602 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
603 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
604
605 value = list->AsValue(false)->ToString();
606 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
607 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
608 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
609 }
610
611 TEST(DisplayItemListTest, AsValueWithEmptyRectAndItems) {
612 scoped_refptr<DisplayItemList> list =
613 DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings());
614 gfx::Transform transform;
615 transform.Translate(6.f, 7.f);
616 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform);
617 AppendFirstSerializationTestPicture(list, gfx::Size());
618 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect);
619 list->Finalize();
620
621 std::string value = list->AsValue(true)->ToString();
622 EXPECT_NE(value.find("\"items\":[\"TransformDisplayItem"), std::string::npos);
623 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
624 // There should be one skp64 entry present associated with the test picture
625 // item, though the overall list has no skp64 as the layer rect is empty.
626 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
627
628 value = list->AsValue(false)->ToString();
629 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
630 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
631 // There should be no skp64 entry present as the items aren't included and the
632 // layer rect is empty.
633 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
634 }
635
636 } // namespace cc 589 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698