Skip to main content

AppContext

Struct AppContext 

Source
pub struct AppContext<'a> {
    pub shell: &'a dyn WindowShell,
    pub tasks: &'a TaskExecutor,
    /* private fields */
}
Expand description

应用回调可用的运行时句柄(由 Runner 持有)。

应用侧不暴露 wgpu/winit 类型:GPU 相关能力通过中性的统计/查询方法提供。

Fields§

§shell: &'a dyn WindowShell

窗口/DPI/IME 能力 —— 应用不直接依赖 winit

§tasks: &'a TaskExecutor

UI 线程任务执行器:应用可 spawn 异步任务,回调在 UI 线程执行

Implementations§

Source§

impl AppContext<'_>

Source

pub fn is_software(&self) -> bool

Source

pub fn metrics(&self) -> ShellMetrics

Source

pub fn scale_factor(&self) -> f32

DPR(文字/布局的物理像素比)

Source

pub fn logical_size(&self) -> Size

当前逻辑尺寸(由窗口物理尺寸与 DPR 推导)

Source

pub fn request_redraw(&self)

请求下一帧重绘。

Source

pub fn image_texture_stats(&self) -> ImageTextureStats

图片纹理占用快照(软件回退时为默认值)。

Source

pub fn resolve_gpu_profile(&mut self) -> Option<u32>

解析 GPU timestamp(仅 GPU 后端且 profiler 可用时返回)。

Source

pub fn render_stats(&self) -> RenderStats

P2-1.5:上一帧绘制统计(draw calls / segments / scratch 内存)

Source

pub fn present_stats(&self) -> PresentStats

上一段 present 的读数(含实际生效的 present_mode 与 max_frame_latency)。

应用侧读它是为了把“呈现节奏不匀“拆成两件不同的事:等 vsync 的时间(配额)与 相邻两次 present 的间隔(节奏)。软件回退那一路不 present 到屏幕,所以 presents == 0 —— 那是“没量到“,不是“节奏完美“。

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for AppContext<'a>

§

impl<'a> !Send for AppContext<'a>

§

impl<'a> !Sync for AppContext<'a>

§

impl<'a> !UnwindSafe for AppContext<'a>

§

impl<'a> Forget for AppContext<'a>

§

impl<'a> Freeze for AppContext<'a>

§

impl<'a> Move for AppContext<'a>

§

impl<'a> Unpin for AppContext<'a>

§

impl<'a> UnsafeUnpin for AppContext<'a>

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> ErasedDestructor for T
where T: 'static,

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, 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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>