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

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

Issue 1226503006: cc: More consistent reasoning about display list memory usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: capacity unit test Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/playback/display_item_list.h" 5 #include "cc/playback/display_item_list.h"
6 6
7 #include <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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 scoped_refptr<DisplayItemList> list_with_caching = 277 scoped_refptr<DisplayItemList> list_with_caching =
278 DisplayItemList::Create(layer_rect, use_cached_picture); 278 DisplayItemList::Create(layer_rect, use_cached_picture);
279 auto* item2 = list_with_caching->CreateAndAppendItem<DrawingDisplayItem>(); 279 auto* item2 = list_with_caching->CreateAndAppendItem<DrawingDisplayItem>();
280 item2->SetNew(picture); 280 item2->SetNew(picture);
281 list_with_caching->Finalize(); 281 list_with_caching->Finalize();
282 DrawDisplayList(expected_pixels, layer_rect, list_with_caching); 282 DrawDisplayList(expected_pixels, layer_rect, list_with_caching);
283 283
284 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100)); 284 EXPECT_EQ(0, memcmp(pixels, expected_pixels, 4 * 100 * 100));
285 } 285 }
286 286
287 TEST(DisplayItemListTest, PictureMemoryUsage) { 287 TEST(DisplayItemListTest, ApproximateMemoryUsage) {
288 scoped_refptr<DisplayItemList> list; 288 scoped_refptr<DisplayItemList> list;
289 size_t memory_usage; 289 size_t memory_usage;
290 290
291 // Make an SkPicture whose size is known. 291 // Make an SkPicture whose size is known.
292 gfx::Rect layer_rect(100, 100); 292 gfx::Rect layer_rect(100, 100);
293 SkPictureRecorder recorder; 293 SkPictureRecorder recorder;
294 SkPaint blue_paint; 294 SkPaint blue_paint;
295 blue_paint.setColor(SK_ColorBLUE); 295 blue_paint.setColor(SK_ColorBLUE);
296 SkCanvas* canvas = recorder.beginRecording(gfx::RectFToSkRect(layer_rect)); 296 SkCanvas* canvas = recorder.beginRecording(gfx::RectFToSkRect(layer_rect));
297 for (int i = 0; i < 100; i++) 297 for (int i = 0; i < 100; i++)
298 canvas->drawPaint(blue_paint); 298 canvas->drawPaint(blue_paint);
299 skia::RefPtr<SkPicture> picture = 299 skia::RefPtr<SkPicture> picture =
300 skia::AdoptRef(recorder.endRecordingAsPicture()); 300 skia::AdoptRef(recorder.endRecordingAsPicture());
301 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get()); 301 size_t picture_size = SkPictureUtils::ApproximateBytesUsed(picture.get());
302 ASSERT_GE(picture_size, 100 * sizeof(SkPaint)); 302 ASSERT_GE(picture_size, 100 * sizeof(SkPaint));
303 ASSERT_LE(picture_size, 200 * sizeof(SkPaint)); 303 ASSERT_LE(picture_size, 200 * sizeof(SkPaint));
304 304
305 // Using a cached picture, we should get about the right size. 305 // Using a cached picture, we should get about the right size.
306 list = DisplayItemList::Create(layer_rect, true); 306 list = DisplayItemList::Create(layer_rect, true);
307 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>(); 307 auto* item = list->CreateAndAppendItem<DrawingDisplayItem>();
308 item->SetNew(picture); 308 item->SetNew(picture);
309 list->Finalize(); 309 list->Finalize();
310 memory_usage = list->PictureMemoryUsage(); 310 memory_usage = list->ApproximateMemoryUsage();
311 EXPECT_GE(memory_usage, picture_size); 311 EXPECT_GE(memory_usage, picture_size);
312 EXPECT_LE(memory_usage, 2 * picture_size); 312 EXPECT_LE(memory_usage, 2 * picture_size);
313 313
314 // Using no cached picture, we should still get the right size. 314 // Using no cached picture, we should still get the right size.
315 list = DisplayItemList::Create(layer_rect, false); 315 list = DisplayItemList::Create(layer_rect, false);
316 item = list->CreateAndAppendItem<DrawingDisplayItem>(); 316 item = list->CreateAndAppendItem<DrawingDisplayItem>();
317 item->SetNew(picture); 317 item->SetNew(picture);
318 list->Finalize(); 318 list->Finalize();
319 memory_usage = list->PictureMemoryUsage(); 319 memory_usage = list->ApproximateMemoryUsage();
320 EXPECT_GE(memory_usage, picture_size); 320 EXPECT_GE(memory_usage, picture_size);
321 EXPECT_LE(memory_usage, 2 * picture_size); 321 EXPECT_LE(memory_usage, 2 * picture_size);
322 322
323 // To avoid double counting, we expect zero size to be computed if both the 323 // To avoid double counting, we expect zero size to be computed if both the
324 // picture and items are retained (currently this only happens due to certain 324 // picture and items are retained (currently this only happens due to certain
325 // categories being traced). 325 // categories being traced).
326 DisplayItemListSettings settings; 326 DisplayItemListSettings settings;
327 settings.use_cached_picture = true; 327 settings.use_cached_picture = true;
328 list = new DisplayItemList(layer_rect, settings, true); 328 list = new DisplayItemList(layer_rect, settings, true);
329 item = list->CreateAndAppendItem<DrawingDisplayItem>(); 329 item = list->CreateAndAppendItem<DrawingDisplayItem>();
330 item->SetNew(picture); 330 item->SetNew(picture);
331 list->Finalize(); 331 list->Finalize();
332 memory_usage = list->PictureMemoryUsage(); 332 memory_usage = list->ApproximateMemoryUsage();
333 EXPECT_EQ(static_cast<size_t>(0), memory_usage); 333 EXPECT_EQ(static_cast<size_t>(0), memory_usage);
334 } 334 }
335 335
336 } // namespace cc 336 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698