39 return !frame_->MaybeHasOverlapping();
43 inherited_opacity_ = opacity;
51 force_text_color_ =
value;
55 return frame_->GetBounds().TransformBounds(entity.
GetTransform());
59 const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
61 lazy_glyph_atlas->AddTextFrame(*frame_,
scale);
69 if (
color.IsTransparent()) {
73 auto type = frame_->GetAtlasType();
74 const std::shared_ptr<GlyphAtlas>& atlas =
75 renderer.GetLazyGlyphAtlas()->CreateOrGetGlyphAtlas(
76 *renderer.GetContext(),
type);
78 if (!atlas || !atlas->IsValid()) {
87 pass.
SetPipeline(renderer.GetGlyphAtlasPipeline(opts));
93 VS::FrameInfo frame_info;
96 frame_info.atlas_size =
98 static_cast<Scalar>(atlas->GetTexture()->GetSize().
height)};
99 frame_info.offset = offset_;
100 frame_info.is_translation_scale =
104 VS::BindFrameInfo(pass,
105 renderer.GetTransientsBuffer().EmplaceUniform(frame_info));
107 FS::FragInfo frag_info;
108 frag_info.use_text_color = force_text_color_ ? 1.0 : 0.0;
112 FS::BindFragInfo(pass,
113 renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
116 if (frame_info.is_translation_scale) {
130 FS::BindGlyphAtlasSampler(
133 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
144 constexpr std::array<Point, 6> unit_points = {
Point{0, 0},
Point{1, 0},
148 auto& host_buffer = renderer.GetTransientsBuffer();
149 size_t vertex_count = 0;
150 for (
const auto&
run : frame_->GetRuns()) {
151 vertex_count +=
run.GetGlyphPositions().size();
156 vertex_count *
sizeof(VS::PerVertexData),
alignof(VS::PerVertexData),
157 [&](uint8_t* contents) {
158 VS::PerVertexData
vtx;
159 VS::PerVertexData* vtx_contents =
160 reinterpret_cast<VS::PerVertexData*
>(contents);
162 for (
const TextRun&
run : frame_->GetRuns()) {
163 const Font& font =
run.GetFont();
165 scale_, font.GetMetrics().point_size);
167 atlas->GetFontGlyphAtlas(font, rounded_scale);
174 run.GetGlyphPositions()) {
175 std::optional<Rect> maybe_atlas_glyph_bounds =
177 if (!maybe_atlas_glyph_bounds.has_value()) {
181 const Rect& atlas_glyph_bounds = maybe_atlas_glyph_bounds.value();
183 vtx.glyph_bounds =
Vector4(glyph_position.glyph.bounds.GetXYWH());
184 vtx.glyph_position = glyph_position.position;
186 for (
const Point& point : unit_points) {
187 vtx.unit_position = point;
195 .vertex_buffer = std::move(buffer_view),
197 .vertex_count = vertex_count,
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
float GetShaderClipDepth() const
An object that can look up glyph locations within the GlyphAtlas for a particular typeface.
std::optional< Rect > FindGlyphBounds(const Glyph &glyph) const
Find the location of a glyph in the atlas.
Describes a typeface along with any modifications to its intrinsic properties.
Render passes encode render commands directed as one specific render target into an underlying comman...
virtual bool SetVertexBuffer(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
virtual void SetPipeline(const std::shared_ptr< Pipeline< PipelineDescriptor > > &pipeline)
The pipeline to use for this command.
virtual fml::Status Draw()
Record the currently pending command.
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
VertexShader_ VertexShader
FragmentShader_ FragmentShader
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...
void SetOffset(Vector2 offset)
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
void SetForceTextColor(bool value)
Force the text color to apply to the rendered glyphs, even if those glyphs are bitmaps.
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
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.
void SetTextFrame(const std::shared_ptr< TextFrame > &frame)
void SetColor(Color color)
static Scalar RoundScaledFontSize(Scalar scale, Scalar point_size)
Represents a collection of positioned glyphs from a specific font.
@ kNone
Does not use the index buffer.
@ kNearest
Sample from the nearest mip level.
constexpr Vector4 ToVector(Color color)
@ kNearest
Select nearest to the sample point. Most widely supported.
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
SolidFillVertexShader::PerVertexData vtx
constexpr Color WithAlpha(Scalar new_alpha) const
A 4x4 matrix using column-major storage.
constexpr bool IsTranslationScaleOnly() const
Returns true if the matrix has a scale-only basis and is non-projective. Note that an identity matrix...
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.