Skip to main content

OffscreenCompositor

Struct OffscreenCompositor 

Source
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>

Source

pub fn new(width: i16, height: i16) -> Self

创建指定视口宽高 (width, height) 的双槽位离屏合成器。

Source

pub fn resize(&mut self, width: i16, height: i16)

调整离屏合成器视口尺寸并失效旧尺寸缓存。

Source

pub fn invalidate(&mut self, page_key: u32)

使指定 page_key 的离屏缓存失效。

Source

pub fn invalidate_all(&mut self)

清空全部离屏页面缓存标识(保留底层已分配内存以便复用)。

Source

pub const fn total_rasterizations(&self) -> usize

返回自创建以来实际执行离屏整页光栅化的累计次数(用于验证转场期间的 0 重绘复用)。

Source

pub fn has_cached_layer(&self, page_key: u32) -> bool

查询指定 page_key 是否已缓存在离屏槽位中。

Source

pub fn layer_pixels(&self, page_key: u32) -> Option<&[P]>

获取已缓存的 page_key 离屏像素切片。

Source

pub fn cache_layer_with<F>( &mut self, page_key: u32, force_reraster: bool, raster_fn: F, ) -> &[P]
where F: FnOnce(&mut [P], i16, i16),

确保 page_key 对应的离屏缓冲已就绪:若命中缓存且 !force_reraster,直接 O(1) 返回缓存切片; 否则调用一次 raster_fn 渲染到离屏槽位并缓存。

Source

pub fn cache_engine_page( &mut self, page_key: u32, force_reraster: bool, engine: &mut VeloxEngine, ) -> &[P]

将 crate::engine::VeloxEngine 当前视图光栅化并缓存至 page_key 对应的离屏缓冲(若已缓存且 !force_reraster 则跳过光栅化)。

Source

pub fn composite_transition( &self, prev_layer: Option<(u32, i16, i16, u8)>, curr_layer: (u32, i16, i16, u8), backdrop: Color, target: &mut [P], )

将前后两个缓存图层 prev_layer (key, offset_x, offset_y, alpha) 与 curr_layer (key, offset_x, offset_y, alpha) 合成至目标帧缓冲 target。

Trait Implementations§

Source§

impl<P: Clone + PixelFormat> Clone for OffscreenCompositor<P>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Debug + PixelFormat> Debug for OffscreenCompositor<P>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P> Forget for OffscreenCompositor<P>

§

impl<P> Freeze for OffscreenCompositor<P>
where [OffscreenLayerSlot<P>; 2]: Freeze,

§

impl<P> Move for OffscreenCompositor<P>

§

impl<P> RefUnwindSafe for OffscreenCompositor<P>
where [OffscreenLayerSlot<P>; 2]: RefUnwindSafe,

§

impl<P> Send for OffscreenCompositor<P>
where [OffscreenLayerSlot<P>; 2]: Send,

§

impl<P> Sync for OffscreenCompositor<P>
where [OffscreenLayerSlot<P>; 2]: Sync,

§

impl<P> Unpin for OffscreenCompositor<P>
where [OffscreenLayerSlot<P>; 2]: Unpin,

§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> FluentBuilder for T

Source§

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

根据 condition 在两个修饰分支之间二选一。
Source§

fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self

当 option 为 Some(value) 时执行闭包修饰自身,否则原样返回。
Source§

fn when_none<O>( self, option: &Option<O>, then: impl FnOnce(Self) -> Self, ) -> Self

当 option 为 None 时执行闭包修饰自身,否则原样返回。
Source§

fn apply<U>(self, f: impl FnOnce(Self) -> U) -> U

通用管道映射变换(避免与 Iterator::map / Option::map 重名)。
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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