5 #ifndef FLUTTER_IMPELLER_TYPOGRAPHER_GLYPH_ATLAS_H_
6 #define FLUTTER_IMPELLER_TYPOGRAPHER_GLYPH_ATLAS_H_
12 #include "flutter/fml/build_config.h"
14 #if defined(OS_FUCHSIA)
17 #define IMPELLER_TYPOGRAPHER_USE_STD_HASH
19 #include "flutter/third_party/abseil-cpp/absl/container/flat_hash_map.h"
36 template <
typename... Args>
38 const Args&... args) {
39 combiner.
value = fml::HashCombine(combiner.
value, args...);
48 constexpr std::size_t
operator()(
const T& element)
const {
50 combiner = AbslHashValue(std::move(combiner), element);
51 return combiner.
value;
112 void SetTexture(std::shared_ptr<Texture> texture);
119 const std::shared_ptr<Texture>&
GetTexture()
const;
150 const std::function<
bool(
const ScaledFont& scaled_font,
152 const Rect& rect)>& iterator)
const;
193 std::shared_ptr<Texture> texture_;
194 size_t generation_ = 0;
196 #if defined(IMPELLER_TYPOGRAPHER_USE_STD_HASH)
197 using FontAtlasMap = std::unordered_map<
ScaledFont,
202 using FontAtlasMap = absl::flat_hash_map<
ScaledFont,
204 absl::Hash<ScaledFont>,
208 FontAtlasMap font_atlas_map_;
250 int64_t height_adjustment_);
255 std::shared_ptr<GlyphAtlas> atlas_;
257 std::shared_ptr<RectanglePacker> rect_packer_;
258 int64_t height_adjustment_;
294 #if defined(IMPELLER_TYPOGRAPHER_USE_STD_HASH)
302 absl::Hash<SubpixelGlyph>,
306 PositionsMap positions_;
An object that can look up glyph locations within the GlyphAtlas for a particular typeface.
void AppendGlyph(const SubpixelGlyph &glyph, const FrameBounds &frame_bounds)
Append the frame bounds of a glyph to this atlas.
std::optional< FrameBounds > FindGlyphBounds(const SubpixelGlyph &glyph) const
Find the location of a glyph in the atlas.
FontGlyphAtlas(FontGlyphAtlas &&)=default
A container for caching a glyph atlas across frames.
GlyphAtlasContext(GlyphAtlas::Type type)
std::shared_ptr< RectanglePacker > GetRectPacker() const
Retrieve the previous (if any) rect packer.
void UpdateRectPacker(std::shared_ptr< RectanglePacker > rect_packer)
std::shared_ptr< GlyphAtlas > GetGlyphAtlas() const
Retrieve the current glyph atlas.
const ISize & GetAtlasSize() const
Retrieve the size of the current glyph atlas.
int64_t GetHeightAdjustment() const
A y-coordinate shift that must be applied to glyphs appended to the atlas.
virtual ~GlyphAtlasContext()
void UpdateGlyphAtlas(std::shared_ptr< GlyphAtlas > atlas, ISize size, int64_t height_adjustment_)
Update the context with a newly constructed glyph atlas.
A texture containing the bitmap representation of glyphs in different fonts along with the ability to...
std::optional< FrameBounds > FindFontGlyphBounds(const FontGlyphPair &pair) const
Find the location of a specific font-glyph pair in the atlas.
void SetTexture(std::shared_ptr< Texture > texture)
Set the texture for the glyph atlas.
void SetAtlasGeneration(size_t value)
Update the atlas generation.
FontGlyphAtlas * GetOrCreateFontGlyphAtlas(const ScaledFont &scaled_font)
Obtain an interface for querying the location of glyphs in the atlas for the given font and scale....
Type
Describes how the glyphs are represented in the texture.
size_t GetAtlasGeneration() const
Retrieve the generation id for this glyph atlas.
Type GetType() const
Describes how the glyphs are represented in the texture.
const std::shared_ptr< Texture > & GetTexture() const
Get the texture for the glyph atlas.
GlyphAtlas(Type type, size_t initial_generation)
Create an empty glyph atlas.
size_t IterateGlyphs(const std::function< bool(const ScaledFont &scaled_font, const SubpixelGlyph &glyph, const Rect &rect)> &iterator) const
Iterate of all the glyphs along with their locations in the atlas.
void AddTypefaceGlyphPositionAndBounds(const FontGlyphPair &pair, Rect position, Rect bounds)
Record the location of a specific font-glyph pair within the atlas.
size_t GetGlyphCount() const
Get the number of unique font-glyph pairs in this atlas.
Helper for AbslHashAdapter. Tallies a hash value with fml::HashCombine.
static AbslHashAdapterCombiner combine(AbslHashAdapterCombiner combiner, const Args &... args)
constexpr std::size_t operator()(const T &element) const
A font along with a glyph in that font rendered at a particular scale and subpixel position.
Rect atlas_bounds
The bounds of the glyph within the glyph atlas.
Rect glyph_bounds
The local glyph bounds.
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
A glyph and its subpixel position.