30constexpr bool kPlatformGammaCorrectionDefault =
42using VS = GlyphAtlasPipeline::VertexShader;
43using FS = GlyphAtlasPipeline::FragmentShader;
62 inherited_opacity_ = opacity;
74 force_text_color_ =
value;
78 return frame_->GetBounds().TransformBounds(entity.
GetTransform());
83 const std::optional<StrokeParameters>& stroke) {
84 if (frame_->HasColor()) {
91 properties_.
stroke = stroke;
98 const Scalar epsilon = 0.005f;
99 if (std::abs(
x - 1.f) < epsilon) {
102 if (std::abs(
x + 1.f) < epsilon) {
111 const Matrix& entity_offset_transform,
112 const std::shared_ptr<TextFrame>& frame,
114 const Matrix& screen_transform,
116 const std::shared_ptr<GlyphAtlas>& atlas) {
124 constexpr std::array<Point, 4> unit_points = {
Point{0, 0},
Point{1, 0},
127 ISize atlas_size = atlas->GetTexture()->GetSize();
129 Matrix basis_transform = entity_offset_transform.
Basis();
131 VS::PerVertexData vtx;
134 const Matrix frame_transform =
145 unscaled_basis.
m[0] = AttractToOne(unscaled_basis.
m[0]);
146 unscaled_basis.
m[5] = AttractToOne(unscaled_basis.
m[5]);
149 Point screen_offset = (entity_offset_transform *
Point(0, 0));
151 for (
const TextRun& run : frame->GetRuns()) {
152 const Font& font = run.GetFont();
153 const ScaledFont scaled_font{.
font = font, .scale = rounded_scale};
154 const FontGlyphAtlas* font_atlas = atlas->GetFontGlyphAtlas(scaled_font);
169 Point subpixel_adjustment(0.5, 0.5);
174 subpixel_adjustment.
x = 0.125;
177 subpixel_adjustment.
y = 0.125;
180 subpixel_adjustment.
x = 0.125;
181 subpixel_adjustment.
y = 0.125;
186 run.GetGlyphPositions()) {
214 for (
const Point& point : unit_points) {
216 if (is_translation_scale) {
217 Point unrounded_glyph_position =
220 (basis_transform * glyph_position.position);
222 Point screen_glyph_position =
223 (screen_offset + unrounded_glyph_position + subpixel_adjustment)
226 (screen_glyph_position +
232 position = entity_offset_transform *
233 (glyph_position.position + scaled_bounds.
GetLeftTop() +
234 point * scaled_bounds.
GetSize());
236 vtx.uv = uv_origin + (uv_size * point);
237 vtx.position = position;
238 vtx_contents[
i++] = vtx;
253 const std::shared_ptr<GlyphAtlas>& atlas =
257 if (!atlas || !atlas->IsValid()) {
269 VS::FrameInfo frame_info;
278 FS::FragInfo frag_info;
279 frag_info.use_text_color = force_text_color_ ? 1.0 : 0.0;
282 bool enable_gamma_correction = frame_->GetEnableGammaCorrection().value_or(
283 kPlatformGammaCorrectionDefault);
284 if (enable_gamma_correction) {
287 color.
red * 0.2126f + color.
green * 0.7152f + color.
blue * 0.0722f;
291 constexpr Scalar kMaxGammaCorrection = 1.2f;
292 frag_info.text_contrast = 1.0f + luma * kMaxGammaCorrection;
294 frag_info.text_contrast = 1.0f;
301 if (is_translation_scale) {
311 constexpr Scalar kMinScaleForRatio = 0.001f;
312 constexpr Scalar kAnisotropicScaleThreshold = 1.15f;
315 const Scalar ratio = (sx > sy) ? sx / std::max(sy, kMinScaleForRatio)
316 : sy / std::max(sx, kMinScaleForRatio);
317 if (ratio > kAnisotropicScaleThreshold) {
338 FS::BindGlyphAtlasSampler(
341 renderer.
GetContext()->GetSamplerLibrary()->GetSampler(
347 size_t glyph_count = 0;
348 for (
const auto& run : frame_->GetRuns()) {
349 glyph_count += run.GetGlyphPositions().size();
351 size_t vertex_count = glyph_count * 4;
352 size_t index_count = glyph_count * 6;
355 vertex_count *
sizeof(VS::PerVertexData),
alignof(VS::PerVertexData),
357 VS::PerVertexData* vtx_contents =
358 reinterpret_cast<VS::PerVertexData*
>(data);
368 index_count *
sizeof(uint16_t),
alignof(uint16_t), [&](uint8_t* data) {
369 uint16_t* indices =
reinterpret_cast<uint16_t*
>(data);
371 for (
auto i = 0u;
i < glyph_count;
i++) {
373 indices[j++] =
base + 0;
374 indices[j++] =
base + 1;
375 indices[j++] =
base + 2;
376 indices[j++] =
base + 1;
377 indices[j++] =
base + 2;
378 indices[j++] =
base + 3;
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
const std::shared_ptr< LazyGlyphAtlas > & GetLazyGlyphAtlas() const
PipelineRef GetGlyphAtlasPipeline(ContentContextOptions opts) const
HostBuffer & GetTransientsIndexesBuffer() const
Retrieve the current host buffer for transient storage of indexes used for indexed draws.
std::shared_ptr< Context > GetContext() const
Matrix GetShaderTransform(const RenderPass &pass) const
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< FrameBounds > 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.
AxisAlignment GetAxisAlignment() const
Type
Describes how the glyphs are represented in the texture.
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
BufferView EmplaceUniform(const UniformType &uniform)
Emplace uniform data onto the host buffer. Ensure that backend specific uniform alignment requirement...
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 bool SetIndexBuffer(BufferView index_buffer, IndexType index_type)
Specify an index buffer to use for this command. To unset the index buffer, pass IndexType::kNone to ...
virtual void SetPipeline(PipelineRef pipeline)
The pipeline to use for this command.
virtual fml::Status Draw()
Record the currently pending command.
virtual void SetElementCount(size_t count)
virtual void SetCommandLabel(std::string_view label)
The debugging label to use for the command.
static void ComputeVertexData(GlyphAtlasPipeline::VertexShader::PerVertexData *vtx_contents, const Matrix &entity_transform, const std::shared_ptr< TextFrame > &frame, Point position, const Matrix &screen_transform, GlyphProperties glyph_properties, const std::shared_ptr< GlyphAtlas > &atlas)
Computes the vertex data for the render operation from a collection of data drawn from the DrawTextFr...
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.
void SetTextProperties(Color color, const std::optional< StrokeParameters > &stroke)
Must be set after text frame.
void SetPosition(Point position)
void SetScreenTransform(const Matrix &transform)
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 Rational RoundScaledFontSize(Scalar scale)
static SubpixelPosition ComputeSubpixelPosition(const TextRun::GlyphPosition &glyph_position, AxisAlignment alignment, const Matrix &transform)
Represents a collection of positioned glyphs from a specific font.
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
LinePipeline::FragmentShader FS
@ kBase
The texture is sampled as if it only had a single mipmap level.
constexpr Vector4 ToVector(Color color)
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
@ kNearest
Select nearest to the sample point. Most widely supported.
impeller::ShaderType type
constexpr bool IsTransparent() const
constexpr Color WithAlpha(Scalar new_alpha) const
constexpr Color Premultiply() const
Rect atlas_bounds
The bounds of the glyph within the glyph atlas texture.
Rect glyph_bounds
The glyph bounds within the local coordinate system.
static Tone ComputeTone(const Color &c)
ToneOrColor tone_or_color
std::optional< StrokeParameters > stroke
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeTranslation(const Vector3 &t)
constexpr Vector3 GetBasisY() const
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).
static constexpr Matrix MakeScale(const Vector3 &s)
constexpr Vector3 GetBasisX() const
Scalar GetMaxBasisLengthXY() const
Return the maximum scale applied specifically to either the X axis or Y axis unit vectors (the bases)...
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
A glyph and its subpixel position.
static constexpr TPoint Round(const TPoint< U > &other)
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