 |
Flutter Impeller
|
|
Go to the documentation of this file.
38 return !frame_->MaybeHasOverlapping();
42 inherited_opacity_ = opacity;
50 force_text_color_ = value;
54 return frame_->GetBounds().TransformBounds(entity.
GetTransform());
58 const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
60 lazy_glyph_atlas->AddTextFrame(*frame_,
scale);
68 if (color.IsTransparent()) {
72 auto type = frame_->GetAtlasType();
73 const std::shared_ptr<GlyphAtlas>& atlas =
77 if (!atlas || !atlas->IsValid()) {
97 VS::FrameInfo frame_info;
100 frame_info.atlas_size =
101 Vector2{
static_cast<Scalar>(atlas->GetTexture()->GetSize().width),
102 static_cast<Scalar>(atlas->GetTexture()->GetSize().height)};
103 frame_info.offset = offset_;
104 frame_info.is_translation_scale =
107 frame_info.text_color =
ToVector(color.Premultiply());
109 VS::BindFrameInfo(pass,
114 FSS::FragInfo frag_info;
115 frag_info.use_text_color = force_text_color_ ? 1.0 : 0.0;
116 FSS::BindFragInfo(pass,
121 if (frame_info.is_translation_scale) {
135 FS::BindGlyphAtlasSampler(
138 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
149 constexpr std::array<Point, 6> unit_points = {
Point{0, 0},
Point{1, 0},
154 size_t vertex_count = 0;
155 for (
const auto& run : frame_->GetRuns()) {
156 vertex_count += run.GetGlyphPositions().size();
160 auto buffer_view = host_buffer.
Emplace(
161 vertex_count *
sizeof(VS::PerVertexData),
alignof(VS::PerVertexData),
162 [&](uint8_t* contents) {
163 VS::PerVertexData
vtx;
164 VS::PerVertexData* vtx_contents =
165 reinterpret_cast<VS::PerVertexData*
>(contents);
166 for (
const TextRun& run : frame_->GetRuns()) {
167 const Font& font = run.GetFont();
171 atlas->GetFontGlyphAtlas(font, rounded_scale);
178 run.GetGlyphPositions()) {
179 std::optional<Rect> maybe_atlas_glyph_bounds =
181 if (!maybe_atlas_glyph_bounds.has_value()) {
185 const Rect& atlas_glyph_bounds = maybe_atlas_glyph_bounds.value();
187 vtx.glyph_bounds =
Vector4(glyph_position.glyph.bounds.GetXYWH());
188 vtx.glyph_position = glyph_position.position;
190 for (
const Point& point : unit_points) {
191 vtx.unit_position = point;
192 std::memcpy(vtx_contents++, &
vtx,
sizeof(VS::PerVertexData));
199 .vertex_buffer = std::move(buffer_view),
201 .vertex_count = vertex_count,
205 return pass.
Draw().ok();
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
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
float GetShaderClipDepth() const
Describes a typeface along with any modifications to its intrinsic properties.
const std::shared_ptr< LazyGlyphAtlas > & GetLazyGlyphAtlas() const
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
SolidFillVertexShader::PerVertexData vtx
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
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
static Scalar RoundScaledFontSize(Scalar scale, Scalar point_size)
Represents a collection of positioned glyphs from a specific font.
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
void SetColor(Color color)
virtual fml::Status Draw()
Record the currently pending command.
@ 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...
@ kNone
Does not use the index buffer.
virtual void SetStencilReference(uint32_t value)
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
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.
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor >> &pipeline)
The pipeline to use for this command.
void SetTextFrame(const std::shared_ptr< TextFrame > &frame)
std::shared_ptr< Pipeline< PipelineDescriptor > > GetGlyphAtlasPipeline(ContentContextOptions opts) const
VertexShader_ VertexShader
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.
A 4x4 matrix using column-major storage.
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.