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

Side by Side Diff: cc/trees/layer_tree_host_pixeltest_blending.cc

Issue 532003003: Adding support for blending in cc::SoftwareRenderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/layers/solid_color_layer.h" 5 #include "cc/layers/solid_color_layer.h"
6 #include "cc/layers/texture_layer.h" 6 #include "cc/layers/texture_layer.h"
7 #include "cc/test/layer_tree_pixel_test.h" 7 #include "cc/test/layer_tree_pixel_test.h"
8 #include "cc/test/pixel_test.h"
8 9
9 #if !defined(OS_ANDROID) 10 #if !defined(OS_ANDROID)
10 11
11 namespace cc { 12 namespace cc {
12 namespace { 13 namespace {
13 14
14 SkXfermode::Mode const kBlendModes[] = { 15 SkXfermode::Mode const kBlendModes[] = {
15 SkXfermode::kSrcOver_Mode, SkXfermode::kScreen_Mode, 16 SkXfermode::kSrcOver_Mode, SkXfermode::kScreen_Mode,
16 SkXfermode::kOverlay_Mode, SkXfermode::kDarken_Mode, 17 SkXfermode::kOverlay_Mode, SkXfermode::kDarken_Mode,
17 SkXfermode::kLighten_Mode, SkXfermode::kColorDodge_Mode, 18 SkXfermode::kLighten_Mode, SkXfermode::kColorDodge_Mode,
18 SkXfermode::kColorBurn_Mode, SkXfermode::kHardLight_Mode, 19 SkXfermode::kColorBurn_Mode, SkXfermode::kHardLight_Mode,
19 SkXfermode::kSoftLight_Mode, SkXfermode::kDifference_Mode, 20 SkXfermode::kSoftLight_Mode, SkXfermode::kDifference_Mode,
20 SkXfermode::kExclusion_Mode, SkXfermode::kMultiply_Mode, 21 SkXfermode::kExclusion_Mode, SkXfermode::kMultiply_Mode,
21 SkXfermode::kHue_Mode, SkXfermode::kSaturation_Mode, 22 SkXfermode::kHue_Mode, SkXfermode::kSaturation_Mode,
22 SkXfermode::kColor_Mode, SkXfermode::kLuminosity_Mode}; 23 SkXfermode::kColor_Mode, SkXfermode::kLuminosity_Mode};
23 24
24 const int kBlendModesCount = arraysize(kBlendModes); 25 const int kBlendModesCount = arraysize(kBlendModes);
25 26
27 // All pixels can be off by one, but any more than that is an error.
28 class FuzzyPixelOffByOneComparator : public FuzzyPixelComparator {
enne (OOO) 2014/09/05 17:49:08 I feel like this is duplicated elsewhere. Can you
rosca 2014/09/05 20:52:27 Done.
29 public:
30 explicit FuzzyPixelOffByOneComparator(bool discard_alpha)
31 : FuzzyPixelComparator(discard_alpha, 100.f, 0.f, 1.f, 1, 0) {}
32 };
33
26 class LayerTreeHostBlendingPixelTest : public LayerTreePixelTest { 34 class LayerTreeHostBlendingPixelTest : public LayerTreePixelTest {
27 protected: 35 protected:
28 void RunBlendingWithRootPixelTestType(PixelTestType type) { 36 void RunBlendingWithRootPixelTestType(PixelTestType type) {
29 const int kLaneWidth = 15; 37 const int kLaneWidth = 15;
30 const int kLaneHeight = kBlendModesCount * kLaneWidth; 38 const int kLaneHeight = kBlendModesCount * kLaneWidth;
31 const int kRootSize = (kBlendModesCount + 2) * kLaneWidth; 39 const int kRootSize = (kBlendModesCount + 2) * kLaneWidth;
32 40
33 scoped_refptr<SolidColorLayer> background = 41 scoped_refptr<SolidColorLayer> background =
34 CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), kCSSOrange); 42 CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), kCSSOrange);
35 43
36 // Orange child layers will blend with the green background 44 // Orange child layers will blend with the green background
37 for (int i = 0; i < kBlendModesCount; ++i) { 45 for (int i = 0; i < kBlendModesCount; ++i) {
38 gfx::Rect child_rect( 46 gfx::Rect child_rect(
39 (i + 1) * kLaneWidth, kLaneWidth, kLaneWidth, kLaneHeight); 47 (i + 1) * kLaneWidth, kLaneWidth, kLaneWidth, kLaneHeight);
40 scoped_refptr<SolidColorLayer> green_lane = 48 scoped_refptr<SolidColorLayer> green_lane =
41 CreateSolidColorLayer(child_rect, kCSSGreen); 49 CreateSolidColorLayer(child_rect, kCSSGreen);
42 background->AddChild(green_lane); 50 background->AddChild(green_lane);
43 green_lane->SetBlendMode(kBlendModes[i]); 51 green_lane->SetBlendMode(kBlendModes[i]);
44 } 52 }
45 53
54 if (type == SOFTWARE_WITH_BITMAP)
enne (OOO) 2014/09/05 17:49:08 I'd be ok with making all the blending tests use a
rosca 2014/09/05 20:52:28 Done.
55 pixel_comparator_.reset(new FuzzyPixelOffByOneComparator(true));
56
46 RunPixelTest(type, 57 RunPixelTest(type,
47 background, 58 background,
48 base::FilePath(FILE_PATH_LITERAL("blending_with_root.png"))); 59 base::FilePath(FILE_PATH_LITERAL("blending_with_root.png")));
49 } 60 }
50 61
51 void RunBlendingWithTransparentPixelTestType(PixelTestType type) { 62 void RunBlendingWithTransparentPixelTestType(PixelTestType type) {
52 const int kLaneWidth = 15; 63 const int kLaneWidth = 15;
53 const int kLaneHeight = kBlendModesCount * kLaneWidth; 64 const int kLaneHeight = kBlendModesCount * kLaneWidth;
54 const int kRootSize = (kBlendModesCount + 2) * kLaneWidth; 65 const int kRootSize = (kBlendModesCount + 2) * kLaneWidth;
55 66
56 scoped_refptr<SolidColorLayer> root = 67 scoped_refptr<SolidColorLayer> root =
57 CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), kCSSBrown); 68 CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), kCSSBrown);
58 69
59 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( 70 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
60 gfx::Rect(0, kLaneWidth * 2, kRootSize, kLaneWidth), kCSSOrange); 71 gfx::Rect(0, kLaneWidth * 2, kRootSize, kLaneWidth), kCSSOrange);
61 72
62 root->AddChild(background); 73 root->AddChild(background);
63 background->SetIsRootForIsolatedGroup(true); 74 background->SetIsRootForIsolatedGroup(true);
64 75
65 // Orange child layers will blend with the green background 76 // Orange child layers will blend with the green background
66 for (int i = 0; i < kBlendModesCount; ++i) { 77 for (int i = 0; i < kBlendModesCount; ++i) {
67 gfx::Rect child_rect( 78 gfx::Rect child_rect(
68 (i + 1) * kLaneWidth, -kLaneWidth, kLaneWidth, kLaneHeight); 79 (i + 1) * kLaneWidth, -kLaneWidth, kLaneWidth, kLaneHeight);
69 scoped_refptr<SolidColorLayer> green_lane = 80 scoped_refptr<SolidColorLayer> green_lane =
70 CreateSolidColorLayer(child_rect, kCSSGreen); 81 CreateSolidColorLayer(child_rect, kCSSGreen);
71 background->AddChild(green_lane); 82 background->AddChild(green_lane);
72 green_lane->SetBlendMode(kBlendModes[i]); 83 green_lane->SetBlendMode(kBlendModes[i]);
73 } 84 }
74 85
86 if (type == SOFTWARE_WITH_BITMAP)
87 pixel_comparator_.reset(new FuzzyPixelOffByOneComparator(true));
88
75 RunPixelTest(type, 89 RunPixelTest(type,
76 root, 90 root,
77 base::FilePath(FILE_PATH_LITERAL("blending_transparent.png"))); 91 base::FilePath(FILE_PATH_LITERAL("blending_transparent.png")));
78 } 92 }
79 }; 93 };
80 94
81 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot_GL) { 95 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot_GL) {
82 RunBlendingWithRootPixelTestType(GL_WITH_BITMAP); 96 RunBlendingWithRootPixelTestType(GL_WITH_BITMAP);
83 } 97 }
84 98
99 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot_Software) {
100 RunBlendingWithRootPixelTestType(SOFTWARE_WITH_BITMAP);
101 }
102
85 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithBackgroundFilter) { 103 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithBackgroundFilter) {
86 const int kLaneWidth = 15; 104 const int kLaneWidth = 15;
87 const int kLaneHeight = kBlendModesCount * kLaneWidth; 105 const int kLaneHeight = kBlendModesCount * kLaneWidth;
88 const int kRootSize = (kBlendModesCount + 2) * kLaneWidth; 106 const int kRootSize = (kBlendModesCount + 2) * kLaneWidth;
89 107
90 scoped_refptr<SolidColorLayer> background = 108 scoped_refptr<SolidColorLayer> background =
91 CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), kCSSOrange); 109 CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), kCSSOrange);
92 110
93 // Orange child layers have a background filter set and they will blend with 111 // Orange child layers have a background filter set and they will blend with
94 // the green background 112 // the green background
(...skipping 12 matching lines...) Expand all
107 125
108 RunPixelTest(GL_WITH_BITMAP, 126 RunPixelTest(GL_WITH_BITMAP,
109 background, 127 background,
110 base::FilePath(FILE_PATH_LITERAL("blending_and_filter.png"))); 128 base::FilePath(FILE_PATH_LITERAL("blending_and_filter.png")));
111 } 129 }
112 130
113 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent_GL) { 131 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent_GL) {
114 RunBlendingWithTransparentPixelTestType(GL_WITH_BITMAP); 132 RunBlendingWithTransparentPixelTestType(GL_WITH_BITMAP);
115 } 133 }
116 134
135 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent_Software) {
136 RunBlendingWithTransparentPixelTestType(SOFTWARE_WITH_BITMAP);
137 }
138
117 } // namespace 139 } // namespace
118 } // namespace cc 140 } // namespace cc
119 141
120 #endif // OS_ANDROID 142 #endif // OS_ANDROID
OLDNEW
« cc/output/software_renderer.cc ('K') | « cc/output/software_renderer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698