Package icyllis.arc3d.engine

# Class Context

java.lang.Object
icyllis.arc3d.core.RefCnt
icyllis.arc3d.engine.Context

All Implemented Interfaces:
  `RefCounted`

Direct Known Subclasses:
  `ImmediateContext`, `RecordingContext`

public abstract sealed class Context extends RefCnt permits ImmediateContext, RecordingContext
This class is a public API, except where noted.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final Device`
  `mDevice`
  `protected final Thread`
  `mOwnerThread`
  `protected ResourceProvider`
  `mResourceProvider`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Context(Device device)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final void`
  `checkOwnerThread()`
  Checks if calling from the context-creating thread, or throws a runtime exception.
  `protected void`
  `deallocate()`
  Override this method to invoke de-allocation of the underlying resource.
  `abstract void`
  `freeGpuResources()`
  Frees GPU resources created and held by the Context.
  `final int`
  `getBackend()`
  The 3D API backing this context.
  `final Caps`
  `getCaps()`
  `final BackendFormat`
  `getCompressedBackendFormat(int compressionType)`
  Retrieve the `BackendFormat` for a given `CompressionType`.
  `final int`
  `getContextID()`
  An identifier for this context.
  `long`
  `getCurrentBudgetedBytes()`
  Returns the number of bytes of the Context's gpu memory cache budget that are currently in use.
  `long`
  `getCurrentPurgeableBytes()`
  Returns the number of bytes of the Context's resource cache that are currently purgeable.
  `final BackendFormat`
  `getDefaultBackendFormat(int colorType, boolean renderable)`
  Retrieve the default `BackendFormat` for a given `ColorType` and renderability.
  `final Device`
  `getDevice()`
  `final org.slf4j.Logger`
  `getLogger()`
  `long`
  `getMaxBudgetedBytes()`
  Returns the size of Context's gpu memory cache budget in bytes.
  `final int`
  `getMaxRenderTargetSize()`
  Gets the maximum supported render target size.
  `final int`
  `getMaxSurfaceSampleCount(int colorType)`
  Gets the maximum supported sample count for a color type.
  `final int`
  `getMaxTextureSize()`
  Gets the maximum supported texture size.
  `final ContextOptions`
  `getOptions()`
  `final Thread`
  `getOwnerThread()`
  `final RendererProvider`
  `getRendererProvider()`
  `final ResourceProvider`
  `getResourceProvider()`
  `final SharedResourceCache`
  `getSharedResourceCache()`
  `protected boolean`
  `init(BaseContextOptions options)`
  `boolean`
  `isDeviceLost()`
  `final boolean`
  `isImmediate()`
  `final boolean`
  `isOwnerThread()`
  `final boolean`
  `matches(Context c)`
  `abstract void`
  `performDeferredCleanup(long msNotUsed)`
  Purge GPU resources on the Context that haven't been used in the past 'msNotUsed' milliseconds or are otherwise marked for deletion, regardless of whether the context is under budget.

  ### Methods inherited from class icyllis.arc3d.core.RefCnt

  `create, create, getRefCnt, getRefCntAcquire, getRefCntVolatile, move, move, ref, unique, unref`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### mDevice

    protected final Device mDevice

  - ### mOwnerThread

    protected final Thread mOwnerThread

  - ### mResourceProvider

    protected ResourceProvider mResourceProvider

- ## Constructor Details

  - ### Context

    protected Context(Device device)

- ## Method Details

  - ### getBackend

    public final int getBackend()
    The 3D API backing this context.
    Returns:
      see `Engine.BackendApi`

  - ### getDefaultBackendFormat

    @Nullable public final BackendFormat getDefaultBackendFormat(int colorType, boolean renderable)
    Retrieve the default `BackendFormat` for a given `ColorType` and renderability. It is guaranteed that this backend format will be the one used by the following `ColorType` and `SurfaceCharacterization.createBackendFormat(int, BackendFormat)`.

    The caller should check that the returned format is valid (nullability).

    Parameters:
      `colorType` - see `ImageDesc`
      `renderable` - true if the format will be used as color attachments

  - ### getCompressedBackendFormat

    @Nullable public final BackendFormat getCompressedBackendFormat(int compressionType)
    Retrieve the `BackendFormat` for a given `CompressionType`. This is guaranteed to match the backend format used by the following createCompressedBackendTexture methods that take a `CompressionType`.

    The caller should check that the returned format is valid (nullability).

    Parameters:
      `compressionType` - see `ImageDesc`

  - ### getMaxSurfaceSampleCount

    public final int getMaxSurfaceSampleCount(int colorType)
    Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA rendering is supported for the color type. 0 is returned if rendering to this color type is not supported at all.
    Parameters:
      `colorType` - see `ImageDesc`

  - ### isImmediate

    public final boolean isImmediate()

  - ### getDevice

    @Internal public final Device getDevice()

  - ### matches

    @Internal public final boolean matches(Context c)

  - ### getOptions

    @Internal public final ContextOptions getOptions()

  - ### getContextID

    @Internal public final int getContextID()
    An identifier for this context. The id is used by all compatible contexts. For example, if Images are created on one thread using an image creation context, then fed into a Recorder on second thread (which has a recording context) and finally replayed on a third thread with a direct context, then all three contexts will report the same id. It is an error for an image to be used with contexts that report different ids.

  - ### isDeviceLost

    public boolean isDeviceLost()

  - ### getCaps

    @Internal public final Caps getCaps()

  - ### getResourceProvider

    @Internal public final ResourceProvider getResourceProvider()

  - ### getMaxTextureSize

    public final int getMaxTextureSize()
    Gets the maximum supported texture size.

  - ### getMaxRenderTargetSize

    public final int getMaxRenderTargetSize()
    Gets the maximum supported render target size.

  - ### freeGpuResources

    public abstract void freeGpuResources()
    Frees GPU resources created and held by the Context. Can be called to reduce GPU memory pressure. Any resources that are still in use (e.g. being used by work submitted to the GPU) will not be deleted by this call. If the caller wants to make sure all resources are freed, then they should first make sure to submit and wait on any outstanding work.

  - ### performDeferredCleanup

    public abstract void performDeferredCleanup(long msNotUsed)
    Purge GPU resources on the Context that haven't been used in the past 'msNotUsed' milliseconds or are otherwise marked for deletion, regardless of whether the context is under budget.

  - ### getCurrentBudgetedBytes

    public long getCurrentBudgetedBytes()
    Returns the number of bytes of the Context's gpu memory cache budget that are currently in use.

  - ### getCurrentPurgeableBytes

    public long getCurrentPurgeableBytes()
    Returns the number of bytes of the Context's resource cache that are currently purgeable.

  - ### getMaxBudgetedBytes

    public long getMaxBudgetedBytes()
    Returns the size of Context's gpu memory cache budget in bytes.

  - ### getSharedResourceCache

    @Internal public final SharedResourceCache getSharedResourceCache()

  - ### getRendererProvider

    @Internal public final RendererProvider getRendererProvider()

  - ### getLogger

    public final org.slf4j.Logger getLogger()

  - ### init

    protected boolean init(BaseContextOptions options)

  - ### deallocate

    protected void deallocate()
    Description copied from class: `RefCnt`
    Override this method to invoke de-allocation of the underlying resource.
    Specified by:
      `deallocate` in class `RefCnt`

  - ### getOwnerThread

    public final Thread getOwnerThread()
    Returns:
      the context-creating thread

  - ### isOwnerThread

    public final boolean isOwnerThread()
    Returns:
      true if calling from the context-creating thread

  - ### checkOwnerThread

    public final void checkOwnerThread()
    Checks if calling from the context-creating thread, or throws a runtime exception.