13#include "flutter/fml/logging.h"
14#include "flutter/fml/trace_event.h"
56 return SkPaint::Cap::kButt_Cap;
58 return SkPaint::Cap::kRound_Cap;
60 return SkPaint::Cap::kSquare_Cap;
68 return SkPaint::Join::kMiter_Join;
70 return SkPaint::Join::kRound_Join;
72 return SkPaint::Join::kBevel_Join;
79 return std::make_shared<TypographerContextSkia>();
86std::shared_ptr<GlyphAtlasContext>
88 return std::make_shared<GlyphAtlasContext>(
type);
92 switch (
atlas.GetType()) {
95 static_cast<int32_t
>(
size.height)});
105 const std::shared_ptr<GlyphAtlas>&
atlas,
106 const std::vector<FontGlyphPair>& extra_pairs,
107 std::vector<Rect>& glyph_positions,
108 const std::vector<Rect>& glyph_sizes,
110 int64_t height_adjustment,
111 const std::shared_ptr<RectanglePacker>& rect_packer) {
113 if (!rect_packer || atlas_size.
IsEmpty()) {
117 for (
size_t i = 0;
i < extra_pairs.size();
i++) {
128 location_in_atlas.
x() + 1,
129 location_in_atlas.
y() + height_adjustment + 1,
135 return extra_pairs.size();
139 const std::vector<FontGlyphPair>& pairs,
140 const ISize& atlas_size,
141 std::vector<Rect>& glyph_positions,
142 const std::vector<Rect>& glyph_sizes,
143 int64_t height_adjustment,
144 const std::shared_ptr<RectanglePacker>& rect_packer,
145 size_t start_index) {
148 for (
size_t i = start_index;
i < pairs.size();
i++) {
158 location_in_atlas.
x() + 1,
159 location_in_atlas.
y() + height_adjustment + 1,
169 const std::shared_ptr<GlyphAtlasContext>& atlas_context,
170 const std::vector<FontGlyphPair>& extra_pairs,
171 std::vector<Rect>& glyph_positions,
172 const std::vector<Rect>& glyph_sizes,
173 size_t glyph_index_start,
174 int64_t max_texture_height) {
177 static constexpr int64_t kAtlasWidth = 4096;
178 static constexpr int64_t kMinAtlasHeight = 1024;
180 ISize current_size =
ISize(kAtlasWidth, kMinAtlasHeight);
181 if (atlas_context->GetAtlasSize().height > current_size.
height) {
182 current_size.
height = atlas_context->GetAtlasSize().height * 2;
185 auto height_adjustment = atlas_context->GetAtlasSize().height;
186 while (current_size.
height <= max_texture_height) {
187 std::shared_ptr<RectanglePacker> rect_packer;
188 if (atlas_context->GetRectPacker() || glyph_index_start) {
191 current_size.
height - atlas_context->GetAtlasSize().height);
195 glyph_positions.erase(glyph_positions.begin() + glyph_index_start,
196 glyph_positions.end());
197 atlas_context->UpdateRectPacker(rect_packer);
199 extra_pairs, current_size, glyph_positions, glyph_sizes,
200 height_adjustment, rect_packer, glyph_index_start);
201 if (next_index == extra_pairs.size()) {
212 const Rect& scaled_bounds,
221 metrics.point_size, metrics.scaleX, metrics.skewX);
253 std::shared_ptr<BlitPass>& blit_pass,
255 const std::shared_ptr<Texture>&
texture,
256 const std::vector<FontGlyphPair>& new_pairs,
263 for (
size_t i = start_index;
i < end_index;
i++) {
265 auto data =
atlas.FindFontGlyphBounds(pair);
266 if (!
data.has_value()) {
271 if (
size.IsEmpty()) {
281 if (!
bitmap.tryAllocPixels()) {
289 auto canvas =
surface->getCanvas();
302 atlas.GetTexture()->GetTextureDescriptor().format),
319 return blit_pass->ConvertTextureToShaderRead(
texture);
334 font.getBounds(&glyph.
glyph.
index, 1, &scaled_bounds, &glyph_paint);
342 scaled_bounds.
fRight + adjustment,
350 const std::shared_ptr<GlyphAtlasContext>& atlas_context,
356 std::shared_ptr<GlyphAtlas> last_atlas = atlas_context->GetGlyphAtlas();
359 if (font_glyph_map.empty()) {
368 std::vector<Rect> glyph_sizes;
369 std::vector<FontGlyphPair> new_glyphs;
370 for (
const auto& font_value : font_glyph_map) {
371 const ScaledFont& scaled_font = font_value.first;
373 last_atlas->GetFontGlyphAtlas(scaled_font.
font, scaled_font.
scale);
379 metrics.point_size, metrics.scaleX, metrics.skewX);
389 if (font_glyph_atlas) {
392 new_glyphs.emplace_back(scaled_font, glyph);
393 glyph_sizes.push_back(
399 new_glyphs.emplace_back(scaled_font, glyph);
400 glyph_sizes.push_back(
405 if (new_glyphs.size() == 0) {
413 std::vector<Rect> glyph_positions;
414 glyph_positions.reserve(new_glyphs.size());
415 size_t first_missing_index = 0;
417 if (last_atlas->GetTexture()) {
420 last_atlas, new_glyphs, glyph_positions, glyph_sizes,
421 atlas_context->GetAtlasSize(), atlas_context->GetHeightAdjustment(),
422 atlas_context->GetRectPacker());
428 for (
size_t i = 0;
i < first_missing_index;
i++) {
429 last_atlas->AddTypefaceGlyphPositionAndBounds(
430 new_glyphs[
i], glyph_positions[
i], glyph_sizes[
i]);
434 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
446 last_atlas->GetTexture(), new_glyphs, 0,
447 first_missing_index)) {
452 if (first_missing_index == new_glyphs.size()) {
457 int64_t height_adjustment = atlas_context->GetAtlasSize().height;
458 const int64_t max_texture_height =
466 bool blit_old_atlas =
true;
467 std::shared_ptr<GlyphAtlas> new_atlas = last_atlas;
468 if (atlas_context->GetAtlasSize().height >= max_texture_height ||
470 blit_old_atlas =
false;
471 first_missing_index = 0;
472 glyph_positions.clear();
473 height_adjustment = 0;
474 new_atlas = std::make_shared<GlyphAtlas>(
type);
475 atlas_context->UpdateRectPacker(
nullptr);
476 atlas_context->UpdateGlyphAtlas(new_atlas, {0, 0}, 0);
488 atlas_context->UpdateGlyphAtlas(new_atlas, atlas_size, height_adjustment);
492 FML_DCHECK(new_glyphs.size() == glyph_positions.size());
504 descriptor.
size = atlas_size;
507 std::shared_ptr<Texture> new_texture =
513 new_texture->SetLabel(
"GlyphAtlas");
516 std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
524 new_texture->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
540 if (new_atlas->GetTexture() && blit_old_atlas) {
541 blit_pass->AddCopy(new_atlas->GetTexture(), new_texture,
547 new_atlas->SetTexture(std::move(new_texture));
553 for (
size_t i = first_missing_index;
i < glyph_positions.size();
i++) {
554 new_atlas->AddTypefaceGlyphPositionAndBounds(
555 new_glyphs[
i], glyph_positions[
i], glyph_sizes[
i]);
563 new_atlas->GetTexture(), new_glyphs,
564 first_missing_index, new_glyphs.size())) {
constexpr SkColor SK_ColorBLACK
@ kSlight
minimal modification to improve constrast
void translate(SkScalar dx, SkScalar dy)
void drawGlyphs(int count, const SkGlyphID glyphs[], const SkPoint positions[], const uint32_t clusters[], int textByteCount, const char utf8text[], SkPoint origin, const SkFont &font, const SkPaint &paint)
void setSubpixel(bool subpixel)
void setEdging(Edging edging)
void setSize(SkScalar textSize)
void setHinting(SkFontHinting hintingLevel)
@ kAntiAlias
may have transparent pixels on glyph edges
void setEmbolden(bool embolden)
void setColor(SkColor color)
void setStrokeMiter(SkScalar miter)
void setStrokeCap(Cap cap)
void setStrokeJoin(Join join)
void setBlendMode(SkBlendMode mode)
void setStrokeWidth(SkScalar width)
Wraps a closure that is invoked in the destructor unless released by the caller.
static TypefaceSkia & Cast(Typeface &base)
To do anything rendering related with Impeller, you need a context.
virtual std::shared_ptr< CommandQueue > GetCommandQueue() const =0
Return the graphics queue for submitting command buffers.
virtual const std::shared_ptr< const Capabilities > & GetCapabilities() const =0
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
virtual BackendType GetBackendType() const =0
Get the graphics backend of an Impeller context.
virtual std::shared_ptr< CommandBuffer > CreateCommandBuffer() const =0
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
virtual std::shared_ptr< Allocator > GetResourceAllocator() const =0
Returns the allocator used to create textures and buffers on the device.
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.
const std::shared_ptr< Typeface > & GetTypeface() const
The typeface whose intrinsic properties this font modifies.
const Metrics & GetMetrics() const
A texture containing the bitmap representation of glyphs in different fonts along with the ability to...
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.
static std::shared_ptr< RectanglePacker > Factory(int width, int height)
Return an empty packer with area specified by width and height.
const sk_sp< SkTypeface > & GetSkiaTypeface() const
std::shared_ptr< GlyphAtlas > CreateGlyphAtlas(Context &context, GlyphAtlas::Type type, HostBuffer &host_buffer, const std::shared_ptr< GlyphAtlasContext > &atlas_context, const FontGlyphMap &font_glyph_map) const override
~TypographerContextSkia() override
std::shared_ptr< GlyphAtlasContext > CreateGlyphAtlasContext(GlyphAtlas::Type type) const override
static std::shared_ptr< TypographerContext > Make()
virtual bool IsValid() const
#define FML_UNREACHABLE()
#define FML_DCHECK(condition)
sk_sp< const SkImage > atlas
Optional< SkRect > bounds
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
it will be possible to load the file into Perfetto s trace viewer 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
std::function< void()> closure
font
Font Metadata and Metrics.
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
static void DrawGlyph(SkCanvas *canvas, const ScaledFont &scaled_font, const SubpixelGlyph &glyph, const Rect &scaled_bounds, const GlyphProperties &prop, bool has_color)
static Rect ComputeGlyphSize(const SkFont &font, const SubpixelGlyph &glyph, Scalar scale)
static size_t PairsFitInAtlasOfSize(const std::vector< FontGlyphPair > &pairs, const ISize &atlas_size, std::vector< Rect > &glyph_positions, const std::vector< Rect > &glyph_sizes, int64_t height_adjustment, const std::shared_ptr< RectanglePacker > &rect_packer, size_t start_index)
static SkImageInfo GetImageInfo(const GlyphAtlas &atlas, Size size)
static size_t AppendToExistingAtlas(const std::shared_ptr< GlyphAtlas > &atlas, const std::vector< FontGlyphPair > &extra_pairs, std::vector< Rect > &glyph_positions, const std::vector< Rect > &glyph_sizes, ISize atlas_size, int64_t height_adjustment, const std::shared_ptr< RectanglePacker > &rect_packer)
static ISize ComputeNextAtlasSize(const std::shared_ptr< GlyphAtlasContext > &atlas_context, const std::vector< FontGlyphPair > &extra_pairs, std::vector< Rect > &glyph_positions, const std::vector< Rect > &glyph_sizes, size_t glyph_index_start, int64_t max_texture_height)
std::unordered_map< ScaledFont, std::unordered_set< SubpixelGlyph > > FontGlyphMap
static bool UpdateAtlasBitmap(const GlyphAtlas &atlas, std::shared_ptr< BlitPass > &blit_pass, HostBuffer &host_buffer, const std::shared_ptr< Texture > &texture, const std::vector< FontGlyphPair > &new_pairs, size_t start_index, size_t end_index)
constexpr size_t DefaultUniformAlignment()
static SkScalar prop(SkScalar radius, SkScalar newSize, SkScalar oldSize)
static SkString join(const CommandLineFlags::StringArray &)
static SkImageInfo MakeN32Premul(int width, int height)
static SkImageInfo MakeA8(int width, int height)
static constexpr SkPoint Make(float x, float y)
SkScalar fBottom
larger y-axis bounds
SkScalar fLeft
smaller x-axis bounds
SkScalar fRight
larger x-axis bounds
SkScalar fTop
smaller y-axis bounds
constexpr uint32_t ToARGB() const
Convert to ARGB 32 bit color.
A font along with a glyph in that font rendered at a particular scale and subpixel position.
const SubpixelGlyph & glyph
const ScaledFont & scaled_font
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
A glyph and its subpixel position.
GlyphProperties properties
constexpr auto GetTop() const
constexpr auto GetLeft() const
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
static constexpr TRect MakeSize(const TSize< U > &size)
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
constexpr TSize Ceil() const
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
std::shared_ptr< const fml::Mapping > data
#define TRACE_EVENT0(category_group, name)