2 * Copyright 2022 Google LLC
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef sktext_gpu_GlyphVector_DEFINED
9 #define sktext_gpu_GlyphVector_DEFINED
11 #include "include/core/SkSpan.h"
12 #include "src/core/SkGlyph.h"
13 #include "src/core/SkGlyphBuffer.h"
14 #include "src/gpu/AtlasTypes.h"
15 #include "src/text/gpu/Glyph.h"
16 #include "src/text/gpu/StrikeCache.h"
17 #include "src/text/gpu/SubRunAllocator.h"
21 class GrMeshDrawTarget;
24 namespace sktext::gpu {
26 // -- GlyphVector ----------------------------------------------------------------------------------
27 // GlyphVector provides a way to delay the lookup of Glyphs until the code is running on the GPU
28 // in single threaded mode. The GlyphVector is created in a multi-threaded environment, but the
29 // StrikeCache is only single threaded (and must be single threaded because of the atlas).
33 // Initially, filled with packed id, but changed to Glyph* in the onPrepare stage.
34 SkPackedGlyphID packedGlyphID;
36 // Add ctors to help SkArenaAlloc create arrays.
37 Variant() : glyph{nullptr} {}
38 Variant(SkPackedGlyphID id) : packedGlyphID{id} {}
41 GlyphVector(sk_sp<SkStrike>&& strike, SkSpan<Variant> glyphs);
43 static GlyphVector Make(
44 sk_sp<SkStrike>&& strike, SkSpan<SkGlyphVariant> glyphs, SubRunAllocator* alloc);
45 SkSpan<const Glyph*> glyphs() const;
47 static std::optional<GlyphVector> MakeFromBuffer(SkReadBuffer& buffer,
48 const SkStrikeClient* strikeClient,
49 SubRunAllocator* alloc);
50 void flatten(SkWriteBuffer& buffer);
52 // This doesn't need to include sizeof(GlyphVector) because this is embedded in each of
54 int unflattenSize() const { return GlyphVectorSize(fGlyphs.size()); }
56 void packedGlyphIDToGlyph(StrikeCache* cache);
59 std::tuple<bool, int> regenerateAtlas(
61 skgpu::MaskFormat maskFormat,
66 static size_t GlyphVectorSize(size_t count) {
67 return sizeof(Variant) * count;
71 friend class TestingPeer;
72 sk_sp<SkStrike> fSkStrike;
73 SkSpan<Variant> fGlyphs;
74 sk_sp<TextStrike> fTextStrike{nullptr};
75 uint64_t fAtlasGeneration{skgpu::AtlasGenerationCounter::kInvalidGeneration};
76 skgpu::BulkUsePlotUpdater fBulkUseUpdater;
79 } // namespace sktext::gpu
81 #endif // sktext_gpu_GlyphVector_DEFINED