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 scoped_refptr<SolidColorLayer> background = |
| 190 CreateSolidColorLayer(gfx::Rect(100, 100), SK_ColorWHITE); |
| 191 |
| 192 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( |
| 193 gfx::Rect(0, 0, 100, 100), kCSSGreen, 1, SK_ColorBLACK); |
| 194 background->AddChild(green); |
| 195 |
| 196 gfx::Size mask_bounds(100, 100); |
| 197 MaskContentLayerClient client(mask_bounds); |
| 198 scoped_refptr<FakePictureLayer> mask = FakePictureLayer::Create(&client); |
| 199 mask->SetBounds(mask_bounds); |
| 200 mask->SetIsDrawable(true); |
| 201 mask->SetLayerMaskType(mask_type_); |
| 202 mask->set_fixed_tile_size(gfx::Size(173, 135)); |
| 203 green->SetMaskLayer(mask.get()); |
| 204 |
| 205 RunPixelResourceTest(background, |
| 206 base::FilePath(FILE_PATH_LITERAL( |
| 207 "mask_with_non_exact_texture_size.png"))); |
| 208 } |
| 209 |
152 class CheckerContentLayerClient : public ContentLayerClient { | 210 class CheckerContentLayerClient : public ContentLayerClient { |
153 public: | 211 public: |
154 CheckerContentLayerClient(const gfx::Size& bounds, | 212 CheckerContentLayerClient(const gfx::Size& bounds, |
155 SkColor color, | 213 SkColor color, |
156 bool vertical) | 214 bool vertical) |
157 : bounds_(bounds), color_(color), vertical_(vertical) {} | 215 : bounds_(bounds), color_(color), vertical_(vertical) {} |
158 ~CheckerContentLayerClient() override {} | 216 ~CheckerContentLayerClient() override {} |
159 bool FillsBoundsCompletely() const override { return false; } | 217 bool FillsBoundsCompletely() const override { return false; } |
160 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 218 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
161 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } | 219 gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 397 |
340 RunPixelResourceTest(background, | 398 RunPixelResourceTest(background, |
341 base::FilePath( | 399 base::FilePath( |
342 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); | 400 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); |
343 } | 401 } |
344 | 402 |
345 } // namespace | 403 } // namespace |
346 } // namespace cc | 404 } // namespace cc |
347 | 405 |
348 #endif // !defined(OS_ANDROID) | 406 #endif // !defined(OS_ANDROID) |
OLD | NEW |