 |
Flutter Impeller
|
|
Go to the documentation of this file.
31 std::shared_ptr<GlyphAtlas> TextContents::ResolveAtlas(
34 const std::shared_ptr<LazyGlyphAtlas>& lazy_atlas)
const {
35 FML_DCHECK(lazy_atlas);
37 return lazy_atlas->CreateOrGetGlyphAtlas(context, type);
52 return !frame_->MaybeHasOverlapping();
56 inherited_opacity_ = opacity;
68 const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
70 lazy_glyph_atlas->AddTextFrame(*frame_, scale);
78 if (color.IsTransparent()) {
82 auto type = frame_->GetAtlasType();
86 if (!atlas || !atlas->IsValid()) {
107 VS::FrameInfo frame_info;
109 frame_info.atlas_size =
110 Vector2{
static_cast<Scalar>(atlas->GetTexture()->GetSize().width),
111 static_cast<Scalar>(atlas->GetTexture()->GetSize().height)};
112 frame_info.offset = offset_;
113 frame_info.is_translation_scale =
116 frame_info.text_color =
ToVector(color.Premultiply());
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();
186 vtx.atlas_glyph_bounds =
Vector4(
189 vtx.glyph_bounds =
Vector4(glyph_position.glyph.bounds.origin.x,
190 glyph_position.glyph.bounds.origin.y,
191 glyph_position.glyph.bounds.size.width,
192 glyph_position.glyph.bounds.size.height);
193 vtx.glyph_position = glyph_position.position;
195 for (
const Point& point : unit_points) {
196 vtx.unit_position = point;
197 std::memcpy(vtx_contents++, &vtx,
sizeof(VS::PerVertexData));
204 .vertex_buffer = buffer_view,
206 .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
uint32_t GetStencilDepth() const
Describes a typeface along with any modifications to its intrinsic properties.
std::shared_ptr< LazyGlyphAtlas > GetLazyGlyphAtlas() const
An object that can look up glyph locations within the GlyphAtlas for a particular typeface.
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the screen space bounding rectangle that this contents affects.
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.
void SetColor(Color color)
const Matrix & GetTransformation() const
@ 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.
ISize GetRenderTargetSize() const
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.
@ 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 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
static constexpr Matrix MakeOrthographic(TSize< T > size)
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)
bool BindVertices(const VertexBuffer &buffer)
Specify the vertex and index buffer to use for this command.
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...
HostBuffer & GetTransientsBuffer()