Class DrawAtlas
- All Implemented Interfaces:
AutoCloseable
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classKeep track of generation number for atlases and Plots.static classAtlasLocator handles atlas position information.static classAtlasToken is used to sequence uploads relative to each other and to batches of draws.static classThe TokenTracker encapsulates the incrementing and distribution of AtlasTokens.static classThe backing texture for an atlas is broken into a spatial grid of Plots.static classA class which can be handed back to an atlas for updating plots in bulk.static interfaceAn interface for eviction callbacks.static classUsed to locate a plot in aDrawAtlas. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionDrawAtlas(int ct, int width, int height, int plotWidth, int plotHeight, @NonNull DrawAtlas.AtlasGenerationCounter generationCounter, boolean useMultiPages, boolean useStorageTextures, String label) -
Method Summary
Modifier and TypeMethodDescriptionintaddRect(@NonNull RecordingContext context, int width, int height, @NonNull DrawAtlas.AtlasLocator atlasLocator) Adds a width x height sub-image to the atlas.intaddToAtlas(@NonNull RecordingContext context, int width, int height, Object imageBase, long imageAddr, @NonNull DrawAtlas.AtlasLocator atlasLocator) This is a combination ofaddRect(RecordingContext, int, int, AtlasLocator), and copy the existing data togetDataAt(AtlasLocator)if success.voidclose()voidcompact(long startTokenForNextFlush) booleancontains(@NonNull DrawAtlas.PlotLocator plotLocator) voidlonglonggetDataAt(@NonNull DrawAtlas.AtlasLocator atlasLocator) Returns the pointer to the plot data at the given position.intintintintintgetTexture(int pageIndex) static @NonNull DrawAtlasmake(int ct, int width, int height, int plotWidth, int plotHeight, @NonNull DrawAtlas.AtlasGenerationCounter generationCounter, boolean useMultiPages, boolean useStorageTextures, DrawAtlas.PlotEvictionCallback evictor, String label) Creates a DrawAtlas.voidpurge(long startTokenForNextFlush) booleanrecordUploads(RecordingContext context, SurfaceDrawContext sdc) voidsetLastUseToken(@NonNull DrawAtlas.AtlasLocator atlasLocator, long token) voidsetLastUseTokenBulk(@NonNull DrawAtlas.PlotBulkUseUpdater updater, long token)
-
Field Details
-
kSuccess_Result
public static final int kSuccess_Result- See Also:
-
kFailure_Result
public static final int kFailure_Result- See Also:
-
kTryAgain_Result
public static final int kTryAgain_Result- See Also:
-
-
Constructor Details
-
DrawAtlas
public DrawAtlas(int ct, int width, int height, int plotWidth, int plotHeight, @NonNull DrawAtlas.AtlasGenerationCounter generationCounter, boolean useMultiPages, boolean useStorageTextures, String label)
-
-
Method Details
-
make
public static @NonNull DrawAtlas make(int ct, int width, int height, int plotWidth, int plotHeight, @NonNull DrawAtlas.AtlasGenerationCounter generationCounter, boolean useMultiPages, boolean useStorageTextures, DrawAtlas.PlotEvictionCallback evictor, String label) Creates a DrawAtlas.- Parameters:
ct- The colorType which this atlas will store.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.plotHeight- The height of each plot. height/plotHeight should be an integer.generationCounter- A pointer to the context's generation counter.useMultiPages- 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.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
addRect
public int addRect(@NonNull RecordingContext context, int width, int height, @NonNull DrawAtlas.AtlasLocator atlasLocator) Adds a width x height sub-image to the atlas. Upon success, it returnskSuccess_Resultand returns the plot location and the sub-image's coordinates in the backing texture.kTryAgain_Resultis returned if the sub-image cannot fit in the atlas without overwriting texels that will be read in the current list of draws. This indicates that theGraniteDeviceshould end its current draw, snap aDrawPass, and begin another before adding more data.kFailure_Resultwill be returned when some unrecoverable error was encountered while trying to add the sub-image. In this case the draw being created should be discarded.This tracking does not generate
UploadTasksper se. Instead, when theRenderPassTaskis ready to be snapped,recordUploads(icyllis.arc3d.granite.RecordingContext, icyllis.arc3d.granite.SurfaceDrawContext)will be called by theGraniteDeviceand that will generate the necessaryUploadTasks.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.
-
getDataAt
Returns the pointer to the plot data at the given position. The row bytes of the dst is bpp * plotWidth in the constructor. This must be called and can only be called once afteraddRect(RecordingContext, int, int, AtlasLocator)to update the data. -
addToAtlas
public int addToAtlas(@NonNull RecordingContext context, int width, int height, Object imageBase, long imageAddr, @NonNull DrawAtlas.AtlasLocator atlasLocator) This is a combination ofaddRect(RecordingContext, int, int, AtlasLocator), and copy the existing data togetDataAt(AtlasLocator)if success. -
recordUploads
-
getTexture
-
getAtlasGeneration
public long getAtlasGeneration() -
getNumActivePages
public int getNumActivePages() -
getNumPlots
public int getNumPlots() -
getMaxPages
public int getMaxPages() -
getPlotWidth
public int getPlotWidth() -
getPlotHeight
public int getPlotHeight() -
contains
-
setLastUseToken
-
setLastUseTokenBulk
-
compact
public void compact(long startTokenForNextFlush) -
purge
public void purge(long startTokenForNextFlush) -
evictAllPlots
public void evictAllPlots()
-