Index: cc/trees/layer_tree_host_pixeltest_masks.cc |
diff --git a/cc/trees/layer_tree_host_pixeltest_masks.cc b/cc/trees/layer_tree_host_pixeltest_masks.cc |
index eecc5a0e3eddc68ea43530e3359c64e3f1705bf0..7b0e53bab7cb46ca4345a9e8d86b68e46056b20d 100644 |
--- a/cc/trees/layer_tree_host_pixeltest_masks.cc |
+++ b/cc/trees/layer_tree_host_pixeltest_masks.cc |
@@ -282,6 +282,188 @@ TEST_P(LayerTreeHostMasksPixelTest, MaskOfReplicaOfClippedLayer) { |
#endif // !defined(OS_WIN) |
+class CheckerContentLayerClient : public ContentLayerClient { |
+ public: |
+ CheckerContentLayerClient(const gfx::Size& bounds, |
+ SkColor color, |
+ bool vertical) |
+ : bounds_(bounds), color_(color), vertical_(vertical) {} |
+ ~CheckerContentLayerClient() override {} |
+ bool FillsBoundsCompletely() const override { return false; } |
+ void PaintContents(SkCanvas* canvas, |
+ const gfx::Rect& rect, |
+ PaintingControlSetting picture_control) override { |
+ SkPaint paint; |
+ paint.setStyle(SkPaint::kStroke_Style); |
+ paint.setStrokeWidth(SkIntToScalar(4)); |
+ paint.setColor(color_); |
+ canvas->clear(SK_ColorTRANSPARENT); |
+ if (vertical_) { |
+ for (int i = 4; i < bounds_.width(); i += 16) { |
+ canvas->drawLine(i, 0, i, bounds_.height(), paint); |
+ } |
+ } else { |
+ for (int i = 4; i < bounds_.height(); i += 16) { |
+ canvas->drawLine(0, i, bounds_.width(), i, paint); |
+ } |
+ } |
+ } |
+ scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
+ const gfx::Rect& clip, |
+ PaintingControlSetting picture_control) override { |
+ NOTIMPLEMENTED(); |
+ return DisplayItemList::Create(); |
+ } |
+ |
+ private: |
+ gfx::Size bounds_; |
+ SkColor color_; |
+ bool vertical_; |
+}; |
+ |
+class CircleContentLayerClient : public ContentLayerClient { |
+ public: |
+ explicit CircleContentLayerClient(const gfx::Size& bounds) |
+ : bounds_(bounds) {} |
+ ~CircleContentLayerClient() override {} |
+ bool FillsBoundsCompletely() const override { return false; } |
+ void PaintContents(SkCanvas* canvas, |
+ const gfx::Rect& rect, |
+ PaintingControlSetting picture_control) override { |
+ SkPaint paint; |
+ paint.setStyle(SkPaint::kFill_Style); |
+ paint.setColor(SK_ColorWHITE); |
+ canvas->clear(SK_ColorTRANSPARENT); |
+ canvas->drawCircle(bounds_.width() / 2, |
+ bounds_.height() / 2, |
+ bounds_.width() / 4, |
+ paint); |
+ } |
+ scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
+ const gfx::Rect& clip, |
+ PaintingControlSetting picture_control) override { |
+ NOTIMPLEMENTED(); |
+ return DisplayItemList::Create(); |
+ } |
+ |
+ private: |
+ gfx::Size bounds_; |
+}; |
+ |
+using LayerTreeHostMasksForBackgroundFiltersPixelTest = |
+ ParameterizedPixelResourceTest; |
+ |
+INSTANTIATE_TEST_CASE_P( |
+ PixelResourceTest, |
+ LayerTreeHostMasksForBackgroundFiltersPixelTest, |
+ ::testing::Values( |
+ // SOFTWARE, Background filters aren't implemented in software |
+ GL_GPU_RASTER_2D_DRAW, |
+ GL_ONE_COPY_2D_STAGING_2D_DRAW, |
+ GL_ONE_COPY_RECT_STAGING_2D_DRAW, |
+ GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW, |
+ GL_ZERO_COPY_2D_DRAW, |
+ GL_ZERO_COPY_RECT_DRAW, |
+ GL_ZERO_COPY_EXTERNAL_DRAW, |
+ GL_ASYNC_UPLOAD_2D_DRAW)); |
+ |
+TEST_P(LayerTreeHostMasksForBackgroundFiltersPixelTest, |
+ MaskOfLayerWithBackgroundFilter) { |
+ scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
+ gfx::Rect(256, 256), SK_ColorWHITE); |
+ |
+ gfx::Size picture_bounds(256, 256); |
+ CheckerContentLayerClient picture_client(picture_bounds, SK_ColorGREEN, true); |
+ scoped_refptr<PictureLayer> picture = PictureLayer::Create(&picture_client); |
+ picture->SetBounds(picture_bounds); |
+ picture->SetIsDrawable(true); |
+ |
+ scoped_refptr<SolidColorLayer> blur = CreateSolidColorLayer( |
+ gfx::Rect(256, 256), SK_ColorTRANSPARENT); |
+ background->AddChild(picture); |
+ background->AddChild(blur); |
+ |
+ FilterOperations filters; |
+ filters.Append(FilterOperation::CreateBlurFilter(2.f)); |
+ blur->SetBackgroundFilters(filters); |
+ |
+ gfx::Size mask_bounds(256, 256); |
+ CircleContentLayerClient mask_client(mask_bounds); |
+ scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); |
+ mask->SetBounds(mask_bounds); |
+ mask->SetIsDrawable(true); |
+ mask->SetIsMask(true); |
+ blur->SetMaskLayer(mask.get()); |
+ |
+ float percentage_pixels_large_error = 2.5f; // 2.5%, ~1600px / (256*256) |
+ float percentage_pixels_small_error = 0.0f; |
+ float average_error_allowed_in_bad_pixels = 60.0f; |
+ int large_error_allowed = 100; |
+ int small_error_allowed = 0; |
+ pixel_comparator_.reset(new FuzzyPixelComparator( |
+ true, // discard_alpha |
+ percentage_pixels_large_error, |
+ percentage_pixels_small_error, |
+ average_error_allowed_in_bad_pixels, |
+ large_error_allowed, |
+ small_error_allowed)); |
+ |
+ RunPixelResourceTest(background, |
+ base::FilePath( |
+ FILE_PATH_LITERAL("mask_of_background_filter.png"))); |
+} |
+ |
+TEST_P(LayerTreeHostMasksForBackgroundFiltersPixelTest, |
+ MaskOfLayerWithBlend) { |
+ scoped_refptr<SolidColorLayer> background = CreateSolidColorLayer( |
+ gfx::Rect(256, 256), SK_ColorWHITE); |
+ |
+ gfx::Size picture_bounds(256, 256); |
+ CheckerContentLayerClient picture_client_vertical( |
+ picture_bounds, SK_ColorGREEN, true); |
+ scoped_refptr<PictureLayer> picture_vertical = |
+ PictureLayer::Create(&picture_client_vertical); |
+ picture_vertical->SetBounds(picture_bounds); |
+ picture_vertical->SetIsDrawable(true); |
+ |
+ CheckerContentLayerClient picture_client_horizontal( |
+ picture_bounds, SK_ColorMAGENTA, false); |
+ scoped_refptr<PictureLayer> picture_horizontal = |
+ PictureLayer::Create(&picture_client_horizontal); |
+ picture_horizontal->SetBounds(picture_bounds); |
+ picture_horizontal->SetIsDrawable(true); |
+ picture_horizontal->SetContentsOpaque(false); |
+ picture_horizontal->SetBlendMode(SkXfermode::kMultiply_Mode); |
+ |
+ background->AddChild(picture_vertical); |
+ background->AddChild(picture_horizontal); |
+ |
+ gfx::Size mask_bounds(256, 256); |
+ CircleContentLayerClient mask_client(mask_bounds); |
+ scoped_refptr<PictureLayer> mask = PictureLayer::Create(&mask_client); |
+ mask->SetBounds(mask_bounds); |
+ mask->SetIsDrawable(true); |
+ mask->SetIsMask(true); |
+ picture_horizontal->SetMaskLayer(mask.get()); |
+ |
+ float percentage_pixels_large_error = 0.01f; // 0.01%, ~6px / (256*256) |
+ float percentage_pixels_small_error = 0.0f; |
+ float average_error_allowed_in_bad_pixels = 256.0f; |
+ int large_error_allowed = 256; |
+ int small_error_allowed = 0; |
+ pixel_comparator_.reset(new FuzzyPixelComparator( |
+ true, // discard_alpha |
+ percentage_pixels_large_error, |
+ percentage_pixels_small_error, |
+ average_error_allowed_in_bad_pixels, |
+ large_error_allowed, |
+ small_error_allowed)); |
+ |
+ RunPixelResourceTest(background, |
+ base::FilePath( |
+ FILE_PATH_LITERAL("mask_of_layer_with_blend.png"))); |
+} |
+ |
} // namespace |
} // namespace cc |