Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4842f0d

Browse files
[CP] [Impeller] Use untransformed text bounds to calculate the size of ColorSourceTextContents (#42218)
CP for #42142
1 parent 3fb6195 commit 4842f0d

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

impeller/entity/contents/color_source_text_contents.cc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ void ColorSourceTextContents::SetTextPosition(Point position) {
3636
bool ColorSourceTextContents::Render(const ContentContext& renderer,
3737
const Entity& entity,
3838
RenderPass& pass) const {
39-
auto coverage = text_contents_->GetCoverage(entity);
40-
if (!coverage.has_value()) {
39+
auto text_bounds = text_contents_->GetTextFrameBounds();
40+
if (!text_bounds.has_value()) {
4141
return true;
4242
}
43-
auto transform = entity.GetTransformation();
4443

4544
text_contents_->SetColor(Color::Black());
4645
color_source_contents_->SetGeometry(
47-
Geometry::MakeRect(Rect::MakeSize(coverage->size)));
46+
Geometry::MakeRect(Rect::MakeSize(text_bounds->size)));
4847

4948
// offset the color source so it behaves as if it were drawn in the original
5049
// position.
@@ -53,10 +52,9 @@ bool ColorSourceTextContents::Render(const ContentContext& renderer,
5352
color_source_contents_->SetEffectTransform(effect_transform);
5453

5554
auto new_texture = renderer.MakeSubpass(
56-
"Text Color Blending", ISize::Ceil(coverage.value().size),
55+
"Text Color Blending", ISize::Ceil(text_bounds.value().size),
5756
[&](const ContentContext& context, RenderPass& pass) {
5857
Entity sub_entity;
59-
sub_entity.SetTransformation(transform);
6058
sub_entity.SetContents(text_contents_);
6159
sub_entity.SetBlendMode(BlendMode::kSource);
6260
if (!sub_entity.Render(context, pass)) {
@@ -71,9 +69,7 @@ bool ColorSourceTextContents::Render(const ContentContext& renderer,
7169
return false;
7270
}
7371

74-
auto dest_rect = Rect::MakeSize(new_texture->GetSize())
75-
.TransformBounds(transform.Invert())
76-
.Shift(position_);
72+
auto dest_rect = Rect::MakeSize(new_texture->GetSize()).Shift(position_);
7773

7874
auto texture_contents = TextureContents::MakeRect(dest_rect);
7975
texture_contents->SetTexture(new_texture);

impeller/entity/contents/text_contents.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ void TextContents::SetOffset(Vector2 offset) {
6666
offset_ = offset;
6767
}
6868

69+
std::optional<Rect> TextContents::GetTextFrameBounds() const {
70+
return frame_.GetBounds();
71+
}
72+
6973
std::optional<Rect> TextContents::GetCoverage(const Entity& entity) const {
7074
auto bounds = frame_.GetBounds();
7175
if (!bounds.has_value()) {

impeller/entity/contents/text_contents.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class TextContents final : public Contents {
4040

4141
void SetOffset(Vector2 offset);
4242

43+
std::optional<Rect> GetTextFrameBounds() const;
44+
4345
// |Contents|
4446
std::optional<Rect> GetCoverage(const Entity& entity) const override;
4547

0 commit comments

Comments
 (0)