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 =
103 renderer.GetLazyGlyphAtlas()->CreateOrGetGlyphAtlas(
121 VS::FrameInfo frame_info;
124 ISize atlas_size =
atlas->GetTexture()->GetSize();
129 VS::BindFrameInfo(pass,
130 renderer.GetTransientsBuffer().EmplaceUniform(frame_info));
132 FS::FragInfo frag_info;
133 frag_info.use_text_color = force_text_color_ ? 1.0 : 0.0;
137 FS::BindFragInfo(pass,
138 renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
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},
175 auto& host_buffer =
renderer.GetTransientsBuffer();
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()) {
192 scale_,
font.GetMetrics().point_size);
194 atlas->GetFontGlyphAtlas(
font, rounded_scale);
202 Point subpixel_adjustment(0.5, 0.5);
203 switch (
font.GetAxisAlignment()) {
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()) {
223 glyph_position,
font.GetAxisAlignment(), offset_, scale_);
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;
243 (atlas_glyph_bounds.
GetSize() +
Point(1, 1)) / atlas_size;
245 Point unrounded_glyph_position =
246 (basis_transform * glyph_position.position) +
248 Point screen_glyph_position =
249 (screen_offset + unrounded_glyph_position + subpixel_adjustment)
253 for (
const Point& point : unit_points) {
255 if (is_translation_scale) {
256 position = screen_glyph_position + (point * scaled_size);
258 Rect scaled_bounds = glyph_bounds.
Scale(1.0 / rounded_scale);
259 position = entity_transform * (glyph_position.position +
261 point * scaled_bounds.
GetSize());
263 vtx.uv = uv_origin + (uv_size * point);
264 vtx.position = position;
265 vtx_contents[
i++] =
vtx;
274 .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< std::pair< Rect, Rect > > FindGlyphBounds(const SubpixelGlyph &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 SetTextProperties(Color color, bool stroke, Scalar stroke_width, Cap stroke_cap, Join stroke_join, Scalar stroke_miter)
Must be set after text frame.
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)
static Point ComputeSubpixelPosition(const TextRun::GlyphPosition &glyph_position, AxisAlignment alignment, Point offset, Scalar scale)
Represents a collection of positioned glyphs from a specific font.
sk_sp< const SkImage > atlas
font
Font Metadata and Metrics.
@ kNone
Does not use the index buffer.
@ kBase
The texture is sampled as if it only had a single mipmap 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
const Scalar stroke_width
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 Matrix Basis() const
The Matrix without its w components (without translation).
A glyph and its subpixel position.
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...
constexpr TPoint< T > GetLeftTop() const
constexpr TRect Scale(Type scale) const