pub struct Resources { /* private fields */ }Expand description
One session’s registry. The maps are secondary to the process-wide the process-wide mint (see the module doc), so a lookup that misses is a handle this session never registered or has since removed — never somebody else’s entry.
Implementations§
Source§impl Resources
impl Resources
Sourcepub fn new(session: SessionId) -> Resources
pub fn new(session: SessionId) -> Resources
The registry for session session; keys come from the process’s
mint.
Sourcepub fn font_family(&self, id: FontId) -> Option<&str>
pub fn font_family(&self, id: FontId) -> Option<&str>
The registered family name, if the handle is live here.
pub fn add_image(&mut self, width: u32, height: u32, rgba: Vec<u8>) -> ImageId
Sourcepub fn update_image(
&mut self,
id: ImageId,
width: u32,
height: u32,
rgba: Vec<u8>,
) -> bool
pub fn update_image( &mut self, id: ImageId, width: u32, height: u32, rgba: Vec<u8>, ) -> bool
Replaces an image’s pixels in place: the
handle is unchanged, so every node declaring it shows the new
pixels next frame with no view change; the dimensions may change.
From the first update on the image is texture-backed for life.
Returns whether the pixels were taken: false for a foreign or
removed handle (noted as a miss), and for a buffer that is not
width × height × 4 bytes, which changes nothing rather than
handing a backend a short upload it would refuse with a validation
error — the doors that take bytes from an app check the length
first and say so; this is the guard behind them.
Sourcepub fn update_image_with(
&mut self,
id: ImageId,
width: u32,
height: u32,
fill: impl FnOnce(&mut [u8]),
) -> bool
pub fn update_image_with( &mut self, id: ImageId, width: u32, height: u32, fill: impl FnOnce(&mut [u8]), ) -> bool
Self::update_image into a buffer the core recycles: fill is
handed width × height × 4 bytes to write the new pixels into, and
is not called for a foreign or removed handle (noted as a miss),
or for a size whose byte count overflows. The bytes it is handed
hold an earlier frame’s pixels, not zeros, so fill writes every
one. The buffer is the image’s own when no display list still
holds it, else the one the previous update replaced, else a new
one — so a stream updated every frame, between frames or inside
them, allocates at most three times and then never again. The replaced
buffer is kept only for an image updated before
at the same size, and let go SPARE_FRAMES frames after the
last update. What every door that copies an app’s bytes goes
through.
pub fn remove_image(&mut self, id: ImageId) -> Option<ImageEntry>
Sourcepub fn image(&self, id: ImageId) -> Option<&ImageEntry>
pub fn image(&self, id: ImageId) -> Option<&ImageEntry>
The pixels behind an image handle, if it is live here.
Sourcepub fn fragment(&self, id: FragmentId) -> Option<&Arc<str>>
pub fn fragment(&self, id: FragmentId) -> Option<&Arc<str>>
The WGSL behind a fragment handle, if it is live here. A miss is what makes the node draw nothing, and records a foreign handle.
Sourcepub fn add_sound(&mut self, bytes: Vec<u8>) -> SoundId
pub fn add_sound(&mut self, bytes: Vec<u8>) -> SoundId
Registers a sound from its encoded file bytes.
pub fn remove_sound(&mut self, id: SoundId) -> Option<SoundEntry>
Sourcepub fn has_sounds(&self) -> bool
pub fn has_sounds(&self) -> bool
Whether any sound is registered: what tells an audio backend it will be asked to play something, before it is.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Resources
impl !RefUnwindSafe for Resources
impl !Sync for Resources
impl Send for Resources
impl Unpin for Resources
impl UnsafeUnpin for Resources
impl UnwindSafe for Resources
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.