Skip to main content

LayerHandle

Struct LayerHandle 

Source
pub struct LayerHandle<T> { /* private fields */ }
Expand description

A handle to prevent a Layer’s platform graphics resources from being disposed.

Layer objects retain native resources such as Picture objects. These objects may in turn retain large chunks of texture memory, either directly or indirectly.

The layer’s native resources must be retained as long as there is some object that can add it to a scene. Typically, this is either its parent or an undisposed RenderObject that will append it to a ContainerLayer. Layers automatically hold a handle to their children, and RenderObjects automatically hold a handle to their RenderObject.layer as well as any PictureLayers that they paint into using the PaintingContext.canvas. A layer automatically releases its resources once at least one handle has been acquired and all handles have been disposed. RenderObjects that create additional layer objects must manually manage the handles for that layer similarly to the implementation of RenderObject.layer.

If a RenderObject creates layers in addition to its RenderObject.layer and it intends to reuse those layers separately from RenderObject.layer, it must create a handle to that layer and dispose of it when the layer is no longer needed. For example, if it re-creates or nulls out an existing layer in RenderObject.paint, it should dispose of the handle to the old layer. It should also dispose of any layer handles it holds in RenderObject.dispose.

To dispose of a layer handle, set its layer to None with set_layer. The handle lives inside an arena object, so the setter reaches it through the App rather than through &mut self; a handle dropped without clearing keeps its layer until the App goes, as a Dart handle that is never nulled would. See PORTING.md.

Implementations§

Source§

impl<T> LayerHandle<T>

Source

pub const fn new() -> LayerHandle<T>

Create a new layer handle referencing no Layer. Dart’s LayerHandle([layer]) with a layer is new then set_layer.

Source§

impl<T: ErasedLayer> LayerHandle<T>

Source

pub fn layer(&self) -> Option<T>

The Layer whose resources this object keeps alive.

Source

pub fn set_layer( app: &mut App, at: impl Fn(&mut App) -> &mut LayerHandle<T>, layer: Option<T>, )

Dart’s handle.layer = layer for the handle at reaches inside app.

Setting a new value or None will dispose the previously held layer if there are no other open handles to that layer.

§Panics

In debug builds, if layer is already disposed.

Trait Implementations§

Source§

impl<T: Debug> Debug for LayerHandle<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for LayerHandle<T>

Source§

fn default() -> LayerHandle<T>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for LayerHandle<T>
where Option<T>: Freeze,

§

impl<T> RefUnwindSafe for LayerHandle<T>

§

impl<T> Send for LayerHandle<T>
where Option<T>: Send,

§

impl<T> Sync for LayerHandle<T>
where Option<T>: Sync,

§

impl<T> Unpin for LayerHandle<T>
where Option<T>: Unpin,

§

impl<T> UnsafeUnpin for LayerHandle<T>
where Option<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for LayerHandle<T>
where Option<T>: UnwindSafe,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> 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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,