MCPcopy Create free account
hub / github.com/Snapchat/Valdi / make

Method make

snap_drawing/src/snap_drawing/cpp/Text/TextShaperCache.cpp:67–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65 : Valdi::LRUCacheNode<TextShaperCacheKey, TextShaperCacheValue>(std::move(keyValue)) {}
66
67Ref<TextShaperCacheNode> TextShaperCacheNode::make(FontId fontId,
68 Scalar letterSpacing,
69 TextScript script,
70 bool isRightToLeft,
71 const Character* characters,
72 size_t charactersLength,
73 const ShapedGlyph* glyphs,
74 size_t glyphsLength,
75 size_t hash) {
76 /**
77 This does a single allocation containing the TextShaperCacheNode structure, the characters array, and the shaped
78 glyphs.
79 */
80
81 auto charactersAllocSize = charactersLength * sizeof(Character);
82 auto glyphsAllocSize = glyphsLength * sizeof(ShapedGlyph);
83
84 auto baseAllocSize = sizeof(TextShaperCacheNode);
85 auto withCharactersAllocSize = Valdi::alignUp(baseAllocSize + charactersAllocSize, alignof(Character));
86 auto withGlyphsAllocSize = Valdi::alignUp(withCharactersAllocSize + glyphsAllocSize, alignof(ShapedGlyph));
87
88 std::allocator<uint8_t> allocator;
89 auto* region = allocator.allocate(withGlyphsAllocSize);
90
91 auto* allocatedCharacters = reinterpret_cast<Character*>(&region[withCharactersAllocSize - charactersAllocSize]);
92 auto* allocatedGlyphs = reinterpret_cast<ShapedGlyph*>(&region[withGlyphsAllocSize - glyphsAllocSize]);
93
94 if (characters != nullptr) {
95 std::memcpy(allocatedCharacters, characters, charactersAllocSize);
96 }
97 if (glyphs != nullptr) {
98 std::memcpy(allocatedGlyphs, glyphs, glyphsAllocSize);
99 }
100
101 auto cacheKey =
102 TextShaperCacheKey(fontId, letterSpacing, script, isRightToLeft, allocatedCharacters, charactersLength, hash);
103 auto cacheValue = TextShaperCacheValue(allocatedGlyphs, glyphsLength);
104
105 new (region)(TextShaperCacheNode)(std::make_pair(cacheKey, cacheValue));
106
107 return Ref<TextShaperCacheNode>(reinterpret_cast<TextShaperCacheNode*>(region));
108}
109
110TextShaperCache::TextShaperCache(size_t capacity) : _cache(capacity) {}
111

Callers

nothing calls this directly

Calls 4

TextShaperCacheKeyClass · 0.85
alignUpFunction · 0.50
allocateMethod · 0.45

Tested by

no test coverage detected