pub struct RenderSession { /* private fields */ }Expand description
A render session: a renderer that draws a map into a target, on a thread of its own or on the host’s.
The host demands frames, which finish with FrameResults that
drain_frame_results takes. A demand shows
the map’s commands sent before it, except the changes that an open
command group holds back. The session’s work runs on its thread in the
order it was sent, and reports through a Completion. Clone is
another handle to the same session, and any thread may use one.
A session that attached with Driver::CallerThread runs its work only
when the host services its DriverWork, which
take_driver_work hands out.
The session lives until detach,
release, dispose or
abandon, or until its last handle drops, and it holds
its map until then. A call that sends work to a session that no longer
takes it fails with ErrorKind::InvalidState, or
with the failure of a session that failed.
Implementations§
Source§impl RenderSession
impl RenderSession
Sourcepub fn take_driver_work(&self) -> Result<DriverWork, Error>
pub fn take_driver_work(&self) -> Result<DriverWork, Error>
Hands out the work of a Driver::CallerThread session, for the
calling thread to run: the session’s graphics work runs only in its
service, and on no other thread.
Take it once, on the host’s graphics thread, from the attach on: the attach itself completes in a service. It stays available after a release, which the host services to its end.
Fails with ErrorKind::Unsupported for a
session on a core worker, and with
ErrorKind::InvalidState once it was taken.
Sourcepub fn capabilities(&self) -> Result<RenderSessionCapabilities, Error>
pub fn capabilities(&self) -> Result<RenderSessionCapabilities, Error>
What the session can do. Fails with
ErrorKind::InvalidState once it is released.
Sourcepub fn snapshot(&self) -> Result<RenderSessionSnapshot, Error>
pub fn snapshot(&self) -> Result<RenderSessionSnapshot, Error>
The session’s state now. Fails with
ErrorKind::InvalidState once it is released.
Sourcepub fn acquire_frame(&self) -> Result<Option<AcquiredFrame>, Error>
pub fn acquire_frame(&self) -> Result<Option<AcquiredFrame>, Error>
Takes the newest frame that a borrowed ring rendered, if one waits: the older frames that the host didn’t acquire are dropped, and the session may render into their textures again. While the host holds a frame in every texture, demands wait for a release.
Fails with ErrorKind::Unsupported for a
session without a ring, and as a call that sends work does once the
session no longer takes work.
Sourcepub fn set_ring(
&self,
size: Size,
ring: BorrowedRing,
) -> Result<Completion<Applied>, Error>
pub fn set_ring( &self, size: Size, ring: BorrowedRing, ) -> Result<Completion<Applied>, Error>
Gives a borrowed ring new textures, of size logical pixels: as many
as it has, of its format. Once the completion reports success, the
session no longer uses the old textures, and no longer waits for the
consumer sync that they were given back with: the host may reuse or
destroy them. The session’s thread polls that sync on its later turns,
for a second at most, and logs a wait that runs out. Frames wait for
it meanwhile.
Fails with ErrorKind::Unsupported for a
session without a borrowed ring, with
ErrorKind::InvalidArgument for another number
of textures, and with ErrorKind::InvalidState
while the host holds one of the ring’s frames. Completes with
ErrorKind::Unsupported for textures of
another format or kind.
Sourcepub fn demand_frame(&self, demand: FrameDemand) -> Result<(), Error>
pub fn demand_frame(&self, demand: FrameDemand) -> Result<(), Error>
Asks the session to render a frame, which shows the map commands sent before the call, except the changes that an open command group holds back. A demand sent while the session attaches waits for it.
Every demand finishes with one FrameResult that carries its token.
A demand that isn’t DemandMode::Force
replaces the demands with the same mode still on their way, which
finish as FrameDisposition::Superseded.
While the session has no target, or a surface has no texture to
render into, a demand finishes as
FrameDisposition::TargetNotReady.
Sourcepub fn drain_frame_results(&self) -> Result<Vec<FrameResult>, Error>
pub fn drain_frame_results(&self) -> Result<Vec<FrameResult>, Error>
Takes the frame results that wait, oldest first. Fails with
ErrorKind::InvalidState once the session is
released.
Sourcepub fn resize(
&self,
extent: LogicalExtent,
) -> Result<Completion<Applied>, Error>
pub fn resize( &self, extent: LogicalExtent, ) -> Result<Completion<Applied>, Error>
Resizes the target, and the map with it, to extent’s size in
logical pixels, and sets the map’s scale factor to extent’s, such
as when a window moves to a display of another density. The map keeps
its tiles, and the renderer draws the next frame at the new scale
factor. A later demand shows the new extent, and one sent before
shows the old. An exported ring gets images of the new size, and the
frames that the host holds keep theirs until it gives them back.
Fails with ErrorKind::InvalidArgument for an
empty size, or a scale factor that isn’t finite and positive, and
with ErrorKind::Unsupported for a borrowed
ring, which set_ring resizes.
Sourcepub fn release_target(&self) -> Result<Completion<()>, Error>
pub fn release_target(&self) -> Result<Completion<()>, Error>
Lets go of a surface session’s surface, and keeps the rest of the
session, such as when the platform takes the window away. The demands
on their way, and later ones until
set_surface gives the session a surface again,
finish as FrameDisposition::TargetNotReady.
Once the release completes, the session no longer uses the surface or
the window it was made from, or a ring’s textures, and no longer waits
for the consumer sync that the textures were given back with: the host
may reuse or destroy them. The session’s thread polls that sync on its
later turns, for a second at most, and logs a wait that runs out. The
session keeps nothing of the released textures: one that a later ring
has again starts fresh, even one that the host gave up.
Fails with ErrorKind::Unsupported for an
offscreen session or an exported ring, whose targets are their own.
Sourcepub fn set_surface(
&self,
size: Size,
surface: Surface,
) -> Result<Completion<Applied>, Error>
pub fn set_surface( &self, size: Size, surface: Surface, ) -> Result<Completion<Applied>, Error>
Gives a surface session a new surface of size logical pixels, after
release_target, or in place of the one it
has, and resizes the map to it. Once the completion reports success,
the session no longer uses the old surface. The session presents to
it on its device: a window becomes a surface of the device’s backend,
and a Surface::wgpu must come from the instance of a WebGPU
device. Where the backend made for the old surface can’t present to
the new one, as OpenGL ES’s context can’t to another window, the
session makes its backend and renderer again.
Fails with ErrorKind::InvalidArgument for an
empty size, with ErrorKind::Unsupported for
an offscreen session, and with
ErrorKind::InvalidState for a window that is
minimized or has no client area. Completes with
ErrorKind::Unsupported when the session’s
device can’t present to the surface in the format that the session
renders in: attach a new session instead. Completes with
ErrorKind::InvalidState when the window had no
area to present to by then. The session then keeps the surface it had,
at the new size.
Sourcepub fn barrier(&self) -> Result<Completion<()>, Error>
pub fn barrier(&self) -> Result<Completion<()>, Error>
Ends the frame demands on their way, including those that wait for a
map update, which finish as
FrameDisposition::NoUpdate, and completes
once the work sent before it has run.
Sourcepub fn reduce_memory_use(&self) -> Result<Completion<()>, Error>
pub fn reduce_memory_use(&self) -> Result<Completion<()>, Error>
Frees memory that the renderer can rebuild, such as caches.
Sourcepub fn clear_data(&self) -> Result<Completion<()>, Error>
pub fn clear_data(&self) -> Result<Completion<()>, Error>
Clears what the renderer holds, such as loaded tiles, so that the next frame loads and draws the map again.
Sourcepub fn dump_debug_logs(&self) -> Result<Completion<()>, Error>
pub fn dump_debug_logs(&self) -> Result<Completion<()>, Error>
Logs the renderer’s sources and tiles.
Sourcepub fn read_texture(&self) -> Result<Completion<PremultipliedImage>, Error>
pub fn read_texture(&self) -> Result<Completion<PremultipliedImage>, Error>
The pixels of the last frame that an offscreen session rendered: premultiplied RGBA, in rows from top to bottom, at the target’s size in pixels.
Fails with ErrorKind::Unsupported for a
surface session. Completes with
ErrorKind::InvalidState when the session
hasn’t rendered a frame since it attached or resized.
Sourcepub fn query_rendered_features(
&self,
geometry: RenderedQueryGeometry,
options: RenderedQueryOptions,
) -> Result<Completion<Vec<Feature>>, Error>
pub fn query_rendered_features( &self, geometry: RenderedQueryGeometry, options: RenderedQueryOptions, ) -> Result<Completion<Vec<Feature>>, Error>
The features that the session drew in an area of the screen, in its last frame. A feature that several layers draw appears once for each. A box covers only its part inside the target, so one past every edge covers the whole target.
Fails with ErrorKind::InvalidArgument for a
point that isn’t finite or a line string without points.
Sourcepub fn query_source_features(
&self,
source_id: impl Into<String>,
options: SourceQueryOptions,
) -> Result<Completion<Vec<Feature>>, Error>
pub fn query_source_features( &self, source_id: impl Into<String>, options: SourceQueryOptions, ) -> Result<Completion<Vec<Feature>>, Error>
The features of the source source_id in the tiles that it loaded
for the current view. A source loads tiles only while a visible layer
uses it.
Fails with ErrorKind::InvalidArgument for an
empty source_id.
Sourcepub fn cluster_children(
&self,
source_id: impl Into<String>,
cluster_id: u32,
) -> Result<Completion<Vec<Feature<f64>>>, Error>
pub fn cluster_children( &self, source_id: impl Into<String>, cluster_id: u32, ) -> Result<Completion<Vec<Feature<f64>>>, Error>
The clusters and points that a cluster of a clustered GeoJSON source
splits into at the next zoom level. cluster_id is a cluster
feature’s cluster_id property.
The query reads the source as the session’s most recent render attempt had it. A cluster ID belongs to one version of the source’s data, so query the features again after the data changes.
Completes with ErrorKind::NotFound when that
render had no source source_id, or the source has no cluster
cluster_id, and with ErrorKind::InvalidArgument
when the source isn’t a clustered GeoJSON source.
Sourcepub fn cluster_leaves(
&self,
source_id: impl Into<String>,
cluster_id: u32,
limit: u32,
offset: u32,
) -> Result<Completion<Vec<Feature<f64>>>, Error>
pub fn cluster_leaves( &self, source_id: impl Into<String>, cluster_id: u32, limit: u32, offset: u32, ) -> Result<Completion<Vec<Feature<f64>>>, Error>
The points in a cluster of a clustered GeoJSON source: it skips the
first offset, then holds up to limit. It fails as
cluster_children does.
Sourcepub fn cluster_expansion_zoom(
&self,
source_id: impl Into<String>,
cluster_id: u32,
) -> Result<Completion<u8>, Error>
pub fn cluster_expansion_zoom( &self, source_id: impl Into<String>, cluster_id: u32, ) -> Result<Completion<u8>, Error>
The zoom level at which a cluster of a clustered GeoJSON source splits
into two or more clusters or points. It fails as
cluster_children does.
Sourcepub fn detach(&self) -> Result<Completion<()>, Error>
pub fn detach(&self) -> Result<Completion<()>, Error>
Detaches the session from its map and frees its graphics objects. The
demands on their way finish as
FrameDisposition::TargetNotReady. Once
the detach completes, another session can attach to the map.
Sourcepub fn abandon(&self) -> Result<(), Error>
pub fn abandon(&self) -> Result<(), Error>
Stops the session at once, without its pending graphics work: that
work completes with ErrorKind::TargetLost
before this returns, and the demands on their way finish as
FrameDisposition::TargetNotReady. Once it
returns, the session renders no more, and another session can attach
to the map. Release the session afterward.
A caller-driven session lets go of its graphics objects on the host’s
thread, at its next service or when its DriverWork drops.
It waits for a frame that the session is rendering. Fails with
ErrorKind::Busy on the session’s own thread
while that runs, and with ErrorKind::InvalidState
once the session is detached, abandoned or released.
Sourcepub fn abandon_keeping_graphics(&self) -> Result<u32, Error>
pub fn abandon_keeping_graphics(&self) -> Result<u32, Error>
Abandons the session as abandon does, but makes no
graphics call: the session keeps its graphics objects until the
process exits. Returns how many it keeps, such as its renderer and
the backend it draws with.
This is for a host whose shutdown may already have destroyed the graphics objects behind the session.
Sourcepub fn release(&self) -> Result<Completion<()>, Error>
pub fn release(&self) -> Result<Completion<()>, Error>
Releases the session, detaching it first when it is attached. The
completion reports when the session has let go of its map and its
graphics objects. Every call on the session fails with
ErrorKind::InvalidState after.
A caller-driven session detaches at the host’s next service, so keep servicing it until the release completes. One that isn’t attached, such as while it attaches or after it failed, is abandoned instead, and so is one whose map is released before that service.
Sourcepub fn dispose(&self) -> Result<(), Error>
pub fn dispose(&self) -> Result<(), Error>
Releases the session in any state, without waiting. Dropping the last handle does the same.
Sourcepub fn dispose_keeping_graphics(&self) -> Result<(), Error>
pub fn dispose_keeping_graphics(&self) -> Result<(), Error>
Releases the session in any state, without waiting and without a
graphics call past the one in progress. A session that hasn’t ended
is abandoned, keeping its graphics objects until the process exits,
as abandon_keeping_graphics does.
Trait Implementations§
Source§impl Clone for RenderSession
impl Clone for RenderSession
Source§impl Debug for RenderSession
impl Debug for RenderSession
impl Eq for RenderSession
Auto Trait Implementations§
impl !RefUnwindSafe for RenderSession
impl !UnwindSafe for RenderSession
impl Forget for RenderSession
impl Freeze for RenderSession
impl Move for RenderSession
impl Send for RenderSession
impl Sync for RenderSession
impl Unpin for RenderSession
impl UnsafeUnpin for RenderSession
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.