Skip to main content

LayerCache

Struct LayerCache 

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

A pool of off-screen render targets, keyed by layer_id: u64.

Implementations§

Source§

impl LayerCache

Source

pub fn new(max_layers: usize) -> Self

Create a new cache that holds at most max_layers layers simultaneously.

Source

pub fn set_max_idle_frames(&mut self, frames: u64)

Set the number of idle frames after which a layer is evicted.

A larger value trades GPU memory for reduced re-render cost when a layer goes temporarily off-screen.

Source

pub fn begin_frame(&mut self)

Advance the internal frame counter and evict any layers that have not been accessed for max_idle_frames frames.

Must be called once per frame, before any get/get_or_create calls for that frame.

Source

pub fn get(&mut self, layer_id: u64) -> Option<&mut RenderTarget>

Look up an existing layer by layer_id.

Updates the last-access frame counter. Returns None if no layer with this id is currently cached.

Source

pub fn get_or_create( &mut self, device: &Device, layer_id: u64, width: u32, height: u32, sample_count: u32, ) -> Result<&mut RenderTarget, UiError>

Return the RenderTarget for layer_id, creating a new one if absent.

If a new target is created it is width × height pixels with the given sample_count. If the layer already exists but has different dimensions it is not resized — the existing target is returned as-is. Call LayerCache::invalidate + LayerCache::remove then re-create if you need a different size.

When the cache is at capacity (max_layers), the LRU layer is evicted before creating the new entry.

§Errors

Propagates RenderTarget::new errors.

Source

pub fn invalidate(&mut self, layer_id: u64)

Invalidate a layer by layer_id, marking it dirty and bumping its generation counter. If the layer is not cached, this is a no-op.

Source

pub fn invalidate_all(&mut self)

Invalidate all cached layers.

Source

pub fn remove(&mut self, layer_id: u64)

Remove a layer by layer_id, freeing the associated GPU texture.

Source

pub fn clear(&mut self)

Remove all cached layers, freeing all associated GPU textures.

Source

pub fn len(&self) -> usize

Return the number of live layers currently in the cache.

Source

pub fn is_empty(&self) -> bool

Return true if the cache is empty.

Source

pub fn current_frame(&self) -> u64

Return the current frame counter.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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,