Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix bounds of image_filter_layer" #17074

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions flow/layers/image_filter_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,9 @@ ImageFilterLayer::ImageFilterLayer(sk_sp<SkImageFilter> filter)

void ImageFilterLayer::Preroll(PrerollContext* context,
const SkMatrix& matrix) {
TRACE_EVENT0("flutter", "ImageFilterLayer::Preroll");

Layer::AutoPrerollSaveLayerState save =
Layer::AutoPrerollSaveLayerState::Create(context);

SkRect child_paint_bounds = SkRect::MakeEmpty();
PrerollChildren(context, matrix, &child_paint_bounds);
if (filter_) {
const SkIRect filter_input_bounds = child_paint_bounds.roundOut();
SkIRect filter_output_bounds =
filter_->filterBounds(filter_input_bounds, SkMatrix::I(),
SkImageFilter::kForward_MapDirection);
child_paint_bounds = SkRect::Make(filter_output_bounds);
}
set_paint_bounds(child_paint_bounds);
ContainerLayer::Preroll(context, matrix);

if (!context->has_platform_view && context->raster_cache &&
SkRect::Intersects(context->cull_rect, paint_bounds())) {
Expand Down
52 changes: 11 additions & 41 deletions flow/layers/image_filter_layer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,8 @@ TEST_F(ImageFilterLayerTest, SimpleFilter) {
auto layer = std::make_shared<ImageFilterLayer>(layer_filter);
layer->Add(mock_layer);

const SkRect child_rounded_bounds =
SkRect::MakeLTRB(5.0f, 6.0f, 21.0f, 22.0f);

layer->Preroll(preroll_context(), initial_transform);
EXPECT_EQ(layer->paint_bounds(), child_rounded_bounds);
EXPECT_EQ(layer->paint_bounds(), child_bounds);
EXPECT_TRUE(layer->needs_painting());
EXPECT_EQ(mock_layer->parent_matrix(), initial_transform);

Expand All @@ -99,35 +96,15 @@ TEST_F(ImageFilterLayerTest, SimpleFilter) {
MockCanvas::DrawCall{0, MockCanvas::SaveData{1}},
MockCanvas::DrawCall{1, MockCanvas::SetMatrixData{SkMatrix()}},
MockCanvas::DrawCall{
1, MockCanvas::SaveLayerData{child_rounded_bounds,
filter_paint, nullptr, 2}},
1, MockCanvas::SaveLayerData{child_bounds, filter_paint,
nullptr, 2}},
MockCanvas::DrawCall{
2, MockCanvas::DrawPathData{child_path, child_paint}},
MockCanvas::DrawCall{2, MockCanvas::RestoreData{1}},
MockCanvas::DrawCall{1, MockCanvas::RestoreData{0}},
}));
}

TEST_F(ImageFilterLayerTest, SimpleFilterBounds) {
const SkMatrix initial_transform = SkMatrix::MakeTrans(0.5f, 1.0f);
const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 20.5f, 21.5f);
const SkPath child_path = SkPath().addRect(child_bounds);
const SkPaint child_paint = SkPaint(SkColors::kYellow);
const SkMatrix filter_transform = SkMatrix::MakeScale(2.0, 2.0);
auto layer_filter = SkImageFilter::MakeMatrixFilter(
filter_transform, SkFilterQuality::kMedium_SkFilterQuality, nullptr);
auto mock_layer = std::make_shared<MockLayer>(child_path, child_paint);
auto layer = std::make_shared<ImageFilterLayer>(layer_filter);
layer->Add(mock_layer);

const SkRect filter_bounds = SkRect::MakeLTRB(10.0f, 12.0f, 42.0f, 44.0f);

layer->Preroll(preroll_context(), initial_transform);
EXPECT_EQ(layer->paint_bounds(), filter_bounds);
EXPECT_TRUE(layer->needs_painting());
EXPECT_EQ(mock_layer->parent_matrix(), initial_transform);
}

TEST_F(ImageFilterLayerTest, MultipleChildren) {
const SkMatrix initial_transform = SkMatrix::MakeTrans(0.5f, 1.0f);
const SkRect child_bounds = SkRect::MakeLTRB(5.0f, 6.0f, 2.5f, 3.5f);
Expand All @@ -146,12 +123,10 @@ TEST_F(ImageFilterLayerTest, MultipleChildren) {

SkRect children_bounds = child_path1.getBounds();
children_bounds.join(child_path2.getBounds());
SkRect children_rounded_bounds = SkRect::Make(children_bounds.roundOut());

layer->Preroll(preroll_context(), initial_transform);
EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds());
EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds());
EXPECT_EQ(layer->paint_bounds(), children_rounded_bounds);
EXPECT_EQ(layer->paint_bounds(), children_bounds);
EXPECT_TRUE(mock_layer1->needs_painting());
EXPECT_TRUE(mock_layer2->needs_painting());
EXPECT_TRUE(layer->needs_painting());
Expand All @@ -166,8 +141,8 @@ TEST_F(ImageFilterLayerTest, MultipleChildren) {
{MockCanvas::DrawCall{0, MockCanvas::SaveData{1}},
MockCanvas::DrawCall{1, MockCanvas::SetMatrixData{SkMatrix()}},
MockCanvas::DrawCall{
1, MockCanvas::SaveLayerData{children_rounded_bounds,
filter_paint, nullptr, 2}},
1, MockCanvas::SaveLayerData{children_bounds, filter_paint,
nullptr, 2}},
MockCanvas::DrawCall{
2, MockCanvas::DrawPathData{child_path1, child_paint1}},
MockCanvas::DrawCall{
Expand Down Expand Up @@ -198,16 +173,11 @@ TEST_F(ImageFilterLayerTest, Nested) {

SkRect children_bounds = child_path1.getBounds();
children_bounds.join(child_path2.getBounds());
const SkRect children_rounded_bounds =
SkRect::Make(children_bounds.roundOut());
const SkRect mock_layer2_rounded_bounds =
SkRect::Make(child_path2.getBounds().roundOut());

layer1->Preroll(preroll_context(), initial_transform);
EXPECT_EQ(mock_layer1->paint_bounds(), child_path1.getBounds());
EXPECT_EQ(mock_layer2->paint_bounds(), child_path2.getBounds());
EXPECT_EQ(layer1->paint_bounds(), children_rounded_bounds);
EXPECT_EQ(layer2->paint_bounds(), mock_layer2_rounded_bounds);
EXPECT_EQ(layer1->paint_bounds(), children_bounds);
EXPECT_EQ(layer2->paint_bounds(), mock_layer2->paint_bounds());
EXPECT_TRUE(mock_layer1->needs_painting());
EXPECT_TRUE(mock_layer2->needs_painting());
EXPECT_TRUE(layer1->needs_painting());
Expand All @@ -224,14 +194,14 @@ TEST_F(ImageFilterLayerTest, Nested) {
MockCanvas::DrawCall{0, MockCanvas::SaveData{1}},
MockCanvas::DrawCall{1, MockCanvas::SetMatrixData{SkMatrix()}},
MockCanvas::DrawCall{
1, MockCanvas::SaveLayerData{children_rounded_bounds,
filter_paint1, nullptr, 2}},
1, MockCanvas::SaveLayerData{children_bounds, filter_paint1,
nullptr, 2}},
MockCanvas::DrawCall{
2, MockCanvas::DrawPathData{child_path1, child_paint1}},
MockCanvas::DrawCall{2, MockCanvas::SaveData{3}},
MockCanvas::DrawCall{3, MockCanvas::SetMatrixData{SkMatrix()}},
MockCanvas::DrawCall{
3, MockCanvas::SaveLayerData{mock_layer2_rounded_bounds,
3, MockCanvas::SaveLayerData{child_path2.getBounds(),
filter_paint2, nullptr, 4}},
MockCanvas::DrawCall{
4, MockCanvas::DrawPathData{child_path2, child_paint2}},
Expand Down