Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
TextAtlasManager.h
Go to the documentation of 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 skgpu_graphite_TextAtlasManager_DEFINED
9#define skgpu_graphite_TextAtlasManager_DEFINED
10
12#include "src/gpu/AtlasTypes.h"
15
16namespace sktext::gpu {
17class Glyph;
18}
19class SkGlyph;
20
21namespace skgpu::graphite {
22
23class Recorder;
24class UploadList;
25
26//////////////////////////////////////////////////////////////////////////////////////////////////
27/** The TextAtlasManager manages the lifetime of and access to DrawAtlases used in glyph rendering.
28 */
30public:
33
34 // If getProxies returns nullptr, the client must not try to use other functions on the
35 // StrikeCache which use the atlas. This function *must* be called first, before other
36 // functions which use the atlas.
38 unsigned int* numActiveProxies) {
39 format = this->resolveMaskFormat(format);
40 if (this->initAtlas(format)) {
41 *numActiveProxies = this->getAtlas(format)->numActivePages();
42 return this->getAtlas(format)->getProxies();
43 }
44 *numActiveProxies = 0;
45 return nullptr;
46 }
47
48 void freeAll();
49
51
54 int srcPadding);
55
56 // To ensure the DrawAtlas does not evict the Glyph Mask from its texture backing store,
57 // the client must pass in the current draw token along with the sktext::gpu::Glyph.
58 // A BulkUsePlotUpdater is used to manage bulk last use token updating in the Atlas.
59 // For convenience, this function will also set the use token for the current glyph if required
60 // NOTE: the bulk uploader is only valid if the subrun has a valid atlasGeneration
63
65 AtlasToken token,
67 this->getAtlas(format)->setLastUseTokenBulk(updater, token);
68 }
69
70 bool recordUploads(DrawContext* dc);
71
72 void evictAtlases() {
73 for (int i = 0; i < kMaskFormatCount; ++i) {
74 if (fAtlases[i]) {
75 fAtlases[i]->evictAllPlots();
76 }
77 }
78 }
79
80 void postFlush();
81
82 // Some clients may wish to verify the integrity of the texture backing store of the
83 // GrDrawOpAtlas. The atlasGeneration returned below is a monotonically increasing number which
84 // changes every time something is removed from the texture backing store.
86 return this->getAtlas(format)->atlasGeneration();
87 }
88
89 ///////////////////////////////////////////////////////////////////////////
90 // Functions intended debug only
91
93 void setMaxPages_TestingOnly(uint32_t maxPages);
94
95private:
96 bool initAtlas(MaskFormat);
97 // Change an expected 565 mask format to 8888 if 565 is not supported (will happen when using
98 // Metal on Intel MacOS). The actual conversion of the data is handled in
99 // get_packed_glyph_image() in StrikeCache.cpp
100 MaskFormat resolveMaskFormat(MaskFormat format) const;
101
102 // There is a 1:1 mapping between skgpu::MaskFormats and atlas indices
103 static int MaskFormatToAtlasIndex(skgpu::MaskFormat format) {
104 return static_cast<int>(format);
105 }
106 static skgpu::MaskFormat AtlasIndexToMaskFormat(int idx) {
107 return static_cast<skgpu::MaskFormat>(idx);
108 }
109
110 DrawAtlas* getAtlas(skgpu::MaskFormat format) const {
111 format = this->resolveMaskFormat(format);
112 int atlasIndex = MaskFormatToAtlasIndex(format);
113 SkASSERT(fAtlases[atlasIndex]);
114 return fAtlases[atlasIndex].get();
115 }
116
117 Recorder* fRecorder;
118 DrawAtlas::AllowMultitexturing fAllowMultitexturing;
119 std::unique_ptr<DrawAtlas> fAtlases[kMaskFormatCount];
120 static_assert(kMaskFormatCount == 3);
121 bool fSupportBilerpAtlas;
122 DrawAtlasConfig fAtlasConfig;
123};
124
125} // namespace skgpu::graphite
126
127#endif // skgpu_graphite_TextAtlasManager_DEFINED
#define SkASSERT(cond)
Definition SkAssert.h:116
uint32_t numActivePages() const
Definition DrawAtlas.h:118
uint64_t atlasGeneration() const
Definition DrawAtlas.h:117
void setLastUseTokenBulk(const BulkUsePlotUpdater &updater, AtlasToken token)
Definition DrawAtlas.h:140
const sk_sp< TextureProxy > * getProxies() const
Definition DrawAtlas.h:114
const sk_sp< TextureProxy > * getProxies(MaskFormat format, unsigned int *numActiveProxies)
uint64_t atlasGeneration(skgpu::MaskFormat format) const
void setMaxPages_TestingOnly(uint32_t maxPages)
DrawAtlas::ErrorCode addGlyphToAtlas(const SkGlyph &, sktext::gpu::Glyph *, int srcPadding)
void setUseTokenBulk(const BulkUsePlotUpdater &updater, AtlasToken token, MaskFormat format)
void addGlyphToBulkAndSetUseToken(BulkUsePlotUpdater *, MaskFormat, sktext::gpu::Glyph *, AtlasToken)
bool hasGlyph(MaskFormat, sktext::gpu::Glyph *)
uint32_t uint32_t * format
static const int kMaskFormatCount
Definition AtlasTypes.h:105