diff --git a/engine/src/flutter/impeller/entity/contents/texture_contents.cc b/engine/src/flutter/impeller/entity/contents/texture_contents.cc index 4e77668d1d..758b31e16d 100644 --- a/engine/src/flutter/impeller/entity/contents/texture_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/texture_contents.cc @@ -56,15 +56,20 @@ std::optional TextureContents::GetCoverage(const Entity& entity) const { std::optional TextureContents::RenderToSnapshot( const ContentContext& renderer, const Entity& entity) const { + auto bounds = path_.GetBoundingBox(); + if (!bounds.has_value()) { + return std::nullopt; + } + // Passthrough textures that have simple rectangle paths and complete source // rects. if (is_rect_ && source_rect_ == Rect::MakeSize(texture_->GetSize())) { - auto scale = - Vector2(path_.GetBoundingBox()->size / Size(texture_->GetSize())); - return Snapshot{ - .texture = texture_, - .transform = entity.GetTransformation() * Matrix::MakeScale(scale), - .sampler_descriptor = sampler_descriptor_}; + auto scale = Vector2(bounds->size / Size(texture_->GetSize())); + return Snapshot{.texture = texture_, + .transform = entity.GetTransformation() * + Matrix::MakeTranslation(bounds->origin) * + Matrix::MakeScale(scale), + .sampler_descriptor = sampler_descriptor_}; } return Contents::RenderToSnapshot(renderer, entity); } diff --git a/engine/src/flutter/impeller/entity/entity_unittests.cc b/engine/src/flutter/impeller/entity/entity_unittests.cc index d74c38a939..4fa1f959ee 100644 --- a/engine/src/flutter/impeller/entity/entity_unittests.cc +++ b/engine/src/flutter/impeller/entity/entity_unittests.cc @@ -871,6 +871,9 @@ TEST_P(EntityTest, GaussianBlurFilter) { static float rotation = 0; static float scale[2] = {0.65, 0.65}; static float skew[2] = {0, 0}; + static float path_rect[4] = {0, 0, + static_cast(boston->GetSize().width), + static_cast(boston->GetSize().height)}; ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); { @@ -889,7 +892,7 @@ TEST_P(EntityTest, GaussianBlurFilter) { pass_variation_names, sizeof(pass_variation_names) / sizeof(char*)); } - ImGui::SliderFloat2("Sigma", &blur_amount[0], 0, 200); + ImGui::SliderFloat2("Sigma", blur_amount, 0, 200); ImGui::Combo("Blur style", &selected_blur_style, blur_style_names, sizeof(blur_style_names) / sizeof(char*)); ImGui::Combo("Tile mode", &selected_tile_mode, tile_mode_names, @@ -897,21 +900,23 @@ TEST_P(EntityTest, GaussianBlurFilter) { ImGui::ColorEdit4("Cover color", reinterpret_cast(&cover_color)); ImGui::ColorEdit4("Bounds color", reinterpret_cast(&bounds_color)); - ImGui::SliderFloat2("Translation", &offset[0], 0, + ImGui::SliderFloat2("Translation", offset, 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::SliderFloat2("Scale", scale, 0, 3); + ImGui::SliderFloat2("Skew", skew, -3, 3); + ImGui::SliderFloat4("Path XYWH", path_rect, -1000, 1000); } ImGui::End(); std::shared_ptr input; Size input_size; + auto input_rect = + Rect::MakeXYWH(path_rect[0], path_rect[1], path_rect[2], path_rect[3]); if (selected_input_type == 0) { auto texture = std::make_shared(); - auto input_rect = Rect::MakeSize(boston->GetSize()); - texture->SetSourceRect(input_rect); + texture->SetSourceRect(Rect::MakeSize(boston->GetSize())); texture->SetPath(PathBuilder{}.AddRect(input_rect).TakePath()); texture->SetTexture(boston); texture->SetOpacity(input_color.alpha); @@ -920,7 +925,6 @@ TEST_P(EntityTest, GaussianBlurFilter) { input_size = input_rect.size; } else { auto fill = std::make_shared(); - auto input_rect = Rect::MakeSize(boston->GetSize()); fill->SetColor(input_color); fill->SetPath(PathBuilder{}.AddRect(input_rect).TakePath()); @@ -964,8 +968,7 @@ TEST_P(EntityTest, GaussianBlurFilter) { // unfiltered input. Entity cover_entity; cover_entity.SetContents(SolidColorContents::Make( - PathBuilder{}.AddRect(Rect::MakeSize(input_size)).TakePath(), - cover_color)); + PathBuilder{}.AddRect(input_rect).TakePath(), cover_color)); cover_entity.SetTransformation(ctm); cover_entity.Render(context, pass); @@ -1504,7 +1507,8 @@ TEST_P(EntityTest, ColorMatrixFilterEditable) { 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); + &(color_matrix.array[i]), 5, nullptr, nullptr, + "%.2f", 0); label[2]++; }