pub trait Surface: WasmNotSendSync {
type A: Api;
// Required methods
unsafe fn configure(
&self,
device: &<Self::A as Api>::Device,
config: &SurfaceConfiguration
) -> Result<(), SurfaceError>;
unsafe fn unconfigure(&self, device: &<Self::A as Api>::Device);
unsafe fn acquire_texture(
&self,
timeout: Option<Duration>,
fence: &<Self::A as Api>::Fence
) -> Result<Option<AcquiredSurfaceTexture<Self::A>>, SurfaceError>;
unsafe fn discard_texture(&self, texture: <Self::A as Api>::SurfaceTexture);
}
Required Associated Types§
Required Methods§
sourceunsafe fn configure(
&self,
device: &<Self::A as Api>::Device,
config: &SurfaceConfiguration
) -> Result<(), SurfaceError>
unsafe fn configure( &self, device: &<Self::A as Api>::Device, config: &SurfaceConfiguration ) -> Result<(), SurfaceError>
Configure self
to use device
.
§Safety
- All GPU work using
self
must have been completed. - All
AcquiredSurfaceTexture
s must have been destroyed. - All
Api::TextureView
s derived from theAcquiredSurfaceTexture
s must have been destroyed. - The surface
self
must not currently be configured to use any otherDevice
.
sourceunsafe fn unconfigure(&self, device: &<Self::A as Api>::Device)
unsafe fn unconfigure(&self, device: &<Self::A as Api>::Device)
Unconfigure self
on device
.
§Safety
- All GPU work that uses
surface
must have been completed. - All
AcquiredSurfaceTexture
s must have been destroyed. - All
Api::TextureView
s derived from theAcquiredSurfaceTexture
s must have been destroyed. - The surface
self
must have been configured ondevice
.
sourceunsafe fn acquire_texture(
&self,
timeout: Option<Duration>,
fence: &<Self::A as Api>::Fence
) -> Result<Option<AcquiredSurfaceTexture<Self::A>>, SurfaceError>
unsafe fn acquire_texture( &self, timeout: Option<Duration>, fence: &<Self::A as Api>::Fence ) -> Result<Option<AcquiredSurfaceTexture<Self::A>>, SurfaceError>
Return the next texture to be presented by self
, for the caller to draw on.
On success, return an AcquiredSurfaceTexture
representing the
texture into which the caller should draw the image to be displayed on
self
.
If timeout
elapses before self
has a texture ready to be acquired,
return Ok(None)
. If timeout
is None
, wait indefinitely, with no
timeout.
§Using an AcquiredSurfaceTexture
On success, this function returns an AcquiredSurfaceTexture
whose
texture
field is a SurfaceTexture
from which the caller can
borrow
a Texture
to draw on. The AcquiredSurfaceTexture
also
carries some metadata about that SurfaceTexture
.
All calls to Queue::submit
that draw on that Texture
must also
include the SurfaceTexture
in the surface_textures
argument.
When you are done drawing on the texture, you can display it on self
by passing the SurfaceTexture
and self
to Queue::present
.
If you do not wish to display the texture, you must pass the
SurfaceTexture
to self.discard_texture
, so that it can be reused
by future acquisitions.
§Portability
Some backends can’t support a timeout when acquiring a texture. On these
backends, timeout
is ignored.
§Safety
-
The surface
self
must currently be configured on someDevice
. -
The
fence
argument must be the sameFence
passed to all calls toQueue::submit
that usedTexture
s acquired from this surface. -
You may only have one texture acquired from
self
at a time. Whenacquire_texture
returnsOk(Some(ast))
, you must pass the returnedSurfaceTexture
ast.texture
to eitherQueue::present
orSurface::discard_texture
before callingacquire_texture
again.
sourceunsafe fn discard_texture(&self, texture: <Self::A as Api>::SurfaceTexture)
unsafe fn discard_texture(&self, texture: <Self::A as Api>::SurfaceTexture)
Relinquish an acquired texture without presenting it.
After this call, the texture underlying SurfaceTexture
may be
returned by subsequent calls to self.acquire_texture
.
§Safety
-
The surface
self
must currently be configured on someDevice
. -
texture
must be aSurfaceTexture
returned by a call toself.acquire_texture
that has not yet been passed toQueue::present
.