[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.
This commit is contained in:
Jonah Williams
2024-07-11 16:28:56 -07:00
committed by GitHub
parent 7a68f6ab1a
commit a53478d613
3 changed files with 21 additions and 5 deletions

View File

@@ -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)});

View File

@@ -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());

View File

@@ -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