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

Side by Side Diff: cc/paint/paint_op_buffer_unittest.cc

Issue 2830243002: cc: Don't perform image analysis if the DisplayItemList has no images. (Closed)
Patch Set: rebase Created 3 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/paint/paint_op_buffer.cc ('k') | cc/paint/transform_display_item.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/paint/paint_op_buffer.h" 5 #include "cc/paint/paint_op_buffer.h"
6 #include "cc/paint/display_item_list.h"
7 #include "cc/test/skia_common.h"
6 #include "cc/test/test_skcanvas.h" 8 #include "cc/test/test_skcanvas.h"
7 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
8 10
9 namespace { 11 namespace {
10 12
11 template <typename T> 13 template <typename T>
12 void CheckRefCnt(const T& obj, int32_t count) { 14 void CheckRefCnt(const T& obj, int32_t count) {
13 // Skia doesn't define getRefCnt in all builds. 15 // Skia doesn't define getRefCnt in all builds.
14 #ifdef SK_DEBUG 16 #ifdef SK_DEBUG
15 EXPECT_EQ(obj->getRefCnt(), count); 17 EXPECT_EQ(obj->getRefCnt(), count);
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 buffer.push<DrawRecordOp>(std::move(record)); 412 buffer.push<DrawRecordOp>(std::move(record));
411 buffer.push<RestoreOp>(); 413 buffer.push<RestoreOp>();
412 414
413 SaveCountingCanvas canvas; 415 SaveCountingCanvas canvas;
414 buffer.playback(&canvas); 416 buffer.playback(&canvas);
415 417
416 EXPECT_EQ(1, canvas.save_count_); 418 EXPECT_EQ(1, canvas.save_count_);
417 EXPECT_EQ(1, canvas.restore_count_); 419 EXPECT_EQ(1, canvas.restore_count_);
418 } 420 }
419 421
422 TEST(PaintOpBufferTest, DiscardableImagesTracking_EmptyBuffer) {
423 PaintOpBuffer buffer;
424 EXPECT_FALSE(buffer.HasDiscardableImages());
425 }
426
427 TEST(PaintOpBufferTest, DiscardableImagesTracking_NoImageOp) {
428 PaintOpBuffer buffer;
429 PaintFlags flags;
430 buffer.push<DrawRectOp>(SkRect::MakeWH(100, 100), flags);
431 EXPECT_FALSE(buffer.HasDiscardableImages());
432 }
433
434 TEST(PaintOpBufferTest, DiscardableImagesTracking_DrawImage) {
435 PaintOpBuffer buffer;
436 PaintImage image = PaintImage(CreateDiscardableImage(gfx::Size(100, 100)));
437 buffer.push<DrawImageOp>(image, SkIntToScalar(0), SkIntToScalar(0), nullptr);
438 EXPECT_TRUE(buffer.HasDiscardableImages());
439 }
440
441 TEST(PaintOpBufferTest, DiscardableImagesTracking_DrawImageRect) {
442 PaintOpBuffer buffer;
443 PaintImage image = PaintImage(CreateDiscardableImage(gfx::Size(100, 100)));
444 buffer.push<DrawImageRectOp>(
445 image, SkRect::MakeWH(100, 100), SkRect::MakeWH(100, 100), nullptr,
446 PaintCanvas::SrcRectConstraint::kFast_SrcRectConstraint);
447 EXPECT_TRUE(buffer.HasDiscardableImages());
448 }
449
450 TEST(PaintOpBufferTest, DiscardableImagesTracking_NestedDrawOp) {
451 sk_sp<PaintRecord> record = sk_make_sp<PaintRecord>();
452 PaintImage image = PaintImage(CreateDiscardableImage(gfx::Size(100, 100)));
453 record->push<DrawImageOp>(image, SkIntToScalar(0), SkIntToScalar(0), nullptr);
454
455 PaintOpBuffer buffer;
456 buffer.push<DrawRecordOp>(record);
457 EXPECT_TRUE(buffer.HasDiscardableImages());
458
459 scoped_refptr<DisplayItemList> list = new DisplayItemList;
460 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
461 gfx::Rect(0, 0, 100, 100), record);
462 list->Finalize();
463 PaintOpBuffer new_buffer;
464 new_buffer.push<DrawDisplayItemListOp>(list);
465 EXPECT_TRUE(new_buffer.HasDiscardableImages());
466 }
467
468 TEST(PaintOpBufferTest, DiscardableImagesTracking_OpWithFlags) {
469 PaintOpBuffer buffer;
470 PaintFlags flags;
471 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(100, 100));
472 flags.setShader(
473 image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode));
474 buffer.push<DrawRectOp>(SkRect::MakeWH(100, 100), flags);
475 EXPECT_TRUE(buffer.HasDiscardableImages());
476 }
477
420 } // namespace cc 478 } // namespace cc
OLDNEW
« no previous file with comments | « cc/paint/paint_op_buffer.cc ('k') | cc/paint/transform_display_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698