Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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:277
bool supportBilerpFromGlyphAtlas() const
Definition Caps.h:278
size_t glyphCacheTextureMaximumBytes() const
Definition Caps.h:274
const SkSL::ShaderCaps * shaderCaps() const
Definition Caps.h:74
int maxTextureSize() const
Definition Caps.h:134
const Caps * caps() const
bool fIntegerSupport
Definition SkSLUtil.h:89

◆ ~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 166 of file TextAtlasManager.cpp.

168 {
169#if !defined(SK_DISABLE_SDF_TEXT)
170 SkASSERT(0 <= srcPadding && srcPadding <= SK_DistanceFieldInset);
171#else
172 SkASSERT(0 <= srcPadding);
173#endif
174
175 if (skGlyph.image() == nullptr) {
177 }
178 SkASSERT(glyph != nullptr);
179
180 MaskFormat glyphFormat = Glyph::FormatFromSkGlyph(skGlyph.maskFormat());
181 MaskFormat expectedMaskFormat = this->resolveMaskFormat(glyphFormat);
182 int bytesPerPixel = MaskFormatBytesPerPixel(expectedMaskFormat);
183
184 int padding;
185 switch (srcPadding) {
186 case 0:
187 // The direct mask/image case.
188 padding = 0;
189 if (fSupportBilerpAtlas) {
190 // Force direct masks (glyph with no padding) to have padding.
191 padding = 1;
192 srcPadding = 1;
193 }
194 break;
195 case 1:
196 // The transformed mask/image case.
197 padding = 1;
198 break;
199#if !defined(SK_DISABLE_SDF_TEXT)
201 // The SDFT case.
202 // If the srcPadding == SK_DistanceFieldInset (SDFT case) then the padding is built
203 // into the image on the glyph; no extra padding needed.
204 // TODO: can the SDFT glyph image in the cache be reduced by the padding?
205 padding = 0;
206 break;
207#endif
208 default:
209 // The padding is not one of the know forms.
211 }
212
213 const int width = skGlyph.width() + 2*padding;
214 const int height = skGlyph.height() + 2*padding;
215 int rowBytes = width * bytesPerPixel;
216 size_t size = height * rowBytes;
217
218 // Temporary storage for normalizing glyph image.
219 SkAutoSMalloc<1024> storage(size);
220 void* dataPtr = storage.get();
221 if (padding > 0) {
222 sk_bzero(dataPtr, size);
223 // Advance in one row and one column.
224 dataPtr = (char*)(dataPtr) + rowBytes + bytesPerPixel;
225 }
226
227 get_packed_glyph_image(skGlyph, rowBytes, expectedMaskFormat, dataPtr);
228
229 DrawAtlas* atlas = this->getAtlas(expectedMaskFormat);
230 auto errorCode = atlas->addToAtlas(fRecorder,
231 width,
232 height,
233 storage.get(),
234 &glyph->fAtlasLocator);
235
236 if (errorCode == DrawAtlas::ErrorCode::kSucceeded) {
237 glyph->fAtlasLocator.insetSrc(srcPadding);
238 }
239
240 return errorCode;
241}
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SK_DistanceFieldInset
static void sk_bzero(void *buffer, size_t size)
Definition SkMalloc.h:105
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
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 253 of file TextAtlasManager.cpp.

256 {
257 SkASSERT(glyph);
258 if (updater->add(glyph->fAtlasLocator)) {
259 this->getAtlas(format)->setLastUseToken(glyph->fAtlasLocator, token);
260 }
261}
void setLastUseToken(const AtlasLocator &atlasLocator, AtlasToken token)
Definition DrawAtlas.h:135
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:117

◆ 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:118
const sk_sp< TextureProxy > * getProxies() const
Definition DrawAtlas.h:114

◆ 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:122

◆ postFlush()

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

Definition at line 295 of file TextAtlasManager.cpp.

295 {
296 auto tokenTracker = fRecorder->priv().tokenTracker();
297 for (int i = 0; i < kMaskFormatCount; ++i) {
298 if (fAtlases[i]) {
299 fAtlases[i]->compact(tokenTracker->nextFlushToken());
300 }
301 }
302}
TokenTracker * tokenTracker()

◆ recordUploads()

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

Definition at line 243 of file TextAtlasManager.cpp.

243 {
244 for (int i = 0; i < skgpu::kMaskFormatCount; i++) {
245 if (fAtlases[i] && !fAtlases[i]->recordUploads(dc, fRecorder)) {
246 return false;
247 }
248 }
249
250 return true;
251}

◆ setAtlasDimensionsToMinimum_ForTesting()

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

Definition at line 263 of file TextAtlasManager.cpp.

263 {
264 // Delete any old atlases.
265 // This should be safe to do as long as we are not in the middle of a flush.
266 for (int i = 0; i < skgpu::kMaskFormatCount; i++) {
267 fAtlases[i] = nullptr;
268 }
269
270 // Set all the atlas sizes to 1x1 plot each.
271 new (&fAtlasConfig) DrawAtlasConfig{2048, 0};
272}

◆ 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:140

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