From a53478d6132b47699afd818f84f14c25a46e5844 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 11 Jul 2024 16:28:56 -0700 Subject: [PATCH] [Impeller] Ensure full transform is applied to text contents (flutter/engine#53819) Fixes https://github.com/flutter/flutter/issues/151521 My change made the text size absorb the scale, so I wasn't applying the full transform. That is incorrect if there are negative scales. --- engine/src/flutter/impeller/aiks/aiks_unittests.cc | 12 ++++++++++++ .../impeller/entity/contents/text_contents.cc | 11 ++++++----- .../flutter/testing/impeller_golden_tests_output.txt | 3 +++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/impeller/aiks/aiks_unittests.cc b/engine/src/flutter/impeller/aiks/aiks_unittests.cc index 2d61b3fb0b..73833f3a77 100644 --- a/engine/src/flutter/impeller/aiks/aiks_unittests.cc +++ b/engine/src/flutter/impeller/aiks/aiks_unittests.cc @@ -626,6 +626,18 @@ TEST_P(AiksTest, CanRenderTextFrame) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } +TEST_P(AiksTest, CanRenderTextFrameWithInvertedTransform) { + Canvas canvas; + canvas.DrawPaint({.color = Color(0.1, 0.1, 0.1, 1.0)}); + + canvas.Translate({1000, 0, 0}); + canvas.Scale({-1, 1, 1}); + ASSERT_TRUE(RenderTextInCanvasSkia( + GetContext(), canvas, "the quick brown fox jumped over the lazy dog!.?", + "Roboto-Regular.ttf")); + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); +} + TEST_P(AiksTest, CanRenderStrokedTextFrame) { Canvas canvas; canvas.DrawPaint({.color = Color(0.1, 0.1, 0.1, 1.0)}); diff --git a/engine/src/flutter/impeller/entity/contents/text_contents.cc b/engine/src/flutter/impeller/entity/contents/text_contents.cc index b4cbdbabf1..9090118dc7 100644 --- a/engine/src/flutter/impeller/entity/contents/text_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/text_contents.cc @@ -231,6 +231,7 @@ bool TextContents::Render(const ContentContext& renderer, const Rect& atlas_glyph_bounds = maybe_atlas_glyph_bounds.value().first; Rect glyph_bounds = maybe_atlas_glyph_bounds.value().second; + Rect scaled_bounds = glyph_bounds.Scale(1.0 / rounded_scale); // For each glyph, we compute two rectangles. One for the vertex // positions and one for the texture coordinates (UVs). The atlas // glyph bounds are used to compute UVs in cases where the @@ -243,19 +244,19 @@ bool TextContents::Render(const ContentContext& renderer, (atlas_glyph_bounds.GetSize() + Point(1, 1)) / atlas_size; Point unrounded_glyph_position = - (basis_transform * glyph_position.position) + - glyph_bounds.GetLeftTop(); + basis_transform * + (glyph_position.position + scaled_bounds.GetLeftTop()); + Point screen_glyph_position = (screen_offset + unrounded_glyph_position + subpixel_adjustment) .Floor(); - Size scaled_size = glyph_bounds.GetSize(); for (const Point& point : unit_points) { Point position; if (is_translation_scale) { - position = screen_glyph_position + (point * scaled_size); + position = screen_glyph_position + + (basis_transform * point * scaled_bounds.GetSize()); } else { - Rect scaled_bounds = glyph_bounds.Scale(1.0 / rounded_scale); position = entity_transform * (glyph_position.position + scaled_bounds.GetLeftTop() + point * scaled_bounds.GetSize()); diff --git a/engine/src/flutter/testing/impeller_golden_tests_output.txt b/engine/src/flutter/testing/impeller_golden_tests_output.txt index 9373f399b9..82812e676a 100644 --- a/engine/src/flutter/testing/impeller_golden_tests_output.txt +++ b/engine/src/flutter/testing/impeller_golden_tests_output.txt @@ -445,6 +445,9 @@ impeller_Play_AiksTest_CanRenderTextFrameWithFractionScaling_Vulkan.png impeller_Play_AiksTest_CanRenderTextFrameWithHalfScaling_Metal.png impeller_Play_AiksTest_CanRenderTextFrameWithHalfScaling_OpenGLES.png impeller_Play_AiksTest_CanRenderTextFrameWithHalfScaling_Vulkan.png +impeller_Play_AiksTest_CanRenderTextFrameWithInvertedTransform_Metal.png +impeller_Play_AiksTest_CanRenderTextFrameWithInvertedTransform_OpenGLES.png +impeller_Play_AiksTest_CanRenderTextFrameWithInvertedTransform_Vulkan.png impeller_Play_AiksTest_CanRenderTextFrame_Metal.png impeller_Play_AiksTest_CanRenderTextFrame_OpenGLES.png impeller_Play_AiksTest_CanRenderTextFrame_Vulkan.png