Skip to content

Commit

Permalink
[Impeller] Use untransformed text bounds to calculate the size of Col…
Browse files Browse the repository at this point in the history
…orSourceTextContents (#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 flutter/flutter#127103
  • Loading branch information
jason-simmons authored May 22, 2023
1 parent c7acf57 commit d95dfc8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
14 changes: 5 additions & 9 deletions impeller/entity/contents/color_source_text_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)) {
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions impeller/entity/contents/text_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ void TextContents::SetOffset(Vector2 offset) {
offset_ = offset;
}

std::optional<Rect> TextContents::GetTextFrameBounds() const {
return frame_.GetBounds();
}

std::optional<Rect> TextContents::GetCoverage(const Entity& entity) const {
auto bounds = frame_.GetBounds();
if (!bounds.has_value()) {
Expand Down
2 changes: 2 additions & 0 deletions impeller/entity/contents/text_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class TextContents final : public Contents {

void SetOffset(Vector2 offset);

std::optional<Rect> GetTextFrameBounds() const;

// |Contents|
std::optional<Rect> GetCoverage(const Entity& entity) const override;

Expand Down

0 comments on commit d95dfc8

Please sign in to comment.