Class SurfaceProxy
- All Implemented Interfaces:
RefCounted
- Direct Known Subclasses:
RenderTargetProxy
SurfaceProxy
implements the proxy pattern for GpuSurface
,
it targets a GpuSurface
with three instantiation methods: deferred,
lazy-callback and wrapped.
Target: The backing GPU texture or framebuffer that referenced by this proxy.
Instantiate: Create new GPU surfaces or find surfaces in ResourceCache
when they are actually required on flush.
BackingFit: Indicates whether a backing store needs to be an exact match or
can be larger than is strictly necessary. True: Exact; False: Approx. See
ISurface.FLAG_APPROX_FIT
, the default is exact.
UseAllocator:
- False: This surface will be instantiated outside the allocator (e.g. for surfaces that are instantiated in on-flush callbacks).
- True:
SurfaceAllocator
should instantiate this surface.
Threading: Proxies can be created on any thread, and change the reference count
through RefCnt.ref()
and RefCnt.unref()
. If proxy is, or will be used by
render thread, its final RefCnt.unref()
must be called on render thread (the
case where render thread will have ownership). This is because the backing GPU
texture can only be operated on render thread.
Use ImageProxyCache
to obtain SurfaceProxy
objects.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static interface
Lazy-callback function. -
Method Summary
Modifier and TypeMethodDescriptionabstract void
clear()
De-instantiate.abstract boolean
doLazyInstantiation
(ResourceProvider resourceProvider) boolean
final BackendFormat
abstract int
Returns the physical height of the backing surface.abstract UniqueID
abstract int
Returns the physical width of the backing surface.If this is a texturable surface and the surface is already instantiated, return its backingImage
; if not, return null.If this is a renderable surface and the surface is already instantiated, return its backingGpuRenderTarget
; if not, return null.abstract @RawPtr GpuSurface
final int
Returns the logical height of this surface.long
Retrieves the amount of GPU memory that will be or currently is used by this resource in bytes.abstract int
Returns the number of samples per pixel in color buffers (one if non-MSAA).final int
How many render tasks has this surface been the target of?final UniqueID
The contract for the unique ID is: For wrapped resources: the unique ID will match that of the wrapped resource For deferred resources: The unique ID will be different from the real resource, when it is allocated The surface's unique ID will not change across the instantiates call The unique IDs of the proxies and the resources draw from the same pool What this boils down to is that the unique ID of a surface can be used to consistently track/identify a surface but should never be used to distinguish between resources and proxies - beware!final int
getWidth()
Returns the logical width of this surface.int
hashCode()
abstract boolean
instantiate
(ResourceProvider resourceProvider) Instantiates the backing store, if necessary.abstract boolean
Returns whether the backing store references the wrapped object.final boolean
Does the resource count against the resource budget?final boolean
final boolean
isExact()
If set to exact or approx size is equal to exact size.abstract boolean
Returns true if the backing store is instantiated.abstract boolean
isLazy()
Returns true if the surface has a lazy callback and not instantiated.final boolean
Returns true if the surface has a lazy callback, not instantiated, loose fit and dimension is not known.final boolean
final boolean
final boolean
The pixel values of this surface's texture cannot be modified (e.g.final void
Called when this task becomes a target of aRenderTask
.final boolean
void
abstract boolean
Proxies that are already instantiated and whose backing texture cannot be recycled to instantiate other proxies do not need to be considered bySurfaceAllocator
.final boolean
final boolean
Methods inherited from class icyllis.arc3d.core.RefCnt
create, create, deallocate, getRefCnt, getRefCntAcquire, getRefCntVolatile, move, move, ref, unique, unref
-
Method Details
-
isLazy
public abstract boolean isLazy()Returns true if the surface has a lazy callback and not instantiated. -
isLazyMost
public final boolean isLazyMost()Returns true if the surface has a lazy callback, not instantiated, loose fit and dimension is not known. -
getWidth
public final int getWidth()Returns the logical width of this surface. The result is undefined ifisLazyMost()
returns true.- Returns:
- the desired width of the surface
-
getHeight
public final int getHeight()Returns the logical height of this surface. The result is undefined ifisLazyMost()
returns true.- Returns:
- the desired height of the surface
-
getBackingWidth
public abstract int getBackingWidth()Returns the physical width of the backing surface. The result is undefined ifisLazyMost()
returns true.- Returns:
- the width of the backing store
-
getBackingHeight
public abstract int getBackingHeight()Returns the physical height of the backing surface. The result is undefined ifisLazyMost()
returns true.- Returns:
- the height of the backing store
-
isExact
public final boolean isExact()If set to exact or approx size is equal to exact size. Must call when not lazy-most. Equivalent to getWidth() == getBackingWidth() invalid input: '&'invalid input: '&' getHeight() == getBackingHeight();- Returns:
- true if backing fit is (as if) exact
- See Also:
-
getSampleCount
public abstract int getSampleCount()Returns the number of samples per pixel in color buffers (one if non-MSAA). If this surface it non-renderable, this method always returns one.- Returns:
- the number of samples, greater than (multisample) or equal to one
-
getBackendFormat
- Returns:
- the backend format of the surface
-
getUniqueID
The contract for the unique ID is:- For wrapped resources: the unique ID will match that of the wrapped resource
- For deferred resources:
- The unique ID will be different from the real resource, when it is allocated
- The surface's unique ID will not change across the instantiates call
- The unique IDs of the proxies and the resources draw from the same pool
- Returns:
- a reference for identity hash map
-
getBackingUniqueID
-
isInstantiated
public abstract boolean isInstantiated()Returns true if the backing store is instantiated. -
instantiate
Instantiates the backing store, if necessary.- Parameters:
resourceProvider
- the resource provider to create textures- Returns:
- success or not
-
clear
public abstract void clear()De-instantiate. Called after instantiated. -
shouldSkipAllocator
public abstract boolean shouldSkipAllocator()Proxies that are already instantiated and whose backing texture cannot be recycled to instantiate other proxies do not need to be considered bySurfaceAllocator
. -
isBackingWrapped
public abstract boolean isBackingWrapped()Returns whether the backing store references the wrapped object. Always false if not instantiated. -
isUsedAsTaskTarget
public final void isUsedAsTaskTarget()Called when this task becomes a target of aRenderTask
. -
getTaskTargetCount
public final int getTaskTargetCount()How many render tasks has this surface been the target of? -
getGpuSurface
-
getGpuImage
If this is a texturable surface and the surface is already instantiated, return its backingImage
; if not, return null. -
getGpuRenderTarget
If this is a renderable surface and the surface is already instantiated, return its backingGpuRenderTarget
; if not, return null. -
isBudgeted
public final boolean isBudgeted()Does the resource count against the resource budget?Always true for lazy-callback resources; set from the backing resource for wrapped resources; only meaningful if 'mLazyInstantiateCallback' is non-null.
-
isReadOnly
public final boolean isReadOnly()The pixel values of this surface's texture cannot be modified (e.g. doesn't support write pixels or MIP map level regen). Read-only proxies also bypass interval tracking and assignment in ResourceAllocator. -
isProtected
public final boolean isProtected() -
isManualMSAAResolve
public final boolean isManualMSAAResolve() -
wrapsGLDefaultFB
public final boolean wrapsGLDefaultFB() -
wrapsVkSecondaryCB
public final boolean wrapsVkSecondaryCB() -
isDeferredListTarget
public final boolean isDeferredListTarget() -
setIsDeferredListTarget
@Internal public void setIsDeferredListTarget() -
isUserExact
@Internal public final boolean isUserExact() -
asImageProxy
- Returns:
- the texture proxy associated with the surface proxy, may be NULL.
-
asRenderTargetProxy
- Returns:
- the render target proxy associated with the surface proxy, may be NULL.
-
getUniqueKey
- Returns:
- the unique key for this proxy, may be NULL
-
getMemorySize
public long getMemorySize()Retrieves the amount of GPU memory that will be or currently is used by this resource in bytes. It is approximate since we aren't aware of additional padding or copies made by the driver.- Returns:
- the amount of GPU memory used in bytes
-
hashCode
public int hashCode() -
equals
-
doLazyInstantiation
-