Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
skgpu::graphite::TextAtlasManager Class Reference

#include <TextAtlasManager.h>

Inheritance diagram for skgpu::graphite::TextAtlasManager:
skgpu::AtlasGenerationCounter

Public Member Functions

 TextAtlasManager (Recorder *)
 
 ~TextAtlasManager ()
 
const sk_sp< TextureProxy > * getProxies (MaskFormat format, unsigned int *numActiveProxies)
 
void freeAll ()
 
bool hasGlyph (MaskFormat, sktext::gpu::Glyph *)
 
DrawAtlas::ErrorCode addGlyphToAtlas (const SkGlyph &, sktext::gpu::Glyph *, int srcPadding)
 
void addGlyphToBulkAndSetUseToken (BulkUsePlotUpdater *, MaskFormat, sktext::gpu::Glyph *, AtlasToken)
 
void setUseTokenBulk (const BulkUsePlotUpdater &updater, AtlasToken token, MaskFormat format)
 
bool recordUploads (DrawContext *dc)
 
void evictAtlases ()
 
void postFlush ()
 
uint64_t atlasGeneration (skgpu::MaskFormat format) const
 
void setAtlasDimensionsToMinimum_ForTesting ()
 
void setMaxPages_TestingOnly (uint32_t maxPages)
 
- Public Member Functions inherited from skgpu::AtlasGenerationCounter
uint64_t next ()
 

Additional Inherited Members

- Static Public Attributes inherited from skgpu::AtlasGenerationCounter
static constexpr uint64_t kInvalidGeneration = 0
 

Detailed Description

The TextAtlasManager manages the lifetime of and access to DrawAtlases used in glyph rendering.

Definition at line 29 of file TextAtlasManager.h.

Constructor & Destructor Documentation

◆ TextAtlasManager()

skgpu::graphite::TextAtlasManager::TextAtlasManager ( Recorder recorder)

Definition at line 28 of file TextAtlasManager.cpp.

29 : fRecorder(recorder)
30 , fSupportBilerpAtlas{recorder->priv().caps()->supportBilerpFromGlyphAtlas()}
31 , fAtlasConfig{recorder->priv().caps()->maxTextureSize(),
32 recorder->priv().caps()->glyphCacheTextureMaximumBytes()} {
33 if (!recorder->priv().caps()->allowMultipleAtlasTextures() ||
34 // multitexturing supported only if range can represent the index + texcoords fully
35 !(recorder->priv().caps()->shaderCaps()->fFloatIs32Bits ||
36 recorder->priv().caps()->shaderCaps()->fIntegerSupport)) {
37 fAllowMultitexturing = DrawAtlas::AllowMultitexturing::kNo;
38 } else {
39 fAllowMultitexturing = DrawAtlas::AllowMultitexturing::kYes;
40 }
41}
bool allowMultipleAtlasTextures() const
Definition: Caps.h:284
bool supportBilerpFromGlyphAtlas() const
Definition: Caps.h:285
size_t glyphCacheTextureMaximumBytes() const
Definition: Caps.h:281
const SkSL::ShaderCaps * shaderCaps() const
Definition: Caps.h:75
int maxTextureSize() const
Definition: Caps.h:141
const Caps * caps() const
Definition: RecorderPriv.h:31
bool fIntegerSupport
Definition: SkSLUtil.h:89
bool fFloatIs32Bits
Definition: SkSLUtil.h:100

◆ ~TextAtlasManager()

skgpu::graphite::TextAtlasManager::~TextAtlasManager ( )
default

Member Function Documentation

◆ addGlyphToAtlas()

DrawAtlas::ErrorCode skgpu::graphite::TextAtlasManager::addGlyphToAtlas ( const SkGlyph skGlyph,
sktext::gpu::Glyph glyph,
int  srcPadding 
)

Definition at line 176 of file TextAtlasManager.cpp.

178 {
179#if !defined(SK_DISABLE_SDF_TEXT)
180 SkASSERT(0 <= srcPadding && srcPadding <= SK_DistanceFieldInset);
181#else
182 SkASSERT(0 <= srcPadding);
183#endif
184
185 if (skGlyph.image() == nullptr) {
187 }
188 SkASSERT(glyph != nullptr);
189
190 MaskFormat glyphFormat = Glyph::FormatFromSkGlyph(skGlyph.maskFormat());
191 MaskFormat expectedMaskFormat = this->resolveMaskFormat(glyphFormat);
192 int bytesPerPixel = MaskFormatBytesPerPixel(expectedMaskFormat);
193
194 int padding;
195 switch (srcPadding) {
196 case 0:
197 // The direct mask/image case.
198 padding = 0;
199 if (fSupportBilerpAtlas) {
200 // Force direct masks (glyph with no padding) to have padding.
201 padding = 1;
202 srcPadding = 1;
203 }
204 break;
205 case 1:
206 // The transformed mask/image case.
207 padding = 1;
208 break;
209#if !defined(SK_DISABLE_SDF_TEXT)
211 // The SDFT case.
212 // If the srcPadding == SK_DistanceFieldInset (SDFT case) then the padding is built
213 // into the image on the glyph; no extra padding needed.
214 // TODO: can the SDFT glyph image in the cache be reduced by the padding?
215 padding = 0;
216 break;
217#endif
218 default:
219 // The padding is not one of the know forms.
221 }
222
223 const int width = skGlyph.width() + 2*padding;
224 const int height = skGlyph.height() + 2*padding;
225 int rowBytes = width * bytesPerPixel;
226 size_t size = height * rowBytes;
227
228 // Temporary storage for normalizing glyph image.
229 SkAutoSMalloc<1024> storage(size);
230 void* dataPtr = storage.get();
231 if (padding > 0) {
232 sk_bzero(dataPtr, size);
233 // Advance in one row and one column.
234 dataPtr = (char*)(dataPtr) + rowBytes + bytesPerPixel;
235 }
236
237 get_packed_glyph_image(skGlyph, rowBytes, expectedMaskFormat, dataPtr);
238
239 DrawAtlas* atlas = this->getAtlas(expectedMaskFormat);
240 auto errorCode = atlas->addToAtlas(fRecorder,
241 width,
242 height,
243 storage.get(),
244 &glyph->fAtlasLocator);
245
246 if (errorCode == DrawAtlas::ErrorCode::kSucceeded) {
247 glyph->fAtlasLocator.insetSrc(srcPadding);
248 }
249
250 return errorCode;
251}
sk_bzero(glyphs, sizeof(glyphs))
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SK_DistanceFieldInset
SkMask::Format maskFormat() const
Definition: SkGlyph.h:500
int height() const
Definition: SkGlyph.h:513
int width() const
Definition: SkGlyph.h:512
const void * image() const
Definition: SkGlyph.h:465
void insetSrc(int padding)
Definition: AtlasTypes.h:327
skgpu::AtlasLocator fAtlasLocator
Definition: Glyph.h:40
static skgpu::MaskFormat FormatFromSkGlyph(SkMask::Format format)
Definition: Glyph.h:19
sk_sp< const SkImage > atlas
Definition: SkRecords.h:331
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
static void get_packed_glyph_image(const SkGlyph &glyph, int dstRB, MaskFormat expectedMaskFormat, void *dst)
constexpr int MaskFormatBytesPerPixel(MaskFormat format)
Definition: AtlasTypes.h:110
MaskFormat
Definition: AtlasTypes.h:98
skgpu::graphite::DrawAtlas DrawAtlas
int32_t height
int32_t width

◆ addGlyphToBulkAndSetUseToken()

void skgpu::graphite::TextAtlasManager::addGlyphToBulkAndSetUseToken ( BulkUsePlotUpdater updater,
MaskFormat  format,
sktext::gpu::Glyph glyph,
AtlasToken  token 
)

Definition at line 263 of file TextAtlasManager.cpp.

266 {
267 SkASSERT(glyph);
268 if (updater->add(glyph->fAtlasLocator)) {
269 this->getAtlas(format)->setLastUseToken(glyph->fAtlasLocator, token);
270 }
271}
void setLastUseToken(const AtlasLocator &atlasLocator, AtlasToken token)
Definition: DrawAtlas.h:141
uint32_t uint32_t * format

◆ atlasGeneration()

uint64_t skgpu::graphite::TextAtlasManager::atlasGeneration ( skgpu::MaskFormat  format) const
inline

Definition at line 85 of file TextAtlasManager.h.

85 {
86 return this->getAtlas(format)->atlasGeneration();
87 }
uint64_t atlasGeneration() const
Definition: DrawAtlas.h:123

◆ evictAtlases()

void skgpu::graphite::TextAtlasManager::evictAtlases ( )
inline

Definition at line 72 of file TextAtlasManager.h.

72 {
73 for (int i = 0; i < kMaskFormatCount; ++i) {
74 if (fAtlases[i]) {
75 fAtlases[i]->evictAllPlots();
76 }
77 }
78 }
static const int kMaskFormatCount
Definition: AtlasTypes.h:105

◆ freeAll()

void skgpu::graphite::TextAtlasManager::freeAll ( )

Definition at line 45 of file TextAtlasManager.cpp.

45 {
46 for (int i = 0; i < kMaskFormatCount; ++i) {
47 fAtlases[i] = nullptr;
48 }
49}

◆ getProxies()

const sk_sp< TextureProxy > * skgpu::graphite::TextAtlasManager::getProxies ( MaskFormat  format,
unsigned int numActiveProxies 
)
inline

Definition at line 37 of file TextAtlasManager.h.

38 {
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 }
uint32_t numActivePages() const
Definition: DrawAtlas.h:124
const sk_sp< TextureProxy > * getProxies() const
Definition: DrawAtlas.h:120

◆ hasGlyph()

bool skgpu::graphite::TextAtlasManager::hasGlyph ( MaskFormat  format,
sktext::gpu::Glyph glyph 
)

Definition at line 51 of file TextAtlasManager.cpp.

51 {
52 SkASSERT(glyph);
53 return this->getAtlas(format)->hasID(glyph->fAtlasLocator.plotLocator());
54}
PlotLocator plotLocator() const
Definition: AtlasTypes.h:301
bool hasID(const PlotLocator &plotLocator)
Definition: DrawAtlas.h:128

◆ postFlush()

void skgpu::graphite::TextAtlasManager::postFlush ( )

Definition at line 306 of file TextAtlasManager.cpp.

306 {
307 auto tokenTracker = fRecorder->priv().tokenTracker();
308 for (int i = 0; i < kMaskFormatCount; ++i) {
309 if (fAtlases[i]) {
310 fAtlases[i]->compact(tokenTracker->nextFlushToken());
311 }
312 }
313}
TokenTracker * tokenTracker()
Definition: RecorderPriv.h:62

◆ recordUploads()

bool skgpu::graphite::TextAtlasManager::recordUploads ( DrawContext dc)

Definition at line 253 of file TextAtlasManager.cpp.

253 {
254 for (int i = 0; i < skgpu::kMaskFormatCount; i++) {
255 if (fAtlases[i] && !fAtlases[i]->recordUploads(dc, fRecorder)) {
256 return false;
257 }
258 }
259
260 return true;
261}

◆ setAtlasDimensionsToMinimum_ForTesting()

void skgpu::graphite::TextAtlasManager::setAtlasDimensionsToMinimum_ForTesting ( )

Definition at line 273 of file TextAtlasManager.cpp.

273 {
274 // Delete any old atlases.
275 // This should be safe to do as long as we are not in the middle of a flush.
276 for (int i = 0; i < skgpu::kMaskFormatCount; i++) {
277 fAtlases[i] = nullptr;
278 }
279
280 // Set all the atlas sizes to 1x1 plot each.
281 new (&fAtlasConfig) DrawAtlasConfig{2048, 0};
282}

◆ setMaxPages_TestingOnly()

void skgpu::graphite::TextAtlasManager::setMaxPages_TestingOnly ( uint32_t  maxPages)

◆ setUseTokenBulk()

void skgpu::graphite::TextAtlasManager::setUseTokenBulk ( const BulkUsePlotUpdater updater,
AtlasToken  token,
MaskFormat  format 
)
inline

Definition at line 64 of file TextAtlasManager.h.

66 {
67 this->getAtlas(format)->setLastUseTokenBulk(updater, token);
68 }
void setLastUseTokenBulk(const BulkUsePlotUpdater &updater, AtlasToken token)
Definition: DrawAtlas.h:146

The documentation for this class was generated from the following files: