• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SkXfermode::Mode const kBlendModes[] = {
15     SkXfermode::kSrcOver_Mode,   SkXfermode::kScreen_Mode,
16     SkXfermode::kOverlay_Mode,   SkXfermode::kDarken_Mode,
17     SkXfermode::kLighten_Mode,   SkXfermode::kColorDodge_Mode,
18     SkXfermode::kColorBurn_Mode, SkXfermode::kHardLight_Mode,
19     SkXfermode::kSoftLight_Mode, SkXfermode::kDifference_Mode,
20     SkXfermode::kExclusion_Mode, SkXfermode::kMultiply_Mode,
21     SkXfermode::kHue_Mode,       SkXfermode::kSaturation_Mode,
22     SkXfermode::kColor_Mode,     SkXfermode::kLuminosity_Mode};
23 
24 const int kBlendModesCount = arraysize(kBlendModes);
25 
26 class LayerTreeHostBlendingPixelTest : public LayerTreePixelTest {
27  protected:
RunBlendingWithRootPixelTestType(PixelTestType type)28   void RunBlendingWithRootPixelTestType(PixelTestType type) {
29     const int kLaneWidth = 15;
30     const int kLaneHeight = kBlendModesCount * kLaneWidth;
31     const int kRootSize = (kBlendModesCount + 2) * kLaneWidth;
32 
33     scoped_refptr<SolidColorLayer> background =
34         CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), kCSSOrange);
35 
36     // Orange child layers will blend with the green background
37     for (int i = 0; i < kBlendModesCount; ++i) {
38       gfx::Rect child_rect(
39           (i + 1) * kLaneWidth, kLaneWidth, kLaneWidth, kLaneHeight);
40       scoped_refptr<SolidColorLayer> green_lane =
41           CreateSolidColorLayer(child_rect, kCSSGreen);
42       background->AddChild(green_lane);
43       green_lane->SetBlendMode(kBlendModes[i]);
44     }
45 
46     RunPixelTest(type,
47                  background,
48                  base::FilePath(FILE_PATH_LITERAL("blending_with_root.png")));
49   }
50 
RunBlendingWithTransparentPixelTestType(PixelTestType type)51   void RunBlendingWithTransparentPixelTestType(PixelTestType type) {
52     const int kLaneWidth = 15;
53     const int kLaneHeight = kBlendModesCount * kLaneWidth;
54     const int kRootSize = (kBlendModesCount + 2) * kLaneWidth;
55 
56     scoped_refptr<SolidColorLayer> root =
57         CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), kCSSBrown);
58 
59     scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
60         gfx::Rect(0, kLaneWidth * 2, kRootSize, kLaneWidth), kCSSOrange);
61 
62     root->AddChild(background);
63     background->SetIsRootForIsolatedGroup(true);
64 
65     // Orange child layers will blend with the green background
66     for (int i = 0; i < kBlendModesCount; ++i) {
67       gfx::Rect child_rect(
68           (i + 1) * kLaneWidth, -kLaneWidth, kLaneWidth, kLaneHeight);
69       scoped_refptr<SolidColorLayer> green_lane =
70           CreateSolidColorLayer(child_rect, kCSSGreen);
71       background->AddChild(green_lane);
72       green_lane->SetBlendMode(kBlendModes[i]);
73     }
74 
75     RunPixelTest(type,
76                  root,
77                  base::FilePath(FILE_PATH_LITERAL("blending_transparent.png")));
78   }
79 };
80 
TEST_F(LayerTreeHostBlendingPixelTest,BlendingWithRoot_GL)81 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithRoot_GL) {
82   RunBlendingWithRootPixelTestType(GL_WITH_BITMAP);
83 }
84 
TEST_F(LayerTreeHostBlendingPixelTest,BlendingWithBackgroundFilter)85 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithBackgroundFilter) {
86   const int kLaneWidth = 15;
87   const int kLaneHeight = kBlendModesCount * kLaneWidth;
88   const int kRootSize = (kBlendModesCount + 2) * kLaneWidth;
89 
90   scoped_refptr<SolidColorLayer> background =
91       CreateSolidColorLayer(gfx::Rect(kRootSize, kRootSize), kCSSOrange);
92 
93   // Orange child layers have a background filter set and they will blend with
94   // the green background
95   for (int i = 0; i < kBlendModesCount; ++i) {
96     gfx::Rect child_rect(
97         (i + 1) * kLaneWidth, kLaneWidth, kLaneWidth, kLaneHeight);
98     scoped_refptr<SolidColorLayer> green_lane =
99         CreateSolidColorLayer(child_rect, kCSSGreen);
100     background->AddChild(green_lane);
101 
102     FilterOperations filters;
103     filters.Append(FilterOperation::CreateGrayscaleFilter(.75));
104     green_lane->SetBackgroundFilters(filters);
105     green_lane->SetBlendMode(kBlendModes[i]);
106   }
107 
108   RunPixelTest(GL_WITH_BITMAP,
109                background,
110                base::FilePath(FILE_PATH_LITERAL("blending_and_filter.png")));
111 }
112 
TEST_F(LayerTreeHostBlendingPixelTest,BlendingWithTransparent_GL)113 TEST_F(LayerTreeHostBlendingPixelTest, BlendingWithTransparent_GL) {
114   RunBlendingWithTransparentPixelTestType(GL_WITH_BITMAP);
115 }
116 
117 }  // namespace
118 }  // namespace cc
119 
120 #endif  // OS_ANDROID
121