| 65 | : Valdi::LRUCacheNode<TextShaperCacheKey, TextShaperCacheValue>(std::move(keyValue)) {} |
| 66 | |
| 67 | Ref<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*>(®ion[withCharactersAllocSize - charactersAllocSize]); |
| 92 | auto* allocatedGlyphs = reinterpret_cast<ShapedGlyph*>(®ion[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 | |
| 110 | TextShaperCache::TextShaperCache(size_t capacity) : _cache(capacity) {} |
| 111 |
nothing calls this directly
no test coverage detected