This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Moved font glyph atlas to flat_hash_map #56847
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
324a9f9
Moved font glyph to flat_hash_map
gaaclarke 250cadc
moved to absl hash
gaaclarke 483effe
updated abseil
gaaclarke 5d0bbca
Revert "updated abseil"
gaaclarke 2068788
removed hash dependency
gaaclarke f6a9a03
try my abseil branch
gaaclarke c420b45
Revert "try my abseil branch"
gaaclarke bb3fc1a
ifdef'd out absl
gaaclarke f17c2be
ifdef'd absl for fuchsia
gaaclarke 124c874
added build_config include
gaaclarke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,16 @@ | |
| #include <functional> | ||
| #include <memory> | ||
| #include <optional> | ||
| #include <unordered_map> | ||
|
|
||
| #include "flutter/fml/build_config.h" | ||
|
|
||
| #if defined(OS_FUCHSIA) | ||
| // TODO(gaaclarke): Migrate to use absl. I couldn't get it working since absl | ||
| // has special logic in its GN files for Fuchsia that I couldn't sort out. | ||
| #define IMPELLER_TYPOGRAPHER_USE_STD_HASH | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🫡 |
||
| #else | ||
| #include "flutter/third_party/abseil-cpp/absl/container/flat_hash_map.h" | ||
| #endif | ||
|
|
||
| #include "impeller/core/texture.h" | ||
| #include "impeller/geometry/rect.h" | ||
|
|
@@ -19,6 +28,30 @@ namespace impeller { | |
|
|
||
| class FontGlyphAtlas; | ||
|
|
||
| /// Helper for AbslHashAdapter. Tallies a hash value with fml::HashCombine. | ||
| template <typename T> | ||
| struct AbslHashAdapterCombiner { | ||
| std::size_t value = 0; | ||
|
|
||
| template <typename... Args> | ||
| static AbslHashAdapterCombiner combine(AbslHashAdapterCombiner combiner, | ||
| const Args&... args) { | ||
| combiner.value = fml::HashCombine(combiner.value, args...); | ||
| return combiner; | ||
| } | ||
| }; | ||
|
|
||
| /// Adapts AbslHashValue functions to be used with std::unordered_map and the | ||
| /// fml hash functions. | ||
| template <typename T> | ||
| struct AbslHashAdapter { | ||
| constexpr std::size_t operator()(const T& element) const { | ||
| AbslHashAdapterCombiner<T> combiner; | ||
| combiner = AbslHashValue(std::move(combiner), element); | ||
| return combiner.value; | ||
| } | ||
| }; | ||
|
|
||
| struct FrameBounds { | ||
| /// The bounds of the glyph within the glyph atlas. | ||
| Rect atlas_bounds; | ||
|
|
@@ -160,11 +193,19 @@ class GlyphAtlas { | |
| std::shared_ptr<Texture> texture_; | ||
| size_t generation_ = 0; | ||
|
|
||
| std::unordered_map<ScaledFont, | ||
| FontGlyphAtlas, | ||
| ScaledFont::Hash, | ||
| ScaledFont::Equal> | ||
| font_atlas_map_; | ||
| #if defined(IMPELLER_TYPOGRAPHER_USE_STD_HASH) | ||
| using FontAtlasMap = std::unordered_map<ScaledFont, | ||
| FontGlyphAtlas, | ||
| AbslHashAdapter<ScaledFont>, | ||
| ScaledFont::Equal>; | ||
| #else | ||
| using FontAtlasMap = absl::flat_hash_map<ScaledFont, | ||
| FontGlyphAtlas, | ||
| absl::Hash<ScaledFont>, | ||
| ScaledFont::Equal>; | ||
| #endif | ||
|
|
||
| FontAtlasMap font_atlas_map_; | ||
|
|
||
| GlyphAtlas(const GlyphAtlas&) = delete; | ||
|
|
||
|
|
@@ -228,6 +269,7 @@ class GlyphAtlasContext { | |
| class FontGlyphAtlas { | ||
| public: | ||
| FontGlyphAtlas() = default; | ||
| FontGlyphAtlas(FontGlyphAtlas&&) = default; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Find the location of a glyph in the atlas. | ||
|
|
@@ -249,12 +291,19 @@ class FontGlyphAtlas { | |
| private: | ||
| friend class GlyphAtlas; | ||
|
|
||
| std::unordered_map<SubpixelGlyph, | ||
| FrameBounds, | ||
| SubpixelGlyph::Hash, | ||
| SubpixelGlyph::Equal> | ||
| positions_; | ||
|
|
||
| #if defined(IMPELLER_TYPOGRAPHER_USE_STD_HASH) | ||
| using PositionsMap = std::unordered_map<SubpixelGlyph, | ||
| FrameBounds, | ||
| AbslHashAdapter<SubpixelGlyph>, | ||
| SubpixelGlyph::Equal>; | ||
| #else | ||
| using PositionsMap = absl::flat_hash_map<SubpixelGlyph, | ||
| FrameBounds, | ||
| absl::Hash<SubpixelGlyph>, | ||
| SubpixelGlyph::Equal>; | ||
| #endif | ||
|
|
||
| PositionsMap positions_; | ||
| FontGlyphAtlas(const FontGlyphAtlas&) = delete; | ||
| }; | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this flow had 3 lookups, the new one has 1