| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 display_list->Finalize(); | 66 display_list->Finalize(); |
| 67 return display_list; | 67 return display_list; |
| 68 } | 68 } |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 gfx::Size bounds_; | 71 gfx::Size bounds_; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 TEST_P(LayerTreeHostMasksPixelTest, MaskOfLayer) { | 74 TEST_P(LayerTreeHostMasksPixelTest, MaskOfLayer) { |
| 75 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 75 scoped_refptr<SolidColorLayer> background = |
| 76 gfx::Rect(100, 100), SK_ColorWHITE); | 76 CreateSolidColorLayer(gfx::Rect(100, 100), SK_ColorWHITE); |
| 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->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); | 87 mask->SetLayerMaskType(mask_type_); |
| 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 = |
| 96 gfx::Rect(100, 100), SK_ColorWHITE); | 96 CreateSolidColorLayer(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->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); | 102 mask->SetLayerMaskType(mask_type_); |
| 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 SkCanvas* canvas = surface->getCanvas(); | 106 SkCanvas* 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); |
| 113 mask->SetImage(PaintImage(surface->makeImageSnapshot())); | 113 mask->SetImage(PaintImage(surface->makeImageSnapshot())); |
| 114 | 114 |
| 115 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( | 115 scoped_refptr<SolidColorLayer> green = CreateSolidColorLayerWithBorder( |
| 116 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); | 116 gfx::Rect(25, 25, 50, 50), kCSSGreen, 1, SK_ColorBLACK); |
| 117 green->SetMaskLayer(mask.get()); | 117 green->SetMaskLayer(mask.get()); |
| 118 background->AddChild(green); | 118 background->AddChild(green); |
| 119 | 119 |
| 120 RunPixelResourceTest( | 120 RunPixelResourceTest( |
| 121 background, base::FilePath(FILE_PATH_LITERAL("image_mask_of_layer.png"))); | 121 background, base::FilePath(FILE_PATH_LITERAL("image_mask_of_layer.png"))); |
| 122 } | 122 } |
| 123 | 123 |
| 124 TEST_P(LayerTreeHostMasksPixelTest, MaskOfClippedLayer) { | 124 TEST_P(LayerTreeHostMasksPixelTest, MaskOfClippedLayer) { |
| 125 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 125 scoped_refptr<SolidColorLayer> background = |
| 126 gfx::Rect(100, 100), SK_ColorWHITE); | 126 CreateSolidColorLayer(gfx::Rect(100, 100), SK_ColorWHITE); |
| 127 | 127 |
| 128 // Clip to the top half of the green layer. | 128 // Clip to the top half of the green layer. |
| 129 scoped_refptr<Layer> clip = Layer::Create(); | 129 scoped_refptr<Layer> clip = Layer::Create(); |
| 130 clip->SetPosition(gfx::PointF()); | 130 clip->SetPosition(gfx::PointF()); |
| 131 clip->SetBounds(gfx::Size(100, 50)); | 131 clip->SetBounds(gfx::Size(100, 50)); |
| 132 clip->SetMasksToBounds(true); | 132 clip->SetMasksToBounds(true); |
| 133 background->AddChild(clip); | 133 background->AddChild(clip); |
| 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->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); | 144 mask->SetLayerMaskType(mask_type_); |
| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 return display_list; | 223 return display_list; |
| 224 } | 224 } |
| 225 | 225 |
| 226 private: | 226 private: |
| 227 gfx::Size bounds_; | 227 gfx::Size bounds_; |
| 228 }; | 228 }; |
| 229 | 229 |
| 230 using LayerTreeHostMasksForBackgroundFiltersPixelTest = | 230 using LayerTreeHostMasksForBackgroundFiltersPixelTest = |
| 231 ParameterizedPixelResourceTest; | 231 ParameterizedPixelResourceTest; |
| 232 | 232 |
| 233 INSTANTIATE_TEST_CASE_P(PixelResourceTest, | 233 INSTANTIATE_TEST_CASE_P( |
| 234 LayerTreeHostMasksForBackgroundFiltersPixelTest, | 234 PixelResourceTest, |
| 235 ::testing::Values(SOFTWARE, | 235 LayerTreeHostMasksForBackgroundFiltersPixelTest, |
| 236 GL_GPU_RASTER_2D_DRAW, | 236 ::testing::Combine( |
| 237 GL_ONE_COPY_2D_STAGING_2D_DRAW, | 237 ::testing::Values(SOFTWARE, |
| 238 GL_ONE_COPY_RECT_STAGING_2D_DRAW, | 238 GL_GPU_RASTER_2D_DRAW, |
| 239 GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW, | 239 GL_ONE_COPY_2D_STAGING_2D_DRAW, |
| 240 GL_ZERO_COPY_2D_DRAW, | 240 GL_ONE_COPY_RECT_STAGING_2D_DRAW, |
| 241 GL_ZERO_COPY_RECT_DRAW, | 241 GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW, |
| 242 GL_ZERO_COPY_EXTERNAL_DRAW)); | 242 GL_ZERO_COPY_2D_DRAW, |
| 243 GL_ZERO_COPY_RECT_DRAW, |
| 244 GL_ZERO_COPY_EXTERNAL_DRAW), |
| 245 ::testing::Values(Layer::LayerMaskType::SINGLE_TEXTURE_MASK, |
| 246 Layer::LayerMaskType::MULTI_TEXTURE_MASK))); |
| 243 | 247 |
| 244 TEST_P(LayerTreeHostMasksForBackgroundFiltersPixelTest, | 248 TEST_P(LayerTreeHostMasksForBackgroundFiltersPixelTest, |
| 245 MaskOfLayerWithBackgroundFilter) { | 249 MaskOfLayerWithBackgroundFilter) { |
| 246 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( | 250 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
| 247 gfx::Rect(100, 100), SK_ColorWHITE); | 251 gfx::Rect(100, 100), SK_ColorWHITE); |
| 248 | 252 |
| 249 gfx::Size picture_bounds(100, 100); | 253 gfx::Size picture_bounds(100, 100); |
| 250 CheckerContentLayerClient picture_client(picture_bounds, SK_ColorGREEN, true); | 254 CheckerContentLayerClient picture_client(picture_bounds, SK_ColorGREEN, true); |
| 251 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&picture_client); | 255 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&picture_client); |
| 252 picture->SetBounds(picture_bounds); | 256 picture->SetBounds(picture_bounds); |
| 253 picture->SetIsDrawable(true); | 257 picture->SetIsDrawable(true); |
| 254 | 258 |
| 255 scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayer( | 259 scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayer( |
| 256 gfx::Rect(100, 100), SK_ColorTRANSPARENT); | 260 gfx::Rect(100, 100), SK_ColorTRANSPARENT); |
| 257 background->AddChild(picture); | 261 background->AddChild(picture); |
| 258 background->AddChild(blur); | 262 background->AddChild(blur); |
| 259 | 263 |
| 260 FilterOperations filters; | 264 FilterOperations filters; |
| 261 filters.Append(FilterOperation::CreateGrayscaleFilter(1.0)); | 265 filters.Append(FilterOperation::CreateGrayscaleFilter(1.0)); |
| 262 blur->SetBackgroundFilters(filters); | 266 blur->SetBackgroundFilters(filters); |
| 263 | 267 |
| 264 gfx::Size mask_bounds(100, 100); | 268 gfx::Size mask_bounds(100, 100); |
| 265 CircleContentLayerClient mask_client(mask_bounds); | 269 CircleContentLayerClient mask_client(mask_bounds); |
| 266 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); | 270 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); |
| 267 mask->SetBounds(mask_bounds); | 271 mask->SetBounds(mask_bounds); |
| 268 mask->SetIsDrawable(true); | 272 mask->SetIsDrawable(true); |
| 269 mask->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); | 273 mask->SetLayerMaskType(mask_type_); |
| 270 blur->SetMaskLayer(mask.get()); | 274 blur->SetMaskLayer(mask.get()); |
| 271 | 275 |
| 272 float percentage_pixels_large_error = 2.5f; // 2.5%, ~250px / (100*100) | 276 float percentage_pixels_large_error = 2.5f; // 2.5%, ~250px / (100*100) |
| 273 float percentage_pixels_small_error = 0.0f; | 277 float percentage_pixels_small_error = 0.0f; |
| 274 float average_error_allowed_in_bad_pixels = 100.0f; | 278 float average_error_allowed_in_bad_pixels = 100.0f; |
| 275 int large_error_allowed = 256; | 279 int large_error_allowed = 256; |
| 276 int small_error_allowed = 0; | 280 int small_error_allowed = 0; |
| 277 pixel_comparator_.reset(new FuzzyPixelComparator( | 281 pixel_comparator_.reset(new FuzzyPixelComparator( |
| 278 true, // discard_alpha | 282 true, // discard_alpha |
| 279 percentage_pixels_large_error, | 283 percentage_pixels_large_error, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 310 picture_horizontal->SetBlendMode(SkBlendMode::kMultiply); | 314 picture_horizontal->SetBlendMode(SkBlendMode::kMultiply); |
| 311 | 315 |
| 312 background->AddChild(picture_vertical); | 316 background->AddChild(picture_vertical); |
| 313 background->AddChild(picture_horizontal); | 317 background->AddChild(picture_horizontal); |
| 314 | 318 |
| 315 gfx::Size mask_bounds(128, 128); | 319 gfx::Size mask_bounds(128, 128); |
| 316 CircleContentLayerClient mask_client(mask_bounds); | 320 CircleContentLayerClient mask_client(mask_bounds); |
| 317 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); | 321 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); |
| 318 mask->SetBounds(mask_bounds); | 322 mask->SetBounds(mask_bounds); |
| 319 mask->SetIsDrawable(true); | 323 mask->SetIsDrawable(true); |
| 320 mask->SetLayerMaskType(Layer::LayerMaskType::MULTI_TEXTURE_MASK); | 324 mask->SetLayerMaskType(mask_type_); |
| 321 picture_horizontal->SetMaskLayer(mask.get()); | 325 picture_horizontal->SetMaskLayer(mask.get()); |
| 322 | 326 |
| 323 float percentage_pixels_large_error = 0.04f; // 0.04%, ~6px / (128*128) | 327 float percentage_pixels_large_error = 0.04f; // 0.04%, ~6px / (128*128) |
| 324 float percentage_pixels_small_error = 0.0f; | 328 float percentage_pixels_small_error = 0.0f; |
| 325 float average_error_allowed_in_bad_pixels = 256.0f; | 329 float average_error_allowed_in_bad_pixels = 256.0f; |
| 326 int large_error_allowed = 256; | 330 int large_error_allowed = 256; |
| 327 int small_error_allowed = 0; | 331 int small_error_allowed = 0; |
| 328 pixel_comparator_.reset(new FuzzyPixelComparator( | 332 pixel_comparator_.reset(new FuzzyPixelComparator( |
| 329 true, // discard_alpha | 333 true, // discard_alpha |
| 330 percentage_pixels_large_error, | 334 percentage_pixels_large_error, |
| 331 percentage_pixels_small_error, | 335 percentage_pixels_small_error, |
| 332 average_error_allowed_in_bad_pixels, | 336 average_error_allowed_in_bad_pixels, |
| 333 large_error_allowed, | 337 large_error_allowed, |
| 334 small_error_allowed)); | 338 small_error_allowed)); |
| 335 | 339 |
| 336 RunPixelResourceTest(background, | 340 RunPixelResourceTest(background, |
| 337 base::FilePath( | 341 base::FilePath( |
| 338 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); | 342 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); |
| 339 } | 343 } |
| 340 | 344 |
| 341 } // namespace | 345 } // namespace |
| 342 } // namespace cc | 346 } // namespace cc |
| 343 | 347 |
| 344 #endif // !defined(OS_ANDROID) | 348 #endif // !defined(OS_ANDROID) |
| OLD | NEW |