This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] support for foreground shaders on text #40193
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
27ab650
[Impeller] foreground and background text support
jonahwilliams 5b090dc
what have I done?
jonahwilliams a86bfa4
cleanups
jonahwilliams 9d9af7b
++
jonahwilliams 0b16964
++
jonahwilliams 95e58cf
add test
jonahwilliams 2d9bdcc
Merge branch 'main' into text_shader_stuff
jonahwilliams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "impeller/entity/contents/color_source_text_contents.h" | ||
|
||
#include "impeller/entity/contents/content_context.h" | ||
#include "impeller/entity/contents/texture_contents.h" | ||
#include "impeller/renderer/render_pass.h" | ||
|
||
namespace impeller { | ||
|
||
ColorSourceTextContents::ColorSourceTextContents() = default; | ||
|
||
ColorSourceTextContents::~ColorSourceTextContents() = default; | ||
|
||
void ColorSourceTextContents::SetTextContents( | ||
std::shared_ptr<TextContents> text_contents) { | ||
text_contents_ = std::move(text_contents); | ||
} | ||
|
||
void ColorSourceTextContents::SetColorSourceContents( | ||
std::shared_ptr<ColorSourceContents> color_source_contents) { | ||
color_source_contents_ = std::move(color_source_contents); | ||
} | ||
|
||
std::optional<Rect> ColorSourceTextContents::GetCoverage( | ||
const Entity& entity) const { | ||
return text_contents_->GetCoverage(entity); | ||
} | ||
|
||
void ColorSourceTextContents::SetTextPosition(Point position) { | ||
position_ = position; | ||
} | ||
|
||
bool ColorSourceTextContents::Render(const ContentContext& renderer, | ||
const Entity& entity, | ||
RenderPass& pass) const { | ||
auto coverage = text_contents_->GetCoverage(entity); | ||
if (!coverage.has_value()) { | ||
return true; | ||
} | ||
auto transform = entity.GetTransformation(); | ||
|
||
text_contents_->SetColor(Color::Black()); | ||
color_source_contents_->SetGeometry( | ||
Geometry::MakeRect(Rect::MakeSize(coverage->size))); | ||
|
||
// offset the color source so it behaves as if it were drawn in the original | ||
// position. | ||
auto effect_transform = | ||
color_source_contents_->GetInverseMatrix().Invert().Translate(-position_); | ||
color_source_contents_->SetEffectTransform(effect_transform); | ||
|
||
auto new_texture = renderer.MakeSubpass( | ||
"Text Color Blending", ISize::Ceil(coverage.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)) { | ||
return false; | ||
} | ||
|
||
sub_entity.SetContents(color_source_contents_); | ||
sub_entity.SetBlendMode(BlendMode::kSourceIn); | ||
return sub_entity.Render(context, pass); | ||
}); | ||
if (!new_texture) { | ||
return false; | ||
} | ||
|
||
auto dest_rect = Rect::MakeSize(new_texture->GetSize()) | ||
.TransformBounds(transform.Invert()) | ||
.Shift(position_); | ||
|
||
auto texture_contents = TextureContents::MakeRect(dest_rect); | ||
texture_contents->SetTexture(new_texture); | ||
texture_contents->SetSourceRect(Rect::MakeSize(new_texture->GetSize())); | ||
return texture_contents->Render(renderer, entity, pass); | ||
} | ||
|
||
} // namespace impeller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <memory> | ||
#include <variant> | ||
#include <vector> | ||
|
||
#include "flutter/fml/macros.h" | ||
#include "impeller/entity/contents/color_source_contents.h" | ||
#include "impeller/entity/contents/contents.h" | ||
#include "impeller/entity/contents/text_contents.h" | ||
|
||
namespace impeller { | ||
|
||
class ColorSourceTextContents final : public Contents { | ||
public: | ||
ColorSourceTextContents(); | ||
|
||
~ColorSourceTextContents(); | ||
|
||
void SetTextContents(std::shared_ptr<TextContents> text_contents); | ||
|
||
void SetColorSourceContents( | ||
std::shared_ptr<ColorSourceContents> color_source_contents); | ||
|
||
void SetTextPosition(Point position); | ||
|
||
// |Contents| | ||
std::optional<Rect> GetCoverage(const Entity& entity) const override; | ||
|
||
// |Contents| | ||
bool Render(const ContentContext& renderer, | ||
const Entity& entity, | ||
RenderPass& pass) const override; | ||
|
||
private: | ||
Point position_; | ||
std::shared_ptr<TextContents> text_contents_; | ||
std::shared_ptr<ColorSourceContents> color_source_contents_; | ||
|
||
FML_DISALLOW_COPY_AND_ASSIGN(ColorSourceTextContents); | ||
}; | ||
|
||
} // namespace impeller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than creating a new parameter, just amend this matrix to the entity transform?