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

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

Issue 1835843002: WIP: Fix foreignObject cullrect Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/playback/display_item_list.cc ('k') | cc/playback/display_list_raster_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 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 skia::RefPtr<SkColorFilter> filter = skia::AdoptRef( 197 skia::RefPtr<SkColorFilter> filter = skia::AdoptRef(
194 SkColorMatrixFilter::CreateLightingFilter(SK_ColorRED, SK_ColorGREEN)); 198 SkColorMatrixFilter::CreateLightingFilter(SK_ColorRED, SK_ColorGREEN));
195 list->CreateAndAppendItem<CompositingDisplayItem>( 199 list->CreateAndAppendItem<CompositingDisplayItem>(
196 kVisualRect, 150, SkXfermode::Mode::kDst_Mode, nullptr, filter, false); 200 kVisualRect, 150, SkXfermode::Mode::kDst_Mode, nullptr, filter, 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 skia::RefPtr<SkCanvas> canvas; 264 skia::RefPtr<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 = skia::SharePtr( 276 canvas = skia::SharePtr(
271 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 277 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 skia::RefPtr<SkCanvas> canvas; 306 skia::RefPtr<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 = skia::SharePtr( 318 canvas = skia::SharePtr(
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 skia::RefPtr<SkCanvas> canvas; 365 skia::RefPtr<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 = skia::SharePtr( 377 canvas = skia::SharePtr(
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 skia::RefPtr<SkSurface> source_surface = 428 skia::RefPtr<SkSurface> source_surface =
427 skia::AdoptRef(SkSurface::NewRasterN32Premul(50, 50)); 429 skia::AdoptRef(SkSurface::NewRasterN32Premul(50, 50));
428 SkCanvas* source_canvas = source_surface->getCanvas(); 430 SkCanvas* source_canvas = source_surface->getCanvas();
429 source_canvas->clear(SkColorSetRGB(128, 128, 128)); 431 source_canvas->clear(SkColorSetRGB(128, 128, 128));
430 skia::RefPtr<SkImage> source_image = 432 skia::RefPtr<SkImage> source_image =
431 skia::AdoptRef(source_surface->newImageSnapshot()); 433 skia::AdoptRef(source_surface->newImageSnapshot());
432 434
433 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are 435 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are
434 // dependent on the provided |src| bounds. This means, for example, that 436 // dependent on the provided |src| bounds. This means, for example, that
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 SkPaint blue_paint; 475 SkPaint blue_paint;
474 blue_paint.setColor(SK_ColorBLUE); 476 blue_paint.setColor(SK_ColorBLUE);
475 SkPaint red_paint; 477 SkPaint red_paint;
476 red_paint.setColor(SK_ColorRED); 478 red_paint.setColor(SK_ColorRED);
477 unsigned char pixels[4 * 100 * 100] = {0}; 479 unsigned char pixels[4 * 100 * 100] = {0};
478 480
479 gfx::PointF offset(8.f, 9.f); 481 gfx::PointF offset(8.f, 9.f);
480 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); 482 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
481 483
482 DisplayItemListSettings no_caching_settings; 484 DisplayItemListSettings no_caching_settings;
483 no_caching_settings.use_cached_picture = false;
484 scoped_refptr<DisplayItemList> list_without_caching = 485 scoped_refptr<DisplayItemList> list_without_caching =
485 DisplayItemList::Create(layer_rect, no_caching_settings); 486 DisplayItemList::Create(no_caching_settings);
486 487
487 canvas = skia::SharePtr( 488 canvas = skia::SharePtr(
488 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 489 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
489 canvas->translate(offset.x(), offset.y()); 490 canvas->translate(offset.x(), offset.y());
490 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 491 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
491 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 492 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
492 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 493 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
493 list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, 494 list_without_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect,
494 picture); 495 picture);
495 list_without_caching->Finalize(); 496 list_without_caching->Finalize();
496 DrawDisplayList(pixels, layer_rect, list_without_caching); 497 DrawDisplayList(pixels, layer_rect, list_without_caching);
497 498
498 unsigned char expected_pixels[4 * 100 * 100] = {0}; 499 unsigned char expected_pixels[4 * 100 * 100] = {0};
499 DisplayItemListSettings caching_settings; 500 DisplayItemListSettings caching_settings;
500 caching_settings.use_cached_picture = true; 501 caching_settings.use_cached_picture = true;
501 scoped_refptr<DisplayItemList> list_with_caching = 502 scoped_refptr<DisplayItemList> list_with_caching =
502 DisplayItemList::Create(layer_rect, caching_settings); 503 DisplayItemList::Create(caching_settings);
503 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, 504 list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect,
504 picture); 505 picture);
505 list_with_caching->Finalize(); 506 list_with_caching->Finalize();
506 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); 507 DrawDisplayList(expected_pixels, layer_rect, list_with_caching);
507 508
508 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 509 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
509 } 510 }
510 511
511 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithCachedPicture) {
512 gfx::Rect layer_rect(1000, 1000);
513 SkPictureRecorder recorder;
514 skia::RefPtr<SkCanvas> canvas;
515
516 DisplayItemListSettings settings;
517 settings.use_cached_picture = true;
518 scoped_refptr<DisplayItemList> list =
519 DisplayItemList::Create(layer_rect, settings);
520 canvas =
521 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect)));
522
523 SkPath path;
524 path.moveTo(0, 0);
525 path.lineTo(0, 100);
526 path.lineTo(50, 50);
527 path.lineTo(100, 100);
528 path.lineTo(100, 0);
529 path.close();
530
531 SkPaint paint;
532 paint.setAntiAlias(true);
533 canvas->drawPath(path, paint);
534
535 sk_sp<SkPicture> suitable_picture = recorder.finishRecordingAsPicture();
536 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, suitable_picture);
537 list->Finalize();
538
539 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger
540 // a veto.
541 EXPECT_TRUE(list->IsSuitableForGpuRasterization());
542
543 // Now check the RasterIntoCanvas path.
544 list = DisplayItemList::Create(layer_rect, settings);
545 DrawingDisplayItem suitable_item(suitable_picture);
546 list->RasterIntoCanvas(suitable_item);
547 list->Finalize();
548 EXPECT_TRUE(list->IsSuitableForGpuRasterization());
549
550 list = DisplayItemList::Create(layer_rect, settings);
551 canvas =
552 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect)));
553 for (int i = 0; i < 10; ++i)
554 canvas->drawPath(path, paint);
555 sk_sp<SkPicture> unsuitable_picture = recorder.finishRecordingAsPicture();
556 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect,
557 unsuitable_picture);
558 list->Finalize();
559
560 // A single DrawingDisplayItem with several large AA concave paths should
561 // trigger a veto.
562 EXPECT_FALSE(list->IsSuitableForGpuRasterization());
563
564 // Now check the RasterIntoCanvas path.
565 list = DisplayItemList::Create(layer_rect, settings);
566 DrawingDisplayItem unsuitable_item(unsuitable_picture);
567 list->RasterIntoCanvas(unsuitable_item);
568 list->Finalize();
569 EXPECT_FALSE(list->IsSuitableForGpuRasterization());
570 }
571
572 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) { 512 TEST(DisplayItemListTest, IsSuitableForGpuRasterizationWithoutCachedPicture) {
573 gfx::Rect layer_rect(1000, 1000); 513 gfx::Rect layer_rect(1000, 1000);
574 SkPictureRecorder recorder; 514 SkPictureRecorder recorder;
575 skia::RefPtr<SkCanvas> canvas; 515 skia::RefPtr<SkCanvas> canvas;
576 skia::RefPtr<SkPicture> picture; 516 skia::RefPtr<SkPicture> picture;
577 517
578 DisplayItemListSettings settings; 518 DisplayItemListSettings settings;
579 settings.use_cached_picture = false; 519 settings.use_cached_picture = false;
580 scoped_refptr<DisplayItemList> list = 520 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
581 DisplayItemList::Create(layer_rect, settings);
582 canvas = 521 canvas =
583 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); 522 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect)));
584 523
585 SkPath path; 524 SkPath path;
586 path.moveTo(0, 0); 525 path.moveTo(0, 0);
587 path.lineTo(0, 100); 526 path.lineTo(0, 100);
588 path.lineTo(50, 50); 527 path.lineTo(50, 50);
589 path.lineTo(100, 100); 528 path.lineTo(100, 100);
590 path.lineTo(100, 0); 529 path.lineTo(100, 0);
591 path.close(); 530 path.close();
592 531
593 SkPaint paint; 532 SkPaint paint;
594 paint.setAntiAlias(true); 533 paint.setAntiAlias(true);
595 canvas->drawPath(path, paint); 534 canvas->drawPath(path, paint);
596 535
597 list->CreateAndAppendItem<DrawingDisplayItem>( 536 list->CreateAndAppendItem<DrawingDisplayItem>(
598 kVisualRect, recorder.finishRecordingAsPicture()); 537 kVisualRect, recorder.finishRecordingAsPicture());
599 list->Finalize(); 538 list->Finalize();
600 539
601 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger 540 // A single DrawingDisplayItem with a large AA concave path shouldn't trigger
602 // a veto. 541 // a veto.
603 EXPECT_TRUE(list->IsSuitableForGpuRasterization()); 542 EXPECT_TRUE(list->IsSuitableForGpuRasterization());
604 543
605 list = DisplayItemList::Create(layer_rect, settings); 544 list = DisplayItemList::Create(settings);
606 canvas = 545 canvas =
607 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); 546 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect)));
608 for (int i = 0; i < 10; ++i) 547 for (int i = 0; i < 10; ++i)
609 canvas->drawPath(path, paint); 548 canvas->drawPath(path, paint);
610 list->CreateAndAppendItem<DrawingDisplayItem>( 549 list->CreateAndAppendItem<DrawingDisplayItem>(
611 kVisualRect, recorder.finishRecordingAsPicture()); 550 kVisualRect, recorder.finishRecordingAsPicture());
612 list->Finalize(); 551 list->Finalize();
613 552
614 // A single DrawingDisplayItem with several large AA concave paths should 553 // A single DrawingDisplayItem with several large AA concave paths should
615 // trigger a veto. 554 // trigger a veto.
616 EXPECT_FALSE(list->IsSuitableForGpuRasterization()); 555 EXPECT_FALSE(list->IsSuitableForGpuRasterization());
617 556
618 list = DisplayItemList::Create(layer_rect, settings); 557 list = DisplayItemList::Create(settings);
619 for (int i = 0; i < 10; ++i) { 558 for (int i = 0; i < 10; ++i) {
620 canvas = 559 canvas =
621 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect))); 560 skia::SharePtr(recorder.beginRecording(gfx::RectToSkRect(layer_rect)));
622 canvas->drawPath(path, paint); 561 canvas->drawPath(path, paint);
623 list->CreateAndAppendItem<DrawingDisplayItem>( 562 list->CreateAndAppendItem<DrawingDisplayItem>(
624 kVisualRect, recorder.finishRecordingAsPicture()); 563 kVisualRect, recorder.finishRecordingAsPicture());
625 } 564 }
626 list->Finalize(); 565 list->Finalize();
627 566
628 // Without a cached picture, having several DrawingDisplayItems that each 567 // Without a cached picture, having several DrawingDisplayItems that each
(...skipping 15 matching lines...) Expand all
644 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); 583 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect));
645 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) 584 for (int i = 0; i < kNumCommandsInTestSkPicture; i++)
646 canvas->drawPaint(blue_paint); 585 canvas->drawPaint(blue_paint);
647 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 586 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
648 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); 587 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get());
649 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); 588 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint));
650 589
651 // Using a cached picture, we should get about the right size. 590 // Using a cached picture, we should get about the right size.
652 DisplayItemListSettings caching_settings; 591 DisplayItemListSettings caching_settings;
653 caching_settings.use_cached_picture = true; 592 caching_settings.use_cached_picture = true;
654 list = DisplayItemList::Create(layer_rect, caching_settings); 593 list = DisplayItemList::Create(caching_settings);
655 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); 594 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture);
656 list->Finalize(); 595 list->Finalize();
657 memory_usage = list->ApproximateMemoryUsage(); 596 memory_usage = list->ApproximateMemoryUsage();
658 EXPECT_GE(memory_usage, picture_size); 597 EXPECT_GE(memory_usage, picture_size);
659 EXPECT_LE(memory_usage, 2 * picture_size); 598 EXPECT_LE(memory_usage, 2 * picture_size);
660 599
661 // Using no cached picture, we should still get the right size. 600 // Using no cached picture, we should still get the right size.
662 DisplayItemListSettings no_caching_settings; 601 DisplayItemListSettings no_caching_settings;
663 no_caching_settings.use_cached_picture = false; 602 no_caching_settings.use_cached_picture = false;
664 list = DisplayItemList::Create(layer_rect, no_caching_settings); 603 list = DisplayItemList::Create(no_caching_settings);
665 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture); 604 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture);
666 list->Finalize(); 605 list->Finalize();
667 memory_usage = list->ApproximateMemoryUsage(); 606 memory_usage = list->ApproximateMemoryUsage();
668 EXPECT_GE(memory_usage, picture_size); 607 EXPECT_GE(memory_usage, picture_size);
669 EXPECT_LE(memory_usage, 2 * picture_size); 608 EXPECT_LE(memory_usage, 2 * picture_size);
670
671 // To avoid double counting, we expect zero size to be computed if both the
672 // picture and items are retained (currently this only happens due to certain
673 // categories being traced).
674 list = new DisplayItemList(layer_rect, caching_settings, true);
675 list->CreateAndAppendItem<DrawingDisplayItem>(kVisualRect, picture);
676 list->Finalize();
677 memory_usage = list->ApproximateMemoryUsage();
678 EXPECT_EQ(static_cast<size_t>(0), memory_usage);
679 } 609 }
680 610
681 TEST(DisplayItemListTest, AsValueWithRectAndNoItems) { 611 TEST(DisplayItemListTest, AsValueWithNoItems) {
682 scoped_refptr<DisplayItemList> list = 612 scoped_refptr<DisplayItemList> list =
683 DisplayItemList::Create(gfx::Rect(1, 2, 8, 9), DisplayItemListSettings()); 613 DisplayItemList::Create(DisplayItemListSettings());
614 list->SetRetainVisualRectsForTesting(true);
684 list->Finalize(); 615 list->Finalize();
685 616
686 std::string value = list->AsValue(true)->ToString(); 617 std::string value = list->AsValue(true)->ToString();
687 EXPECT_NE(value.find("\"items\":[]"), std::string::npos); 618 EXPECT_NE(value.find("\"items\":[]"), std::string::npos);
688 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 619 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
689 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 620 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
690 621
691 value = list->AsValue(false)->ToString(); 622 value = list->AsValue(false)->ToString();
692 EXPECT_EQ(value.find("\"items\":"), std::string::npos); 623 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
693 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 624 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
694 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 625 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
695 } 626 }
696 627
697 TEST(DisplayItemListTest, AsValueWithRectAndItems) { 628 TEST(DisplayItemListTest, AsValueWithItems) {
698 gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9); 629 gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9);
699 scoped_refptr<DisplayItemList> list = 630 scoped_refptr<DisplayItemList> list =
700 DisplayItemList::Create(layer_rect, DisplayItemListSettings()); 631 DisplayItemList::Create(DisplayItemListSettings());
632 list->SetRetainVisualRectsForTesting(true);
701 gfx::Transform transform; 633 gfx::Transform transform;
702 transform.Translate(6.f, 7.f); 634 transform.Translate(6.f, 7.f);
703 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform); 635 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform);
704 AppendFirstSerializationTestPicture(list, layer_rect.size()); 636 AppendFirstSerializationTestPicture(list, layer_rect.size());
705 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect); 637 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect);
706 list->Finalize(); 638 list->Finalize();
707 639
708 std::string value = list->AsValue(true)->ToString(); 640 std::string value = list->AsValue(true)->ToString();
709 EXPECT_NE(value.find("{\"items\":[\"TransformDisplayItem"), 641 EXPECT_NE(value.find("{\"items\":[\"TransformDisplayItem"),
710 std::string::npos); 642 std::string::npos);
711 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 643 EXPECT_NE(value.find("visualRect: [0,0 42x42]"), std::string::npos);
712 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 644 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
713 645
714 value = list->AsValue(false)->ToString(); 646 value = list->AsValue(false)->ToString();
715 EXPECT_EQ(value.find("{\"items\":[\"TransformDisplayItem"), 647 EXPECT_EQ(value.find("{\"items\":[\"TransformDisplayItem"),
716 std::string::npos); 648 std::string::npos);
717 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 649 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
718 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 650 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
719 } 651 }
720 652
721 TEST(DisplayItemListTest, AsValueWithEmptyRectAndNoItems) {
722 scoped_refptr<DisplayItemList> list =
723 DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings());
724 list->Finalize();
725
726 std::string value = list->AsValue(true)->ToString();
727 EXPECT_NE(value.find("\"items\":[]"), std::string::npos);
728 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
729 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
730
731 value = list->AsValue(false)->ToString();
732 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
733 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
734 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
735 }
736
737 TEST(DisplayItemListTest, AsValueWithEmptyRectAndItems) {
738 scoped_refptr<DisplayItemList> list =
739 DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings());
740 gfx::Transform transform;
741 transform.Translate(6.f, 7.f);
742 list->CreateAndAppendItem<TransformDisplayItem>(kVisualRect, transform);
743 AppendFirstSerializationTestPicture(list, gfx::Size());
744 list->CreateAndAppendItem<EndTransformDisplayItem>(kVisualRect);
745 list->Finalize();
746
747 std::string value = list->AsValue(true)->ToString();
748 EXPECT_NE(value.find("\"items\":[\"TransformDisplayItem"), std::string::npos);
749 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
750 // There should be one skp64 entry present associated with the test picture
751 // item, though the overall list has no skp64 as the layer rect is empty.
752 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
753
754 value = list->AsValue(false)->ToString();
755 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
756 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
757 // There should be no skp64 entry present as the items aren't included and the
758 // layer rect is empty.
759 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
760 }
761
762 } // namespace cc 653 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/display_item_list.cc ('k') | cc/playback/display_list_raster_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698