pub struct LayerCache { /* private fields */ }Expand description
A pool of off-screen render targets, keyed by layer_id: u64.
Implementations§
Source§impl LayerCache
impl LayerCache
Sourcepub fn new(max_layers: usize) -> Self
pub fn new(max_layers: usize) -> Self
Create a new cache that holds at most max_layers layers simultaneously.
Sourcepub fn set_max_idle_frames(&mut self, frames: u64)
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.
Sourcepub fn begin_frame(&mut self)
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.
Sourcepub fn get(&mut self, layer_id: u64) -> Option<&mut RenderTarget>
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.
Sourcepub fn get_or_create(
&mut self,
device: &Device,
layer_id: u64,
width: u32,
height: u32,
sample_count: u32,
) -> Result<&mut RenderTarget, UiError>
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.
Sourcepub fn invalidate(&mut self, layer_id: u64)
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.
Sourcepub fn invalidate_all(&mut self)
pub fn invalidate_all(&mut self)
Invalidate all cached layers.
Sourcepub fn remove(&mut self, layer_id: u64)
pub fn remove(&mut self, layer_id: u64)
Remove a layer by layer_id, freeing the associated GPU texture.
Sourcepub fn current_frame(&self) -> u64
pub fn current_frame(&self) -> u64
Return the current frame counter.
Auto Trait Implementations§
impl !RefUnwindSafe for LayerCache
impl !UnwindSafe for LayerCache
impl Freeze for LayerCache
impl Send for LayerCache
impl Sync for LayerCache
impl Unpin for LayerCache
impl UnsafeUnpin for LayerCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 more