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

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

Issue 2659023003: [cc] Add SkBlendMode::kDstIn support to cc::Layer (Closed)
Patch Set: Created 3 years, 10 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "cc/layers/picture_image_layer.h" 7 #include "cc/layers/picture_image_layer.h"
8 #include "cc/layers/solid_color_layer.h" 8 #include "cc/layers/solid_color_layer.h"
9 #include "cc/test/layer_tree_pixel_resource_test.h" 9 #include "cc/test/layer_tree_pixel_resource_test.h"
10 #include "cc/test/pixel_comparator.h" 10 #include "cc/test/pixel_comparator.h"
11 #include "third_party/skia/include/core/SkImage.h" 11 #include "third_party/skia/include/core/SkImage.h"
12 #include "third_party/skia/include/core/SkSurface.h" 12 #include "third_party/skia/include/core/SkSurface.h"
13 13
14 #if !defined(OS_ANDROID) 14 #if !defined(OS_ANDROID)
15 15
16 namespace cc { 16 namespace cc {
17 namespace { 17 namespace {
18 18
19 SkBlendMode const kBlendModes[] = { 19 SkBlendMode const kBlendModes[] = {
20 SkBlendMode::kSrcOver, SkBlendMode::kScreen, 20 SkBlendMode::kSrcOver, SkBlendMode::kScreen,
21 SkBlendMode::kOverlay, SkBlendMode::kDarken, 21 SkBlendMode::kOverlay, SkBlendMode::kDarken,
22 SkBlendMode::kLighten, SkBlendMode::kColorDodge, 22 SkBlendMode::kLighten, SkBlendMode::kColorDodge,
23 SkBlendMode::kColorBurn, SkBlendMode::kHardLight, 23 SkBlendMode::kColorBurn, SkBlendMode::kHardLight,
24 SkBlendMode::kSoftLight, SkBlendMode::kDifference, 24 SkBlendMode::kSoftLight, SkBlendMode::kDifference,
25 SkBlendMode::kExclusion, SkBlendMode::kMultiply, 25 SkBlendMode::kExclusion, SkBlendMode::kMultiply,
26 SkBlendMode::kHue, SkBlendMode::kSaturation, 26 SkBlendMode::kHue, SkBlendMode::kSaturation,
27 SkBlendMode::kColor, SkBlendMode::kLuminosity}; 27 SkBlendMode::kColor, SkBlendMode::kLuminosity,
28 SkBlendMode::kDstIn};
28 29
29 SkColor kCSSTestColors[] = { 30 SkColor kCSSTestColors[] = {
30 0xffff0000, // red 31 0xffff0000, // red
31 0xff00ff00, // lime 32 0xff00ff00, // lime
32 0xff0000ff, // blue 33 0xff0000ff, // blue
33 0xff00ffff, // aqua 34 0xff00ffff, // aqua
34 0xffff00ff, // fuchsia 35 0xffff00ff, // fuchsia
35 0xffffff00, // yellow 36 0xffffff00, // yellow
36 0xff008000, // green 37 0xff008000, // green
37 0xff800000, // maroon 38 0xff800000, // maroon
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 void SetupColorMatrix(scoped_refptr<Layer> layer) { 174 void SetupColorMatrix(scoped_refptr<Layer> layer) {
174 FilterOperations filter_operations; 175 FilterOperations filter_operations;
175 filter_operations.Append(FilterOperation::CreateSepiaFilter(.001f)); 176 filter_operations.Append(FilterOperation::CreateSepiaFilter(.001f));
176 layer->SetFilters(filter_operations); 177 layer->SetFilters(filter_operations);
177 } 178 }
178 179
179 void CreateBlendingColorLayers(int lane_width, 180 void CreateBlendingColorLayers(int lane_width,
180 int lane_height, 181 int lane_height,
181 scoped_refptr<Layer> background, 182 scoped_refptr<Layer> background,
182 RenderPassOptions flags) { 183 RenderPassOptions flags) {
183 const int kLanesCount = kBlendModesCount + 4; 184 const int kLanesCount = kBlendModesCount + 6;
184 const SkColor kMiscOpaqueColor = 0xffc86464; 185 const SkColor kMiscOpaqueColor = 0xffc86464;
185 const SkColor kMiscTransparentColor = 0x80c86464; 186 const SkColor kMiscTransparentColor = 0x80c86464;
186 const SkBlendMode kCoeffBlendMode = SkBlendMode::kScreen; 187 const SkBlendMode kCoeffBlendMode = SkBlendMode::kScreen;
187 const SkBlendMode kShaderBlendMode = SkBlendMode::kColorBurn; 188 const SkBlendMode kShaderBlendMode = SkBlendMode::kColorBurn;
188 // add vertical lanes with each of the blend modes 189 // add vertical lanes with each of the blend modes
189 for (int i = 0; i < kLanesCount; ++i) { 190 for (int i = 0; i < kLanesCount; ++i) {
190 gfx::Rect child_rect(i * lane_width, 0, lane_width, lane_height); 191 gfx::Rect child_rect(i * lane_width, 0, lane_width, lane_height);
191 SkBlendMode blend_mode = SkBlendMode::kSrcOver; 192 SkBlendMode blend_mode = SkBlendMode::kSrcOver;
192 float opacity = 1.f; 193 float opacity = 1.f;
193 SkColor color = kMiscOpaqueColor; 194 SkColor color = kMiscOpaqueColor;
194 195
195 if (i < kBlendModesCount) { 196 if (i < kBlendModesCount) {
196 blend_mode = kBlendModes[i]; 197 blend_mode = kBlendModes[i];
197 } else if (i == kBlendModesCount) { 198 } else if (i == kBlendModesCount) {
198 blend_mode = kCoeffBlendMode; 199 blend_mode = kCoeffBlendMode;
199 opacity = 0.5f; 200 opacity = 0.5f;
200 } else if (i == kBlendModesCount + 1) { 201 } else if (i == kBlendModesCount + 1) {
201 blend_mode = kCoeffBlendMode; 202 blend_mode = kCoeffBlendMode;
202 color = kMiscTransparentColor; 203 color = kMiscTransparentColor;
203 } else if (i == kBlendModesCount + 2) { 204 } else if (i == kBlendModesCount + 2) {
204 blend_mode = kShaderBlendMode; 205 blend_mode = kShaderBlendMode;
205 opacity = 0.5f; 206 opacity = 0.5f;
206 } else if (i == kBlendModesCount + 3) { 207 } else if (i == kBlendModesCount + 3) {
207 blend_mode = kShaderBlendMode; 208 blend_mode = kShaderBlendMode;
208 color = kMiscTransparentColor; 209 color = kMiscTransparentColor;
210 } else if (i == kBlendModesCount + 4) {
211 blend_mode = SkBlendMode::kDstIn;
212 opacity = 0.5f;
213 } else if (i == kBlendModesCount + 5) {
214 blend_mode = SkBlendMode::kDstIn;
215 color = kMiscTransparentColor;
209 } 216 }
210 217
211 scoped_refptr<SolidColorLayer> lane = 218 scoped_refptr<SolidColorLayer> lane =
212 CreateSolidColorLayer(child_rect, color); 219 CreateSolidColorLayer(child_rect, color);
213 lane->SetBlendMode(blend_mode); 220 lane->SetBlendMode(blend_mode);
214 lane->SetOpacity(opacity); 221 lane->SetOpacity(opacity);
215 lane->SetForceRenderSurfaceForTesting(true); 222 lane->SetForceRenderSurfaceForTesting(true);
216 if (flags & kUseMasks) 223 // Layers with kDstIn blend mode with a mask is not supported.
224 if (flags & kUseMasks && blend_mode != SkBlendMode::kDstIn)
217 SetupMaskLayer(lane); 225 SetupMaskLayer(lane);
218 if (flags & kUseColorMatrix) { 226 if (flags & kUseColorMatrix) {
219 SetupColorMatrix(lane); 227 SetupColorMatrix(lane);
220 } 228 }
221 background->AddChild(lane); 229 background->AddChild(lane);
222 } 230 }
223 } 231 }
224 232
225 void RunBlendingWithRenderPass(PixelResourceTestCase type, 233 void RunBlendingWithRenderPass(PixelResourceTestCase type,
226 const base::FilePath::CharType* expected_path, 234 const base::FilePath::CharType* expected_path,
227 RenderPassOptions flags) { 235 RenderPassOptions flags) {
228 const int kLaneWidth = 8; 236 const int kLaneWidth = 8;
229 const int kLaneHeight = kLaneWidth * kCSSTestColorsCount; 237 const int kRootWidth = kLaneWidth * (kBlendModesCount + 6);
230 const int kRootSize = kLaneHeight; 238 const int kRootHeight = kLaneWidth * kCSSTestColorsCount;
231 InitializeFromTestCase(type); 239 InitializeFromTestCase(type);
232 240
233 scoped_refptr<SolidColorLayer> root = 241 scoped_refptr<SolidColorLayer> root = CreateSolidColorLayer(
234 CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), SK_ColorWHITE); 242 gfx::Rect(kRootWidth, kRootHeight), SK_ColorWHITE);
235 scoped_refptr<Layer> background = 243 scoped_refptr<Layer> background =
236 CreateColorfulBackdropLayer(kRootSize, kRootSize); 244 CreateColorfulBackdropLayer(kRootWidth, kRootHeight);
237 245
238 background->SetIsRootForIsolatedGroup(true); 246 background->SetIsRootForIsolatedGroup(true);
239 root->AddChild(background); 247 root->AddChild(background);
240 248
241 CreateBlendingColorLayers(kLaneWidth, kLaneHeight, background.get(), flags); 249 CreateBlendingColorLayers(kLaneWidth, kRootHeight, background.get(), flags);
242 250
243 this->force_antialiasing_ = (flags & kUseAntialiasing); 251 this->force_antialiasing_ = (flags & kUseAntialiasing);
244 this->force_blending_with_shaders_ = (flags & kForceShaders); 252 this->force_blending_with_shaders_ = (flags & kForceShaders);
245 253
246 if ((flags & kUseAntialiasing) && (test_type_ == PIXEL_TEST_GL)) { 254 if ((flags & kUseAntialiasing) && (test_type_ == PIXEL_TEST_GL)) {
247 // Anti aliasing causes differences up to 8 pixels at the edges. 255 // Anti aliasing causes differences up to 8 pixels at the edges.
248 int large_error_allowed = 8; 256 int large_error_allowed = 8;
249 // Blending results might differ with one pixel. 257 // Blending results might differ with one pixel.
250 int small_error_allowed = 1; 258 int small_error_allowed = 1;
251 // Most of the errors are one pixel errors. 259 // Most of the errors are one pixel errors.
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 RunBlendingWithRenderPass( 500 RunBlendingWithRenderPass(
493 GL_ZERO_COPY_RECT_DRAW, 501 GL_ZERO_COPY_RECT_DRAW,
494 FILE_PATH_LITERAL("blending_render_pass_mask.png"), 502 FILE_PATH_LITERAL("blending_render_pass_mask.png"),
495 kUseMasks | kUseAntialiasing | kUseColorMatrix | kForceShaders); 503 kUseMasks | kUseAntialiasing | kUseColorMatrix | kForceShaders);
496 } 504 }
497 505
498 } // namespace 506 } // namespace
499 } // namespace cc 507 } // namespace cc
500 508
501 #endif // OS_ANDROID 509 #endif // OS_ANDROID
OLDNEW
« cc/layers/render_surface_impl.cc ('K') | « cc/test/data/blending_with_root.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698