pub struct Surface<'window> {
pub(crate) context: Arc<dyn DynContext>,
pub(crate) _handle_source: Option<Box<dyn WindowHandle + 'window>>,
pub(crate) id: ObjectId,
pub(crate) surface_data: Box<dyn Any + Sync + Send>,
pub(crate) config: Mutex<RawMutex, Option<SurfaceConfiguration<Vec<TextureFormat>>>>,
}
Expand description
Handle to a presentable surface.
A Surface
represents a platform-specific surface (e.g. a window) onto which rendered images may
be presented. A Surface
may be created with the function Instance::create_surface
.
This type is unique to the Rust API of wgpu
. In the WebGPU specification,
GPUCanvasContext
serves a similar role.
Fields§
§context: Arc<dyn DynContext>
§_handle_source: Option<Box<dyn WindowHandle + 'window>>
§id: ObjectId
§surface_data: Box<dyn Any + Sync + Send>
§config: Mutex<RawMutex, Option<SurfaceConfiguration<Vec<TextureFormat>>>>
Implementations§
§impl Surface<'_>
impl Surface<'_>
pub fn get_capabilities(&self, adapter: &Adapter) -> SurfaceCapabilities
pub fn get_capabilities(&self, adapter: &Adapter) -> SurfaceCapabilities
Returns the capabilities of the surface when used with the given adapter.
Returns specified values (see SurfaceCapabilities
) if surface is incompatible with the adapter.
pub fn get_default_config(
&self,
adapter: &Adapter,
width: u32,
height: u32
) -> Option<SurfaceConfiguration<Vec<TextureFormat>>>
pub fn get_default_config( &self, adapter: &Adapter, width: u32, height: u32 ) -> Option<SurfaceConfiguration<Vec<TextureFormat>>>
Return a default SurfaceConfiguration
from width and height to use for the Surface
with this adapter.
Returns None if the surface isn’t supported by this adapter
pub fn configure(
&self,
device: &Device,
config: &SurfaceConfiguration<Vec<TextureFormat>>
)
pub fn configure( &self, device: &Device, config: &SurfaceConfiguration<Vec<TextureFormat>> )
Initializes Surface
for presentation.
§Panics
- A old
SurfaceTexture
is still alive referencing an old surface. - Texture format requested is unsupported on the surface.
config.width
orconfig.height
is zero.
pub fn get_current_texture(&self) -> Result<SurfaceTexture, SurfaceError>
pub fn get_current_texture(&self) -> Result<SurfaceTexture, SurfaceError>
Returns the next texture to be presented by the swapchain for drawing.
In order to present the SurfaceTexture
returned by this method,
first a Queue::submit
needs to be done with some work rendering to this texture.
Then SurfaceTexture::present
needs to be called.
If a SurfaceTexture referencing this surface is alive when the swapchain is recreated, recreating the swapchain will panic.
pub unsafe fn as_hal<A, F, R>(&mut self, hal_surface_callback: F) -> Option<R>
pub unsafe fn as_hal<A, F, R>(&mut self, hal_surface_callback: F) -> Option<R>
Returns the inner hal Surface using a callback. The hal surface will be None
if the
backend type argument does not match with this wgpu Surface
§Safety
- The raw handle obtained from the hal Surface must not be manually destroyed
Trait Implementations§
Auto Trait Implementations§
impl<'window> !Freeze for Surface<'window>
impl<'window> !RefUnwindSafe for Surface<'window>
impl<'window> Send for Surface<'window>
impl<'window> Sync for Surface<'window>
impl<'window> Unpin for Surface<'window>
impl<'window> !UnwindSafe for Surface<'window>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request