Debian Codegraph @

src/text/gpu/GlyphVector.h

raw ◀ ▶
1 Debian patch touch this file
1 /*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef sktext_gpu_GlyphVector_DEFINED
9 #define sktext_gpu_GlyphVector_DEFINED
10
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkSpan.h"
13 #include "src/core/SkGlyph.h"
14 #include "src/core/SkStrike.h" // IWYU pragma: keep
15 #include "src/gpu/AtlasTypes.h"
16 #include "src/text/StrikeForGPU.h"
17 #include "src/text/gpu/StrikeCache.h"
18
19 #include <cstddef>
20 #include <cstdint>
21 #include <optional>
22 #include <tuple>
23
24 class SkReadBuffer;
25 class SkStrikeClient;
26 class SkWriteBuffer;
27
28 class GrMeshDrawTarget;
29 namespace skgpu::ganesh { class AtlasTextOp; }
30 namespace skgpu::graphite {
31 class Device;
32 class Recorder;
33 }
34
35 namespace sktext::gpu {
36 class Glyph;
37 class SubRunAllocator;
38
39 // -- GlyphVector ----------------------------------------------------------------------------------
40 // GlyphVector provides a way to delay the lookup of Glyphs until the code is running on the GPU
41 // in single threaded mode. The GlyphVector is created in a multi-threaded environment, but the
42 // StrikeCache is only single threaded (and must be single threaded because of the atlas).
43 class GlyphVector {
44 public:
45 union Variant {
46 // Initially, filled with packed id, but changed to Glyph* in the onPrepare stage.
47 SkPackedGlyphID packedGlyphID;
48 Glyph* glyph;
49 // Add ctors to help SkArenaAlloc create arrays.
50 Variant() : glyph{nullptr} {}
51 Variant(SkPackedGlyphID id) : packedGlyphID{id} {}
52 };
53
54 GlyphVector(SkStrikePromise&& strikePromise, SkSpan<Variant> glyphs);
55
56 static GlyphVector Make(SkStrikePromise&& promise,
57 SkSpan<const SkPackedGlyphID> glyphs,
58 SubRunAllocator* alloc);
59
60 SkSpan<const Glyph*> glyphs() const;
•61 int glyphCount() const { return SkToInt(fGlyphs.size()); }
62
63 static std::optional<GlyphVector> MakeFromBuffer(SkReadBuffer& buffer,
64 const SkStrikeClient* strikeClient,
65 SubRunAllocator* alloc);
66 void flatten(SkWriteBuffer& buffer) const;
67
68 // This doesn't need to include sizeof(GlyphVector) because this is embedded in each of
69 // the sub runs.
70 int unflattenSize() const { return GlyphVectorSize(fGlyphs.size()); }
71
•72 SkPackedGlyphID getPackedGlyphID(int index) const {
73 SkASSERT(index >= 0 && index < this->glyphCount());
74 return fGlyphs[index].packedGlyphID;
75 }
76
77 SkStrikePromise& strikePromise() { return fStrikePromise; }
78 const SkStrikePromise& strikePromise() const { return fStrikePromise; }
79
80 void packedGlyphIDToGlyph(StrikeCache* cache, skgpu::MaskFormat);
81
82 static size_t GlyphVectorSize(size_t count) {
83 return sizeof(Variant) * count;
84 }
85
86 private:
87 friend class GlyphVectorTestingPeer;
88 friend class ::skgpu::graphite::Device;
89 friend class ::skgpu::ganesh::AtlasTextOp;
90
91 // This function is implemented in ganesh/text/GrAtlasManager.cpp, and should only be called
92 // from AtlasTextOp or linking issues may occur.
93 std::tuple<bool, int> regenerateAtlasForGanesh(
94 int begin, int end,
95 skgpu::MaskFormat maskFormat,
96 int srcPadding,
97 GrMeshDrawTarget*);
98
99 // This function is implemented in graphite/text/AtlasManager.cpp, and should only be called
100 // from graphite::Device or linking issues may occur.
101 std::tuple<bool, int> regenerateAtlasForGraphite(
102 int begin, int end,
103 skgpu::MaskFormat maskFormat,
104 int srcPadding,
105 skgpu::graphite::Recorder*);
106
107 SkStrikePromise fStrikePromise;
108 SkSpan<Variant> fGlyphs;
109 sk_sp<TextStrike> fTextStrike{nullptr};
110 uint64_t fAtlasGeneration{skgpu::AtlasGenerationCounter::kInvalidGeneration};
111 skgpu::BulkUsePlotUpdater fBulkUseUpdater;
112 };
113 } // namespace sktext::gpu
114 #endif // sktext_gpu_GlyphVector_DEFINED