Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / text / gpu / GlyphVector.h
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/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"
18
19 class SkStrikeClient;
20 #if SK_SUPPORT_GPU
21 class GrMeshDrawTarget;
22 #endif
23
24 namespace sktext::gpu {
25
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).
30 class GlyphVector {
31 public:
32     union Variant {
33         // Initially, filled with packed id, but changed to Glyph* in the onPrepare stage.
34         SkPackedGlyphID packedGlyphID;
35         Glyph* glyph;
36         // Add ctors to help SkArenaAlloc create arrays.
37         Variant() : glyph{nullptr} {}
38         Variant(SkPackedGlyphID id) : packedGlyphID{id} {}
39     };
40
41     GlyphVector(sk_sp<SkStrike>&& strike, SkSpan<Variant> glyphs);
42
43     static GlyphVector Make(
44             sk_sp<SkStrike>&& strike, SkSpan<SkGlyphVariant> glyphs, SubRunAllocator* alloc);
45     SkSpan<const Glyph*> glyphs() const;
46
47     static std::optional<GlyphVector> MakeFromBuffer(SkReadBuffer& buffer,
48                                                      const SkStrikeClient* strikeClient,
49                                                      SubRunAllocator* alloc);
50     void flatten(SkWriteBuffer& buffer);
51
52     // This doesn't need to include sizeof(GlyphVector) because this is embedded in each of
53     // the sub runs.
54     int unflattenSize() const { return GlyphVectorSize(fGlyphs.size()); }
55
56     void packedGlyphIDToGlyph(StrikeCache* cache);
57
58 #if SK_SUPPORT_GPU
59     std::tuple<bool, int> regenerateAtlas(
60             int begin, int end,
61             skgpu::MaskFormat maskFormat,
62             int srcPadding,
63             GrMeshDrawTarget*);
64 #endif
65
66     static size_t GlyphVectorSize(size_t count) {
67         return sizeof(Variant) * count;
68     }
69
70 private:
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;
77 };
78
79 }  // namespace sktext::gpu
80
81 #endif  // sktext_gpu_GlyphVector_DEFINED