[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:
@@ -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);
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user