From 956bf40a1c15f66f143c2904f5fdf1ed7d2d0830 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 22 May 2023 13:01:49 -0700 Subject: [PATCH] [Impeller] Use untransformed text bounds to calculate the size of ColorSourceTextContents (#42142) Previously this was attempting to invert the TransformBounds done by GetCoverage. TransformBounds computes a bounding box of the transformed rectangle and can not be reversed. Fixes https://github.com/flutter/flutter/issues/127103 --- .../entity/contents/color_source_text_contents.cc | 14 +++++--------- impeller/entity/contents/text_contents.cc | 4 ++++ impeller/entity/contents/text_contents.h | 2 ++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/impeller/entity/contents/color_source_text_contents.cc b/impeller/entity/contents/color_source_text_contents.cc index 3301fb26c9e7e..9b38287be5b44 100644 --- a/impeller/entity/contents/color_source_text_contents.cc +++ b/impeller/entity/contents/color_source_text_contents.cc @@ -36,15 +36,14 @@ void ColorSourceTextContents::SetTextPosition(Point position) { bool ColorSourceTextContents::Render(const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { - auto coverage = text_contents_->GetCoverage(entity); - if (!coverage.has_value()) { + auto text_bounds = text_contents_->GetTextFrameBounds(); + if (!text_bounds.has_value()) { return true; } - auto transform = entity.GetTransformation(); text_contents_->SetColor(Color::Black()); color_source_contents_->SetGeometry( - Geometry::MakeRect(Rect::MakeSize(coverage->size))); + Geometry::MakeRect(Rect::MakeSize(text_bounds->size))); // offset the color source so it behaves as if it were drawn in the original // position. @@ -53,10 +52,9 @@ bool ColorSourceTextContents::Render(const ContentContext& renderer, color_source_contents_->SetEffectTransform(effect_transform); auto new_texture = renderer.MakeSubpass( - "Text Color Blending", ISize::Ceil(coverage.value().size), + "Text Color Blending", ISize::Ceil(text_bounds.value().size), [&](const ContentContext& context, RenderPass& pass) { Entity sub_entity; - sub_entity.SetTransformation(transform); sub_entity.SetContents(text_contents_); sub_entity.SetBlendMode(BlendMode::kSource); if (!sub_entity.Render(context, pass)) { @@ -71,9 +69,7 @@ bool ColorSourceTextContents::Render(const ContentContext& renderer, return false; } - auto dest_rect = Rect::MakeSize(new_texture->GetSize()) - .TransformBounds(transform.Invert()) - .Shift(position_); + auto dest_rect = Rect::MakeSize(new_texture->GetSize()).Shift(position_); auto texture_contents = TextureContents::MakeRect(dest_rect); texture_contents->SetTexture(new_texture); diff --git a/impeller/entity/contents/text_contents.cc b/impeller/entity/contents/text_contents.cc index d307170272866..65c5333037e3e 100644 --- a/impeller/entity/contents/text_contents.cc +++ b/impeller/entity/contents/text_contents.cc @@ -66,6 +66,10 @@ void TextContents::SetOffset(Vector2 offset) { offset_ = offset; } +std::optional TextContents::GetTextFrameBounds() const { + return frame_.GetBounds(); +} + std::optional TextContents::GetCoverage(const Entity& entity) const { auto bounds = frame_.GetBounds(); if (!bounds.has_value()) { diff --git a/impeller/entity/contents/text_contents.h b/impeller/entity/contents/text_contents.h index b32f37258d91c..aadbfc88739c2 100644 --- a/impeller/entity/contents/text_contents.h +++ b/impeller/entity/contents/text_contents.h @@ -40,6 +40,8 @@ class TextContents final : public Contents { void SetOffset(Vector2 offset); + std::optional GetTextFrameBounds() const; + // |Contents| std::optional GetCoverage(const Entity& entity) const override;