Skip to main content

Layer

Struct Layer 

Source
pub struct Layer {
    pub id: LayerId,
    pub parent: Option<LayerId>,
    pub children: Vec<LayerId>,
    pub root_element: ElementId,
    pub z_order: u32,
    pub dirty: bool,
    pub layout_dirty: bool,
    pub paint_count: u32,
    pub cached_paint_list: Option<Rc<PaintList>>,
    pub offset: Point,
    pub size: Option<Size>,
    pub effect: LayerEffect,
}
Expand description

Layer — 一个独立的“重绘单元“

阶段 4 引入。每个 RepaintBoundary widget 触发 element 树为它建一个 layer。 一个 layer 包含一个 element 子树根 + 子 layer 列表。

合成顺序(z_order):layer 在父 layer 内的绘制顺序。值越大越在上层(后画)。 paint_frame 按 z_order 升序遍历,renderer 把多个 layer 的 paint list 按序叠加到 surface。

字段说明:

  • root_element:该 layer 包含的 element 子树根
  • children:子 layer 列表(嵌套 RepaintBoundary)
  • dirty:是否需要重画(阶段 4-A:event 驱动局部标 dirty,paint_frame 跳过干净 layer 的 paint)
  • layout_dirty:本层子树内是否有 可能影响布局 的变化。与 dirty 分离: hover 等纯外观变化只置 dirty;点击/键盘/滚动/选择性 rebuild 会置 layout_dirty,下一帧从 root 做一次整树布局,让父层/兄弟层感知子层尺寸变化。
  • paint_count:调试字段,累计真正被 paint 的次数(干净 layer 不自增)
  • cached_paint_list:阶段 4-A 上次 paint 出来的 list(干净 layer 复用)
  • offset:阶段 4-D,此 layer 在父 layer (或 root) 内的 logical offset。 Pass 2 blit 时把 layer texture 画到 surface 的 (offset.x, offset.y) 位置。 由 mount_recursive 时 RepaintBoundary 在父中的位置决定。
  • size:阶段 4-D,此 layer 的 logical size。None 表示还没 layout/paint 过, Renderer fallback 用全屏 texture;Some(s) 时按 s 大小创建 texture(节省 fillrate)。 paint_frame 时从 RO.layout 后的 size 写入。

Fields§

§id: LayerId§parent: Option<LayerId>§children: Vec<LayerId>§root_element: ElementId§z_order: u32§dirty: bool§layout_dirty: bool

子树内是否有影响布局的变化(需要从 root 重排,而不是只重排本层)

§paint_count: u32§cached_paint_list: Option<Rc<PaintList>>

阶段 4-A:上次 paint 的结果,干净 layer 在下一帧 paint_frame 时复用。 用 Rc 共享:clean layer 每帧不再深拷贝 PaintCommand(含 Triangles/纹理声明)。

§offset: Point

阶段 4-D(候选 2):layer 在父 layer 内的 logical offset mount_recursive 时由 RepaintBoundary 在父中的位置累计得到

§size: Option<Size>

阶段 4-D(候选 2):layer 的 logical size。None = 未 layout;Some = RO paint 后 算的 size(None 时 Renderer 用全屏 texture 兼容,Some 时按 size 创建,大幅省 fillrate)

§effect: LayerEffect

阶段 5:layer 合成到父 layer/surface 时的视觉效果 (Transform / Opacity / ClipRRect / 未来 Blur / DropShadow…) 由 RepaintBoundary 子类的 RO 在 mount 时写入,Renderer Pass 2 blit 走 shader 分支

Implementations§

Source§

impl Layer

Source

pub fn children(&self) -> &[LayerId]

直接子 layer(只读)。

Auto Trait Implementations§

§

impl !Send for Layer

§

impl !Sync for Layer

§

impl Freeze for Layer

§

impl RefUnwindSafe for Layer

§

impl Unpin for Layer

§

impl UnsafeUnpin for Layer

§

impl UnwindSafe for Layer

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<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, 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.