[Impeller] Fix transform in TextureContents::RenderToSnaphot passthrough path (flutter/engine#35458)

This commit is contained in:
Brandon DeRosier
2022-08-17 09:23:57 -07:00
committed by GitHub
parent 0d6cf4b63f
commit a7c0824c68
2 changed files with 25 additions and 16 deletions

View File

@@ -56,15 +56,20 @@ std::optional<Rect> TextureContents::GetCoverage(const Entity& entity) const {
std::optional<Snapshot> 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);
}

View File

@@ -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<float>(boston->GetSize().width),
static_cast<float>(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<float*>(&cover_color));
ImGui::ColorEdit4("Bounds color",
reinterpret_cast<float*>(&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<Contents> 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<TextureContents>();
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<SolidColorContents>();
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]++;
}