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 TaskExecutorUI 线程任务执行器:应用可 spawn 异步任务,回调在 UI 线程执行
Implementations§
Source§impl AppContext<'_>
impl AppContext<'_>
pub fn is_software(&self) -> bool
pub fn metrics(&self) -> ShellMetrics
Sourcepub fn scale_factor(&self) -> f32
pub fn scale_factor(&self) -> f32
DPR(文字/布局的物理像素比)
Sourcepub fn logical_size(&self) -> Size
pub fn logical_size(&self) -> Size
当前逻辑尺寸(由窗口物理尺寸与 DPR 推导)
Sourcepub fn request_redraw(&self)
pub fn request_redraw(&self)
请求下一帧重绘。
Sourcepub fn image_texture_stats(&self) -> ImageTextureStats
pub fn image_texture_stats(&self) -> ImageTextureStats
图片纹理占用快照(软件回退时为默认值)。
Sourcepub fn resolve_gpu_profile(&mut self) -> Option<u32>
pub fn resolve_gpu_profile(&mut self) -> Option<u32>
解析 GPU timestamp(仅 GPU 后端且 profiler 可用时返回)。
Sourcepub fn render_stats(&self) -> RenderStats
pub fn render_stats(&self) -> RenderStats
P2-1.5:上一帧绘制统计(draw calls / segments / scratch 内存)
Sourcepub fn present_stats(&self) -> PresentStats
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> 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