Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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