Skip to main content

SurfaceTarget

Struct SurfaceTarget 

Source
pub struct SurfaceTarget { /* private fields */ }
Expand description

Frames presented to a wgpu::Surface.

The surface is configured when a frame begins at a size it isn’t configured at, so a target that replaces another on the same window configures it only after the other one has let go of it. A minimized window’s frames keep the size the surface was last configured at.

Implementations§

Source§

impl SurfaceTarget

Source

pub fn new( backend: &RendererBackend, surface: Surface<'static>, framebuffer_size: Size, options: SurfaceOptions, ) -> Result<SurfaceTarget, Error>

A target on backend that presents to surface, made with the instance of the backend’s device, at framebuffer_size physical pixels. The surface is configured with the options’ format, or the device’s surface format, or else an 8-bit RGBA or BGRA format that the surface supports: in the browser the one the canvas prefers, and elsewhere the first of BGRA8 and RGBA8.

Fails with ErrorKind::Unsupported when the device’s adapter can’t present to the surface or the surface supports none of those formats, and with ErrorKind::InvalidArgument when the device has neither an adapter to ask nor a surface format.

Source

pub fn format(&self) -> TextureFormat

The format the surface is configured with.

Source

pub fn size(&self) -> Size

The size of the frames, in physical pixels.

Source

pub fn request_readback(&mut self)

Copies the next presented frame, for take_readback.

Source

pub fn take_readback(&mut self, gpu: &mut WebGpu) -> Option<FramePixels>

The frame copied after request_readback, once it is presented and mapped: natively at once, and in the browser on a later turn of the event loop.

Source

pub fn set_overlay(&mut self, overlay: Option<Overlay>)

Draws overlay over each frame from now on, after the map and before the frame is presented and read back, or stops with None.

Trait Implementations§

Source§

impl FrameTarget for SurfaceTarget

Source§

fn resize(&mut self, _gpu: &mut WebGpu, size: Size)

Draws the next frame at size physical pixels.

Source§

fn begin_frame(&mut self, gpu: &mut WebGpu) -> Option<FrameImage>

Acquires the surface’s next texture, unless the frame has one. A frame without one is skipped.

Source§

fn end_frame(&mut self, gpu: &mut WebGpu) -> Handoff

Draws the overlay over the frame, reads it back if that was asked for, and presents it.

Source§

type Gpu = WebGpu

The Gpu of the target’s backend, whose textures the target’s frames are.
Source§

fn tear_down(&mut self, gpu: &mut WebGpu)

Destroys the target’s textures of gpu, after which the target draws no more frames. A target dropped without it leaves them to the Gpu, which frees them when it drops.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more