From 9c47d57dbb38ec552959b2272ab31fdff911ba87 Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Thu, 18 Dec 2025 15:04:55 -0800 Subject: [PATCH] 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 https://github.com/flutter/flutter/commit/c089837469a3676dd5dafe7886f6971aff2649c3 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. [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 --- .../aiks_dl_runtime_effect_unittests.cc | 51 +++++++++++++++++++ .../src/flutter/impeller/renderer/snapshot.h | 8 ++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/impeller/display_list/aiks_dl_runtime_effect_unittests.cc b/engine/src/flutter/impeller/display_list/aiks_dl_runtime_effect_unittests.cc index 9a55d9f6ea2..c24d7386482 100644 --- a/engine/src/flutter/impeller/display_list/aiks_dl_runtime_effect_unittests.cc +++ b/engine/src/flutter/impeller/display_list/aiks_dl_runtime_effect_unittests.cc @@ -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>(); + 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 runtime_stage = + runtime_stages_result + .value()[PlaygroundBackendToRuntimeStageBackend(GetBackend())]; + ASSERT_TRUE(runtime_stage); + ASSERT_TRUE(runtime_stage->IsDirty()); + + std::vector> sampler_inputs = { + nullptr, + }; + + auto runtime_filter = DlImageFilter::MakeRuntimeEffect( + DlRuntimeEffectImpeller::Make(runtime_stage), sampler_inputs, + uniform_data); + + Scalar rotation = 45; + + auto callback = [&]() -> sk_sp { + 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 diff --git a/engine/src/flutter/impeller/renderer/snapshot.h b/engine/src/flutter/impeller/renderer/snapshot.h index 36d3091e3eb..07f101a6f1e 100644 --- a/engine/src/flutter/impeller/renderer/snapshot.h +++ b/engine/src/flutter/impeller/renderer/snapshot.h @@ -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; }