pub struct OffscreenCompositor<P: PixelFormat = Xrgb8888> { /* private fields */ }Expand description
面向整屏页面转场动画(如 Navigator 推入/弹出切换)的双槽位离屏图层缓存与合成器。
核心优势:
- 页面首次进入或标记脏(
force_reraster = true)时仅执行 1 次 完整光栅化并缓存至离屏帧缓冲; - 在转场动画的每一帧(如 60FPS 连续 15~20 帧)中,不再重新求解与光栅化整屏
DrawOp, 而是直接通过blit_translated_layer对前后两个离屏页面缓冲做平移与 Alpha 合成, 将整屏转场每帧耗时从毫秒级降低至微秒级内存拷贝。
Implementations§
Source§impl<P: PixelFormat> OffscreenCompositor<P>
impl<P: PixelFormat> OffscreenCompositor<P>
Sourcepub fn invalidate(&mut self, page_key: u32)
pub fn invalidate(&mut self, page_key: u32)
使指定 page_key 的离屏缓存失效。
Sourcepub fn invalidate_all(&mut self)
pub fn invalidate_all(&mut self)
清空全部离屏页面缓存标识(保留底层已分配内存以便复用)。
Sourcepub const fn total_rasterizations(&self) -> usize
pub const fn total_rasterizations(&self) -> usize
返回自创建以来实际执行离屏整页光栅化的累计次数(用于验证转场期间的 0 重绘复用)。
Sourcepub fn has_cached_layer(&self, page_key: u32) -> bool
pub fn has_cached_layer(&self, page_key: u32) -> bool
查询指定 page_key 是否已缓存在离屏槽位中。
Sourcepub fn layer_pixels(&self, page_key: u32) -> Option<&[P]>
pub fn layer_pixels(&self, page_key: u32) -> Option<&[P]>
获取已缓存的 page_key 离屏像素切片。
Sourcepub fn cache_layer_with<F>(
&mut self,
page_key: u32,
force_reraster: bool,
raster_fn: F,
) -> &[P]
pub fn cache_layer_with<F>( &mut self, page_key: u32, force_reraster: bool, raster_fn: F, ) -> &[P]
确保 page_key 对应的离屏缓冲已就绪:若命中缓存且 !force_reraster,直接 O(1) 返回缓存切片;
否则调用一次 raster_fn 渲染到离屏槽位并缓存。
Sourcepub fn cache_engine_page(
&mut self,
page_key: u32,
force_reraster: bool,
engine: &mut VeloxEngine,
) -> &[P]
pub fn cache_engine_page( &mut self, page_key: u32, force_reraster: bool, engine: &mut VeloxEngine, ) -> &[P]
将 crate::engine::VeloxEngine 当前视图光栅化并缓存至 page_key 对应的离屏缓冲(若已缓存且 !force_reraster 则跳过光栅化)。
Trait Implementations§
Source§impl<P: Clone + PixelFormat> Clone for OffscreenCompositor<P>
impl<P: Clone + PixelFormat> Clone for OffscreenCompositor<P>
Auto Trait Implementations§
impl<P> Forget for OffscreenCompositor<P>
impl<P> Freeze for OffscreenCompositor<P>
impl<P> Move for OffscreenCompositor<P>
impl<P> RefUnwindSafe for OffscreenCompositor<P>where
[OffscreenLayerSlot<P>; 2]: RefUnwindSafe,
impl<P> Send for OffscreenCompositor<P>
impl<P> Sync for OffscreenCompositor<P>
impl<P> Unpin for OffscreenCompositor<P>
impl<P> UnsafeUnpin for OffscreenCompositor<P>where
[OffscreenLayerSlot<P>; 2]: UnsafeUnpin,
impl<P> UnwindSafe for OffscreenCompositor<P>where
[OffscreenLayerSlot<P>; 2]: UnwindSafe,
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
当
condition 为 true 时执行闭包修饰自身,否则原样返回。Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Self
fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
根据
condition 在两个修饰分支之间二选一。Source§fn when_some<O>(
self,
option: Option<O>,
then: impl FnOnce(Self, O) -> Self,
) -> Self
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
当
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。