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

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

Issue 658483003: Implement mix-blend-mode in GL renderer using shaders. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new shader specific enum for blend modes Created 6 years, 2 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/image_layer.h"
5 #include "cc/layers/solid_color_layer.h" 6 #include "cc/layers/solid_color_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_comparator.h" 8 #include "cc/test/pixel_comparator.h"
9 9
10 #if !defined(OS_ANDROID) 10 #if !defined(OS_ANDROID)
11 11
12 namespace cc { 12 namespace cc {
13 namespace { 13 namespace {
14 14
15 SkXfermode::Mode const kBlendModes[] = { 15 SkXfermode::Mode const kBlendModes[] = {
16 SkXfermode::kSrcOver_Mode, SkXfermode::kScreen_Mode, 16 SkXfermode::kSrcOver_Mode, SkXfermode::kScreen_Mode,
17 SkXfermode::kOverlay_Mode, SkXfermode::kDarken_Mode, 17 SkXfermode::kOverlay_Mode, SkXfermode::kDarken_Mode,
18 SkXfermode::kLighten_Mode, SkXfermode::kColorDodge_Mode, 18 SkXfermode::kLighten_Mode, SkXfermode::kColorDodge_Mode,
19 SkXfermode::kColorBurn_Mode, SkXfermode::kHardLight_Mode, 19 SkXfermode::kColorBurn_Mode, SkXfermode::kHardLight_Mode,
20 SkXfermode::kSoftLight_Mode, SkXfermode::kDifference_Mode, 20 SkXfermode::kSoftLight_Mode, SkXfermode::kDifference_Mode,
21 SkXfermode::kExclusion_Mode, SkXfermode::kMultiply_Mode, 21 SkXfermode::kExclusion_Mode, SkXfermode::kMultiply_Mode,
22 SkXfermode::kHue_Mode, SkXfermode::kSaturation_Mode, 22 SkXfermode::kHue_Mode, SkXfermode::kSaturation_Mode,
23 SkXfermode::kColor_Mode, SkXfermode::kLuminosity_Mode}; 23 SkXfermode::kColor_Mode, SkXfermode::kLuminosity_Mode};
24 24
25 SkColor kCSSTestColors[] = {
26 0xffff0000, // red
27 0xff00ff00, // lime
28 0xff0000ff, // blue
29 0xff00ffff, // aqua
30 0xffff00ff, // fuchsia
31 0xffffff00, // yellow
32 0xff008000, // green
33 0xff800000, // maroon
34 0xff000080, // navy
35 0xff800080, // purple
36 0xff808000, // olive
37 0xff008080, // teal
38 0xfffa8072, // salmon
39 0xffc0c0c0, // silver
40 0xff000000, // black
41 0xff808080, // gray
42 0x80000000, // black with transparency
43 0xffffffff, // white
44 0x80ffffff, // white with transparency
45 0x00000000 // transparent
46 };
47
25 const int kBlendModesCount = arraysize(kBlendModes); 48 const int kBlendModesCount = arraysize(kBlendModes);
49 const int kCSSTestColorsCount = arraysize(kCSSTestColors);
50
51 using RenderPassOptions = uint32;
52 const uint32 kUseMasks = 1 << 0;
53 const uint32 kUseAntialiasing = 1 << 1;
54 const uint32 kUseColorMatrix = 1 << 2;
26 55
27 class LayerTreeHostBlendingPixelTest : public LayerTreePixelTest { 56 class LayerTreeHostBlendingPixelTest : public LayerTreePixelTest {
28 public: 57 public:
29 LayerTreeHostBlendingPixelTest() { 58 LayerTreeHostBlendingPixelTest() {
30 pixel_comparator_.reset(new FuzzyPixelOffByOneComparator(true)); 59 pixel_comparator_.reset(new FuzzyPixelOffByOneComparator(true));
31 } 60 }
32 61
62 virtual void InitializeSettings(LayerTreeSettings* settings) override {
63 settings->force_antialiasing = force_antialiasing_;
64 }
65
33 protected: 66 protected:
34 void RunBlendingWithRootPixelTestType(PixelTestType type) { 67 void RunBlendingWithRootPixelTestType(PixelTestType type) {
35 const int kLaneWidth = 15; 68 const int kLaneWidth = 15;
36 const int kLaneHeight = kBlendModesCount * kLaneWidth; 69 const int kLaneHeight = kBlendModesCount * kLaneWidth;
37 const int kRootSize = (kBlendModesCount + 2) * kLaneWidth; 70 const int kRootSize = (kBlendModesCount + 2) * kLaneWidth;
38 71
39 scoped_refptr<SolidColorLayer> background = 72 scoped_refptr<SolidColorLayer> background =
40 CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), kCSSOrange); 73 CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), kCSSOrange);
41 74
42 // Orange child layers will blend with the green background 75 // Orange child layers will blend with the green background
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 scoped_refptr<SolidColorLayer> green_lane = 108 scoped_refptr<SolidColorLayer> green_lane =
76 CreateSolidColorLayer(child_rect, kCSSGreen); 109 CreateSolidColorLayer(child_rect, kCSSGreen);
77 background->AddChild(green_lane); 110 background->AddChild(green_lane);
78 green_lane->SetBlendMode(kBlendModes[i]); 111 green_lane->SetBlendMode(kBlendModes[i]);
79 } 112 }
80 113
81 RunPixelTest(type, 114 RunPixelTest(type,
82 root, 115 root,
83 base::FilePath(FILE_PATH_LITERAL("blending_transparent.png"))); 116 base::FilePath(FILE_PATH_LITERAL("blending_transparent.png")));
84 } 117 }
118
119 scoped_refptr<Layer> CreateColorfulBackdropLayer(int width, int height) {
120 // Draw the backdrop with horizontal lanes.
121 const int kLaneWidth = width;
122 const int kLaneHeight = height / kCSSTestColorsCount;
123 SkBitmap backing_store;
124 backing_store.allocN32Pixels(width, height);
125 SkCanvas canvas(backing_store);
126 canvas.clear(SK_ColorTRANSPARENT);
127 for (int i = 0; i < kCSSTestColorsCount; ++i) {
128 SkPaint paint;
129 paint.setColor(kCSSTestColors[i]);
130 canvas.drawRect(
131 SkRect::MakeXYWH(0, i * kLaneHeight, kLaneWidth, kLaneHeight), paint);
132 }
133 scoped_refptr<ImageLayer> layer = ImageLayer::Create();
134 layer->SetIsDrawable(true);
135 layer->SetBounds(gfx::Size(width, height));
136 layer->SetBitmap(backing_store);
137 return layer;
138 }
139
140 void SetupMaskLayer(scoped_refptr<Layer> layer) {
141 const int kMaskOffset = 5;
142 gfx::Size bounds = layer->bounds();
143 scoped_refptr<ImageLayer> mask = ImageLayer::Create();
144 mask->SetIsDrawable(true);
145 mask->SetIsMask(true);
146 mask->SetBounds(bounds);
147
148 SkBitmap bitmap;
149 bitmap.allocN32Pixels(bounds.width(), bounds.height());
150 SkCanvas canvas(bitmap);
151 SkPaint paint;
152 paint.setColor(SK_ColorWHITE);
153 canvas.clear(SK_ColorTRANSPARENT);
154 canvas.drawRect(SkRect::MakeXYWH(kMaskOffset,
155 kMaskOffset,
156 bounds.width() - kMaskOffset * 2,
157 bounds.height() - kMaskOffset * 2),
158 paint);
159 mask->SetBitmap(bitmap);
160 layer->SetMaskLayer(mask.get());
161 }
162
163 void SetupColorMatrix(scoped_refptr<Layer> layer) {
164 FilterOperations filter_operations;
165 filter_operations.Append(FilterOperation::CreateSepiaFilter(1.f));
166 layer->SetFilters(filter_operations);
167 }
168
169 void CreateBlendingColorLayers(int width,
170 int height,
171 scoped_refptr<Layer> background,
172 RenderPassOptions flags) {
173 const int kLanesCount = kBlendModesCount + 4;
174 int lane_width = width / kLanesCount;
175 const SkColor kMiscOpaqueColor = 0xffc86464;
176 const SkColor kMiscTransparentColor = 0x80c86464;
177 const SkXfermode::Mode kCoeffBlendMode = SkXfermode::kScreen_Mode;
178 const SkXfermode::Mode kShaderBlendMode = SkXfermode::kColorBurn_Mode;
179 // add vertical lanes with each of the blend modes
180 for (int i = 0; i < kLanesCount; ++i) {
181 gfx::Rect child_rect(i * lane_width, 0, lane_width, height);
182 SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode;
183 float opacity = 1.f;
184 SkColor color = kMiscOpaqueColor;
185
186 if (i < kBlendModesCount) {
187 blend_mode = kBlendModes[i];
188 } else if (i == kBlendModesCount) {
189 blend_mode = kCoeffBlendMode;
190 opacity = 0.5f;
191 } else if (i == kBlendModesCount + 1) {
192 blend_mode = kCoeffBlendMode;
193 color = kMiscTransparentColor;
194 } else if (i == kBlendModesCount + 2) {
195 blend_mode = kShaderBlendMode;
196 opacity = 0.5f;
197 } else if (i == kBlendModesCount + 3) {
198 blend_mode = kShaderBlendMode;
199 color = kMiscTransparentColor;
200 }
201
202 scoped_refptr<SolidColorLayer> lane =
203 CreateSolidColorLayer(child_rect, color);
204 lane->SetBlendMode(blend_mode);
205 lane->SetOpacity(opacity);
206 lane->SetForceRenderSurface(true);
207 if (flags & kUseMasks)
208 SetupMaskLayer(lane);
209 if (flags & kUseColorMatrix) {
210 SetupColorMatrix(lane);
211 }
212 background->AddChild(lane);
213 }
214 }
215
216 void RunBlendingWithRenderPass(PixelTestType type,
217 const base::FilePath::CharType* expected_path,
218 RenderPassOptions flags) {
219 const int kRootSize = 400;
220
221 scoped_refptr<SolidColorLayer> root =
222 CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), SK_ColorWHITE);
223 scoped_refptr<Layer> background =
224 CreateColorfulBackdropLayer(kRootSize, kRootSize);
225
226 background->SetIsRootForIsolatedGroup(true);
227 root->AddChild(background);
228
229 CreateBlendingColorLayers(kRootSize, kRootSize, background.get(), flags);
230
231 this->impl_side_painting_ = false;
232 this->force_antialiasing_ = (flags & kUseAntialiasing);
233
234 #if defined(OS_WIN)
235 if (flags & kUseAntialiasing) {
236 // Anti aliasing causes differences up to 7 pixels at the edges.
237 int large_error_allowed = 7;
238 // Blending results might differ with one pixel.
239 int small_error_allowed = 1;
240 // Most of the errors are one pixel errors.
241 float percentage_pixels_small_error = 12.5f;
242 // Because of anti-aliasing, around 3% of pixels (at the edges) have
243 // bigger errors (from small_error_allowed + 1 to large_error_allowed).
244 float percentage_pixels_error = 15.0f;
245 // The average error is still close to 1.
246 float average_error_allowed_in_bad_pixels = 1.3f;
247
248 // The sepia filter generates more small errors, but the number of large
249 // errors remains around 3%.
250 if (flags & kUseColorMatrix) {
251 percentage_pixels_small_error = 26.f;
252 percentage_pixels_error = 29.f;
253 }
254
255 // Anti-aliased pixels in combination with non-separable blend modes and
256 // a white background produces several black pixels (6 for these tests).
257 // Having a mask will hide the black pixels.
258 // TODO(rosca): fix this issue for non-separable blend modes.
259 if (!(flags & kUseMasks))
260 large_error_allowed = 255;
261
262 pixel_comparator_.reset(
263 new FuzzyPixelComparator(false, // discard_alpha
264 percentage_pixels_error,
265 percentage_pixels_small_error,
266 average_error_allowed_in_bad_pixels,
267 large_error_allowed,
268 small_error_allowed));
269 } else if (flags & kUseColorMatrix) {
270 float percentage_pixels_error = 100.f;
271 float percentage_pixels_small_error = 0.f;
272 float average_error_allowed_in_bad_pixels = 1.f;
273 int large_error_allowed = 2;
274 int small_error_allowed = 0;
275 pixel_comparator_.reset(
276 new FuzzyPixelComparator(false, // discard_alpha
277 percentage_pixels_error,
278 percentage_pixels_small_error,
279 average_error_allowed_in_bad_pixels,
280 large_error_allowed,
281 small_error_allowed));
282 }
283 #endif
284
285 RunPixelTest(type, root, base::FilePath(expected_path));
286 }
287
288 bool force_antialiasing_ = false;
85 }; 289 };
86 290
87 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot_GL) { 291 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot_GL) {
88 RunBlendingWithRootPixelTestType(GL_WITH_BITMAP); 292 RunBlendingWithRootPixelTestType(GL_WITH_BITMAP);
89 } 293 }
90 294
91 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot_Software) { 295 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot_Software) {
92 RunBlendingWithRootPixelTestType(SOFTWARE_WITH_BITMAP); 296 RunBlendingWithRootPixelTestType(SOFTWARE_WITH_BITMAP);
93 } 297 }
94 298
(...skipping 26 matching lines...) Expand all
121 } 325 }
122 326
123 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent_GL) { 327 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent_GL) {
124 RunBlendingWithTransparentPixelTestType(GL_WITH_BITMAP); 328 RunBlendingWithTransparentPixelTestType(GL_WITH_BITMAP);
125 } 329 }
126 330
127 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent_Software) { 331 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent_Software) {
128 RunBlendingWithTransparentPixelTestType(SOFTWARE_WITH_BITMAP); 332 RunBlendingWithTransparentPixelTestType(SOFTWARE_WITH_BITMAP);
129 } 333 }
130 334
335 // Tests for render passes
336 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRenderPass_GL) {
337 RunBlendingWithRenderPass(
338 GL_WITH_BITMAP, FILE_PATH_LITERAL("blending_render_pass.png"), 0);
339 }
340
341 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRenderPass_Software) {
342 RunBlendingWithRenderPass(
343 SOFTWARE_WITH_BITMAP, FILE_PATH_LITERAL("blending_render_pass.png"), 0);
344 }
345
346 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRenderPassAA_GL) {
347 RunBlendingWithRenderPass(GL_WITH_BITMAP,
348 FILE_PATH_LITERAL("blending_render_pass.png"),
349 kUseAntialiasing);
350 }
351
352 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRenderPassAA_Software) {
353 RunBlendingWithRenderPass(SOFTWARE_WITH_BITMAP,
354 FILE_PATH_LITERAL("blending_render_pass.png"),
355 kUseAntialiasing);
356 }
357
358 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRenderPassWithMask_GL) {
359 RunBlendingWithRenderPass(GL_WITH_BITMAP,
360 FILE_PATH_LITERAL("blending_render_pass_mask.png"),
361 kUseMasks);
362 }
363
364 TEST_F(LayerTreeHostBlendingPixelTest,
365 BlendingWithRenderPassWithMask_Software) {
366 RunBlendingWithRenderPass(SOFTWARE_WITH_BITMAP,
367 FILE_PATH_LITERAL("blending_render_pass_mask.png"),
368 kUseMasks);
369 }
370
371 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRenderPassWithMaskAA_GL) {
372 RunBlendingWithRenderPass(GL_WITH_BITMAP,
373 FILE_PATH_LITERAL("blending_render_pass_mask.png"),
374 kUseMasks | kUseAntialiasing);
375 }
376
377 TEST_F(LayerTreeHostBlendingPixelTest,
378 BlendingWithRenderPassWithMaskAA_Software) {
379 RunBlendingWithRenderPass(SOFTWARE_WITH_BITMAP,
380 FILE_PATH_LITERAL("blending_render_pass_mask.png"),
381 kUseMasks | kUseAntialiasing);
382 }
383
384 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRenderPassColorMatrix_GL) {
385 RunBlendingWithRenderPass(GL_WITH_BITMAP,
386 FILE_PATH_LITERAL("blending_render_pass_cm.png"),
387 kUseColorMatrix);
388 }
389
390 TEST_F(LayerTreeHostBlendingPixelTest,
391 BlendingWithRenderPassColorMatrix_Software) {
392 RunBlendingWithRenderPass(SOFTWARE_WITH_BITMAP,
393 FILE_PATH_LITERAL("blending_render_pass_cm.png"),
394 kUseColorMatrix);
395 }
396
397 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRenderPassColorMatrixAA_GL) {
398 RunBlendingWithRenderPass(GL_WITH_BITMAP,
399 FILE_PATH_LITERAL("blending_render_pass_cm.png"),
400 kUseAntialiasing | kUseColorMatrix);
401 }
402
403 TEST_F(LayerTreeHostBlendingPixelTest,
404 BlendingWithRenderPassColorMatrixAA_Software) {
405 RunBlendingWithRenderPass(SOFTWARE_WITH_BITMAP,
406 FILE_PATH_LITERAL("blending_render_pass_cm.png"),
407 kUseAntialiasing | kUseColorMatrix);
408 }
409
410 TEST_F(LayerTreeHostBlendingPixelTest,
411 BlendingWithRenderPassWithMaskColorMatrix_GL) {
412 RunBlendingWithRenderPass(
413 GL_WITH_BITMAP,
414 FILE_PATH_LITERAL("blending_render_pass_mask_cm.png"),
415 kUseMasks | kUseColorMatrix);
416 }
417
418 TEST_F(LayerTreeHostBlendingPixelTest,
419 BlendingWithRenderPassWithMaskColorMatrix_Software) {
420 RunBlendingWithRenderPass(
421 SOFTWARE_WITH_BITMAP,
422 FILE_PATH_LITERAL("blending_render_pass_mask_cm.png"),
423 kUseMasks | kUseColorMatrix);
424 }
425
426 TEST_F(LayerTreeHostBlendingPixelTest,
427 BlendingWithRenderPassWithMaskColorMatrixAA_GL) {
428 RunBlendingWithRenderPass(
429 GL_WITH_BITMAP,
430 FILE_PATH_LITERAL("blending_render_pass_mask_cm.png"),
431 kUseMasks | kUseAntialiasing | kUseColorMatrix);
432 }
433
434 TEST_F(LayerTreeHostBlendingPixelTest,
435 BlendingWithRenderPassWithMaskColorMatrixAA_Software) {
436 RunBlendingWithRenderPass(
437 SOFTWARE_WITH_BITMAP,
438 FILE_PATH_LITERAL("blending_render_pass_mask_cm.png"),
439 kUseMasks | kUseAntialiasing | kUseColorMatrix);
440 }
441
131 } // namespace 442 } // namespace
132 } // namespace cc 443 } // namespace cc
133 444
134 #endif // OS_ANDROID 445 #endif // OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698