 |
Flutter Impeller
|
|
Go to the documentation of this file.
29 std::shared_ptr<GlyphAtlas> TextContents::ResolveAtlas(
32 const std::shared_ptr<LazyGlyphAtlas>& lazy_atlas)
const {
33 FML_DCHECK(lazy_atlas);
35 return lazy_atlas->CreateOrGetGlyphAtlas(context, type);
50 return !frame_->MaybeHasOverlapping();
54 inherited_opacity_ = opacity;
62 force_text_color_ = value;
66 return frame_->GetBounds().TransformBounds(entity.
GetTransform());
70 const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
72 lazy_glyph_atlas->AddTextFrame(*frame_, scale);
80 if (color.IsTransparent()) {
84 auto type = frame_->GetAtlasType();
88 if (!atlas || !atlas->IsValid()) {
109 VS::FrameInfo frame_info;
111 frame_info.atlas_size =
112 Vector2{
static_cast<Scalar>(atlas->GetTexture()->GetSize().width),
113 static_cast<Scalar>(atlas->GetTexture()->GetSize().height)};
114 frame_info.offset = offset_;
115 frame_info.is_translation_scale =
118 frame_info.text_color =
ToVector(color.Premultiply());
124 FSS::FragInfo frag_info;
125 frag_info.use_text_color = force_text_color_ ? 1.0 : 0.0;
126 FSS::BindFragInfo(cmd,
131 if (frame_info.is_translation_scale) {
145 FS::BindGlyphAtlasSampler(
148 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
159 constexpr std::array<Point, 6> unit_points = {
Point{0, 0},
Point{1, 0},
164 size_t vertex_count = 0;
165 for (
const auto& run : frame_->GetRuns()) {
166 vertex_count += run.GetGlyphPositions().size();
170 auto buffer_view = host_buffer.
Emplace(
171 vertex_count *
sizeof(VS::PerVertexData),
alignof(VS::PerVertexData),
172 [&](uint8_t* contents) {
173 VS::PerVertexData vtx;
174 VS::PerVertexData* vtx_contents =
175 reinterpret_cast<VS::PerVertexData*
>(contents);
176 for (
const TextRun& run : frame_->GetRuns()) {
177 const Font& font = run.GetFont();
181 atlas->GetFontGlyphAtlas(font, rounded_scale);
188 run.GetGlyphPositions()) {
189 std::optional<Rect> maybe_atlas_glyph_bounds =
191 if (!maybe_atlas_glyph_bounds.has_value()) {
195 const Rect& atlas_glyph_bounds = maybe_atlas_glyph_bounds.value();
197 vtx.glyph_bounds =
Vector4(glyph_position.glyph.bounds.GetXYWH());
198 vtx.glyph_position = glyph_position.position;
200 for (
const Point& point : unit_points) {
201 vtx.unit_position = point;
202 std::memcpy(vtx_contents++, &vtx,
sizeof(VS::PerVertexData));
209 .vertex_buffer = buffer_view,
211 .vertex_count = vertex_count,
An object used to specify work to the GPU along with references to resources the GPU will used when d...
#define DEBUG_COMMAND_INFO(obj, arg)
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
std::shared_ptr< Pipeline< PipelineDescriptor > > GetGlyphAtlasColorPipeline(ContentContextOptions opts) const
Describes a typeface along with any modifications to its intrinsic properties.
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
std::shared_ptr< LazyGlyphAtlas > GetLazyGlyphAtlas() const
An object that can look up glyph locations within the GlyphAtlas for a particular typeface.
void SetForceTextColor(bool value)
Force the text color to apply to the rendered glyphs, even if those glyphs are bitmaps.
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
BufferView Emplace(const BufferType &buffer)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
FragmentShader_ FragmentShader
static Scalar RoundScaledFontSize(Scalar scale, Scalar point_size)
Represents a collection of positioned glyphs from a specific font.
const Matrix & GetOrthographicTransform() const
void SetColor(Color color)
@ kNearest
Select nearest to the sample point. Most widely supported.
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
@ kNearest
Sample from the nearest mip level.
void PopulateGlyphAtlas(const std::shared_ptr< LazyGlyphAtlas > &lazy_glyph_atlas, Scalar scale) override
Add any text data to the specified lazy atlas. The scale parameter must be used again later when draw...
std::shared_ptr< Context > GetContext() const
constexpr Color WithAlpha(Scalar new_alpha) const
constexpr bool IsTranslationScaleOnly() const
Returns true if the matrix has a scale-only basis and is non-projective. Note that an identity matrix...
Type
Describes how the glyphs are represented in the texture.
bool BindVertices(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
@ kNone
Does not use the index buffer.
const Metrics & GetMetrics() const
void SetOffset(Vector2 offset)
Render passes encode render commands directed as one specific render target into an underlying comman...
uint32_t GetClipDepth() const
uint32_t stencil_reference
To do anything rendering related with Impeller, you need a context.
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
constexpr Vector4 ToVector(Color color)
BufferView EmplaceUniform(const UniformType &uniform)
Emplace uniform data onto the host buffer. Ensure that backend specific uniform alignment requirement...
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
std::optional< Rect > FindGlyphBounds(const Glyph &glyph) const
Find the location of a glyph in the atlas.
void SetTextFrame(const std::shared_ptr< TextFrame > &frame)
std::shared_ptr< Pipeline< PipelineDescriptor > > pipeline
std::shared_ptr< Pipeline< PipelineDescriptor > > GetGlyphAtlasPipeline(ContentContextOptions opts) const
VertexShader_ VertexShader
bool AddCommand(Command &&command)
Record a command for subsequent encoding to the underlying command buffer. No work is encoded into th...
constexpr std::array< T, 4 > GetXYWH() const
Get the x, y coordinates of the origin and the width and height of the rectangle in an array.
HostBuffer & GetTransientsBuffer()