 |
Flutter Impeller
|
|
Go to the documentation of this file.
51 inherited_opacity_ = opacity;
59 force_text_color_ = value;
63 return frame_->GetBounds().TransformBounds(entity.
GetTransform());
67 const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
69 lazy_glyph_atlas->AddTextFrame(*frame_,
scale, offset_, properties_);
79 if (frame_->HasColor()) {
97 if (
color.IsTransparent()) {
101 auto type = frame_->GetAtlasType();
102 const std::shared_ptr<GlyphAtlas>& atlas =
106 if (!atlas || !atlas->IsValid()) {
121 VS::FrameInfo frame_info;
124 ISize atlas_size = atlas->GetTexture()->GetSize();
129 VS::BindFrameInfo(pass,
132 FS::FragInfo frag_info;
133 frag_info.use_text_color = force_text_color_ ? 1.0 : 0.0;
137 FS::BindFragInfo(pass,
141 if (is_translation_scale) {
157 FS::BindGlyphAtlasSampler(
160 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
171 constexpr std::array<Point, 6> unit_points = {
Point{0, 0},
Point{1, 0},
176 size_t vertex_count = 0;
177 for (
const auto& run : frame_->GetRuns()) {
178 vertex_count += run.GetGlyphPositions().size();
183 vertex_count *
sizeof(VS::PerVertexData),
alignof(VS::PerVertexData),
184 [&](uint8_t* contents) {
185 VS::PerVertexData
vtx;
186 VS::PerVertexData* vtx_contents =
187 reinterpret_cast<VS::PerVertexData*
>(contents);
189 for (
const TextRun& run : frame_->GetRuns()) {
190 const Font& font = run.GetFont();
194 atlas->GetFontGlyphAtlas(font, rounded_scale);
202 Point subpixel_adjustment(0.5, 0.5);
207 subpixel_adjustment.
x = 0.125;
210 subpixel_adjustment.
y = 0.125;
213 subpixel_adjustment.
x = 0.125;
214 subpixel_adjustment.
y = 0.125;
218 Point screen_offset = (entity_transform *
Point(0, 0));
220 run.GetGlyphPositions()) {
224 std::optional<std::pair<Rect, Rect>> maybe_atlas_glyph_bounds =
227 if (!maybe_atlas_glyph_bounds.has_value()) {
231 const Rect& atlas_glyph_bounds =
232 maybe_atlas_glyph_bounds.value().first;
233 Rect glyph_bounds = maybe_atlas_glyph_bounds.value().second;
234 Rect scaled_bounds = glyph_bounds.
Scale(1.0 / rounded_scale);
244 (atlas_glyph_bounds.
GetSize() +
Point(1, 1)) / atlas_size;
246 Point unrounded_glyph_position =
248 (glyph_position.position + scaled_bounds.
GetLeftTop());
250 Point screen_glyph_position =
251 (screen_offset + unrounded_glyph_position + subpixel_adjustment)
254 for (
const Point& point : unit_points) {
256 if (is_translation_scale) {
257 position = (screen_glyph_position +
258 (basis_transform * point * scaled_bounds.
GetSize()))
261 position = entity_transform * (glyph_position.position +
263 point * scaled_bounds.
GetSize());
265 vtx.uv = uv_origin + (uv_size * point);
266 vtx.position = position;
267 vtx_contents[i++] =
vtx;
276 .vertex_count = vertex_count,
280 return pass.
Draw().ok();
FragmentShader_ FragmentShader
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.
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.
static Point ComputeSubpixelPosition(const TextRun::GlyphPosition &glyph_position, AxisAlignment alignment, Point offset, Scalar scale)
void SetTextProperties(Color color, bool stroke, Scalar stroke_width, Cap stroke_cap, Join stroke_join, Scalar stroke_miter)
Must be set after text frame.
A glyph and its subpixel position.
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.
constexpr TPoint< T > GetLeftTop() const
static constexpr TPoint Round(const TPoint< U > &other)
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)
const Scalar stroke_width
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)
constexpr Matrix Basis() const
The Matrix without its w components (without translation).
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...
VertexShader_ VertexShader
@ kNone
Does not use the index buffer.
constexpr TRect Scale(Type scale) const
const Metrics & GetMetrics() const
void SetOffset(Vector2 offset)
Render passes encode render commands directed as one specific render target into an underlying comman...
constexpr TSize< Type > GetSize() const
Returns the size of the rectangle which may be negative in either width or height and may have been c...
std::optional< std::pair< Rect, Rect > > FindGlyphBounds(const SubpixelGlyph &glyph) const
Find the location of a glyph in the atlas.
@ kBase
The texture is sampled as if it only had a single mipmap level.
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
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
A 4x4 matrix using column-major storage.
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
AxisAlignment GetAxisAlignment() const