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
Modifier and TypeClassDescriptionstatic class
Keep track of generation number for atlases and Plots.static class
AtlasLocator handles atlas position information.static class
AtlasToken is used to sequence uploads relative to each other and to batches of draws.static class
The TokenTracker encapsulates the incrementing and distribution of AtlasTokens.static class
The backing texture for an atlas is broken into a spatial grid of Plots.static class
A class which can be handed back to an atlas for updating plots in bulk.static interface
An interface for eviction callbacks.static class
Used to locate a plot in aDrawAtlas
. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
-
Constructor Summary
ConstructorDescriptionDrawAtlas
(int ct, int width, int height, int plotWidth, int plotHeight, DrawAtlas.AtlasGenerationCounter generationCounter, boolean useMultiPages, boolean useStorageTextures, String label) -
Method Summary
Modifier and TypeMethodDescriptionint
addRect
(RecordingContext context, int width, int height, DrawAtlas.AtlasLocator atlasLocator) Adds a width x height sub-image to the atlas.int
addToAtlas
(RecordingContext context, int width, int height, Object imageBase, long imageAddr, DrawAtlas.AtlasLocator atlasLocator) This is a combination ofaddRect(RecordingContext, int, int, AtlasLocator)
, and copy the existing data togetDataAt(AtlasLocator)
if success.void
close()
void
compact
(long startTokenForNextFlush) boolean
contains
(DrawAtlas.PlotLocator plotLocator) void
long
long
getDataAt
(DrawAtlas.AtlasLocator atlasLocator) Returns the pointer to the plot data at the given position.int
int
int
int
int
getTexture
(int pageIndex) static DrawAtlas
make
(int ct, int width, int height, int plotWidth, int plotHeight, DrawAtlas.AtlasGenerationCounter generationCounter, boolean useMultiPages, boolean useStorageTextures, DrawAtlas.PlotEvictionCallback evictor, String label) Creates a DrawAtlas.void
purge
(long startTokenForNextFlush) boolean
recordUploads
(RecordingContext context, SurfaceDrawContext sdc) void
setLastUseToken
(DrawAtlas.AtlasLocator atlasLocator, long token) void
setLastUseTokenBulk
(DrawAtlas.PlotBulkUseUpdater updater, long token)
-
Field Details
-
RESULT_SUCCESS
public static final int RESULT_SUCCESS- See Also:
-
RESULT_FAILURE
public static final int RESULT_FAILURE- See Also:
-
RESULT_TRY_AGAIN
public static final int RESULT_TRY_AGAIN- 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
@Nonnull public static 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:
close
in 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 returnsRESULT_SUCCESS
and returns the plot location and the sub-image's coordinates in the backing texture.RESULT_TRY_AGAIN
is 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 theGraniteDevice
should end its current draw, snap aDrawPass
, and begin another before adding more data.RESULT_FAILURE
will 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
UploadTasks
per se. Instead, when theRenderPassTask
is ready to be snapped,recordUploads(icyllis.arc3d.engine.RecordingContext, icyllis.arc3d.granite.SurfaceDrawContext)
will be called by theGraniteDevice
and 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()
-