Skip to main content

RenderTargetBrowserSurface

Struct RenderTargetBrowserSurface 

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

The surface of a view that is rendered through a render target of the page (a WebGL context or a 2D canvas).

The object belongs to the thread of the user interface. What the thread that renders needs of the canvas is in the two objects it shares with that thread: BrowserSurfaceShared (the id of the render target, the size, whether the target exists and its kind) and the BrowserRenderSurface over it, which is the surface the compositor draws to.

Implementations§

Source§

impl RenderTargetBrowserSurface

Source

pub fn create( container: &JsObject, modes: &[BrowserRenderingMode], top_level_id: i32, ) -> Rc<Self>

Creates a canvas in container with a render target of the first of modes the browser supports, and the surface over it.

Source

pub fn compositor(&self) -> Rc<Compositor>

The compositor that renders to the surface.

Source

pub fn scaling(&self) -> f64

The scaling from logical units to device pixels.

Source

pub fn client_size(&self) -> Size

The size in logical units.

Source

pub fn render_size(&self) -> PixelSize

The size in device pixels.

Source

pub fn is_valid(&self) -> bool

Whether the surface has a size it can be rendered at.

Source

pub fn size_changed(&self, handler: Rc<dyn Fn()>) -> u64

Subscribes to changes of the client size.

Source

pub fn scaling_changed(&self, handler: Rc<dyn Fn()>) -> u64

Subscribes to changes of the scaling.

Source

pub fn get_render_surfaces(&self) -> Vec<Arc<dyn IPlatformRenderSurface>>

The surfaces a render backend can draw to: the render surface of the canvas. It is handed out from the start and is not ready until the thread that owns the render target has published it (upstream hands out nothing until then).

Source

pub fn shared(&self) -> &Arc<BrowserSurfaceShared> ⓘ

What the thread of the user interface and the thread that renders share about the canvas.

Source

pub fn on_size_changed(&self, pixel_width: f64, pixel_height: f64, dpr: f64)

The canvas changed its size or its scaling.

Source

pub fn dispose(&self)

Releases the canvas surface.

Upstream posts a job to the compositor, which takes its server compositor out of the render loop, and then destroys the surface of the script side. A job is not what this port can use: it runs with a batch, and the batch of a closed view is the one that is likely never applied (the compositor is dropped as soon as the media context has committed it, and its graph is released in place of the next frame); a job does not run either while the graphics are not ready. So the thread that renders is given the work directly ([release_canvas]):

  • this thread, when it renders the view itself: the work is done here, before the call returns;
  • the render thread, when the compositor is confined to it: the work is queued for that thread, which enters the graph under the compositor lock. Whether it gets there before or after the graph is released does not matter: a graph that is released has released what it drew with, in its own graphics context.

The top-level is disposed before its renderer: the composition target of the view is disposed after this call, in a batch of its own that this thread waits for. The work does not depend on which of the two reaches the thread that renders first.

A canvas that never reached the render thread (the view was closed before that thread had reported itself) is let go of here: the script of this thread still holds it back. When the work cannot be queued for a render thread that runs, the canvas is only marked as disposed and stays alive in the worker, unused.

A surface that is dropped without this call makes it itself: a view that is let go of without being closed releases what it drew with in the same way, and not when its compositor happens to be dropped.

Trait Implementations§

Source§

impl Drop for RenderTargetBrowserSurface

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more