Debian Codegraph @

src/text/gpu/GlyphVector.h

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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
62 static std::optional<GlyphVector> MakeFromBuffer(SkReadBuffer& buffer,
63 const SkStrikeClient* strikeClient,
64 SubRunAllocator* alloc);
65 void flatten(SkWriteBuffer& buffer) const;
66
67 // This doesn't need to include sizeof(GlyphVector) because this is embedded in each of
68 // the sub runs.
69 int unflattenSize() const { return GlyphVectorSize(fGlyphs.size()); }
70
71 void packedGlyphIDToGlyph(StrikeCache* cache, skgpu::MaskFormat);
72
73 static size_t GlyphVectorSize(size_t count) {
74 return sizeof(Variant) * count;
75 }
76
77 private:
78 friend class GlyphVectorTestingPeer;
79 friend class ::skgpu::graphite::Device;
80 friend class ::skgpu::ganesh::AtlasTextOp;
81
82 // This function is implemented in ganesh/text/GrAtlasManager.cpp, and should only be called
83 // from AtlasTextOp or linking issues may occur.
84 std::tuple<bool, int> regenerateAtlasForGanesh(
85 int begin, int end,
86 skgpu::MaskFormat maskFormat,
87 int srcPadding,
88 GrMeshDrawTarget*);
89
90 // This function is implemented in graphite/text/AtlasManager.cpp, and should only be called
91 // from graphite::Device or linking issues may occur.
92 std::tuple<bool, int> regenerateAtlasForGraphite(
93 int begin, int end,
94 skgpu::MaskFormat maskFormat,
95 int srcPadding,
96 skgpu::graphite::Recorder*);
97
98 SkStrikePromise fStrikePromise;
99 SkSpan<Variant> fGlyphs;
100 sk_sp<TextStrike> fTextStrike{nullptr};
101 uint64_t fAtlasGeneration{skgpu::AtlasGenerationCounter::kInvalidGeneration};
102 skgpu::BulkUsePlotUpdater fBulkUseUpdater;
103 };
104 } // namespace sktext::gpu
105 #endif // sktext_gpu_GlyphVector_DEFINED