From 3636f686fad694c9bb2e3f45430d40cea9c4fb6f Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Tue, 16 Aug 2022 19:49:57 -0700 Subject: [PATCH] Pass the snapshot transform to the final blit (flutter/engine#35448) --- .../filters/color_matrix_filter_contents.cc | 6 ++- .../contents/filters/filter_contents.cc | 6 ++- .../impeller/entity/entity_unittests.cc | 39 +++++++++++++------ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc index bcd81ae0d2..3280e98df1 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/color_matrix_filter_contents.cc @@ -95,14 +95,16 @@ std::optional ColorMatrixFilterContents::RenderFilter( return pass.AddCommand(std::move(cmd)); }; - auto out_texture = renderer.MakeSubpass(ISize(coverage.size), callback); + auto out_texture = + renderer.MakeSubpass(input_snapshot->texture->GetSize(), callback); if (!out_texture) { return std::nullopt; } out_texture->SetLabel("ColorMatrixFilter Texture"); return Snapshot{.texture = out_texture, - .transform = Matrix::MakeTranslation(coverage.origin)}; + .transform = input_snapshot->transform, + .sampler_descriptor = input_snapshot->sampler_descriptor}; } } // namespace impeller diff --git a/engine/src/flutter/impeller/entity/contents/filters/filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/filter_contents.cc index cc5c76c930..115eac6b94 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/filter_contents.cc @@ -152,14 +152,16 @@ bool FilterContents::Render(const ContentContext& renderer, // Draw the result texture, respecting the transform and clip stack. - auto contents = TextureContents::MakeRect(filter_coverage.value()); + auto texture_rect = Rect::MakeSize(snapshot.texture->GetSize()); + auto contents = TextureContents::MakeRect(texture_rect); contents->SetTexture(snapshot.texture); contents->SetSamplerDescriptor(snapshot.sampler_descriptor); - contents->SetSourceRect(Rect::MakeSize(snapshot.texture->GetSize())); + contents->SetSourceRect(texture_rect); Entity e; e.SetBlendMode(entity.GetBlendMode()); e.SetStencilDepth(entity.GetStencilDepth()); + e.SetTransformation(snapshot.transform); return contents->Render(renderer, e, pass); } diff --git a/engine/src/flutter/impeller/entity/entity_unittests.cc b/engine/src/flutter/impeller/entity/entity_unittests.cc index a10da41ce5..d74c38a939 100644 --- a/engine/src/flutter/impeller/entity/entity_unittests.cc +++ b/engine/src/flutter/impeller/entity/entity_unittests.cc @@ -1482,8 +1482,7 @@ TEST_P(EntityTest, ColorMatrixFilterEditable) { // If this is the first frame, set the ImGui's initial size and postion. if (first_frame) { first_frame = false; - ImGui::SetNextWindowSize({500, 150}); - ImGui::SetNextWindowPos({260, 600}); + ImGui::SetNextWindowPos({10, 10}); } // UI state. @@ -1493,15 +1492,27 @@ TEST_P(EntityTest, ColorMatrixFilterEditable) { 0, 0, 1, 0, 0, // 0, 0, 0, 1, 0, // }; + static float offset[2] = {500, 400}; + static float rotation = 0; + static float scale[2] = {0.65, 0.65}; + static float skew[2] = {0, 0}; // Define the ImGui - ImGui::Begin("Color Matrix"); - std::string label = "##1"; - label.c_str(); - for (int i = 0; i < 20; i += 5) { - ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float, - &(color_matrix.array[i]), 5, NULL, NULL, "%.2f", 0); - label[2]++; + ImGui::Begin("Color Matrix", nullptr, ImGuiWindowFlags_AlwaysAutoResize); + { + std::string label = "##1"; + label.c_str(); + for (int i = 0; i < 20; i += 5) { + ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float, + &(color_matrix.array[i]), 5, NULL, NULL, "%.2f", 0); + label[2]++; + } + + ImGui::SliderFloat2("Translation", &offset[0], 0, + pass.GetRenderTargetSize().width); + ImGui::SliderFloat("Rotation", &rotation, 0, kPi * 2); + ImGui::SliderFloat2("Scale", &scale[0], 0, 3); + ImGui::SliderFloat2("Skew", &skew[0], -3, 3); } ImGui::End(); @@ -1511,9 +1522,13 @@ TEST_P(EntityTest, ColorMatrixFilterEditable) { // Define the entity with the color matrix filter. Entity entity; - entity.SetTransformation(Matrix::MakeScale(GetContentScale()) * - Matrix::MakeTranslation({250, 200}) * - Matrix::MakeScale(Vector2{0.5, 0.5})); + entity.SetTransformation( + Matrix::MakeScale(GetContentScale()) * + Matrix::MakeTranslation(Vector3(offset[0], offset[1])) * + Matrix::MakeRotationZ(Radians(rotation)) * + Matrix::MakeScale(Vector2(scale[0], scale[1])) * + Matrix::MakeSkew(skew[0], skew[1]) * + Matrix::MakeTranslation(-Point(bay_bridge->GetSize()) / 2)); entity.SetContents(filter); entity.Render(context, pass);