Flutter Engine
The Flutter Engine
|
#include <DrawAtlas.h>
Public Types | |
enum class | AllowMultitexturing : bool { kNo , kYes } |
enum class | UseStorageTextures : bool { kNo , kYes } |
enum class | ErrorCode { kError , kSucceeded , kTryAgain } |
Public Member Functions | |
ErrorCode | addToAtlas (Recorder *, int width, int height, const void *image, AtlasLocator *) |
ErrorCode | addRect (Recorder *, int width, int height, AtlasLocator *) |
SkIPoint | prepForRender (const AtlasLocator &, SkAutoPixmapStorage *) |
bool | recordUploads (DrawContext *, Recorder *) |
const sk_sp< TextureProxy > * | getProxies () const |
uint32_t | atlasID () const |
uint64_t | atlasGeneration () const |
uint32_t | numActivePages () const |
unsigned int | numPlots () const |
SkISize | plotSize () const |
bool | hasID (const PlotLocator &plotLocator) |
void | setLastUseToken (const AtlasLocator &atlasLocator, AtlasToken token) |
void | setLastUseTokenBulk (const BulkUsePlotUpdater &updater, AtlasToken token) |
void | compact (AtlasToken startTokenForNextFlush) |
void | markUsedPlotsAsFull () |
void | evictAllPlots () |
uint32_t | maxPages () const |
int | numAllocated_TestingOnly () const |
void | setMaxPages_TestingOnly (uint32_t maxPages) |
Static Public Member Functions | |
static std::unique_ptr< DrawAtlas > | Make (SkColorType ct, size_t bpp, int width, int height, int plotWidth, int plotHeight, AtlasGenerationCounter *generationCounter, AllowMultitexturing allowMultitexturing, UseStorageTextures useStorageTextures, PlotEvictionCallback *evictor, std::string_view label) |
TODO: the process described here is tentative, and this comment revised once locked down.
This class manages one or more atlas textures on behalf of primitive draws in Device. The drawing processes that use the atlas add preceding UploadTasks when generating RenderPassTasks. The class provides facilities for using DrawTokens to detect data hazards. Plots that need uploads are tracked until it is impossible to add data without overwriting texels read by draws that have not yet been snapped to a RenderPassTask. 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, then the atlas will fail to add a subimage. This gives the Device the chance to end the current draw, snap a RenderpassTask, and begin a new one. Additional uploads will then succeed.
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 AtlasToken system: After a DrawPass is snapped a subarea of the page, or "plot" is checked to see whether it was used in that DrawPass. 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 DrawAtlas's client via the compact() method.
Definition at line 53 of file DrawAtlas.h.
|
strong |
Is the atlas allowed to use more than one texture?
Enumerator | |
---|---|
kNo | |
kYes |
Definition at line 56 of file DrawAtlas.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 list of draws. This indicates that the Device should end its current draw, snap a DrawPass, and begin another before adding more data. 'kError' will be returned when some unrecoverable error was encountered while trying to add the subimage. In this case the draw being created should be discarded.
This tracking does not generate UploadTasks per se. Instead, when the RenderPassTask is ready to be snapped, recordUploads() will be called by the Device and that will generate the necessary UploadTasks. If the useCachedUploads argument in recordUploads() is true, this will generate uploads for the entire area of each Plot that has changed since the last eviction. Otherwise it will only generate uploads for newly added changes.
NOTE: When a draw that reads from the atlas is added to the DrawList, the client using this DrawAtlas must immediately call 'setLastUseToken' with the currentToken from the Recorder, 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 107 of file DrawAtlas.h.
|
strong |
Should the atlas use storage textures?
Enumerator | |
---|---|
kNo | |
kYes |
Definition at line 59 of file DrawAtlas.h.
DrawAtlas::ErrorCode skgpu::graphite::DrawAtlas::addRect | ( | Recorder * | recorder, |
int | width, | ||
int | height, | ||
AtlasLocator * | atlasLocator | ||
) |
Definition at line 189 of file DrawAtlas.cpp.
DrawAtlas::ErrorCode skgpu::graphite::DrawAtlas::addToAtlas | ( | Recorder * | recorder, |
int | width, | ||
int | height, | ||
const void * | image, | ||
AtlasLocator * | atlasLocator | ||
) |
Definition at line 263 of file DrawAtlas.cpp.
|
inline |
Definition at line 123 of file DrawAtlas.h.
|
inline |
Definition at line 122 of file DrawAtlas.h.
void skgpu::graphite::DrawAtlas::compact | ( | AtlasToken | startTokenForNextFlush | ) |
Definition at line 280 of file DrawAtlas.cpp.
void skgpu::graphite::DrawAtlas::evictAllPlots | ( | ) |
Definition at line 522 of file DrawAtlas.cpp.
|
inline |
Definition at line 120 of file DrawAtlas.h.
|
inline |
Definition at line 128 of file DrawAtlas.h.
|
static |
Returns a DrawAtlas.
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. |
atlasGeneration | A pointer to the context's generation counter. |
allowMultitexturing | Can the atlas use more than one texture. |
useStorageTextures | Should the atlas use storage textures. |
evictor | A pointer to an eviction callback class. |
label | Label for texture resources. |
Definition at line 52 of file DrawAtlas.cpp.
void skgpu::graphite::DrawAtlas::markUsedPlotsAsFull | ( | ) |
Definition at line 511 of file DrawAtlas.cpp.
|
inline |
Definition at line 168 of file DrawAtlas.h.
|
inline |
Definition at line 124 of file DrawAtlas.h.
int skgpu::graphite::DrawAtlas::numAllocated_TestingOnly | ( | ) | const |
|
inline |
Definition at line 125 of file DrawAtlas.h.
|
inline |
Definition at line 126 of file DrawAtlas.h.
SkIPoint skgpu::graphite::DrawAtlas::prepForRender | ( | const AtlasLocator & | locator, |
SkAutoPixmapStorage * | pixmap | ||
) |
Definition at line 275 of file DrawAtlas.cpp.
bool skgpu::graphite::DrawAtlas::recordUploads | ( | DrawContext * | dc, |
Recorder * | recorder | ||
) |
Definition at line 148 of file DrawAtlas.cpp.
|
inline |
To ensure the atlas does not evict a given entry, the client must set the last use token.
Definition at line 141 of file DrawAtlas.h.
|
inline |
Definition at line 146 of file DrawAtlas.h.
void skgpu::graphite::DrawAtlas::setMaxPages_TestingOnly | ( | uint32_t | maxPages | ) |