OLD | NEW |
---|---|
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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "cc/layers/content_layer_client.h" | 8 #include "cc/layers/content_layer_client.h" |
9 #include "cc/layers/picture_image_layer.h" | 9 #include "cc/layers/picture_image_layer.h" |
10 #include "cc/layers/picture_layer.h" | 10 #include "cc/layers/picture_layer.h" |
11 #include "cc/layers/solid_color_layer.h" | 11 #include "cc/layers/solid_color_layer.h" |
12 #include "cc/paint/drawing_display_item.h" | 12 #include "cc/paint/drawing_display_item.h" |
13 #include "cc/paint/paint_flags.h" | 13 #include "cc/paint/paint_flags.h" |
14 #include "cc/paint/paint_image.h" | 14 #include "cc/paint/paint_image.h" |
15 #include "cc/paint/paint_recorder.h" | 15 #include "cc/paint/paint_recorder.h" |
16 #include "cc/test/fake_picture_layer.h" | |
16 #include "cc/test/layer_tree_pixel_resource_test.h" | 17 #include "cc/test/layer_tree_pixel_resource_test.h" |
17 #include "cc/test/pixel_comparator.h" | 18 #include "cc/test/pixel_comparator.h" |
18 #include "cc/test/solid_color_content_layer_client.h" | 19 #include "cc/test/solid_color_content_layer_client.h" |
19 #include "third_party/skia/include/core/SkImage.h" | 20 #include "third_party/skia/include/core/SkImage.h" |
20 | 21 |
21 #if !defined(OS_ANDROID) | 22 #if !defined(OS_ANDROID) |
22 | 23 |
23 namespace cc { | 24 namespace cc { |
24 namespace { | 25 namespace { |
25 | 26 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 mask->SetBounds(mask_bounds); | 143 mask->SetBounds(mask_bounds); |
143 mask->SetIsDrawable(true); | 144 mask->SetIsDrawable(true); |
144 mask->SetLayerMaskType(mask_type_); | 145 mask->SetLayerMaskType(mask_type_); |
145 green->SetMaskLayer(mask.get()); | 146 green->SetMaskLayer(mask.get()); |
146 | 147 |
147 RunPixelResourceTest( | 148 RunPixelResourceTest( |
148 background, | 149 background, |
149 base::FilePath(FILE_PATH_LITERAL("mask_of_clipped_layer.png"))); | 150 base::FilePath(FILE_PATH_LITERAL("mask_of_clipped_layer.png"))); |
150 } | 151 } |
151 | 152 |
153 TEST_P(LayerTreeHostMasksPixelTest, MaskOfLargerLayer) { | |
154 scoped_refptr<SolidColorLayer> background = | |
155 CreateSolidColorLayer(gfx::Rect(100, 100), SK_ColorWHITE); | |
156 | |
157 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( | |
158 gfx::Rect(0, 0, 100, 100), kCSSGreen, 1, SK_ColorBLACK); | |
159 background->AddChild(green); | |
160 | |
161 gfx::Size mask_bounds(50, 50); | |
162 MaskContentLayerClient client(mask_bounds); | |
163 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&client); | |
164 mask->SetBounds(mask_bounds); | |
165 mask->SetIsDrawable(true); | |
166 mask->SetLayerMaskType(mask_type_); | |
167 green->SetMaskLayer(mask.get()); | |
168 | |
169 if (raster_buffer_provider_type_ == RASTER_BUFFER_PROVIDER_TYPE_BITMAP) { | |
170 // Bitmap produces a sharper (but equivalent sized) mask. | |
171 float percentage_pixels_large_error = 40.0f; | |
172 float percentage_pixels_small_error = 0.0f; | |
173 float average_error_allowed_in_bad_pixels = 65.0f; | |
174 int large_error_allowed = 120; | |
175 int small_error_allowed = 0; | |
176 pixel_comparator_.reset(new FuzzyPixelComparator( | |
177 true, // discard_alpha | |
178 percentage_pixels_large_error, percentage_pixels_small_error, | |
179 average_error_allowed_in_bad_pixels, large_error_allowed, | |
180 small_error_allowed)); | |
181 } | |
182 | |
183 RunPixelResourceTest( | |
184 background, | |
185 base::FilePath(FILE_PATH_LITERAL("mask_of_larger_layer.png"))); | |
186 } | |
187 | |
188 TEST_P(LayerTreeHostMasksPixelTest, MaskOfLayerNonExactTextureSize) { | |
189 // This test only makes sense in single texture mode. | |
190 if (mask_type_ != Layer::LayerMaskType::SINGLE_TEXTURE_MASK) | |
191 return; | |
192 | |
193 scoped_refptr<SolidColorLayer> background = | |
194 CreateSolidColorLayer(gfx::Rect(100, 100), SK_ColorWHITE); | |
195 | |
196 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( | |
197 gfx::Rect(0, 0, 100, 100), kCSSGreen, 1, SK_ColorBLACK); | |
198 background->AddChild(green); | |
199 | |
200 gfx::Size mask_bounds(100, 100); | |
201 MaskContentLayerClient client(mask_bounds); | |
202 scoped_refptr<FakePictureLayer> mask = FakePictureLayer::Create(&client); | |
203 mask->SetBounds(mask_bounds); | |
204 mask->SetIsDrawable(true); | |
205 mask->SetLayerMaskType(Layer::LayerMaskType::SINGLE_TEXTURE_MASK); | |
sunxd
2017/05/04 19:43:49
Nit: Could you also change this to mask_type_? Tha
ericrk
2017/05/04 19:51:38
I don't think this test makes sense for tiled mask
ericrk
2017/05/04 19:55:06
I guess it can't hurt though... ok, added
| |
206 mask->set_fixed_tile_size(gfx::Size(173, 135)); | |
207 green->SetMaskLayer(mask.get()); | |
208 | |
209 RunPixelResourceTest(background, | |
210 base::FilePath(FILE_PATH_LITERAL( | |
211 "mask_with_non_exact_texture_size.png"))); | |
212 } | |
213 | |
152 class CheckerContentLayerClient : public ContentLayerClient { | 214 class CheckerContentLayerClient : public ContentLayerClient { |
153 public: | 215 public: |
154 CheckerContentLayerClient(const gfx::Size& bounds, | 216 CheckerContentLayerClient(const gfx::Size& bounds, |
155 SkColor color, | 217 SkColor color, |
156 bool vertical) | 218 bool vertical) |
157 : bounds_(bounds), color_(color), vertical_(vertical) {} | 219 : bounds_(bounds), color_(color), vertical_(vertical) {} |
158 ~CheckerContentLayerClient() override {} | 220 ~CheckerContentLayerClient() override {} |
159 bool FillsBoundsCompletely() const override { return false; } | 221 bool FillsBoundsCompletely() const override { return false; } |
160 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 222 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
161 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } | 223 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 | 401 |
340 RunPixelResourceTest(background, | 402 RunPixelResourceTest(background, |
341 base::FilePath( | 403 base::FilePath( |
342 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); | 404 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); |
343 } | 405 } |
344 | 406 |
345 } // namespace | 407 } // namespace |
346 } // namespace cc | 408 } // namespace cc |
347 | 409 |
348 #endif // !defined(OS_ANDROID) | 410 #endif // !defined(OS_ANDROID) |
OLD | NEW |