Skip to main content

PlatformWindow

Struct PlatformWindow 

Source
pub struct PlatformWindow { /* private fields */ }
Expand description

A platform window wrapping a winit window, wgpu surface, renderer, and AccessKit adapter for screen reader support.

Implementations§

Source§

impl PlatformWindow

Source

pub async fn new_with_a11y(window: Window, event_loop: &ActiveEventLoop) -> Self

Create a new platform window from a winit window. The event_loop parameter is needed for the AccessKit adapter.

Source

pub async fn new(window: Window) -> Self

Create a platform window without AccessKit (for contexts without ActiveEventLoop).

Source

pub fn window(&self) -> &Window

Source

pub fn occluded_now(&self) -> Option<bool>

Whether the platform says, when asked, that no part of the window is visible now: covered entirely, or never shown, as a window created while the display slept or the screen was locked is until both end. macOS answers (NSWindow’s occlusionState), and None elsewhere, where winit’s events are all there is.

winit sends WindowEvent::Occluded only when that state changes, so a window that was never visible never hears it; and wgpu refuses every acquire while AppKit does not show the window. Asking is how the caller learns it. A window already showing stays visible here while the displays sleep or the screen is locked: that is the session watch’s to hear.

Source

pub fn window_arc(&self) -> Arc<Window> ⓘ

Get a clonable Arc reference to the underlying winit window. Used by teksilo_platform::create_title_bar_host and other components that need shared ownership of the window.

Source

pub fn renderer(&self) -> &Renderer

Source

pub fn renderer_mut(&mut self) -> &mut Renderer

Source

pub fn scale_factor(&self) -> f64

Source

pub fn set_scale_factor(&mut self, factor: f64)

Source

pub fn track_display_refresh(&mut self)

Read the refresh rate of the display the window is on, and have a presented frame wait about one refresh of it for a producer holding a live picture’s lock. Done when the window is created; call it again when the window may have moved to another display. A display that reports no rate keeps the last one (60 Hz until one is read).

Source

pub fn live_texture_stats(&self) -> LiveTextureStats

What this window’s renderer holds and uploads for live pictures.

Source

pub fn live_texture_timings(&self) -> LiveImageTimings

How long this window’s live pass has taken, each figure over its latest 1,024 samples: see Renderer::live_texture_timings. With the live-image-timings feature.

Source

pub fn resize(&mut self, new_size: PhysicalSize<u32>)

Resize the surface.

A resize that arrives once the display server has gone is dropped: there is nothing left to present to.

Source

pub fn surface_size(&self) -> (u32, u32)

Get current surface dimensions.

Source

pub fn reconfigure_surface(&mut self) -> bool

Reconfigure the surface with the current config. Use after a Lost or Outdated surface error.

Answers whether this window can still present. false means the display server is gone, and the caller should wind down rather than ask for another frame: the next one would come back here unchanged.

Source

pub fn display_lost(&self) -> bool

Whether the display server has gone away under this window.

Source

pub fn render_frame( &mut self, frame: &RenderFrame, clear_color: [f32; 4], ) -> FrameOutcome

Render a frame to the surface.

Source

pub fn capture_offscreen( &mut self, frame: &RenderFrame, clear_color: [f32; 4], crop: Option<Rect>, ) -> Result<OffscreenCapture, ReadbackError>

Render frame into an offscreen texture of the surface’s size and read it back as tightly packed RGBA8.

Used by the debug-only automation bridge to capture a live window without going through the swapchain — the surface texture is configured RENDER_ATTACHMENT only (no COPY_SRC), so it can’t be read back directly. It renders through the window’s own renderer with Renderer::render_capture: every live picture shows its latest commit, and the window’s next frame draws the textures this one filled. The whole frame is rendered, then crop (physical pixels, clamped to the surface) is cut out on the CPU: rendering only part of a frame through the window’s renderer would drop the textures of the live pictures it left out. The offscreen texture uses the window’s own surface format so it matches the renderer’s pipelines; a BGRA readback is swizzled to RGBA here so the output is always RGBA. A crop outside the surface returns an empty capture.

Fails, without panicking, when the device cannot read the texture back (it was lost).

Note: a native WebView subview composites on top of the wgpu surface and is invisible to this readback (a transparent hole).

Source

pub fn request_redraw(&self)

Ask winit for a redraw. A no-op once the window’s wake target is disconnected (disconnect_redraw_waker), which is how a request after the event loop ended stays harmless.

Source

pub fn update_accessibility(&mut self, update: TreeUpdate)

Push an AccessKit TreeUpdate to the adapter (called after layout). Publish a freshly built TreeUpdate to the adapter, and leave a copy where the activation handler can find it.

The copy is what lets an assistive technology that attaches to an idle window see the application instead of an empty window node: the handler runs off the UI thread and cannot build a tree, so the last one the UI thread built is the best answer available synchronously.

Hand it what WidgetTree::deliver_accessibility returns, not sync_accessibility’s update: a node that left the tree a reader sees and came back must reach the adapter under an id it has never had, or a reader on AT-SPI holds it defunct and hears nothing from it.

Source

pub fn update_accessibility_with( &mut self, build: impl FnOnce() -> Option<TreeUpdate>, previous: impl FnOnce() -> TreeUpdate, )

Push an update the adapter builds only when it is actually going to be delivered, and only when build says there is one worth sending.

The caller decides inside the closure, because that is where the decision belongs: update_if_active runs its closure only when an assistive technology is attached, and on Linux it runs it under the adapter’s own state lock. Deciding outside would build a tree for nobody on every frame, and would make the throttle count frames nothing was listening to.

build returning None means “nothing to deliver”; the previously delivered tree is re-sent, which the consumer treats as a no-op.

Source

pub fn accessibility_needs_full_tree(&self) -> bool

Whether an assistive technology has asked this window for its tree and has not yet been given a full one.

Set by the activation handler, which runs on whichever thread the platform’s accessibility layer calls it from, and cleared by the first delivery after it — so a reader that attaches mid-session gets a complete tree rather than a geometry patch onto a tree it has never seen.

Source

pub fn take_accessibility_needs_full_tree(&self) -> bool

Clear the flag above, reporting what it was.

Source

pub fn accessibility_active(&self) -> bool

Whether an AccessKit client is attached to this window’s adapter.

True from the moment the platform accessibility stack asks for an initial tree until it says it has gone away. Read once per frame by teksilo-app and pushed into the window’s tree; see WidgetTree::set_at_client_attached for why attaching and detaching are read asymmetrically.

Always false for a window built without an adapter (PlatformWindow::new).

Source

pub fn process_accessibility_event(&mut self, event: &WindowEvent)

Forward a winit WindowEvent to the AccessKit adapter.

Source

pub fn redraw_waker(&self) -> Arc<dyn RedrawWaker> ⓘ

This window’s wake target, as a waker any thread may call to have the window run a frame. See teksilo_canvas::wake for the two kinds of wake and how a burst coalesces.

On macOS, winit runs a redraw requested off the main thread synchronously on it, so a draw wake made on another thread never asks winit itself there: it posts through the off-main route (set_off_main_wake_route), which teksilo-app installs, or with none hands the request to the main dispatch queue. Either way it returns without waiting for the main thread.

Source

pub fn set_off_main_wake_route(&self, route: Arc<dyn Fn() + Send + Sync>)

The route a draw wake made off the main thread posts through, instead of asking winit for a redraw from there. Set once, before the first wake; later calls are ignored. teksilo-app sets it on macOS, where a redraw requested off the main thread waits for it, so that the wake reaches the event loop it runs.

Source

pub fn disconnect_redraw_waker(&self)

Make every waker redraw_waker handed out a no-op, and request_redraw with them. Waits for a wake already asking winit; idempotent. Dropping the window does it too; teksilo-app does it for every window when the event loop ends.

Source

pub fn set_hidden(&self, hidden: bool)

Record whether the window is hidden (minimised, fully covered, or drawing nothing because its compositor withholds its frames). While it is, draw wakes are dropped; showing it requests one redraw if any was.

Source

pub fn is_hidden(&self) -> bool

Whether the window is hidden, as last set.

Source

pub fn live_wake_stats(&self) -> LiveWakeStats

The window’s wake counters.

Source

pub fn drain_accessibility_actions(&self) -> Vec<ActionRequest>

Drain any pending AccessKit action requests from the adapter.

They name nodes by the ids the adapter was handed; pass each through WidgetTree::resolve_adapter_action before looking its target up in the tree.

Trait Implementations§

Source§

impl Drop for PlatformWindow

Source§

fn drop(&mut self)

Disconnect the wake target first: a waker another thread still holds must not reach a window that is going away.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more