Chromium Code Reviews| Index: cc/trees/layer_tree_host_pixeltest_blending.cc |
| diff --git a/cc/trees/layer_tree_host_pixeltest_blending.cc b/cc/trees/layer_tree_host_pixeltest_blending.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1733e328b4631330964a6520617addef1159a9db |
| --- /dev/null |
| +++ b/cc/trees/layer_tree_host_pixeltest_blending.cc |
| @@ -0,0 +1,122 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/layers/solid_color_layer.h" |
| +#include "cc/layers/texture_layer.h" |
| +#include "cc/test/layer_tree_pixel_test.h" |
| + |
| +#if !defined(OS_ANDROID) |
| + |
| +namespace cc { |
| +namespace { |
| + |
| +class LayerTreeHostBlendingPixelTest : public LayerTreePixelTest {}; |
| + |
| +SkXfermode::Mode const blend_modes[] = { |
| + SkXfermode::kSrcOver_Mode, SkXfermode::kScreen_Mode, |
| + SkXfermode::kOverlay_Mode, SkXfermode::kDarken_Mode, |
| + SkXfermode::kLighten_Mode, SkXfermode::kColorDodge_Mode, |
| + SkXfermode::kColorBurn_Mode, SkXfermode::kHardLight_Mode, |
| + SkXfermode::kSoftLight_Mode, SkXfermode::kDifference_Mode, |
| + SkXfermode::kExclusion_Mode, SkXfermode::kMultiply_Mode, |
| + SkXfermode::kHue_Mode, SkXfermode::kSaturation_Mode, |
| + SkXfermode::kColor_Mode, SkXfermode::kLuminosity_Mode}; |
| + |
| +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.
|
| + |
| +TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot) { |
| + unsigned const lane_width = 15; |
| + unsigned const lane_hight = blend_modes_count * lane_width; |
| + unsigned const root_size = (blend_modes_count + 2) * lane_width; |
| + |
| + scoped_refptr<SolidColorLayer> background = |
| + CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSOrange); |
| + |
| + // Orange child layers will blend with the green background |
| + 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!
|
| + gfx::Rect child_rect( |
| + (i + 1) * lane_width, lane_width, lane_width, lane_hight); |
| + scoped_refptr<SolidColorLayer> orange = |
| + CreateSolidColorLayer(child_rect, kCSSGreen); |
| + background->AddChild(orange); |
| + orange->SetBlendMode(blend_modes[i]); |
| + } |
| + |
| + RunPixelTest(GL_WITH_BITMAP, |
| + background, |
| + base::FilePath(FILE_PATH_LITERAL("blending_with_root.png"))); |
| +} |
| + |
| +TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithBackgroundFilter) { |
| + unsigned const lane_width = 15; |
| + unsigned const lane_hight = blend_modes_count * lane_width; |
| + unsigned const root_size = (blend_modes_count + 2) * lane_width; |
| + |
| + scoped_refptr<SolidColorLayer> background = |
| + CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSOrange); |
| + |
| + // Orange child layers have a background filter set and they will blend with |
| + // the green background |
| + for (unsigned i = 0; i < blend_modes_count; ++i) { |
| + gfx::Rect child_rect( |
| + (i + 1) * lane_width, lane_width, lane_width, lane_hight); |
| + scoped_refptr<SolidColorLayer> orange = |
| + CreateSolidColorLayer(child_rect, kCSSGreen); |
| + background->AddChild(orange); |
| + |
| + FilterOperations filters; |
| + filters.Append(FilterOperation::CreateGrayscaleFilter(.75)); |
| + orange->SetBackgroundFilters(filters); |
| + orange->SetBlendMode(blend_modes[i]); |
| + } |
| + |
| + RunPixelTest(GL_WITH_BITMAP, |
| + background, |
| + base::FilePath(FILE_PATH_LITERAL("blending_and_filter.png"))); |
| +} |
| + |
| +TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent) { |
| + unsigned const lane_width = 15; |
| + 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.
|
| + unsigned const root_size = (blend_modes_count + 2) * lane_width; |
| + |
| + scoped_refptr<SolidColorLayer> root = |
| + CreateSolidColorLayer(gfx::Rect(root_size, root_size), kCSSBrown); |
| + |
| + SkBitmap bitmap; |
| + bitmap.setConfig(SkBitmap::kARGB_8888_Config, root_size, root_size); |
| + bitmap.allocPixels(); |
| + SkCanvas canvas(bitmap); |
| + |
| + SkPaint paint; |
| + paint.setColor(SK_ColorRED); |
| + canvas.clear(SK_ColorTRANSPARENT); |
| + gfx::Rect red_lane_quad(0, lane_width * 2, root_size, lane_width); |
| + canvas.drawRect(SkRect::MakeXYWH(0, lane_width * 2, root_size, lane_width), |
| + paint); |
| + |
| + scoped_refptr<TextureLayer> background = |
| + CreateTextureLayer(gfx::Rect(root_size, root_size), bitmap); |
| + root->AddChild(background); |
| + background->SetIsRootForIsolatedGroup(true); |
| + |
| + // Orange child layers will blend with the green background |
| + for (unsigned i = 0; i < blend_modes_count; ++i) { |
| + gfx::Rect child_rect( |
| + (i + 1) * lane_width, lane_width, lane_width, lane_hight); |
| + scoped_refptr<SolidColorLayer> orange = |
| + CreateSolidColorLayer(child_rect, kCSSGreen); |
| + background->AddChild(orange); |
| + orange->SetBlendMode(blend_modes[i]); |
| + } |
| + |
| + RunPixelTest(GL_WITH_BITMAP, |
| + root, |
| + base::FilePath(FILE_PATH_LITERAL("blending_transparent.png"))); |
| +} |
| + |
| +} // namespace |
| +} // namespace cc |
| + |
| +#endif // OS_ANDROID |