[Impeller] Use untransformed text bounds to calculate the size of ColorSourceTextContents (flutter/engine#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
This commit is contained in:
Jason Simmons
2023-05-22 13:01:49 -07:00
committed by GitHub
parent 19c071da39
commit c40d8bbc8e
3 changed files with 11 additions and 9 deletions

View File

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

View File

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

View File

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