Flutter Engine
The Flutter Engine
|
#include <GrDrawOpAtlas.h>
Public Types | |
enum class | AllowMultitexturing : bool { kNo , kYes } |
enum class | ErrorCode { kError , kSucceeded , kTryAgain } |
Public Member Functions | |
ErrorCode | addToAtlas (GrResourceProvider *, GrDeferredUploadTarget *, int width, int height, const void *image, skgpu::AtlasLocator *) |
const GrSurfaceProxyView * | getViews () const |
uint64_t | atlasGeneration () const |
bool | hasID (const skgpu::PlotLocator &plotLocator) |
void | setLastUseToken (const skgpu::AtlasLocator &atlasLocator, skgpu::AtlasToken token) |
uint32_t | numActivePages () |
void | setLastUseTokenBulk (const skgpu::BulkUsePlotUpdater &updater, skgpu::AtlasToken token) |
void | compact (skgpu::AtlasToken startTokenForNextFlush) |
void | instantiate (GrOnFlushResourceProvider *) |
uint32_t | maxPages () const |
Static Public Member Functions | |
static std::unique_ptr< GrDrawOpAtlas > | Make (GrProxyProvider *proxyProvider, const GrBackendFormat &format, SkColorType ct, size_t bpp, int width, int height, int plotWidth, int plotHeight, skgpu::AtlasGenerationCounter *generationCounter, AllowMultitexturing allowMultitexturing, skgpu::PlotEvictionCallback *evictor, std::string_view label) |
Friends | |
class | GrDrawOpAtlasTools |
This class manages one or more atlas textures on behalf of GrDrawOps. The draw ops that use the atlas perform texture uploads when preparing their draws during flush. The class provides facilities for using GrDrawOpUploadToken to detect data hazards. Op's uploads are performed in "ASAP" mode until it is impossible to add data without overwriting texels read by draws that have not yet executed on the gpu. At that point, the atlas will attempt to allocate a new atlas texture (or "page") of the same size, up to a maximum number of textures, and upload to that texture. If that's not possible, the uploads are performed "inline" between draws. If a single draw would use enough subimage space to overflow the atlas texture then the atlas will fail to add a subimage. This gives the op the chance to end the draw and begin a new one. Additional uploads will then succeed in inline mode.
When the atlas has multiple pages, new uploads are prioritized to the lower index pages, i.e., it will try to upload to page 0 before page 1 or 2. To keep the atlas from continually using excess space, periodic garbage collection is needed to shift data from the higher index pages to the lower ones, and then eventually remove any pages that are no longer in use. "In use" is determined by using the GrDrawUploadToken system: After a flush each subarea of the page is checked to see whether it was used in that flush. If less than a quarter of the plots have been used recently (within kPlotRecentlyUsedCount iterations) and there are available plots in lower index pages, the higher index page will be deactivated, and its glyphs will gradually migrate to other pages via the usual upload system.
Garbage collection is initiated by the GrDrawOpAtlas's client via the compact() method. One solution is to make the client a subclass of GrOnFlushCallbackObject, register it with the GrContext via addOnFlushCallbackObject(), and the client's postFlush() method calls compact() and passes in the given GrDrawUploadToken.
Definition at line 53 of file GrDrawOpAtlas.h.
|
strong |
Is the atlas allowed to use more than one texture?
Enumerator | |
---|---|
kNo | |
kYes |
Definition at line 56 of file GrDrawOpAtlas.h.
|
strong |
Adds a width x height subimage to the atlas. Upon success it returns 'kSucceeded' and returns the ID and the subimage's coordinates in the backing texture. 'kTryAgain' is returned if the subimage cannot fit in the atlas without overwriting texels that will be read in the current draw. This indicates that the op should end its current draw and begin another before adding more data. Upon success, an upload of the provided image data will have been added to the GrDrawOp::Target, in "asap" mode if possible, otherwise in "inline" mode. Successive uploads in either mode may be consolidated. 'kError' will be returned when some unrecoverable error was encountered while trying to add the subimage. In this case the op being created should be discarded.
NOTE: When the GrDrawOp prepares a draw that reads from the atlas, it must immediately call 'setLastUseToken' with the currentToken from the GrDrawOp::Target, otherwise the next call to addToAtlas might cause the previous data to be overwritten before it has been read.
Enumerator | |
---|---|
kError | |
kSucceeded | |
kTryAgain |
Definition at line 103 of file GrDrawOpAtlas.h.
GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas | ( | GrResourceProvider * | resourceProvider, |
GrDeferredUploadTarget * | target, | ||
int | width, | ||
int | height, | ||
const void * | image, | ||
skgpu::AtlasLocator * | atlasLocator | ||
) |
Definition at line 209 of file GrDrawOpAtlas.cpp.
|
inline |
Definition at line 114 of file GrDrawOpAtlas.h.
void GrDrawOpAtlas::compact | ( | skgpu::AtlasToken | startTokenForNextFlush | ) |
Definition at line 318 of file GrDrawOpAtlas.cpp.
|
inline |
Definition at line 112 of file GrDrawOpAtlas.h.
|
inline |
Definition at line 116 of file GrDrawOpAtlas.h.
void GrDrawOpAtlas::instantiate | ( | GrOnFlushResourceProvider * | onFlushResourceProvider | ) |
Definition at line 63 of file GrDrawOpAtlas.cpp.
|
static |
Returns a GrDrawOpAtlas. This function can be called anywhere, but the returned atlas should only be used inside of GrMeshDrawOp::onPrepareDraws.
proxyProvider | Used to create the atlas's texture proxies. |
format | Backend format for the atlas's textures. Should be compatible with ct. |
ct | The colorType which this atlas will store. |
bpp | Size in bytes of each pixel. |
width | Width in pixels of the atlas. |
height | Height in pixels of the atlas. |
plotWidth | The width of each plot. width/plotWidth should be an integer. |
plotWidth | The height of each plot. height/plotHeight should be an integer. |
generationCounter | A pointer to the context's generation counter. |
allowMultitexturing | Can the atlas use more than one texture. |
evictor | A pointer to an eviction callback class. |
label | A label for the atlas texture. |
Definition at line 70 of file GrDrawOpAtlas.cpp.
|
inline |
Definition at line 161 of file GrDrawOpAtlas.h.
|
inline |
Definition at line 140 of file GrDrawOpAtlas.h.
|
inline |
To ensure the atlas does not evict a given entry, the client must set the last use token.
Definition at line 129 of file GrDrawOpAtlas.h.
|
inline |
Definition at line 142 of file GrDrawOpAtlas.h.
|
friend |
Definition at line 166 of file GrDrawOpAtlas.h.