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

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

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

Powered by Google App Engine
This is Rietveld 408576698