| 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" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( | 78 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( |
| 79 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); | 79 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); |
| 80 background->AddChild(green); | 80 background->AddChild(green); |
| 81 | 81 |
| 82 gfx::Size mask_bounds(50, 50); | 82 gfx::Size mask_bounds(50, 50); |
| 83 MaskContentLayerClient client(mask_bounds); | 83 MaskContentLayerClient client(mask_bounds); |
| 84 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&client); | 84 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&client); |
| 85 mask->SetBounds(mask_bounds); | 85 mask->SetBounds(mask_bounds); |
| 86 mask->SetIsDrawable(true); | 86 mask->SetIsDrawable(true); |
| 87 mask->SetIsMask(true); | 87 mask->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); |
| 88 green->SetMaskLayer(mask.get()); | 88 green->SetMaskLayer(mask.get()); |
| 89 | 89 |
| 90 RunPixelResourceTest(background, | 90 RunPixelResourceTest(background, |
| 91 base::FilePath(FILE_PATH_LITERAL("mask_of_layer.png"))); | 91 base::FilePath(FILE_PATH_LITERAL("mask_of_layer.png"))); |
| 92 } | 92 } |
| 93 | 93 |
| 94 TEST_P(LayerTreeHostMasksPixelTest, ImageMaskOfLayer) { | 94 TEST_P(LayerTreeHostMasksPixelTest, ImageMaskOfLayer) { |
| 95 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 95 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
| 96 gfx::Rect(100, 100), SK_ColorWHITE); | 96 gfx::Rect(100, 100), SK_ColorWHITE); |
| 97 | 97 |
| 98 gfx::Size mask_bounds(50, 50); | 98 gfx::Size mask_bounds(50, 50); |
| 99 | 99 |
| 100 scoped_refptr<PictureImageLayer> mask = PictureImageLayer::Create(); | 100 scoped_refptr<PictureImageLayer> mask = PictureImageLayer::Create(); |
| 101 mask->SetIsDrawable(true); | 101 mask->SetIsDrawable(true); |
| 102 mask->SetIsMask(true); | 102 mask->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); |
| 103 mask->SetBounds(mask_bounds); | 103 mask->SetBounds(mask_bounds); |
| 104 | 104 |
| 105 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(200, 200); | 105 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(200, 200); |
| 106 PaintCanvas* canvas = surface->getCanvas(); | 106 PaintCanvas* canvas = surface->getCanvas(); |
| 107 canvas->scale(SkIntToScalar(4), SkIntToScalar(4)); | 107 canvas->scale(SkIntToScalar(4), SkIntToScalar(4)); |
| 108 MaskContentLayerClient client(mask_bounds); | 108 MaskContentLayerClient client(mask_bounds); |
| 109 scoped_refptr<DisplayItemList> mask_display_list = | 109 scoped_refptr<DisplayItemList> mask_display_list = |
| 110 client.PaintContentsToDisplayList( | 110 client.PaintContentsToDisplayList( |
| 111 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 111 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| 112 mask_display_list->Raster(canvas, nullptr); | 112 mask_display_list->Raster(canvas, nullptr); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 134 | 134 |
| 135 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( | 135 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( |
| 136 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); | 136 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); |
| 137 clip->AddChild(green); | 137 clip->AddChild(green); |
| 138 | 138 |
| 139 gfx::Size mask_bounds(50, 50); | 139 gfx::Size mask_bounds(50, 50); |
| 140 MaskContentLayerClient client(mask_bounds); | 140 MaskContentLayerClient client(mask_bounds); |
| 141 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&client); | 141 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&client); |
| 142 mask->SetBounds(mask_bounds); | 142 mask->SetBounds(mask_bounds); |
| 143 mask->SetIsDrawable(true); | 143 mask->SetIsDrawable(true); |
| 144 mask->SetIsMask(true); | 144 mask->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); |
| 145 green->SetMaskLayer(mask.get()); | 145 green->SetMaskLayer(mask.get()); |
| 146 | 146 |
| 147 RunPixelResourceTest( | 147 RunPixelResourceTest( |
| 148 background, | 148 background, |
| 149 base::FilePath(FILE_PATH_LITERAL("mask_of_clipped_layer.png"))); | 149 base::FilePath(FILE_PATH_LITERAL("mask_of_clipped_layer.png"))); |
| 150 } | 150 } |
| 151 | 151 |
| 152 class CheckerContentLayerClient : public ContentLayerClient { | 152 class CheckerContentLayerClient : public ContentLayerClient { |
| 153 public: | 153 public: |
| 154 CheckerContentLayerClient(const gfx::Size& bounds, | 154 CheckerContentLayerClient(const gfx::Size& bounds, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 259 |
| 260 FilterOperations filters; | 260 FilterOperations filters; |
| 261 filters.Append(FilterOperation::CreateGrayscaleFilter(1.0)); | 261 filters.Append(FilterOperation::CreateGrayscaleFilter(1.0)); |
| 262 blur->SetBackgroundFilters(filters); | 262 blur->SetBackgroundFilters(filters); |
| 263 | 263 |
| 264 gfx::Size mask_bounds(100, 100); | 264 gfx::Size mask_bounds(100, 100); |
| 265 CircleContentLayerClient mask_client(mask_bounds); | 265 CircleContentLayerClient mask_client(mask_bounds); |
| 266 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); | 266 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); |
| 267 mask->SetBounds(mask_bounds); | 267 mask->SetBounds(mask_bounds); |
| 268 mask->SetIsDrawable(true); | 268 mask->SetIsDrawable(true); |
| 269 mask->SetIsMask(true); | 269 mask->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); |
| 270 blur->SetMaskLayer(mask.get()); | 270 blur->SetMaskLayer(mask.get()); |
| 271 | 271 |
| 272 float percentage_pixels_large_error = 2.5f; // 2.5%, ~250px / (100*100) | 272 float percentage_pixels_large_error = 2.5f; // 2.5%, ~250px / (100*100) |
| 273 float percentage_pixels_small_error = 0.0f; | 273 float percentage_pixels_small_error = 0.0f; |
| 274 float average_error_allowed_in_bad_pixels = 100.0f; | 274 float average_error_allowed_in_bad_pixels = 100.0f; |
| 275 int large_error_allowed = 256; | 275 int large_error_allowed = 256; |
| 276 int small_error_allowed = 0; | 276 int small_error_allowed = 0; |
| 277 pixel_comparator_.reset(new FuzzyPixelComparator( | 277 pixel_comparator_.reset(new FuzzyPixelComparator( |
| 278 true, // discard_alpha | 278 true, // discard_alpha |
| 279 percentage_pixels_large_error, | 279 percentage_pixels_large_error, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 310 picture_horizontal->SetBlendMode(SkBlendMode::kMultiply); | 310 picture_horizontal->SetBlendMode(SkBlendMode::kMultiply); |
| 311 | 311 |
| 312 background->AddChild(picture_vertical); | 312 background->AddChild(picture_vertical); |
| 313 background->AddChild(picture_horizontal); | 313 background->AddChild(picture_horizontal); |
| 314 | 314 |
| 315 gfx::Size mask_bounds(128, 128); | 315 gfx::Size mask_bounds(128, 128); |
| 316 CircleContentLayerClient mask_client(mask_bounds); | 316 CircleContentLayerClient mask_client(mask_bounds); |
| 317 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); | 317 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); |
| 318 mask->SetBounds(mask_bounds); | 318 mask->SetBounds(mask_bounds); |
| 319 mask->SetIsDrawable(true); | 319 mask->SetIsDrawable(true); |
| 320 mask->SetIsMask(true); | 320 mask->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); |
| 321 picture_horizontal->SetMaskLayer(mask.get()); | 321 picture_horizontal->SetMaskLayer(mask.get()); |
| 322 | 322 |
| 323 float percentage_pixels_large_error = 0.04f; // 0.04%, ~6px / (128*128) | 323 float percentage_pixels_large_error = 0.04f; // 0.04%, ~6px / (128*128) |
| 324 float percentage_pixels_small_error = 0.0f; | 324 float percentage_pixels_small_error = 0.0f; |
| 325 float average_error_allowed_in_bad_pixels = 256.0f; | 325 float average_error_allowed_in_bad_pixels = 256.0f; |
| 326 int large_error_allowed = 256; | 326 int large_error_allowed = 256; |
| 327 int small_error_allowed = 0; | 327 int small_error_allowed = 0; |
| 328 pixel_comparator_.reset(new FuzzyPixelComparator( | 328 pixel_comparator_.reset(new FuzzyPixelComparator( |
| 329 true, // discard_alpha | 329 true, // discard_alpha |
| 330 percentage_pixels_large_error, | 330 percentage_pixels_large_error, |
| 331 percentage_pixels_small_error, | 331 percentage_pixels_small_error, |
| 332 average_error_allowed_in_bad_pixels, | 332 average_error_allowed_in_bad_pixels, |
| 333 large_error_allowed, | 333 large_error_allowed, |
| 334 small_error_allowed)); | 334 small_error_allowed)); |
| 335 | 335 |
| 336 RunPixelResourceTest(background, | 336 RunPixelResourceTest(background, |
| 337 base::FilePath( | 337 base::FilePath( |
| 338 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); | 338 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); |
| 339 } | 339 } |
| 340 | 340 |
| 341 } // namespace | 341 } // namespace |
| 342 } // namespace cc | 342 } // namespace cc |
| 343 | 343 |
| 344 #endif // !defined(OS_ANDROID) | 344 #endif // !defined(OS_ANDROID) |
| OLD | NEW |