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

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

Issue 1123983002: cc: Use a ListContainer for DisplayItemList to reduce allocations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: displaylistcontainer: fixdcheck Created 5 years, 7 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/resources/display_item_list.cc ('k') | cc/resources/display_list_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/resources/display_item_list.h" 5 #include "cc/resources/display_item_list.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "cc/output/filter_operation.h" 9 #include "cc/output/filter_operation.h"
10 #include "cc/output/filter_operations.h" 10 #include "cc/output/filter_operations.h"
(...skipping 30 matching lines...) Expand all
41 DisplayItemList::Create(layer_rect, use_cached_picture); 41 DisplayItemList::Create(layer_rect, use_cached_picture);
42 42
43 gfx::PointF offset(8.f, 9.f); 43 gfx::PointF offset(8.f, 9.f);
44 gfx::RectF recording_rect(offset, layer_rect.size()); 44 gfx::RectF recording_rect(offset, layer_rect.size());
45 canvas = skia::SharePtr( 45 canvas = skia::SharePtr(
46 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 46 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
47 canvas->translate(offset.x(), offset.y()); 47 canvas->translate(offset.x(), offset.y());
48 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 48 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
49 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 49 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
50 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); 50 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
51 list->AppendItem(DrawingDisplayItem::Create(picture)); 51 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>();
52 item->SetNew(picture);
53 list->ProcessAppendedItems();
52 list->CreateAndCacheSkPicture(); 54 list->CreateAndCacheSkPicture();
53 DrawDisplayList(pixels, layer_rect, list); 55 DrawDisplayList(pixels, layer_rect, list);
54 56
55 SkBitmap expected_bitmap; 57 SkBitmap expected_bitmap;
56 unsigned char expected_pixels[4 * 100 * 100] = {0}; 58 unsigned char expected_pixels[4 * 100 * 100] = {0};
57 SkImageInfo info = 59 SkImageInfo info =
58 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 60 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
59 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 61 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
60 SkCanvas expected_canvas(expected_bitmap); 62 SkCanvas expected_canvas(expected_bitmap);
61 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect)); 63 expected_canvas.clipRect(gfx::RectToSkRect(layer_rect));
(...skipping 21 matching lines...) Expand all
83 scoped_refptr<DisplayItemList> list = 85 scoped_refptr<DisplayItemList> list =
84 DisplayItemList::Create(layer_rect, use_cached_picture); 86 DisplayItemList::Create(layer_rect, use_cached_picture);
85 87
86 gfx::PointF first_offset(8.f, 9.f); 88 gfx::PointF first_offset(8.f, 9.f);
87 gfx::RectF first_recording_rect(first_offset, layer_rect.size()); 89 gfx::RectF first_recording_rect(first_offset, layer_rect.size());
88 canvas = skia::SharePtr( 90 canvas = skia::SharePtr(
89 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); 91 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
90 canvas->translate(first_offset.x(), first_offset.y()); 92 canvas->translate(first_offset.x(), first_offset.y());
91 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 93 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
92 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); 94 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
93 list->AppendItem(DrawingDisplayItem::Create(picture)); 95 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>();
96 item1->SetNew(picture.Pass());
94 97
95 gfx::Rect clip_rect(60, 60, 10, 10); 98 gfx::Rect clip_rect(60, 60, 10, 10);
96 list->AppendItem(ClipDisplayItem::Create(clip_rect, std::vector<SkRRect>())); 99 auto* item2 = list->CreateAndAppendItem<ClipDisplayItem>();
100 item2->SetNew(clip_rect, std::vector<SkRRect>());
97 101
98 gfx::PointF second_offset(2.f, 3.f); 102 gfx::PointF second_offset(2.f, 3.f);
99 gfx::RectF second_recording_rect(second_offset, layer_rect.size()); 103 gfx::RectF second_recording_rect(second_offset, layer_rect.size());
100 canvas = skia::SharePtr( 104 canvas = skia::SharePtr(
101 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); 105 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)));
102 canvas->translate(second_offset.x(), second_offset.y()); 106 canvas->translate(second_offset.x(), second_offset.y());
103 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 107 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
104 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); 108 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
105 list->AppendItem(DrawingDisplayItem::Create(picture)); 109 auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>();
110 item3->SetNew(picture.Pass());
106 111
107 list->AppendItem(EndClipDisplayItem::Create()); 112 list->CreateAndAppendItem<EndClipDisplayItem>();
113 list->ProcessAppendedItems();
108 list->CreateAndCacheSkPicture(); 114 list->CreateAndCacheSkPicture();
109 115
110 DrawDisplayList(pixels, layer_rect, list); 116 DrawDisplayList(pixels, layer_rect, list);
111 117
112 SkBitmap expected_bitmap; 118 SkBitmap expected_bitmap;
113 unsigned char expected_pixels[4 * 100 * 100] = {0}; 119 unsigned char expected_pixels[4 * 100 * 100] = {0};
114 SkImageInfo info = 120 SkImageInfo info =
115 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 121 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
116 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 122 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
117 SkCanvas expected_canvas(expected_bitmap); 123 SkCanvas expected_canvas(expected_bitmap);
(...skipping 23 matching lines...) Expand all
141 scoped_refptr<DisplayItemList> list = 147 scoped_refptr<DisplayItemList> list =
142 DisplayItemList::Create(layer_rect, use_cached_picture); 148 DisplayItemList::Create(layer_rect, use_cached_picture);
143 149
144 gfx::PointF first_offset(8.f, 9.f); 150 gfx::PointF first_offset(8.f, 9.f);
145 gfx::RectF first_recording_rect(first_offset, layer_rect.size()); 151 gfx::RectF first_recording_rect(first_offset, layer_rect.size());
146 canvas = skia::SharePtr( 152 canvas = skia::SharePtr(
147 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect))); 153 recorder.beginRecording(gfx::RectFToSkRect(first_recording_rect)));
148 canvas->translate(first_offset.x(), first_offset.y()); 154 canvas->translate(first_offset.x(), first_offset.y());
149 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 155 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
150 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); 156 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
151 list->AppendItem(DrawingDisplayItem::Create(picture)); 157 auto* item1 = list->CreateAndAppendItem<DrawingDisplayItem>();
158 item1->SetNew(picture);
152 159
153 gfx::Transform transform; 160 gfx::Transform transform;
154 transform.Rotate(45.0); 161 transform.Rotate(45.0);
155 list->AppendItem(TransformDisplayItem::Create(transform)); 162 auto* item2 = list->CreateAndAppendItem<TransformDisplayItem>();
163 item2->SetNew(transform);
156 164
157 gfx::PointF second_offset(2.f, 3.f); 165 gfx::PointF second_offset(2.f, 3.f);
158 gfx::RectF second_recording_rect(second_offset, layer_rect.size()); 166 gfx::RectF second_recording_rect(second_offset, layer_rect.size());
159 canvas = skia::SharePtr( 167 canvas = skia::SharePtr(
160 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect))); 168 recorder.beginRecording(gfx::RectFToSkRect(second_recording_rect)));
161 canvas->translate(second_offset.x(), second_offset.y()); 169 canvas->translate(second_offset.x(), second_offset.y());
162 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 170 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
163 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); 171 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
164 list->AppendItem(DrawingDisplayItem::Create(picture)); 172 auto* item3 = list->CreateAndAppendItem<DrawingDisplayItem>();
173 item3->SetNew(picture);
165 174
166 list->AppendItem(EndTransformDisplayItem::Create()); 175 list->CreateAndAppendItem<EndTransformDisplayItem>();
176 list->ProcessAppendedItems();
167 list->CreateAndCacheSkPicture(); 177 list->CreateAndCacheSkPicture();
168 178
169 DrawDisplayList(pixels, layer_rect, list); 179 DrawDisplayList(pixels, layer_rect, list);
170 180
171 SkBitmap expected_bitmap; 181 SkBitmap expected_bitmap;
172 unsigned char expected_pixels[4 * 100 * 100] = {0}; 182 unsigned char expected_pixels[4 * 100 * 100] = {0};
173 SkImageInfo info = 183 SkImageInfo info =
174 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 184 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
175 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes()); 185 expected_bitmap.installPixels(info, expected_pixels, info.minRowBytes());
176 SkCanvas expected_canvas(expected_bitmap); 186 SkCanvas expected_canvas(expected_bitmap);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // translating |dst| after it is computed by computeFastBounds, rather than 218 // translating |dst| after it is computed by computeFastBounds, rather than
209 // translating |src| before it provided to computedFastBounds) can cause 219 // translating |src| before it provided to computedFastBounds) can cause
210 // incorrect clipping of filter output. To test for this, we include an 220 // incorrect clipping of filter output. To test for this, we include an
211 // SkBitmapSource filter in |filters|. Here, |src| is |filter_bounds|, defined 221 // SkBitmapSource filter in |filters|. Here, |src| is |filter_bounds|, defined
212 // below. 222 // below.
213 skia::RefPtr<SkImageFilter> image_filter = 223 skia::RefPtr<SkImageFilter> image_filter =
214 skia::AdoptRef(SkBitmapSource::Create(source_bitmap)); 224 skia::AdoptRef(SkBitmapSource::Create(source_bitmap));
215 filters.Append(FilterOperation::CreateReferenceFilter(image_filter)); 225 filters.Append(FilterOperation::CreateReferenceFilter(image_filter));
216 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f)); 226 filters.Append(FilterOperation::CreateBrightnessFilter(0.5f));
217 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f); 227 gfx::RectF filter_bounds(10.f, 10.f, 50.f, 50.f);
218 list->AppendItem(FilterDisplayItem::Create(filters, filter_bounds)); 228 auto* item = list->CreateAndAppendItem<FilterDisplayItem>();
219 list->AppendItem(EndFilterDisplayItem::Create()); 229 item->SetNew(filters, filter_bounds);
230 list->CreateAndAppendItem<EndFilterDisplayItem>();
231 list->ProcessAppendedItems();
220 list->CreateAndCacheSkPicture(); 232 list->CreateAndCacheSkPicture();
221 233
222 DrawDisplayList(pixels, layer_rect, list); 234 DrawDisplayList(pixels, layer_rect, list);
223 235
224 SkBitmap expected_bitmap; 236 SkBitmap expected_bitmap;
225 unsigned char expected_pixels[4 * 100 * 100] = {0}; 237 unsigned char expected_pixels[4 * 100 * 100] = {0};
226 SkPaint paint; 238 SkPaint paint;
227 paint.setColor(SkColorSetRGB(64, 64, 64)); 239 paint.setColor(SkColorSetRGB(64, 64, 64));
228 SkImageInfo info = 240 SkImageInfo info =
229 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height()); 241 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
(...skipping 21 matching lines...) Expand all
251 bool use_cached_picture = false; 263 bool use_cached_picture = false;
252 scoped_refptr<DisplayItemList> list_without_caching = 264 scoped_refptr<DisplayItemList> list_without_caching =
253 DisplayItemList::Create(layer_rect, use_cached_picture); 265 DisplayItemList::Create(layer_rect, use_cached_picture);
254 266
255 canvas = skia::SharePtr( 267 canvas = skia::SharePtr(
256 recorder.beginRecording(gfx::RectFToSkRect(recording_rect))); 268 recorder.beginRecording(gfx::RectFToSkRect(recording_rect)));
257 canvas->translate(offset.x(), offset.y()); 269 canvas->translate(offset.x(), offset.y());
258 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint); 270 canvas->drawRectCoords(0.f, 0.f, 60.f, 60.f, red_paint);
259 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint); 271 canvas->drawRectCoords(50.f, 50.f, 75.f, 75.f, blue_paint);
260 picture = skia::AdoptRef(recorder.endRecordingAsPicture()); 272 picture = skia::AdoptRef(recorder.endRecordingAsPicture());
261 list_without_caching->AppendItem(DrawingDisplayItem::Create(picture)); 273 auto* item1 = list_without_caching->CreateAndAppendItem<DrawingDisplayItem>();
274 item1->SetNew(picture);
275 list_without_caching->ProcessAppendedItems();
262 DrawDisplayList(pixels, layer_rect, list_without_caching); 276 DrawDisplayList(pixels, layer_rect, list_without_caching);
263 277
264 unsigned char expected_pixels[4 * 100 * 100] = {0}; 278 unsigned char expected_pixels[4 * 100 * 100] = {0};
265 use_cached_picture = true; 279 use_cached_picture = true;
266 scoped_refptr<DisplayItemList> list_with_caching = 280 scoped_refptr<DisplayItemList> list_with_caching =
267 DisplayItemList::Create(layer_rect, use_cached_picture); 281 DisplayItemList::Create(layer_rect, use_cached_picture);
268 list_with_caching->AppendItem(DrawingDisplayItem::Create(picture)); 282 auto* item2 = list_with_caching->CreateAndAppendItem<DrawingDisplayItem>();
283 item2->SetNew(picture);
284 list_with_caching->ProcessAppendedItems();
269 list_with_caching->CreateAndCacheSkPicture(); 285 list_with_caching->CreateAndCacheSkPicture();
270 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); 286 DrawDisplayList(expected_pixels, layer_rect, list_with_caching);
271 287
272 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 288 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
273 } 289 }
274 290
275 TEST(DisplayItemListTest, PictureMemoryUsage) { 291 TEST(DisplayItemListTest, PictureMemoryUsage) {
276 scoped_refptr<DisplayItemList> list; 292 scoped_refptr<DisplayItemList> list;
277 size_t memory_usage; 293 size_t memory_usage;
278 294
279 // Make an SkPicture whose size is known. 295 // Make an SkPicture whose size is known.
280 gfx::Rect layer_rect(100, 100); 296 gfx::Rect layer_rect(100, 100);
281 SkPictureRecorder recorder; 297 SkPictureRecorder recorder;
282 SkPaint blue_paint; 298 SkPaint blue_paint;
283 blue_paint.setColor(SK_ColorBLUE); 299 blue_paint.setColor(SK_ColorBLUE);
284 SkCanvas* canvas = recorder.beginRecording(gfx::RectFToSkRect(layer_rect)); 300 SkCanvas* canvas = recorder.beginRecording(gfx::RectFToSkRect(layer_rect));
285 for (int i = 0; i < 100; i++) 301 for (int i = 0; i < 100; i++)
286 canvas->drawPaint(blue_paint); 302 canvas->drawPaint(blue_paint);
287 skia::RefPtr<SkPicture> picture = 303 skia::RefPtr<SkPicture> picture =
288 skia::AdoptRef(recorder.endRecordingAsPicture()); 304 skia::AdoptRef(recorder.endRecordingAsPicture());
289 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); 305 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get());
290 ASSERT_GE(picture_size, 100 * sizeof(SkPaint)); 306 ASSERT_GE(picture_size, 100 * sizeof(SkPaint));
291 ASSERT_LE(picture_size, 200 * sizeof(SkPaint)); 307 ASSERT_LE(picture_size, 200 * sizeof(SkPaint));
292 308
293 // Using a cached picture, we should get about the right size. 309 // Using a cached picture, we should get about the right size.
294 list = DisplayItemList::Create(layer_rect, true); 310 list = DisplayItemList::Create(layer_rect, true);
295 list->AppendItem(DrawingDisplayItem::Create(picture)); 311 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>();
312 item->SetNew(picture);
313 list->ProcessAppendedItems();
296 list->CreateAndCacheSkPicture(); 314 list->CreateAndCacheSkPicture();
297 memory_usage = list->PictureMemoryUsage(); 315 memory_usage = list->PictureMemoryUsage();
298 EXPECT_GE(memory_usage, picture_size); 316 EXPECT_GE(memory_usage, picture_size);
299 EXPECT_LE(memory_usage, 2 * picture_size); 317 EXPECT_LE(memory_usage, 2 * picture_size);
300 318
301 // Using no cached picture, we should still get the right size. 319 // Using no cached picture, we should still get the right size.
302 list = DisplayItemList::Create(layer_rect, false); 320 list = DisplayItemList::Create(layer_rect, false);
303 list->AppendItem(DrawingDisplayItem::Create(picture)); 321 item = list->CreateAndAppendItem<DrawingDisplayItem>();
322 item->SetNew(picture);
323 list->ProcessAppendedItems();
304 memory_usage = list->PictureMemoryUsage(); 324 memory_usage = list->PictureMemoryUsage();
305 EXPECT_GE(memory_usage, picture_size); 325 EXPECT_GE(memory_usage, picture_size);
306 EXPECT_LE(memory_usage, 2 * picture_size); 326 EXPECT_LE(memory_usage, 2 * picture_size);
307 327
308 // To avoid double counting, we expect zero size to be computed if both the 328 // To avoid double counting, we expect zero size to be computed if both the
309 // picture and items are retained (currently this only happens due to certain 329 // picture and items are retained (currently this only happens due to certain
310 // categories being traced). 330 // categories being traced).
311 list = new DisplayItemList(layer_rect, true, true); 331 list = new DisplayItemList(layer_rect, true, true);
312 list->AppendItem(DrawingDisplayItem::Create(picture)); 332 item = list->CreateAndAppendItem<DrawingDisplayItem>();
333 item->SetNew(picture);
334 list->ProcessAppendedItems();
313 list->CreateAndCacheSkPicture(); 335 list->CreateAndCacheSkPicture();
314 memory_usage = list->PictureMemoryUsage(); 336 memory_usage = list->PictureMemoryUsage();
315 EXPECT_EQ(static_cast<size_t>(0), memory_usage); 337 EXPECT_EQ(static_cast<size_t>(0), memory_usage);
316 } 338 }
317 339
318 } // namespace cc 340 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/display_item_list.cc ('k') | cc/resources/display_list_recording_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698