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

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

Issue 2820133005: Revert of Back PaintRecord with PaintOpBuffer instead of SkPicture (Closed)
Patch Set: Created 3 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/paint/display_item_list.cc ('k') | cc/paint/paint_canvas.h » ('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/paint/display_item_list.h" 5 #include "cc/paint/display_item_list.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/trace_event/trace_event_argument.h" 12 #include "base/trace_event/trace_event_argument.h"
13 #include "cc/base/filter_operation.h" 13 #include "cc/base/filter_operation.h"
14 #include "cc/base/filter_operations.h" 14 #include "cc/base/filter_operations.h"
15 #include "cc/paint/clip_display_item.h" 15 #include "cc/paint/clip_display_item.h"
16 #include "cc/paint/clip_path_display_item.h" 16 #include "cc/paint/clip_path_display_item.h"
17 #include "cc/paint/compositing_display_item.h" 17 #include "cc/paint/compositing_display_item.h"
18 #include "cc/paint/drawing_display_item.h" 18 #include "cc/paint/drawing_display_item.h"
19 #include "cc/paint/filter_display_item.h" 19 #include "cc/paint/filter_display_item.h"
20
20 #include "cc/paint/float_clip_display_item.h" 21 #include "cc/paint/float_clip_display_item.h"
21 #include "cc/paint/paint_canvas.h" 22 #include "cc/paint/paint_canvas.h"
22 #include "cc/paint/paint_flags.h" 23 #include "cc/paint/paint_flags.h"
23 #include "cc/paint/paint_record.h" 24 #include "cc/paint/paint_record.h"
24 #include "cc/paint/paint_recorder.h" 25 #include "cc/paint/paint_recorder.h"
25 #include "cc/paint/skia_paint_canvas.h"
26 #include "cc/paint/transform_display_item.h" 26 #include "cc/paint/transform_display_item.h"
27 #include "cc/test/geometry_test_utils.h" 27 #include "cc/test/geometry_test_utils.h"
28 #include "cc/test/pixel_test_utils.h" 28 #include "cc/test/pixel_test_utils.h"
29 #include "cc/test/skia_common.h" 29 #include "cc/test/skia_common.h"
30 #include "cc/test/test_skcanvas.h"
31 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
33 #include "third_party/skia/include/core/SkBitmap.h" 32 #include "third_party/skia/include/core/SkBitmap.h"
34 #include "third_party/skia/include/core/SkColor.h" 33 #include "third_party/skia/include/core/SkColor.h"
35 #include "third_party/skia/include/core/SkSurface.h" 34 #include "third_party/skia/include/core/SkSurface.h"
36 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" 35 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
37 #include "third_party/skia/include/effects/SkImageSource.h" 36 #include "third_party/skia/include/effects/SkImageSource.h"
38 #include "ui/gfx/geometry/rect.h" 37 #include "ui/gfx/geometry/rect.h"
39 #include "ui/gfx/geometry/rect_conversions.h" 38 #include "ui/gfx/geometry/rect_conversions.h"
40 #include "ui/gfx/skia_util.h" 39 #include "ui/gfx/skia_util.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 sk_sp<const PaintRecord> CreateRectPicture(const gfx::Rect& bounds) { 73 sk_sp<const PaintRecord> CreateRectPicture(const gfx::Rect& bounds) {
75 PaintRecorder recorder; 74 PaintRecorder recorder;
76 PaintCanvas* canvas = 75 PaintCanvas* canvas =
77 recorder.beginRecording(bounds.width(), bounds.height()); 76 recorder.beginRecording(bounds.width(), bounds.height());
78 canvas->drawRect( 77 canvas->drawRect(
79 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()), 78 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()),
80 PaintFlags()); 79 PaintFlags());
81 return recorder.finishRecordingAsPicture(); 80 return recorder.finishRecordingAsPicture();
82 } 81 }
83 82
84 sk_sp<const PaintRecord> CreateRectPictureWithAlpha(const gfx::Rect& bounds,
85 uint8_t alpha) {
86 PaintRecorder recorder;
87 PaintCanvas* canvas =
88 recorder.beginRecording(bounds.width(), bounds.height());
89 PaintFlags flags;
90 flags.setAlpha(alpha);
91 canvas->drawRect(
92 SkRect::MakeXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height()),
93 flags);
94 return recorder.finishRecordingAsPicture();
95 }
96
97 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list, 83 void AppendFirstSerializationTestPicture(scoped_refptr<DisplayItemList> list,
98 const gfx::Size& layer_size) { 84 const gfx::Size& layer_size) {
99 gfx::PointF offset(2.f, 3.f); 85 gfx::PointF offset(2.f, 3.f);
100 PaintRecorder recorder; 86 PaintRecorder recorder;
101 87
102 PaintFlags red_paint; 88 PaintFlags red_paint;
103 red_paint.setColor(SK_ColorRED); 89 red_paint.setColor(SK_ColorRED);
104 90
105 PaintCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH( 91 PaintCanvas* canvas = recorder.beginRecording(SkRect::MakeXYWH(
106 offset.x(), offset.y(), layer_size.width(), layer_size.height())); 92 offset.x(), offset.y(), layer_size.width(), layer_size.height()));
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>(); 697 list->CreateAndAppendPairedEndItem<EndFilterDisplayItem>();
712 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); 698 list->CreateAndAppendPairedEndItem<EndClipDisplayItem>();
713 699
714 EXPECT_EQ(4u, list->size()); 700 EXPECT_EQ(4u, list->size());
715 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0)); 701 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(0));
716 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1)); 702 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(1));
717 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2)); 703 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(2));
718 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3)); 704 EXPECT_RECT_EQ(filter_bounds, list->VisualRectForTesting(3));
719 } 705 }
720 706
721 // Verify that raster time optimizations for compositing item / draw single op /
722 // end compositing item can be collapsed together into a single draw op
723 // with the opacity from the compositing item folded in.
724 TEST(DisplayItemListTest, SaveDrawRestore) {
725 auto list = make_scoped_refptr(new DisplayItemList);
726
727 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>(
728 80, SkBlendMode::kSrcOver, nullptr, nullptr, false);
729 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
730 kVisualRect, CreateRectPictureWithAlpha(kVisualRect, 40));
731 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>();
732 list->Finalize();
733
734 SaveCountingCanvas canvas;
735 list->Raster(&canvas, nullptr);
736
737 EXPECT_EQ(0, canvas.save_count_);
738 EXPECT_EQ(0, canvas.restore_count_);
739 EXPECT_EQ(gfx::RectToSkRect(kVisualRect), canvas.draw_rect_);
740
741 float expected_alpha = 80 * 40 / 255.f;
742 EXPECT_LE(std::abs(expected_alpha - canvas.paint_.getAlpha()), 1.f);
743 }
744
745 // Verify that compositing item / end compositing item is a noop.
746 // Here we're testing that Skia does an optimization that skips
747 // save/restore with nothing in between. If skia stops doing this
748 // then we should reimplement this optimization in display list raster.
749 TEST(DisplayItemListTest, SaveRestoreNoops) {
750 auto list = make_scoped_refptr(new DisplayItemList);
751
752 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>(
753 80, SkBlendMode::kSrcOver, nullptr, nullptr, false);
754 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>();
755 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>(
756 255, SkBlendMode::kSrcOver, nullptr, nullptr, false);
757 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>();
758 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>(
759 255, SkBlendMode::kSrc, nullptr, nullptr, false);
760 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>();
761 list->Finalize();
762
763 SaveCountingCanvas canvas;
764 list->Raster(&canvas, nullptr);
765
766 EXPECT_EQ(0, canvas.save_count_);
767 EXPECT_EQ(0, canvas.restore_count_);
768 }
769
770 // The same as SaveDrawRestore, but with save flags that prevent the
771 // optimization.
772 TEST(DisplayItemListTest, SaveDrawRestoreFail_BadSaveFlags) {
773 auto list = make_scoped_refptr(new DisplayItemList);
774
775 // Use a blend mode that's not compatible with the SaveDrawRestore
776 // optimization.
777 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>(
778 80, SkBlendMode::kSrc, nullptr, nullptr, false);
779 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
780 kVisualRect, CreateRectPictureWithAlpha(kVisualRect, 40));
781 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>();
782 list->Finalize();
783
784 SaveCountingCanvas canvas;
785 list->Raster(&canvas, nullptr);
786
787 EXPECT_EQ(1, canvas.save_count_);
788 EXPECT_EQ(1, canvas.restore_count_);
789 EXPECT_EQ(gfx::RectToSkRect(kVisualRect), canvas.draw_rect_);
790 EXPECT_LE(40, canvas.paint_.getAlpha());
791 }
792
793 // The same as SaveDrawRestore, but with too many ops in the PaintRecord.
794 TEST(DisplayItemListTest, SaveDrawRestoreFail_TooManyOps) {
795 sk_sp<const PaintRecord> record;
796 {
797 PaintRecorder recorder;
798 PaintCanvas* canvas =
799 recorder.beginRecording(kVisualRect.width(), kVisualRect.height());
800 PaintFlags flags;
801 flags.setAlpha(40);
802 canvas->drawRect(gfx::RectToSkRect(kVisualRect), flags);
803 // Add an extra op here.
804 canvas->drawRect(gfx::RectToSkRect(kVisualRect), flags);
805 record = recorder.finishRecordingAsPicture();
806 }
807 EXPECT_GT(record->approximateOpCount(), 1);
808
809 auto list = make_scoped_refptr(new DisplayItemList);
810
811 list->CreateAndAppendPairedBeginItem<CompositingDisplayItem>(
812 80, SkBlendMode::kSrcOver, nullptr, nullptr, false);
813 list->CreateAndAppendDrawingItem<DrawingDisplayItem>(kVisualRect,
814 std::move(record));
815 list->CreateAndAppendPairedEndItem<EndCompositingDisplayItem>();
816 list->Finalize();
817
818 SaveCountingCanvas canvas;
819 list->Raster(&canvas, nullptr);
820
821 EXPECT_EQ(1, canvas.save_count_);
822 EXPECT_EQ(1, canvas.restore_count_);
823 EXPECT_EQ(gfx::RectToSkRect(kVisualRect), canvas.draw_rect_);
824 EXPECT_LE(40, canvas.paint_.getAlpha());
825 }
826
827 } // namespace cc 707 } // namespace cc
OLDNEW
« no previous file with comments | « cc/paint/display_item_list.cc ('k') | cc/paint/paint_canvas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698