Expand description
Surface lifecycle state machine.
Android destroys and recreates the GPU surface on rotation and
backgrounding — wgpu surfaces raise ERROR_SURFACE_LOST_KHR and panic on
configure-after-resume if this is handled ad hoc. Frust therefore makes
surface state a first-class machine, driven by the platform shells’
surfaceCreated/surfaceChanged/surfaceDestroyed callbacks (Android) and
resumed/Resized/suspended events (desktop).
This module holds only the decisions and the two raw-pointer surface constructors; the renderer that owns the swapchain texture and drives them lives a layer above, so everything here is host-testable with no GPU and no window server in the loop.
§States
on_surface_created acquire == Lost
NoSurface ───────────────▶ SurfaceReady ──────────────────▶ SurfaceLost
▲ on_surface_destroyed │ ▲ on_surface_changed │
└───────────────────────┘ └── (resize, stays Ready) │
▲ on_surface_destroyed │
└──────────────────────────────────────────────────────────┘
on_surface_created (recreate)§Invariants the driving renderer must uphold
- No
SurfaceTextureoutlives a surface transition: a render call acquires and presents within a single call and stores nothing across one. Surface::configureruns only fromSurfacePhase::SurfaceReady(on entry viaon_surface_created/on_surface_changed, or on anOutdatedacquire).- Frame requests in
SurfacePhase::NoSurface/SurfacePhase::SurfaceLostare dropped — the render call reportsFrameOutcome::Skipped, never panicking and never queueing.
The pure decision logic (next_phase, SurfacePhase::can_render,
decide_acquire, next_invalid_streak) is separated from the wgpu
calls so it is unit-testable without a GPU.
Enums§
- Acquire
Action - What the renderer should do after an acquire attempt.
- Acquire
Outcome - The outcome of a single acquire call — the first half of the two-phase present seam (acquire + submit), itself the second phase of the render pipeline after encode.
- Acquire
Status wgpu-independent classification of a swapchain-acquire attempt.- Encode
Outcome - The outcome of a single encode call — the first phase of the two-phase render seam (encode + present).
- Frame
Outcome - The outcome of a single render call.
- Surface
Event - A platform lifecycle event that drives a phase transition.
- Surface
Phase - Which lifecycle state the surface is in.
Constants§
- MAX_
INVALID_ RECONFIGURES - Cap on consecutive
Invalid-acquire reconfigure retries before the machine gives up and transitions toSurfacePhase::SurfaceLost.
Functions§
- create_
android_ ⚠surface - Builds a
wgpu::Surfacefrom a rawANativeWindowpointer. - decide_
acquire - Pure acquire-error policy.
- next_
invalid_ streak - Given the just-observed acquire
statusand theAcquireActiondecide_acquirechose for it, returns the next consecutive-Invalidstreak count the renderer should store. - next_
phase - Pure phase-transition table.