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

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

Issue 2225563002: Reland "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. 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 29 matching lines...) Expand all
40 #include "ui/gfx/geometry/rect_conversions.h" 40 #include "ui/gfx/geometry/rect_conversions.h"
41 #include "ui/gfx/skia_util.h" 41 #include "ui/gfx/skia_util.h"
42 42
43 namespace cc { 43 namespace cc {
44 44
45 namespace { 45 namespace {
46 46
47 const gfx::Rect kVisualRect(0, 0, 42, 42); 47 const gfx::Rect kVisualRect(0, 0, 42, 42);
48 48
49 scoped_refptr<DisplayItemList> CreateDefaultList() { 49 scoped_refptr<DisplayItemList> CreateDefaultList() {
50 return DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings()); 50 return DisplayItemList::Create(DisplayItemListSettings());
51 } 51 }
52 52
53 sk_sp<const SkPicture> CreateRectPicture(const gfx::Rect& bounds) { 53 sk_sp<const SkPicture> CreateRectPicture(const gfx::Rect& bounds) {
54 SkPictureRecorder recorder; 54 SkPictureRecorder recorder;
55 sk_sp<SkCanvas> canvas; 55 sk_sp<SkCanvas> canvas;
56 56
57 canvas = sk_ref_sp(recorder.beginRecording(bounds.width(), bounds.height())); 57 canvas = sk_ref_sp(recorder.beginRecording(bounds.width(), bounds.height()));
58 canvas->drawRect( 58 canvas->drawRect(
59 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()), 59 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()),
60 SkPaint()); 60 SkPaint());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 settings.ToProtobuf(&proto); 146 settings.ToProtobuf(&proto);
147 DisplayItemListSettings deserialized(proto); 147 DisplayItemListSettings deserialized(proto);
148 EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture); 148 EXPECT_EQ(settings.use_cached_picture, deserialized.use_cached_picture);
149 } 149 }
150 } 150 }
151 151
152 TEST(DisplayItemListTest, SerializeSingleDrawingItem) { 152 TEST(DisplayItemListTest, SerializeSingleDrawingItem) {
153 gfx::Size layer_size(10, 10); 153 gfx::Size layer_size(10, 10);
154 154
155 DisplayItemListSettings settings; 155 DisplayItemListSettings settings;
156 scoped_refptr<DisplayItemList> list = 156 settings.use_cached_picture = true;
157 DisplayItemList::Create(gfx::Rect(layer_size), settings); 157 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
158 list->SetRetainVisualRectsForTesting(true);
158 159
159 // Build the DrawingDisplayItem. 160 // Build the DrawingDisplayItem.
160 AppendFirstSerializationTestPicture(list, layer_size); 161 AppendFirstSerializationTestPicture(list, layer_size);
161 162
162 ValidateDisplayItemListSerialization(layer_size, list); 163 ValidateDisplayItemListSerialization(layer_size, list);
163 } 164 }
164 165
165 TEST(DisplayItemListTest, SerializeClipItem) { 166 TEST(DisplayItemListTest, SerializeClipItem) {
166 gfx::Size layer_size(10, 10); 167 gfx::Size layer_size(10, 10);
167 168
168 DisplayItemListSettings settings; 169 DisplayItemListSettings settings;
169 scoped_refptr<DisplayItemList> list = 170 settings.use_cached_picture = true;
170 DisplayItemList::Create(gfx::Rect(layer_size), settings); 171 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
172 list->SetRetainVisualRectsForTesting(true);
171 173
172 // Build the DrawingDisplayItem. 174 // Build the DrawingDisplayItem.
173 AppendFirstSerializationTestPicture(list, layer_size); 175 AppendFirstSerializationTestPicture(list, layer_size);
174 176
175 // Build the ClipDisplayItem. 177 // Build the ClipDisplayItem.
176 gfx::Rect clip_rect(6, 6, 1, 1); 178 gfx::Rect clip_rect(6, 6, 1, 1);
177 std::vector<SkRRect> rrects; 179 std::vector<SkRRect> rrects;
178 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f))); 180 rrects.push_back(SkRRect::MakeOval(SkRect::MakeXYWH(5.f, 5.f, 4.f, 4.f)));
179 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(clip_rect, rrects, 181 list->CreateAndAppendPairedBeginItem<ClipDisplayItem>(clip_rect, rrects,
180 true); 182 true);
181 183
182 // Build the second DrawingDisplayItem. 184 // Build the second DrawingDisplayItem.
183 AppendSecondSerializationTestPicture(list, layer_size); 185 AppendSecondSerializationTestPicture(list, layer_size);
184 186
185 // Build the EndClipDisplayItem. 187 // Build the EndClipDisplayItem.
186 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); 188 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
187 189
188 ValidateDisplayItemListSerialization(layer_size, list); 190 ValidateDisplayItemListSerialization(layer_size, list);
189 } 191 }
190 192
191 TEST(DisplayItemListTest, SerializeClipPathItem) { 193 TEST(DisplayItemListTest, SerializeClipPathItem) {
192 gfx::Size layer_size(10, 10); 194 gfx::Size layer_size(10, 10);
193 195
194 DisplayItemListSettings settings; 196 DisplayItemListSettings settings;
195 scoped_refptr<DisplayItemList> list = 197 settings.use_cached_picture = true;
196 DisplayItemList::Create(gfx::Rect(layer_size), settings); 198 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
199 list->SetRetainVisualRectsForTesting(true);
197 200
198 // Build the DrawingDisplayItem. 201 // Build the DrawingDisplayItem.
199 AppendFirstSerializationTestPicture(list, layer_size); 202 AppendFirstSerializationTestPicture(list, layer_size);
200 203
201 // Build the ClipPathDisplayItem. 204 // Build the ClipPathDisplayItem.
202 SkPath path; 205 SkPath path;
203 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction); 206 path.addCircle(5.f, 5.f, 2.f, SkPath::Direction::kCW_Direction);
204 list->CreateAndAppendPairedBeginItem<ClipPathDisplayItem>( 207 list->CreateAndAppendPairedBeginItem<ClipPathDisplayItem>(
205 path, SkRegion::Op::kReplace_Op, false); 208 path, SkRegion::Op::kReplace_Op, false);
206 209
207 // Build the second DrawingDisplayItem. 210 // Build the second DrawingDisplayItem.
208 AppendSecondSerializationTestPicture(list, layer_size); 211 AppendSecondSerializationTestPicture(list, layer_size);
209 212
210 // Build the EndClipPathDisplayItem. 213 // Build the EndClipPathDisplayItem.
211 list->CreateAndAppendPairedEndItem<EndClipPathDisplayItem>(); 214 list->CreateAndAppendPairedEndItem<EndClipPathDisplayItem>();
212 215
213 ValidateDisplayItemListSerialization(layer_size, list); 216 ValidateDisplayItemListSerialization(layer_size, list);
214 } 217 }
215 218
216 TEST(DisplayItemListTest, SerializeCompositingItem) { 219 TEST(DisplayItemListTest, SerializeCompositingItem) {
217 gfx::Size layer_size(10, 10); 220 gfx::Size layer_size(10, 10);
218 221
219 DisplayItemListSettings settings; 222 DisplayItemListSettings settings;
220 scoped_refptr<DisplayItemList> list = 223 settings.use_cached_picture = true;
221 DisplayItemList::Create(gfx::Rect(layer_size), settings); 224 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
225 list->SetRetainVisualRectsForTesting(true);
222 226
223 // Build the DrawingDisplayItem. 227 // Build the DrawingDisplayItem.
224 AppendFirstSerializationTestPicture(list, layer_size); 228 AppendFirstSerializationTestPicture(list, layer_size);
225 229
226 // Build the CompositingDisplayItem. 230 // Build the CompositingDisplayItem.
227 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>( 231 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>(
228 150, SkXfermode::Mode::kDst_Mode, nullptr, 232 150, SkXfermode::Mode::kDst_Mode, nullptr,
229 SkColorMatrixFilter::MakeLightingFilter(SK_ColorRED, SK_ColorGREEN), 233 SkColorMatrixFilter::MakeLightingFilter(SK_ColorRED, SK_ColorGREEN),
230 false); 234 false);
231 235
232 // Build the second DrawingDisplayItem. 236 // Build the second DrawingDisplayItem.
233 AppendSecondSerializationTestPicture(list, layer_size); 237 AppendSecondSerializationTestPicture(list, layer_size);
234 238
235 // Build the EndCompositingDisplayItem. 239 // Build the EndCompositingDisplayItem.
236 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>(); 240 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>();
237 241
238 ValidateDisplayItemListSerialization(layer_size, list); 242 ValidateDisplayItemListSerialization(layer_size, list);
239 } 243 }
240 244
241 TEST(DisplayItemListTest, SerializeFloatClipItem) { 245 TEST(DisplayItemListTest, SerializeFloatClipItem) {
242 gfx::Size layer_size(10, 10); 246 gfx::Size layer_size(10, 10);
243 247
244 DisplayItemListSettings settings; 248 DisplayItemListSettings settings;
245 scoped_refptr<DisplayItemList> list = 249 settings.use_cached_picture = true;
246 DisplayItemList::Create(gfx::Rect(layer_size), settings); 250 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
251 list->SetRetainVisualRectsForTesting(true);
247 252
248 // Build the DrawingDisplayItem. 253 // Build the DrawingDisplayItem.
249 AppendFirstSerializationTestPicture(list, layer_size); 254 AppendFirstSerializationTestPicture(list, layer_size);
250 255
251 // Build the FloatClipDisplayItem. 256 // Build the FloatClipDisplayItem.
252 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f); 257 gfx::RectF clip_rect(6.f, 6.f, 1.f, 1.f);
253 list->CreateAndAppendPairedBeginItem<FloatClipDisplayItem>(clip_rect); 258 list->CreateAndAppendPairedBeginItem<FloatClipDisplayItem>(clip_rect);
254 259
255 // Build the second DrawingDisplayItem. 260 // Build the second DrawingDisplayItem.
256 AppendSecondSerializationTestPicture(list, layer_size); 261 AppendSecondSerializationTestPicture(list, layer_size);
257 262
258 // Build the EndFloatClipDisplayItem. 263 // Build the EndFloatClipDisplayItem.
259 list->CreateAndAppendPairedEndItem<EndFloatClipDisplayItem>(); 264 list->CreateAndAppendPairedEndItem<EndFloatClipDisplayItem>();
260 265
261 ValidateDisplayItemListSerialization(layer_size, list); 266 ValidateDisplayItemListSerialization(layer_size, list);
262 } 267 }
263 268
264 TEST(DisplayItemListTest, SerializeTransformItem) { 269 TEST(DisplayItemListTest, SerializeTransformItem) {
265 gfx::Size layer_size(10, 10); 270 gfx::Size layer_size(10, 10);
266 271
267 DisplayItemListSettings settings; 272 DisplayItemListSettings settings;
268 scoped_refptr<DisplayItemList> list = 273 settings.use_cached_picture = true;
269 DisplayItemList::Create(gfx::Rect(layer_size), settings); 274 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
275 list->SetRetainVisualRectsForTesting(true);
270 276
271 // Build the DrawingDisplayItem. 277 // Build the DrawingDisplayItem.
272 AppendFirstSerializationTestPicture(list, layer_size); 278 AppendFirstSerializationTestPicture(list, layer_size);
273 279
274 // Build the TransformDisplayItem. 280 // Build the TransformDisplayItem.
275 gfx::Transform transform; 281 gfx::Transform transform;
276 transform.Scale(1.25f, 1.25f); 282 transform.Scale(1.25f, 1.25f);
277 transform.Translate(-1.f, -1.f); 283 transform.Translate(-1.f, -1.f);
278 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); 284 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform);
279 285
280 // Build the second DrawingDisplayItem. 286 // Build the second DrawingDisplayItem.
281 AppendSecondSerializationTestPicture(list, layer_size); 287 AppendSecondSerializationTestPicture(list, layer_size);
282 288
283 // Build the EndTransformDisplayItem. 289 // Build the EndTransformDisplayItem.
284 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); 290 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
285 291
286 ValidateDisplayItemListSerialization(layer_size, list); 292 ValidateDisplayItemListSerialization(layer_size, list);
287 } 293 }
288 294
289 TEST(DisplayItemListTest, SingleDrawingItem) { 295 TEST(DisplayItemListTest, SingleDrawingItem) {
290 gfx::Rect layer_rect(100, 100); 296 gfx::Rect layer_rect(100, 100);
291 SkPictureRecorder recorder; 297 SkPictureRecorder recorder;
292 sk_sp<SkCanvas> canvas; 298 sk_sp<SkCanvas> canvas;
293 SkPaint blue_paint; 299 SkPaint blue_paint;
294 blue_paint.setColor(SK_ColorBLUE); 300 blue_paint.setColor(SK_ColorBLUE);
295 SkPaint red_paint; 301 SkPaint red_paint;
296 red_paint.setColor(SK_ColorRED); 302 red_paint.setColor(SK_ColorRED);
297 unsigned char pixels[4 * 100 * 100] = {0}; 303 unsigned char pixels[4 * 100 * 100] = {0};
298 DisplayItemListSettings settings; 304 DisplayItemListSettings settings;
299 scoped_refptr<DisplayItemList> list = 305 settings.use_cached_picture = true;
300 DisplayItemList::Create(layer_rect, settings); 306 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
301 307
302 gfx::PointF offset(8.f, 9.f); 308 gfx::PointF offset(8.f, 9.f);
303 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); 309 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
304 canvas = 310 canvas =
305 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 311 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
306 canvas->translate(offset.x(), offset.y()); 312 canvas->translate(offset.x(), offset.y());
307 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 313 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
308 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 314 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
309 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 315 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
310 kVisualRect, recorder.finishRecordingAsPicture()); 316 kVisualRect, recorder.finishRecordingAsPicture());
(...skipping 21 matching lines...) Expand all
332 gfx::Rect layer_rect(100, 100); 338 gfx::Rect layer_rect(100, 100);
333 SkPictureRecorder recorder; 339 SkPictureRecorder recorder;
334 sk_sp<SkCanvas> canvas; 340 sk_sp<SkCanvas> canvas;
335 SkPaint blue_paint; 341 SkPaint blue_paint;
336 blue_paint.setColor(SK_ColorBLUE); 342 blue_paint.setColor(SK_ColorBLUE);
337 SkPaint red_paint; 343 SkPaint red_paint;
338 red_paint.setColor(SK_ColorRED); 344 red_paint.setColor(SK_ColorRED);
339 unsigned char pixels[4 * 100 * 100] = {0}; 345 unsigned char pixels[4 * 100 * 100] = {0};
340 DisplayItemListSettings settings; 346 DisplayItemListSettings settings;
341 settings.use_cached_picture = true; 347 settings.use_cached_picture = true;
342 scoped_refptr<DisplayItemList> list = 348 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
343 DisplayItemList::Create(layer_rect, settings);
344 349
345 gfx::PointF first_offset(8.f, 9.f); 350 gfx::PointF first_offset(8.f, 9.f);
346 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); 351 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
347 canvas = sk_ref_sp( 352 canvas = sk_ref_sp(
348 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); 353 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
349 canvas->translate(first_offset.x(), first_offset.y()); 354 canvas->translate(first_offset.x(), first_offset.y());
350 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 355 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
351 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 356 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
352 kVisualRect, recorder.finishRecordingAsPicture()); 357 kVisualRect, recorder.finishRecordingAsPicture());
353 358
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 gfx::Rect layer_rect(100, 100); 397 gfx::Rect layer_rect(100, 100);
393 SkPictureRecorder recorder; 398 SkPictureRecorder recorder;
394 sk_sp<SkCanvas> canvas; 399 sk_sp<SkCanvas> canvas;
395 SkPaint blue_paint; 400 SkPaint blue_paint;
396 blue_paint.setColor(SK_ColorBLUE); 401 blue_paint.setColor(SK_ColorBLUE);
397 SkPaint red_paint; 402 SkPaint red_paint;
398 red_paint.setColor(SK_ColorRED); 403 red_paint.setColor(SK_ColorRED);
399 unsigned char pixels[4 * 100 * 100] = {0}; 404 unsigned char pixels[4 * 100 * 100] = {0};
400 DisplayItemListSettings settings; 405 DisplayItemListSettings settings;
401 settings.use_cached_picture = true; 406 settings.use_cached_picture = true;
402 scoped_refptr<DisplayItemList> list = 407 scoped_refptr<DisplayItemList> list = DisplayItemList::Create(settings);
403 DisplayItemList::Create(layer_rect, settings);
404 408
405 gfx::PointF first_offset(8.f, 9.f); 409 gfx::PointF first_offset(8.f, 9.f);
406 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size())); 410 gfx::RectF first_recording_rect(first_offset, gfx::SizeF(layer_rect.size()));
407 canvas = sk_ref_sp( 411 canvas = sk_ref_sp(
408 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); 412 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
409 canvas->translate(first_offset.x(), first_offset.y()); 413 canvas->translate(first_offset.x(), first_offset.y());
410 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 414 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
411 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 415 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
412 kVisualRect, recorder.finishRecordingAsPicture()); 416 kVisualRect, recorder.finishRecordingAsPicture());
413 417
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 50.f + second_offset.x(), 50.f + second_offset.y(), 449 50.f + second_offset.x(), 50.f + second_offset.y(),
446 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint); 450 75.f + second_offset.x(), 75.f + second_offset.y(), blue_paint);
447 451
448 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 452 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
449 } 453 }
450 454
451 TEST(DisplayItemListTest, FilterItem) { 455 TEST(DisplayItemListTest, FilterItem) {
452 gfx::Rect layer_rect(100, 100); 456 gfx::Rect layer_rect(100, 100);
453 FilterOperations filters; 457 FilterOperations filters;
454 unsigned char pixels[4 * 100 * 100] = {0}; 458 unsigned char pixels[4 * 100 * 100] = {0};
455 DisplayItemListSettings settings;
456 settings.use_cached_picture = true;
457 scoped_refptr<DisplayItemList> list = 459 scoped_refptr<DisplayItemList> list =
458 DisplayItemList::Create(layer_rect, settings); 460 DisplayItemList::Create(DisplayItemListSettings());
459 461
460 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50); 462 sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50);
461 SkCanvas* source_canvas = source_surface->getCanvas(); 463 SkCanvas* source_canvas = source_surface->getCanvas();
462 source_canvas->clear(SkColorSetRGB(128, 128, 128)); 464 source_canvas->clear(SkColorSetRGB(128, 128, 128));
463 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot(); 465 sk_sp<SkImage> source_image = source_surface->makeImageSnapshot();
464 466
465 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are 467 // For most SkImageFilters, the |dst| bounds computed by computeFastBounds are
466 // dependent on the provided |src| bounds. This means, for example, that 468 // dependent on the provided |src| bounds. This means, for example, that
467 // translating |src| results in a corresponding translation of |dst|. But this 469 // translating |src| results in a corresponding translation of |dst|. But this
468 // is not the case for all SkImageFilters; for some of them (e.g. 470 // is not the case for all SkImageFilters; for some of them (e.g.
469 // SkImageSource), the computation of |dst| in computeFastBounds doesn't 471 // SkImageSource), the computation of |dst| in computeFastBounds doesn't
470 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by 472 // involve |src| at all. Incorrectly assuming such a relationship (e.g. by
471 // translating |dst| after it is computed by computeFastBounds, rather than 473 // translating |dst| after it is computed by computeFastBounds, rather than
472 // translating |src| before it provided to computedFastBounds) can cause 474 // translating |src| before it provided to computedFastBounds) can cause
473 // incorrect clipping of filter output. To test for this, we include an 475 // incorrect clipping of filter output. To test for this, we include an
474 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined 476 // SkImageSource filter in |filters|. Here, |src| is |filter_bounds|, defined
475 // below. 477 // below.
476 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image); 478 sk_sp<SkImageFilter> image_filter = SkImageSource::Make(source_image);
477 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); 479 filters.Append(FilterOperation::CreateReferenceFilter(image_filter));
478 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); 480 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f));
479 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); 481 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f);
480 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>(filters, 482 list->CreateAndAppendPairedBeginItem<FilterDisplayItem>(filters,
481 filter_bounds); 483 filter_bounds);
484
485 // Include a rect drawing so that filter is actually applied to something.
486 {
487 SkPictureRecorder recorder;
488 sk_sp<SkCanvas> canvas;
489
490 SkPaint red_paint;
491 red_paint.setColor(SK_ColorRED);
492
493 canvas = sk_ref_sp(recorder.beginRecording(
494 SkRect::MakeXYWH(0, 0, layer_rect.width(), layer_rect.height())));
495 canvas->drawRectCoords(filter_bounds.x(), filter_bounds.y(),
496 filter_bounds.right(), filter_bounds.bottom(),
497 red_paint);
498 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
499 ToNearestRect(filter_bounds), recorder.finishRecordingAsPicture());
500 }
501
482 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); 502 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>();
483 list->Finalize(); 503 list->Finalize();
484 504
485 DrawDisplayList(pixels, layer_rect, list); 505 DrawDisplayList(pixels, layer_rect, list);
486 506
487 SkBitmap expected_bitmap; 507 SkBitmap expected_bitmap;
488 unsigned char expected_pixels[4 * 100 * 100] = {0}; 508 unsigned char expected_pixels[4 * 100 * 100] = {0};
489 SkPaint paint; 509 SkPaint paint;
490 paint.setColor(SkColorSetRGB(64, 64, 64)); 510 paint.setColor(SkColorSetRGB(64, 64, 64));
491 SkImageInfo info = 511 SkImageInfo info =
(...skipping 12 matching lines...) Expand all
504 SkPaint blue_paint; 524 SkPaint blue_paint;
505 blue_paint.setColor(SK_ColorBLUE); 525 blue_paint.setColor(SK_ColorBLUE);
506 SkPaint red_paint; 526 SkPaint red_paint;
507 red_paint.setColor(SK_ColorRED); 527 red_paint.setColor(SK_ColorRED);
508 unsigned char pixels[4 * 100 * 100] = {0}; 528 unsigned char pixels[4 * 100 * 100] = {0};
509 529
510 gfx::PointF offset(8.f, 9.f); 530 gfx::PointF offset(8.f, 9.f);
511 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size())); 531 gfx::RectF recording_rect(offset, gfx::SizeF(layer_rect.size()));
512 532
513 DisplayItemListSettings no_caching_settings; 533 DisplayItemListSettings no_caching_settings;
514 no_caching_settings.use_cached_picture = false;
515 scoped_refptr<DisplayItemList> list_without_caching = 534 scoped_refptr<DisplayItemList> list_without_caching =
516 DisplayItemList::Create(layer_rect, no_caching_settings); 535 DisplayItemList::Create(no_caching_settings);
517 536
518 canvas = 537 canvas =
519 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 538 sk_ref_sp(recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
520 canvas->translate(offset.x(), offset.y()); 539 canvas->translate(offset.x(), offset.y());
521 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 540 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
522 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 541 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
523 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 542 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
524 list_without_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>( 543 list_without_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(
525 kVisualRect, picture); 544 kVisualRect, picture);
526 list_without_caching->Finalize(); 545 list_without_caching->Finalize();
527 DrawDisplayList(pixels, layer_rect, list_without_caching); 546 DrawDisplayList(pixels, layer_rect, list_without_caching);
528 547
529 unsigned char expected_pixels[4 * 100 * 100] = {0}; 548 unsigned char expected_pixels[4 * 100 * 100] = {0};
530 DisplayItemListSettings caching_settings; 549 DisplayItemListSettings caching_settings;
531 caching_settings.use_cached_picture = true; 550 caching_settings.use_cached_picture = true;
532 scoped_refptr<DisplayItemList> list_with_caching = 551 scoped_refptr<DisplayItemList> list_with_caching =
533 DisplayItemList::Create(layer_rect, caching_settings); 552 DisplayItemList::Create(caching_settings);
534 list_with_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, 553 list_with_caching->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect,
535 picture); 554 picture);
536 list_with_caching->Finalize(); 555 list_with_caching->Finalize();
537 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); 556 DrawDisplayList(expected_pixels, layer_rect, list_with_caching);
538 557
539 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 558 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
540 } 559 }
541 560
542 TEST(DisplayItemListTest, ApproximateMemoryUsage) { 561 TEST(DisplayItemListTest, ApproximateMemoryUsage) {
543 const int kNumCommandsInTestSkPicture = 1000; 562 const int kNumCommandsInTestSkPicture = 1000;
544 scoped_refptr<DisplayItemList> list; 563 scoped_refptr<DisplayItemList> list;
545 size_t memory_usage; 564 size_t memory_usage;
546 565
547 // Make an SkPicture whose size is known. 566 // Make an SkPicture whose size is known.
548 gfx::Rect layer_rect(100, 100); 567 gfx::Rect layer_rect(100, 100);
549 SkPictureRecorder recorder; 568 SkPictureRecorder recorder;
550 SkPaint blue_paint; 569 SkPaint blue_paint;
551 blue_paint.setColor(SK_ColorBLUE); 570 blue_paint.setColor(SK_ColorBLUE);
552 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect)); 571 SkCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(layer_rect));
553 for (int i = 0; i < kNumCommandsInTestSkPicture; i++) 572 for (int i = 0; i < kNumCommandsInTestSkPicture; i++)
554 canvas->drawPaint(blue_paint); 573 canvas->drawPaint(blue_paint);
555 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 574 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
556 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); 575 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get());
557 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint)); 576 ASSERT_GE(picture_size, kNumCommandsInTestSkPicture * sizeof(blue_paint));
558 577
559 // Using a cached picture, we should get about the right size. 578 // Using a cached picture, we should get about the right size.
560 DisplayItemListSettings caching_settings; 579 DisplayItemListSettings caching_settings;
561 caching_settings.use_cached_picture = true; 580 caching_settings.use_cached_picture = true;
562 list = DisplayItemList::Create(layer_rect, caching_settings); 581 list = DisplayItemList::Create(caching_settings);
563 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture); 582 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture);
564 list->Finalize(); 583 list->Finalize();
565 memory_usage = list->ApproximateMemoryUsage(); 584 memory_usage = list->ApproximateMemoryUsage();
566 EXPECT_GE(memory_usage, picture_size); 585 EXPECT_GE(memory_usage, picture_size);
567 EXPECT_LE(memory_usage, 2 * picture_size); 586 EXPECT_LE(memory_usage, 2 * picture_size);
568 587
569 // Using no cached picture, we should still get the right size. 588 // Using no cached picture, we should still get the right size.
570 DisplayItemListSettings no_caching_settings; 589 DisplayItemListSettings no_caching_settings;
571 no_caching_settings.use_cached_picture = false; 590 no_caching_settings.use_cached_picture = false;
572 list = DisplayItemList::Create(layer_rect, no_caching_settings); 591 list = DisplayItemList::Create(no_caching_settings);
573 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture); 592 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture);
574 list->Finalize(); 593 list->Finalize();
575 memory_usage = list->ApproximateMemoryUsage(); 594 memory_usage = list->ApproximateMemoryUsage();
576 EXPECT_GE(memory_usage, picture_size); 595 EXPECT_GE(memory_usage, picture_size);
577 EXPECT_LE(memory_usage, 2 * picture_size); 596 EXPECT_LE(memory_usage, 2 * picture_size);
578
579 // To avoid double counting, we expect zero size to be computed if both the
580 // picture and items are retained (currently this only happens due to certain
581 // categories being traced).
582 list = new DisplayItemList(layer_rect, caching_settings, true);
583 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect, picture);
584 list->Finalize();
585 memory_usage = list->ApproximateMemoryUsage();
586 EXPECT_EQ(static_cast<size_t>(0), memory_usage);
587 } 597 }
588 598
589 TEST(DisplayItemListTest, AsValueWithRectAndNoItems) { 599 TEST(DisplayItemListTest, AsValueWithNoItems) {
590 scoped_refptr<DisplayItemList> list = 600 scoped_refptr<DisplayItemList> list =
591 DisplayItemList::Create(gfx::Rect(1, 2, 8, 9), DisplayItemListSettings()); 601 DisplayItemList::Create(DisplayItemListSettings());
602 list->SetRetainVisualRectsForTesting(true);
592 list->Finalize(); 603 list->Finalize();
593 604
594 std::string value = list->AsValue(true)->ToString(); 605 std::string value = list->AsValue(true)->ToString();
606 EXPECT_EQ(value.find("\"layer_rect\": [0,0,0,0]"), std::string::npos);
595 EXPECT_NE(value.find("\"items\":[]"), std::string::npos); 607 EXPECT_NE(value.find("\"items\":[]"), std::string::npos);
596 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 608 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
597 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 609 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
598 610
599 value = list->AsValue(false)->ToString(); 611 value = list->AsValue(false)->ToString();
612 EXPECT_EQ(value.find("\"layer_rect\": [0,0,0,0]"), std::string::npos);
600 EXPECT_EQ(value.find("\"items\":"), std::string::npos); 613 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
601 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 614 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
602 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 615 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
603 } 616 }
604 617
605 TEST(DisplayItemListTest, AsValueWithRectAndItems) { 618 TEST(DisplayItemListTest, AsValueWithItems) {
606 gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9); 619 gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9);
607 scoped_refptr<DisplayItemList> list = 620 scoped_refptr<DisplayItemList> list =
608 DisplayItemList::Create(layer_rect, DisplayItemListSettings()); 621 DisplayItemList::Create(DisplayItemListSettings());
622 list->SetRetainVisualRectsForTesting(true);
609 gfx::Transform transform; 623 gfx::Transform transform;
610 transform.Translate(6.f, 7.f); 624 transform.Translate(6.f, 7.f);
611 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform); 625 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform);
612 AppendFirstSerializationTestPicture(list, layer_rect.size()); 626 AppendFirstSerializationTestPicture(list, layer_rect.size());
613 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>(); 627 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
614 list->Finalize(); 628 list->Finalize();
615 629
616 std::string value = list->AsValue(true)->ToString(); 630 std::string value = list->AsValue(true)->ToString();
631 EXPECT_EQ(value.find("\"layer_rect\": [0,0,42,42]"), std::string::npos);
617 EXPECT_NE(value.find("{\"items\":[\"TransformDisplayItem"), 632 EXPECT_NE(value.find("{\"items\":[\"TransformDisplayItem"),
618 std::string::npos); 633 std::string::npos);
619 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 634 EXPECT_NE(value.find("visualRect: [0,0 42x42]"), std::string::npos);
620 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 635 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
621 636
622 value = list->AsValue(false)->ToString(); 637 value = list->AsValue(false)->ToString();
638 EXPECT_EQ(value.find("\"layer_rect\": [0,0,42,42]"), std::string::npos);
623 EXPECT_EQ(value.find("{\"items\":[\"TransformDisplayItem"), 639 EXPECT_EQ(value.find("{\"items\":[\"TransformDisplayItem"),
624 std::string::npos); 640 std::string::npos);
625 EXPECT_NE(value.find("\"layer_rect\":[1,2,8,9]"), std::string::npos); 641 EXPECT_EQ(value.find("visualRect: [0,0 42x42]"), std::string::npos);
626 EXPECT_NE(value.find("\"skp64\":"), std::string::npos); 642 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
627 } 643 }
628 644
629 TEST(DisplayItemListTest, AsValueWithEmptyRectAndNoItems) {
630 scoped_refptr<DisplayItemList> list = CreateDefaultList();
631 list->Finalize();
632
633 std::string value = list->AsValue(true)->ToString();
634 EXPECT_NE(value.find("\"items\":[]"), std::string::npos);
635 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
636 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
637
638 value = list->AsValue(false)->ToString();
639 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
640 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
641 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
642 }
643
644 TEST(DisplayItemListTest, AsValueWithEmptyRectAndItems) {
645 scoped_refptr<DisplayItemList> list = CreateDefaultList();
646 gfx::Transform transform;
647 transform.Translate(6.f, 7.f);
648 list->CreateAndAppendPairedBeginItem<TransformDisplayItem>(transform);
649 AppendFirstSerializationTestPicture(list, gfx::Size());
650 list->CreateAndAppendPairedEndItem<EndTransformDisplayItem>();
651 list->Finalize();
652
653 std::string value = list->AsValue(true)->ToString();
654 EXPECT_NE(value.find("\"items\":[\"TransformDisplayItem"), std::string::npos);
655 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
656 // There should be one skp64 entry present associated with the test picture
657 // item, though the overall list has no skp64 as the layer rect is empty.
658 EXPECT_NE(value.find("\"skp64\":"), std::string::npos);
659
660 value = list->AsValue(false)->ToString();
661 EXPECT_EQ(value.find("\"items\":"), std::string::npos);
662 EXPECT_NE(value.find("\"layer_rect\":[0,0,0,0]"), std::string::npos);
663 // There should be no skp64 entry present as the items aren't included and the
664 // layer rect is empty.
665 EXPECT_EQ(value.find("\"skp64\":"), std::string::npos);
666 }
667
668 TEST(DisplayItemListTest, SizeEmpty) { 645 TEST(DisplayItemListTest, SizeEmpty) {
669 scoped_refptr<DisplayItemList> list = CreateDefaultList(); 646 scoped_refptr<DisplayItemList> list = CreateDefaultList();
670 EXPECT_EQ(0u, list->size()); 647 EXPECT_EQ(0u, list->size());
671 } 648 }
672 649
673 TEST(DisplayItemListTest, SizeOne) { 650 TEST(DisplayItemListTest, SizeOne) {
674 scoped_refptr<DisplayItemList> list = CreateDefaultList(); 651 scoped_refptr<DisplayItemList> list = CreateDefaultList();
675 gfx::Rect drawing_bounds(5, 6, 1, 1); 652 gfx::Rect drawing_bounds(5, 6, 1, 1);
676 list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 653 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
677 drawing_bounds, CreateRectPicture(drawing_bounds)); 654 drawing_bounds, CreateRectPicture(drawing_bounds));
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); 953 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
977 954
978 EXPECT_EQ(4u, list->size()); 955 EXPECT_EQ(4u, list->size());
979 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); 956 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0));
980 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); 957 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1));
981 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); 958 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2));
982 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); 959 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3));
983 } 960 }
984 961
985 } // namespace cc 962 } // 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