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

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

Issue 23455060: mix-blend-mode implementation for accelerated layers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding compositor pixel tests, clang-format Created 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/layers/solid_color_layer.h"
6 #include "cc/layers/texture_layer.h"
7 #include "cc/test/layer_tree_pixel_test.h"
8
9 #if !defined(OS_ANDROID)
10
11 namespace cc {
12 namespace {
13
14 class LayerTreeHostBlendingPixelTest : public LayerTreePixelTest {};
15
16 SkXfermode::Mode const blend_modes[] = {
17 SkXfermode::kSrcOver_Mode, SkXfermode::kScreen_Mode,
18 SkXfermode::kOverlay_Mode, SkXfermode::kDarken_Mode,
19 SkXfermode::kLighten_Mode, SkXfermode::kColorDodge_Mode,
20 SkXfermode::kColorBurn_Mode, SkXfermode::kHardLight_Mode,
21 SkXfermode::kSoftLight_Mode, SkXfermode::kDifference_Mode,
22 SkXfermode::kExclusion_Mode, SkXfermode::kMultiply_Mode,
23 SkXfermode::kHue_Mode, SkXfermode::kSaturation_Mode,
24 SkXfermode::kColor_Mode, SkXfermode::kLuminosity_Mode};
25
26 unsigned const blend_modes_count = arraysize(blend_modes);
enne (OOO) 2013/11/01 18:49:02 unsigned const => const int, here and elsewhere.
rosca 2013/11/04 17:14:34 Done.
27
28 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot) {
29 unsigned const lane_width = 15;
30 unsigned const lane_hight = blend_modes_count * lane_width;
31 unsigned const root_size = (blend_modes_count + 2) * lane_width;
32
33 scoped_refptr<SolidColorLayer> background =
34 CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSOrange);
35
36 // Orange child layers will blend with the green background
37 for (unsigned i = 0; i < blend_modes_count; ++i) {
enne (OOO) 2013/11/01 18:49:02 I like these these tests a lot, thanks!
38 gfx::Rect child_rect(
39 (i + 1) * lane_width, lane_width, lane_width, lane_hight);
40 scoped_refptr<SolidColorLayer> orange =
41 CreateSolidColorLayer(child_rect, kCSSGreen);
42 background->AddChild(orange);
43 orange->SetBlendMode(blend_modes[i]);
44 }
45
46 RunPixelTest(GL_WITH_BITMAP,
47 background,
48 base::FilePath(FILE_PATH_LITERAL("blending_with_root.png")));
49 }
50
51 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithBackgroundFilter) {
52 unsigned const lane_width = 15;
53 unsigned const lane_hight = blend_modes_count * lane_width;
54 unsigned const root_size = (blend_modes_count + 2) * lane_width;
55
56 scoped_refptr<SolidColorLayer> background =
57 CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSOrange);
58
59 // Orange child layers have a background filter set and they will blend with
60 // the green background
61 for (unsigned i = 0; i < blend_modes_count; ++i) {
62 gfx::Rect child_rect(
63 (i + 1) * lane_width, lane_width, lane_width, lane_hight);
64 scoped_refptr<SolidColorLayer> orange =
65 CreateSolidColorLayer(child_rect, kCSSGreen);
66 background->AddChild(orange);
67
68 FilterOperations filters;
69 filters.Append(FilterOperation::CreateGrayscaleFilter(.75));
70 orange->SetBackgroundFilters(filters);
71 orange->SetBlendMode(blend_modes[i]);
72 }
73
74 RunPixelTest(GL_WITH_BITMAP,
75 background,
76 base::FilePath(FILE_PATH_LITERAL("blending_and_filter.png")));
77 }
78
79 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent) {
80 unsigned const lane_width = 15;
81 unsigned const lane_hight = blend_modes_count * lane_width;
enne (OOO) 2013/11/01 18:49:02 hight => height
rosca 2013/11/04 17:14:34 Done.
82 unsigned const root_size = (blend_modes_count + 2) * lane_width;
83
84 scoped_refptr<SolidColorLayer> root =
85 CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSBrown);
86
87 SkBitmap bitmap;
88 bitmap.setConfig(SkBitmap::kARGB_8888_Config, root_size, root_size);
89 bitmap.allocPixels();
90 SkCanvas canvas(bitmap);
91
92 SkPaint paint;
93 paint.setColor(SK_ColorRED);
94 canvas.clear(SK_ColorTRANSPARENT);
95 gfx::Rect red_lane_quad(0, lane_width * 2, root_size, lane_width);
96 canvas.drawRect(SkRect::MakeXYWH(0, lane_width * 2, root_size, lane_width),
97 paint);
98
99 scoped_refptr<TextureLayer> background =
100 CreateTextureLayer(gfx::Rect(root_size, root_size), bitmap);
101 root->AddChild(background);
102 background->SetIsRootForIsolatedGroup(true);
103
104 // Orange child layers will blend with the green background
105 for (unsigned i = 0; i < blend_modes_count; ++i) {
106 gfx::Rect child_rect(
107 (i + 1) * lane_width, lane_width, lane_width, lane_hight);
108 scoped_refptr<SolidColorLayer> orange =
109 CreateSolidColorLayer(child_rect, kCSSGreen);
110 background->AddChild(orange);
111 orange->SetBlendMode(blend_modes[i]);
112 }
113
114 RunPixelTest(GL_WITH_BITMAP,
115 root,
116 base::FilePath(FILE_PATH_LITERAL("blending_transparent.png")));
117 }
118
119 } // namespace
120 } // namespace cc
121
122 #endif // OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698