Fix rotated image filter shader (#180027)

fixes https://github.com/flutter/flutter/issues/179918

This blocks us from rerasterizing if there is a rotation on the
imagefilter being drawn. This restores the behavior before
c089837469
while keeping the golden introduced in that pr working.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
gaaclarke 2025-12-18 15:04:55 -08:00 committed by GitHub
parent 26978a3a45
commit 9c47d57dbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 57 additions and 2 deletions

View File

@ -473,5 +473,56 @@ TEST_P(AiksTest, ClippedBackdropFilterWithShader) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}
TEST_P(AiksTest, RuntimeEffectImageFilterRotated) {
auto image = DlImageImpeller::Make(CreateTextureForFixture("kalimba.jpg"));
auto size = image->GetBounds().GetSize();
struct FragUniforms {
Size size;
} frag_uniforms = {.size = Size(size.width, size.height)};
auto uniform_data = std::make_shared<std::vector<uint8_t>>();
uniform_data->resize(sizeof(FragUniforms));
memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
auto runtime_stages_result = OpenAssetAsRuntimeStage("gradient.frag.iplr");
ABSL_ASSERT_OK(runtime_stages_result);
std::shared_ptr<RuntimeStage> runtime_stage =
runtime_stages_result
.value()[PlaygroundBackendToRuntimeStageBackend(GetBackend())];
ASSERT_TRUE(runtime_stage);
ASSERT_TRUE(runtime_stage->IsDirty());
std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
nullptr,
};
auto runtime_filter = DlImageFilter::MakeRuntimeEffect(
DlRuntimeEffectImpeller::Make(runtime_stage), sampler_inputs,
uniform_data);
Scalar rotation = 45;
auto callback = [&]() -> sk_sp<DisplayList> {
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SliderFloat("rotation", &rotation, 0, 360);
ImGui::End();
}
DisplayListBuilder builder;
builder.Translate(size.width * 0.5, size.height * 0.5);
builder.Rotate(rotation);
builder.Translate(-size.width * 0.5, -size.height * 0.5);
DlPaint paint;
paint.setImageFilter(runtime_filter);
builder.DrawImage(image, DlPoint(0.0, 0.0),
DlImageSampling::kNearestNeighbor, &paint);
return builder.Build();
};
ASSERT_TRUE(OpenPlaygroundHere(callback));
}
} // namespace testing
} // namespace impeller

View File

@ -45,11 +45,15 @@ struct Snapshot {
/// capture the padding.
bool needs_rasterization_for_runtime_effects = false;
/// Any snapshot that is scaled should rerasterize because we should be
/// Any snapshot that is scaled should re-rasterize because we should be
/// performing the RuntimeEffect at the resolution of the screen, not the
/// scaled up or scaled down version of the snapshot.
bool ShouldRasterizeForRuntimeEffects() const {
return !transform.IsTranslationOnly() ||
// If the transform has a rotation we don't re-rasterize because we'll lose
// the rotation.
// TODO(tbd): We should re-rasterize scaled and rotated snapshots.
return (!transform.IsTranslationOnly() &&
transform.IsTranslationScaleOnly()) ||
needs_rasterization_for_runtime_effects;
}