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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 #include "cc/layers/content_layer_client.h" | 6 #include "cc/layers/content_layer_client.h" |
7 #include "cc/layers/picture_image_layer.h" | 7 #include "cc/layers/picture_image_layer.h" |
8 #include "cc/layers/picture_layer.h" | 8 #include "cc/layers/picture_layer.h" |
9 #include "cc/layers/solid_color_layer.h" | 9 #include "cc/layers/solid_color_layer.h" |
10 #include "cc/test/layer_tree_pixel_resource_test.h" | 10 #include "cc/test/layer_tree_pixel_resource_test.h" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 replica->SetMaskLayer(mask.get()); | 275 replica->SetMaskLayer(mask.get()); |
276 green->SetReplicaLayer(replica.get()); | 276 green->SetReplicaLayer(replica.get()); |
277 | 277 |
278 RunPixelResourceTest(background, | 278 RunPixelResourceTest(background, |
279 base::FilePath(FILE_PATH_LITERAL( | 279 base::FilePath(FILE_PATH_LITERAL( |
280 "mask_of_replica_of_clipped_layer.png"))); | 280 "mask_of_replica_of_clipped_layer.png"))); |
281 } | 281 } |
282 | 282 |
283 #endif // !defined(OS_WIN) | 283 #endif // !defined(OS_WIN) |
284 | 284 |
| 285 class CheckerContentLayerClient : public ContentLayerClient { |
| 286 public: |
| 287 CheckerContentLayerClient(const gfx::Size& bounds, |
| 288 SkColor color, |
| 289 bool vertical) |
| 290 : bounds_(bounds), color_(color), vertical_(vertical) {} |
| 291 ~CheckerContentLayerClient() override {} |
| 292 bool FillsBoundsCompletely() const override { return false; } |
| 293 void PaintContents(SkCanvas* canvas, |
| 294 const gfx::Rect& rect, |
| 295 PaintingControlSetting picture_control) override { |
| 296 SkPaint paint; |
| 297 paint.setStyle(SkPaint::kStroke_Style); |
| 298 paint.setStrokeWidth(SkIntToScalar(4)); |
| 299 paint.setColor(color_); |
| 300 canvas->clear(SK_ColorTRANSPARENT); |
| 301 if (vertical_) { |
| 302 for (int i = 4; i < bounds_.width(); i += 16) { |
| 303 canvas->drawLine(i, 0, i, bounds_.height(), paint); |
| 304 } |
| 305 } else { |
| 306 for (int i = 4; i < bounds_.height(); i += 16) { |
| 307 canvas->drawLine(0, i, bounds_.width(), i, paint); |
| 308 } |
| 309 } |
| 310 } |
| 311 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 312 const gfx::Rect& clip, |
| 313 PaintingControlSetting picture_control) override { |
| 314 NOTIMPLEMENTED(); |
| 315 return DisplayItemList::Create(); |
| 316 } |
| 317 |
| 318 private: |
| 319 gfx::Size bounds_; |
| 320 SkColor color_; |
| 321 bool vertical_; |
| 322 }; |
| 323 |
| 324 class CircleContentLayerClient : public ContentLayerClient { |
| 325 public: |
| 326 explicit CircleContentLayerClient(const gfx::Size& bounds) |
| 327 : bounds_(bounds) {} |
| 328 ~CircleContentLayerClient() override {} |
| 329 bool FillsBoundsCompletely() const override { return false; } |
| 330 void PaintContents(SkCanvas* canvas, |
| 331 const gfx::Rect& rect, |
| 332 PaintingControlSetting picture_control) override { |
| 333 SkPaint paint; |
| 334 paint.setStyle(SkPaint::kFill_Style); |
| 335 paint.setColor(SK_ColorWHITE); |
| 336 canvas->clear(SK_ColorTRANSPARENT); |
| 337 canvas->drawCircle(bounds_.width() / 2, |
| 338 bounds_.height() / 2, |
| 339 bounds_.width() / 4, |
| 340 paint); |
| 341 } |
| 342 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 343 const gfx::Rect& clip, |
| 344 PaintingControlSetting picture_control) override { |
| 345 NOTIMPLEMENTED(); |
| 346 return DisplayItemList::Create(); |
| 347 } |
| 348 |
| 349 private: |
| 350 gfx::Size bounds_; |
| 351 }; |
| 352 |
| 353 using LayerTreeHostMasksForBackgroundFiltersPixelTest = |
| 354 ParameterizedPixelResourceTest; |
| 355 |
| 356 INSTANTIATE_TEST_CASE_P( |
| 357 PixelResourceTest, |
| 358 LayerTreeHostMasksForBackgroundFiltersPixelTest, |
| 359 ::testing::Values( |
| 360 // SOFTWARE, Background filters aren't implemented in software |
| 361 GL_GPU_RASTER_2D_DRAW, |
| 362 GL_ONE_COPY_2D_STAGING_2D_DRAW, |
| 363 GL_ONE_COPY_RECT_STAGING_2D_DRAW, |
| 364 GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW, |
| 365 GL_ZERO_COPY_2D_DRAW, |
| 366 GL_ZERO_COPY_RECT_DRAW, |
| 367 GL_ZERO_COPY_EXTERNAL_DRAW, |
| 368 GL_ASYNC_UPLOAD_2D_DRAW)); |
| 369 |
| 370 TEST_P(LayerTreeHostMasksForBackgroundFiltersPixelTest, |
| 371 MaskOfLayerWithBackgroundFilter) { |
| 372 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
| 373 gfx::Rect(256, 256), SK_ColorWHITE); |
| 374 |
| 375 gfx::Size picture_bounds(256, 256); |
| 376 CheckerContentLayerClient picture_client(picture_bounds, SK_ColorGREEN, true); |
| 377 scoped_refptr<PictureLayer> picture = PictureLayer::Create(&picture_client); |
| 378 picture->SetBounds(picture_bounds); |
| 379 picture->SetIsDrawable(true); |
| 380 |
| 381 scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayer( |
| 382 gfx::Rect(256, 256), SK_ColorTRANSPARENT); |
| 383 background->AddChild(picture); |
| 384 background->AddChild(blur); |
| 385 |
| 386 FilterOperations filters; |
| 387 filters.Append(FilterOperation::CreateBlurFilter(2.f)); |
| 388 blur->SetBackgroundFilters(filters); |
| 389 |
| 390 gfx::Size mask_bounds(256, 256); |
| 391 CircleContentLayerClient mask_client(mask_bounds); |
| 392 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); |
| 393 mask->SetBounds(mask_bounds); |
| 394 mask->SetIsDrawable(true); |
| 395 mask->SetIsMask(true); |
| 396 blur->SetMaskLayer(mask.get()); |
| 397 |
| 398 float percentage_pixels_large_error = 2.5f; // 2.5%, ~1600px / (256*256) |
| 399 float percentage_pixels_small_error = 0.0f; |
| 400 float average_error_allowed_in_bad_pixels = 60.0f; |
| 401 int large_error_allowed = 100; |
| 402 int small_error_allowed = 0; |
| 403 pixel_comparator_.reset(new FuzzyPixelComparator( |
| 404 true, // discard_alpha |
| 405 percentage_pixels_large_error, |
| 406 percentage_pixels_small_error, |
| 407 average_error_allowed_in_bad_pixels, |
| 408 large_error_allowed, |
| 409 small_error_allowed)); |
| 410 |
| 411 RunPixelResourceTest(background, |
| 412 base::FilePath( |
| 413 FILE_PATH_LITERAL("mask_of_background_filter.png"))); |
| 414 } |
| 415 |
| 416 TEST_P(LayerTreeHostMasksForBackgroundFiltersPixelTest, |
| 417 MaskOfLayerWithBlend) { |
| 418 scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
| 419 gfx::Rect(256, 256), SK_ColorWHITE); |
| 420 |
| 421 gfx::Size picture_bounds(256, 256); |
| 422 CheckerContentLayerClient picture_client_vertical( |
| 423 picture_bounds, SK_ColorGREEN, true); |
| 424 scoped_refptr<PictureLayer> picture_vertical = |
| 425 PictureLayer::Create(&picture_client_vertical); |
| 426 picture_vertical->SetBounds(picture_bounds); |
| 427 picture_vertical->SetIsDrawable(true); |
| 428 |
| 429 CheckerContentLayerClient picture_client_horizontal( |
| 430 picture_bounds, SK_ColorMAGENTA, false); |
| 431 scoped_refptr<PictureLayer> picture_horizontal = |
| 432 PictureLayer::Create(&picture_client_horizontal); |
| 433 picture_horizontal->SetBounds(picture_bounds); |
| 434 picture_horizontal->SetIsDrawable(true); |
| 435 picture_horizontal->SetContentsOpaque(false); |
| 436 picture_horizontal->SetBlendMode(SkXfermode::kMultiply_Mode); |
| 437 |
| 438 background->AddChild(picture_vertical); |
| 439 background->AddChild(picture_horizontal); |
| 440 |
| 441 gfx::Size mask_bounds(256, 256); |
| 442 CircleContentLayerClient mask_client(mask_bounds); |
| 443 scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); |
| 444 mask->SetBounds(mask_bounds); |
| 445 mask->SetIsDrawable(true); |
| 446 mask->SetIsMask(true); |
| 447 picture_horizontal->SetMaskLayer(mask.get()); |
| 448 |
| 449 float percentage_pixels_large_error = 0.01f; // 0.01%, ~6px / (256*256) |
| 450 float percentage_pixels_small_error = 0.0f; |
| 451 float average_error_allowed_in_bad_pixels = 256.0f; |
| 452 int large_error_allowed = 256; |
| 453 int small_error_allowed = 0; |
| 454 pixel_comparator_.reset(new FuzzyPixelComparator( |
| 455 true, // discard_alpha |
| 456 percentage_pixels_large_error, |
| 457 percentage_pixels_small_error, |
| 458 average_error_allowed_in_bad_pixels, |
| 459 large_error_allowed, |
| 460 small_error_allowed)); |
| 461 |
| 462 RunPixelResourceTest(background, |
| 463 base::FilePath( |
| 464 FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); |
| 465 } |
| 466 |
285 } // namespace | 467 } // namespace |
286 } // namespace cc | 468 } // namespace cc |
287 | 469 |
288 #endif // OS_ANDROID | 470 #endif // OS_ANDROID |
OLD | NEW |