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

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

Issue 14244021: cc: Remove incorrect dcheck for masks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: With pixel tests Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « cc/trees/layer_tree_host_impl_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/test/layer_tree_pixel_test.h"
10 #include "cc/test/pixel_comparator.h"
11
12 #if !defined(OS_ANDROID)
13
14 namespace cc {
15 namespace {
16
17 class LayerTreeHostMasksPixelTest : public LayerTreePixelTest {};
18
19 class MaskContentLayerClient : public cc::ContentLayerClient {
20 public:
21 MaskContentLayerClient() {}
22 virtual ~MaskContentLayerClient() {}
23
24 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
25
26 virtual void PaintContents(SkCanvas* canvas,
27 gfx::Rect rect,
28 gfx::RectF* opaque_rect) OVERRIDE {
29 SkPaint paint;
30 paint.setStyle(SkPaint::kStroke_Style);
31 paint.setStrokeWidth(SkIntToScalar(2));
32 paint.setColor(SK_ColorWHITE);
33
34 canvas->clear(SK_ColorTRANSPARENT);
35 while (!rect.IsEmpty()) {
36 rect.Inset(3, 3, 2, 2);
37 canvas->drawRect(
38 SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()),
39 paint);
40 rect.Inset(3, 3, 2, 2);
41 }
42 }
43 };
44
45 TEST_F(LayerTreeHostMasksPixelTest, MaskOfLayer) {
46 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
47 gfx::Rect(200, 200), SK_ColorWHITE);
48
49 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
50 gfx::Rect(50, 50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
51 background->AddChild(green);
52
53 MaskContentLayerClient client;
54 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
55 mask->SetBounds(gfx::Size(100, 100));
56 mask->SetIsDrawable(true);
57 mask->SetIsMask(true);
58 green->SetMaskLayer(mask);
59
60 RunPixelTest(background,
61 base::FilePath(FILE_PATH_LITERAL(
62 "mask_of_layer.png")));
63 }
64
65 TEST_F(LayerTreeHostMasksPixelTest, ImageMaskOfLayer) {
66 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
67 gfx::Rect(200, 200), SK_ColorWHITE);
68
69 scoped_refptr<ImageLayer> mask = ImageLayer::Create();
70 mask->SetIsDrawable(true);
71 mask->SetIsMask(true);
72 mask->SetBounds(gfx::Size(100, 100));
73
74 SkBitmap bitmap;
75 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400);
76 bitmap.allocPixels();
77 SkCanvas canvas(bitmap);
78 canvas.scale(SkIntToScalar(4), SkIntToScalar(4));
79 MaskContentLayerClient client;
80 client.PaintContents(&canvas,
81 gfx::Rect(100, 100),
82 NULL);
83 mask->SetBitmap(bitmap);
84
85 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
86 gfx::Rect(50, 50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
87 green->SetMaskLayer(mask);
88 background->AddChild(green);
89
90 RunPixelTest(background,
91 base::FilePath(FILE_PATH_LITERAL(
92 "image_mask_of_layer.png")));
93 }
94
95 TEST_F(LayerTreeHostMasksPixelTest, MaskOfClippedLayer) {
96 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
97 gfx::Rect(200, 200), SK_ColorWHITE);
98
99 // Clip to the top half of the green layer.
100 scoped_refptr<Layer> clip = Layer::Create();
101 clip->SetAnchorPoint(gfx::PointF(0.f, 0.f));
102 clip->SetPosition(gfx::Point(0, 0));
103 clip->SetBounds(gfx::Size(200, 100));
104 clip->SetMasksToBounds(true);
105 background->AddChild(clip);
106
107 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
108 gfx::Rect(50, 50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
109 clip->AddChild(green);
110
111 MaskContentLayerClient client;
112 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
113 mask->SetBounds(gfx::Size(100, 100));
114 mask->SetIsDrawable(true);
115 mask->SetIsMask(true);
116 green->SetMaskLayer(mask);
117
118 RunPixelTest(background,
119 base::FilePath(FILE_PATH_LITERAL(
120 "mask_of_clipped_layer.png")));
121 }
122
123 TEST_F(LayerTreeHostMasksPixelTest, MaskWithReplica) {
124 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
125 gfx::Rect(200, 200), SK_ColorWHITE);
126
127 MaskContentLayerClient client;
128 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
129 mask->SetBounds(gfx::Size(100, 100));
130 mask->SetIsDrawable(true);
131 mask->SetIsMask(true);
132
133 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
134 gfx::Rect(0, 0, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
135 background->AddChild(green);
136 green->SetMaskLayer(mask);
137
138 gfx::Transform replica_transform;
139 replica_transform.Rotate(-90.0);
140
141 scoped_refptr<Layer> replica = Layer::Create();
142 replica->SetAnchorPoint(gfx::PointF(0.5f, 0.5f));
143 replica->SetPosition(gfx::Point(100, 100));
144 replica->SetTransform(replica_transform);
145 green->SetReplicaLayer(replica);
146
147 RunPixelTest(background,
148 base::FilePath(FILE_PATH_LITERAL(
149 "mask_with_replica.png")));
150 }
151
152 TEST_F(LayerTreeHostMasksPixelTest, MaskWithReplicaOfClippedLayer) {
153 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
154 gfx::Rect(200, 200), SK_ColorWHITE);
155
156 MaskContentLayerClient client;
157 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
158 mask->SetBounds(gfx::Size(100, 100));
159 mask->SetIsDrawable(true);
160 mask->SetIsMask(true);
161
162 // Clip to the bottom half of the green layer, and the left half of the
163 // replica.
164 scoped_refptr<Layer> clip = Layer::Create();
165 clip->SetAnchorPoint(gfx::PointF(0.f, 0.f));
166 clip->SetPosition(gfx::Point(0, 50));
167 clip->SetBounds(gfx::Size(150, 150));
168 clip->SetMasksToBounds(true);
169 background->AddChild(clip);
170
171 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
172 gfx::Rect(0, -50, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
173 clip->AddChild(green);
174 green->SetMaskLayer(mask);
175
176 gfx::Transform replica_transform;
177 replica_transform.Rotate(-90.0);
178
179 scoped_refptr<Layer> replica = Layer::Create();
180 replica->SetAnchorPoint(gfx::PointF(0.5f, 0.5f));
181 replica->SetPosition(gfx::Point(100, 100));
182 replica->SetTransform(replica_transform);
183 green->SetReplicaLayer(replica);
184
185 RunPixelTest(background,
186 base::FilePath(FILE_PATH_LITERAL(
187 "mask_with_replica_of_clipped_layer.png")));
188 }
189
190 TEST_F(LayerTreeHostMasksPixelTest, MaskOfReplica) {
191 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
192 gfx::Rect(200, 200), SK_ColorWHITE);
193
194 MaskContentLayerClient client;
195 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
196 mask->SetBounds(gfx::Size(100, 100));
197 mask->SetIsDrawable(true);
198 mask->SetIsMask(true);
199
200 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
201 gfx::Rect(50, 0, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
202 background->AddChild(green);
203
204 scoped_refptr<SolidColorLayer> orange = CreateSolidColorLayer(
205 gfx::Rect(-50, 50, 50, 50), kCSSOrange);
206 green->AddChild(orange);
207
208 gfx::Transform replica_transform;
209 replica_transform.Rotate(180.0);
210 replica_transform.Translate(100.0, 0.0);
211
212 scoped_refptr<Layer> replica = Layer::Create();
213 replica->SetAnchorPoint(gfx::PointF(1.f, 1.f));
214 replica->SetPosition(gfx::Point());
215 replica->SetTransform(replica_transform);
216 replica->SetMaskLayer(mask);
217 green->SetReplicaLayer(replica);
218
219 RunPixelTest(background,
220 base::FilePath(FILE_PATH_LITERAL(
221 "mask_of_replica.png")));
222 }
223
224 TEST_F(LayerTreeHostMasksPixelTest, MaskOfReplicaOfClippedLayer) {
225 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer(
226 gfx::Rect(200, 200), SK_ColorWHITE);
227
228 MaskContentLayerClient client;
229 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client);
230 mask->SetBounds(gfx::Size(100, 100));
231 mask->SetIsDrawable(true);
232 mask->SetIsMask(true);
233
234 // Clip to the bottom 3/4 of the green layer, and the top 3/4 of the replica.
235 scoped_refptr<Layer> clip = Layer::Create();
236 clip->SetAnchorPoint(gfx::PointF(0.f, 0.f));
237 clip->SetPosition(gfx::Point(0, 25));
238 clip->SetBounds(gfx::Size(200, 150));
239 clip->SetMasksToBounds(true);
240 background->AddChild(clip);
241
242 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder(
243 gfx::Rect(50, -25, 100, 100), kCSSGreen, 1, SK_ColorBLACK);
244 clip->AddChild(green);
245
246 scoped_refptr<SolidColorLayer> orange = CreateSolidColorLayer(
247 gfx::Rect(-50, 50, 50, 50), kCSSOrange);
248 green->AddChild(orange);
249
250 gfx::Transform replica_transform;
251 replica_transform.Rotate(180.0);
252 replica_transform.Translate(100.0, 0.0);
253
254 scoped_refptr<Layer> replica = Layer::Create();
255 replica->SetAnchorPoint(gfx::PointF(1.f, 1.f));
256 replica->SetPosition(gfx::Point());
257 replica->SetTransform(replica_transform);
258 replica->SetMaskLayer(mask);
259 green->SetReplicaLayer(replica);
260
261 RunPixelTest(background,
262 base::FilePath(FILE_PATH_LITERAL(
263 "mask_of_replica_of_clipped_layer.png")));
264 }
265
266 } // namespace
267 } // namespace cc
268
269 #endif // OS_ANDROID
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698