Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / trees / layer_tree_host_pixeltest_masks.cc
blob9b386866ee3c4f67e023132aad95faf6a69804c7
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.
5 #include "build/build_config.h"
6 #include "cc/layers/content_layer.h"
7 #include "cc/layers/content_layer_client.h"
8 #include "cc/layers/image_layer.h"
9 #include "cc/layers/solid_color_layer.h"
10 #include "cc/test/layer_tree_pixel_test.h"
11 #include "cc/test/pixel_comparator.h"
13 #if !defined(OS_ANDROID)
15 namespace cc {
16 namespace {
18 class LayerTreeHostMasksPixelTest : public LayerTreePixelTest {};
20 class MaskContentLayerClient : public ContentLayerClient {
21 public:
22 MaskContentLayerClient() {}
23 virtual ~MaskContentLayerClient() {}
25 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
27 virtual bool FillsBoundsCompletely() const OVERRIDE { return false; }
29 virtual void PaintContents(
30 SkCanvas* canvas,
31 const gfx::Rect& rect,
32 gfx::RectF* opaque_rect,
33 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {
34 SkPaint paint;
35 paint.setStyle(SkPaint::kStroke_Style);
36 paint.setStrokeWidth(SkIntToScalar(2));
37 paint.setColor(SK_ColorWHITE);
39 canvas->clear(SK_ColorTRANSPARENT);
40 gfx::Rect inset_rect(rect);
41 while (!inset_rect.IsEmpty()) {
42 inset_rect.Inset(3, 3, 2, 2);
43 canvas->drawRect(
44 SkRect::MakeXYWH(inset_rect.x(), inset_rect.y(),
45 inset_rect.width(), inset_rect.height()),
46 paint);
47 inset_rect.Inset(3, 3, 2, 2);
52 TEST_F(LayerTreeHostMasksPixelTest, MaskOfLayer) {
53 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
54 gfx::Rect(200, 200), SK_ColorWHITE);
56 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
57 gfx::Rect(50, 50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
58 background->AddChild(green);
60 MaskContentLayerClient client;
61 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
62 mask->SetBounds(gfx::Size(100, 100));
63 mask->SetIsDrawable(true);
64 mask->SetIsMask(true);
65 green->SetMaskLayer(mask.get());
67 this->impl_side_painting_ = false;
68 RunPixelTest(GL_WITH_BITMAP,
69 background,
70 base::FilePath(FILE_PATH_LITERAL("mask_of_layer.png")));
73 TEST_F(LayerTreeHostMasksPixelTest, ImageMaskOfLayer) {
74 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
75 gfx::Rect(200, 200), SK_ColorWHITE);
77 scoped_refptr<ImageLayer> mask = ImageLayer::Create();
78 mask->SetIsDrawable(true);
79 mask->SetIsMask(true);
80 mask->SetBounds(gfx::Size(100, 100));
82 SkBitmap bitmap;
83 bitmap.allocN32Pixels(400, 400);
84 SkCanvas canvas(bitmap);
85 canvas.scale(SkIntToScalar(4), SkIntToScalar(4));
86 MaskContentLayerClient client;
87 client.PaintContents(&canvas,
88 gfx::Rect(100, 100),
89 NULL,
90 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED);
91 mask->SetBitmap(bitmap);
93 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
94 gfx::Rect(50, 50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
95 green->SetMaskLayer(mask.get());
96 background->AddChild(green);
98 this->impl_side_painting_ = false;
99 RunPixelTest(GL_WITH_BITMAP,
100 background,
101 base::FilePath(FILE_PATH_LITERAL("image_mask_of_layer.png")));
104 TEST_F(LayerTreeHostMasksPixelTest, MaskOfClippedLayer) {
105 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
106 gfx::Rect(200, 200), SK_ColorWHITE);
108 // Clip to the top half of the green layer.
109 scoped_refptr<Layer> clip = Layer::Create();
110 clip->SetPosition(gfx::Point(0, 0));
111 clip->SetBounds(gfx::Size(200, 100));
112 clip->SetMasksToBounds(true);
113 background->AddChild(clip);
115 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
116 gfx::Rect(50, 50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
117 clip->AddChild(green);
119 MaskContentLayerClient client;
120 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
121 mask->SetBounds(gfx::Size(100, 100));
122 mask->SetIsDrawable(true);
123 mask->SetIsMask(true);
124 green->SetMaskLayer(mask.get());
126 this->impl_side_painting_ = false;
127 RunPixelTest(GL_WITH_BITMAP,
128 background,
129 base::FilePath(FILE_PATH_LITERAL("mask_of_clipped_layer.png")));
132 TEST_F(LayerTreeHostMasksPixelTest, MaskWithReplica) {
133 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
134 gfx::Rect(200, 200), SK_ColorWHITE);
136 MaskContentLayerClient client;
137 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
138 mask->SetBounds(gfx::Size(100, 100));
139 mask->SetIsDrawable(true);
140 mask->SetIsMask(true);
142 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
143 gfx::Rect(0, 0, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
144 background->AddChild(green);
145 green->SetMaskLayer(mask.get());
147 gfx::Transform replica_transform;
148 replica_transform.Rotate(-90.0);
150 scoped_refptr<Layer> replica = Layer::Create();
151 replica->SetTransformOrigin(gfx::Point3F(50.f, 50.f, 0.f));
152 replica->SetPosition(gfx::Point(100, 100));
153 replica->SetTransform(replica_transform);
154 green->SetReplicaLayer(replica.get());
156 this->impl_side_painting_ = false;
157 RunPixelTest(GL_WITH_BITMAP,
158 background,
159 base::FilePath(FILE_PATH_LITERAL("mask_with_replica.png")));
162 TEST_F(LayerTreeHostMasksPixelTest, MaskWithReplicaOfClippedLayer) {
163 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
164 gfx::Rect(200, 200), SK_ColorWHITE);
166 MaskContentLayerClient client;
167 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
168 mask->SetBounds(gfx::Size(100, 100));
169 mask->SetIsDrawable(true);
170 mask->SetIsMask(true);
172 // Clip to the bottom half of the green layer, and the left half of the
173 // replica.
174 scoped_refptr<Layer> clip = Layer::Create();
175 clip->SetPosition(gfx::Point(0, 50));
176 clip->SetBounds(gfx::Size(150, 150));
177 clip->SetMasksToBounds(true);
178 background->AddChild(clip);
180 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
181 gfx::Rect(0, -50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
182 clip->AddChild(green);
183 green->SetMaskLayer(mask.get());
185 gfx::Transform replica_transform;
186 replica_transform.Rotate(-90.0);
188 scoped_refptr<Layer> replica = Layer::Create();
189 replica->SetTransformOrigin(gfx::Point3F(50.f, 50.f, 0.f));
190 replica->SetPosition(gfx::Point(100, 100));
191 replica->SetTransform(replica_transform);
192 green->SetReplicaLayer(replica.get());
194 this->impl_side_painting_ = false;
195 RunPixelTest(GL_WITH_BITMAP,
196 background,
197 base::FilePath(FILE_PATH_LITERAL(
198 "mask_with_replica_of_clipped_layer.png")));
201 TEST_F(LayerTreeHostMasksPixelTest, MaskOfReplica) {
202 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
203 gfx::Rect(200, 200), SK_ColorWHITE);
205 MaskContentLayerClient client;
206 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
207 mask->SetBounds(gfx::Size(100, 100));
208 mask->SetIsDrawable(true);
209 mask->SetIsMask(true);
211 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
212 gfx::Rect(50, 0, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
213 background->AddChild(green);
215 scoped_refptr<SolidColorLayer> orange = CreateSolidColorLayer(
216 gfx::Rect(-50, 50, 50, 50), kCSSOrange);
217 green->AddChild(orange);
219 gfx::Transform replica_transform;
220 replica_transform.Rotate(180.0);
221 replica_transform.Translate(100.0, 0.0);
223 scoped_refptr<Layer> replica = Layer::Create();
224 replica->SetTransformOrigin(gfx::Point3F(100.f, 100.f, 0.f));
225 replica->SetPosition(gfx::Point());
226 replica->SetTransform(replica_transform);
227 replica->SetMaskLayer(mask.get());
228 green->SetReplicaLayer(replica.get());
230 this->impl_side_painting_ = false;
231 RunPixelTest(GL_WITH_BITMAP,
232 background,
233 base::FilePath(FILE_PATH_LITERAL("mask_of_replica.png")));
236 TEST_F(LayerTreeHostMasksPixelTest, MaskOfReplicaOfClippedLayer) {
237 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
238 gfx::Rect(200, 200), SK_ColorWHITE);
240 MaskContentLayerClient client;
241 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
242 mask->SetBounds(gfx::Size(100, 100));
243 mask->SetIsDrawable(true);
244 mask->SetIsMask(true);
246 // Clip to the bottom 3/4 of the green layer, and the top 3/4 of the replica.
247 scoped_refptr<Layer> clip = Layer::Create();
248 clip->SetPosition(gfx::Point(0, 25));
249 clip->SetBounds(gfx::Size(200, 150));
250 clip->SetMasksToBounds(true);
251 background->AddChild(clip);
253 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
254 gfx::Rect(50, -25, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
255 clip->AddChild(green);
257 scoped_refptr<SolidColorLayer> orange = CreateSolidColorLayer(
258 gfx::Rect(-50, 50, 50, 50), kCSSOrange);
259 green->AddChild(orange);
261 gfx::Transform replica_transform;
262 replica_transform.Rotate(180.0);
263 replica_transform.Translate(100.0, 0.0);
265 scoped_refptr<Layer> replica = Layer::Create();
266 replica->SetTransformOrigin(gfx::Point3F(100.f, 100.f, 0.f));
267 replica->SetPosition(gfx::Point());
268 replica->SetTransform(replica_transform);
269 replica->SetMaskLayer(mask.get());
270 green->SetReplicaLayer(replica.get());
272 this->impl_side_painting_ = false;
273 RunPixelTest(GL_WITH_BITMAP,
274 background,
275 base::FilePath(FILE_PATH_LITERAL(
276 "mask_of_replica_of_clipped_layer.png")));
279 } // namespace
280 } // namespace cc
282 #endif // OS_ANDROID