Skip to content

[Impeller] mask blurs on ColorSourceContents stretches the contents #144836

@gaaclarke

Description

@gaaclarke

As part of implementing mask blurs on textures we had to make sure we are sampling outside of texture to give coverage to the blur radius. It was discovered that that is the same sort of math we should be doing in non-solid colors as well. Not doing that is causing slight stretching of gradients.

See also:
flutter/engine#51183 (comment)

reproduction

TEST_P(AiksTest, MaskBlurDoesntStretchContents) {
  Scalar sigma = 70;
  auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
    if (AiksTest::ImGuiBegin("Controls", nullptr,
                             ImGuiWindowFlags_AlwaysAutoResize)) {
      ImGui::SliderFloat("Sigma", &sigma, 0, 500);
      ImGui::End();
    }
    Canvas canvas;
    canvas.Scale(GetContentScale());
    canvas.DrawPaint({.color = Color(0.1, 0.1, 0.1, 1.0)});

    std::shared_ptr<Texture> boston = CreateTextureForFixture("boston.jpg");
    ColorSource image_source = ColorSource::MakeImage(
        boston, Entity::TileMode::kRepeat, Entity::TileMode::kRepeat, {}, {});

    canvas.Transform(Matrix::MakeTranslation({100, 100, 0}) *
                     Matrix::MakeScale({0.5, 0.5, 1.0}));
    Paint paint = {
        .color_source = image_source,
        .mask_blur_descriptor =
            Paint::MaskBlurDescriptor{
                .style = FilterContents::BlurStyle::kNormal,
                .sigma = Sigma(sigma),
            },
    };
    canvas.DrawRect(
        Rect::MakeXYWH(0, 0, boston->GetSize().width, boston->GetSize().height),
        paint);

    return canvas.EndRecordingAsPicture();
  };
  ASSERT_TRUE(OpenPlaygroundHere(callback));
}

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work liste: impellerImpeller rendering backend issues and features requeststeam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions