pub struct SurfaceCapture {
pub request: Arc<AtomicBool>,
pub store: Arc<Mutex<Option<SurfaceFrame>>>,
pub waker: Arc<OnceLock<EventLoopWaker>>,
}Expand description
Coordination handle for on-screen surface screenshots, inserted as a Resource into both worlds.
- The render backend inspects
Self::is_requestedeach frame; when set, it performs a GPU->CPU readback, writes the result viaSelf::write, and clears the flag. - Both fields are
Arc-wrapped (Send + Sync) so MCP-server worker threads can clone the handle and read filled frames.
Fields§
§request: Arc<AtomicBool>One-shot capture request flag; the renderer clears it after writing.
store: Arc<Mutex<Option<SurfaceFrame>>>Latest captured frame; the renderer replaces it wholesale.
waker: Arc<OnceLock<EventLoopWaker>>Optional handle to interrupt a parked platform event loop. The
windowed backend wires this in crate::app::EventLoopWaker via
Self::set_waker once its event-loop proxy exists; Self::request
then nudges the loop so a screenshot request from the off-thread MCP
server is serviced promptly instead of waiting for an unrelated OS
event (the redraw scheduler otherwise leaves the loop parked, so the
capture never runs and the request times out - the “no SurfaceCapture
wired” failure). Shared Arc<OnceLock> so every clone - including the
server thread’s - observes a waker set on any one of them.
Implementations§
Source§impl SurfaceCapture
impl SurfaceCapture
Sourcepub fn is_requested(&self) -> bool
pub fn is_requested(&self) -> bool
Returns true while a capture has been requested but not yet fulfilled.
Sourcepub fn set_waker(&self, waker: EventLoopWaker)
pub fn set_waker(&self, waker: EventLoopWaker)
Installs the platform event-loop waker. First write wins
(OnceLock); later calls are ignored. Idempotent and thread-safe.
Sourcepub fn request(&self)
pub fn request(&self)
Sets the request flag with Release ordering, then nudges the
platform event loop (if Self::set_waker wired one) so a parked
windowed backend wakes to service the readback this frame instead of
sitting idle until the request times out. Idempotent.
Sourcepub fn clear_request(&self)
pub fn clear_request(&self)
Clears the request flag with Release ordering.
Sourcepub fn write(&self, frame: SurfaceFrame)
pub fn write(&self, frame: SurfaceFrame)
Replaces the stored frame with frame.
Sourcepub fn read(&self) -> Option<SurfaceFrame>
pub fn read(&self) -> Option<SurfaceFrame>
Returns a clone of the latest stored frame, if any.
Trait Implementations§
Source§impl Clone for SurfaceCapture
impl Clone for SurfaceCapture
Source§fn clone(&self) -> SurfaceCapture
fn clone(&self) -> SurfaceCapture
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Component for SurfaceCapture
impl Component for SurfaceCapture
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::SparseSet
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::SparseSet
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>,
while immutable components will instead have Component<Mutability = Immutable>. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
ComponentRelationshipAccessor] required for working with relationships in dynamic contexts. Read more§fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
EntityMapper. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component, this is populated by annotating fields containing entities with #[entities] Read moreSource§impl Default for SurfaceCapture
impl Default for SurfaceCapture
Source§fn default() -> SurfaceCapture
fn default() -> SurfaceCapture
impl Resource for SurfaceCapture
Auto Trait Implementations§
impl Freeze for SurfaceCapture
impl !RefUnwindSafe for SurfaceCapture
impl Send for SurfaceCapture
impl Sync for SurfaceCapture
impl Unpin for SurfaceCapture
impl UnsafeUnpin for SurfaceCapture
impl !UnwindSafe for SurfaceCapture
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
§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
§unsafe fn get_components(
ptr: MovingPtr<'_, C>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
) -> <C as DynamicBundle>::Effect
unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
§unsafe fn apply_effect(
_ptr: MovingPtr<'_, MaybeUninit<C>>,
_entity: &mut EntityWorldMut<'_>,
)
unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )
§impl<T> FromTemplate for T
impl<T> FromTemplate for T
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
§impl<T> Template for T
impl<T> Template for T
§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
entity context to produce a Template::Output.§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clone.