pub struct Renderer { /* private fields */ }Expand description
Draws a map’s updates into the frames of one backend’s Gpu: it keeps
the map’s sources, tiles and layers between frames, and the GPU objects
they draw with.
The renderer holds no Gpu. Each call that makes, draws or frees its GPU
objects takes the one it was made for, which its host lends it, as it
does to the target that the renderer draws into. A frame runs in the
host, with one Gpu lent to all of it:
let frame = renderer.update(gpu, &update)?;
let image = target.begin_frame(gpu)?;
let drawn = renderer.render(gpu, &image, frame);
let handoff = target.end_frame(gpu);
renderer.finish_frame(gpu, drawn, handoff);tear_down frees the renderer’s GPU objects. A
renderer dropped without it leaves them to the Gpu, which frees them
when it drops, and its custom layers’ hosts hear that their graphics
objects are lost.
Implementations§
Source§impl Renderer
impl Renderer
Sourcepub fn new(
gpu: &dyn Gpu,
pixel_ratio: f32,
local_glyphs: LocalGlyphs,
waker: Waker,
pool: &Pool,
) -> Self
pub fn new( gpu: &dyn Gpu, pixel_ratio: f32, local_glyphs: LocalGlyphs, waker: Waker, pool: &Pool, ) -> Self
A renderer with a glyph cache of its own, which runs its background
work on pool and draws local_glyphs. Its chooser of the device’s
fonts runs there too, one choice at a time, never on the thread that
calls the renderer.
waker runs, on any thread, when something the renderer waits for
arrives, such as a tile’s data or a font engine that got ready: the
host asks the renderer’s map for an update for it, as by pushing
RendererEvent::Invalidate to the queue the renderer reports to
(set_event_queue). It must not call the
renderer.
The renderer draws with gpu and only with it: every later call
that takes a Gpu takes this one.
Sourcepub fn with_glyph_cache(
gpu: &dyn Gpu,
pixel_ratio: f32,
local_glyphs: LocalGlyphs,
glyph_cache: Arc<GlyphCache>,
waker: Waker,
pool: &Pool,
) -> Self
pub fn with_glyph_cache( gpu: &dyn Gpu, pixel_ratio: f32, local_glyphs: LocalGlyphs, glyph_cache: Arc<GlyphCache>, waker: Waker, pool: &Pool, ) -> Self
A renderer that uses glyph_cache: renderers given the same
GlyphCache share the glyphs they parse from glyph PBFs.
Sourcepub fn with_fonts(
gpu: &dyn Gpu,
pixel_ratio: f32,
local_glyphs: LocalGlyphs,
glyph_cache: Arc<GlyphCache>,
font_face_engine: Arc<dyn FontFaceEngine>,
registry: Arc<Registry>,
waker: Waker,
pool: &Pool,
) -> Self
pub fn with_fonts( gpu: &dyn Gpu, pixel_ratio: f32, local_glyphs: LocalGlyphs, glyph_cache: Arc<GlyphCache>, font_face_engine: Arc<dyn FontFaceEngine>, registry: Arc<Registry>, waker: Waker, pool: &Pool, ) -> Self
A renderer that uses glyph_cache, loads the font files of a style’s
font faces with font_face_engine instead of
font_face_engine::default_engine(), and draws the layer types of
registry instead of the built-in ones.
The map that the renderer draws must have a registry filled by the
same calls: a layer whose type registry lacks isn’t drawn.
Sourcepub fn set_pixel_ratio(&mut self, pixel_ratio: f32)
pub fn set_pixel_ratio(&mut self, pixel_ratio: f32)
Draws at pixel_ratio device pixels per logical pixel from the next
frame on, which should be the map’s (Map::set_pixel_ratio). The
renderer makes its shaders and draws again, frees the ones they
replace, and keeps its tiles. The host sizes the backend’s
framebuffer for the new ratio.
Sourcepub fn pixel_ratio(&self) -> f32
pub fn pixel_ratio(&self) -> f32
The device pixels per logical pixel the renderer draws at.
Sourcepub fn set_tile_workers(&mut self, workers: RemoteWorkers)
pub fn set_tile_workers(&mut self, workers: RemoteWorkers)
Runs the tiles’ jobs, and the raster tiles’ workers, in
workers (by default on the renderer’s pool). Set it before the
first render so that every tile uses it.
Sourcepub fn receive_tiles(&mut self)
pub fn receive_tiles(&mut self)
Takes in what arrived for the tiles since the last frame (their data, their jobs’ replies, glyphs) and starts the jobs it makes ready. Each frame does this first; a host that draws frames on a clock calls it as soon as the renderer asks for an update, so that the tiles’ work doesn’t wait for the next frame to start.
Sourcepub fn set_event_queue(&mut self, events: Option<RendererEvents>)
pub fn set_event_queue(&mut self, events: Option<RendererEvents>)
Sets the queue the renderer pushes its events to: the map’s, which the map’s frontend passes on.
Sourcepub fn update(
&mut self,
gpu: &mut dyn Gpu,
update_parameters: &Arc<UpdateParameters>,
) -> Option<UpdatedFrame>
pub fn update( &mut self, gpu: &mut dyn Gpu, update_parameters: &Arc<UpdateParameters>, ) -> Option<UpdatedFrame>
Brings the renderer’s state to update_parameters: its style,
sources, tiles, layers and placement. Returns the frame to draw,
which the host renders into a frame of its target,
or None when there is nothing to draw: a still image that hasn’t
loaded yet. Custom layers that the update removed or gave a new host
end on gpu.
Sourcepub fn render(
&mut self,
gpu: &mut dyn Gpu,
image: &FrameImage,
frame: UpdatedFrame,
) -> DrawnFrame
pub fn render( &mut self, gpu: &mut dyn Gpu, image: &FrameImage, frame: UpdatedFrame, ) -> DrawnFrame
Draws frame, which the last update returned, into
image, textures of gpu that the host’s target began a frame with,
and submits the frame’s passes. Returns the frame, which the host
ends on its target, whether or not it failed (DrawnFrame::error),
and then finishes.
Sourcepub fn finish_frame(
&mut self,
gpu: &mut dyn Gpu,
frame: DrawnFrame,
handoff: Handoff,
)
pub fn finish_frame( &mut self, gpu: &mut dyn Gpu, frame: DrawnFrame, handoff: Handoff, )
Ends frame, which render drew, once the host’s
target handed it off as handoff: destroys what the frame replaced
and reports the frame with its rendering stats, and with its error
if it failed.
Sourcepub fn drop_on_workers<T: Send + 'static>(&self, value: T)
pub fn drop_on_workers<T: Send + 'static>(&self, value: T)
Drops value on the renderer’s workers instead of this
thread, for data that would take a frame long to free, such as the
sources of an earlier update. The renderer’s drop waits for it.
Sourcepub fn render_timings(&self) -> RenderTimings
pub fn render_timings(&self) -> RenderTimings
What the last frame that render drew
spent on each of its steps.
Sourcepub fn frame_projection(&self) -> Option<FrameProjection>
pub fn frame_projection(&self) -> Option<FrameProjection>
Where the last frame that render drew put the map,
or None before the first.
Sourcepub fn query_rendered_features(
&mut self,
geometry: &[ScreenCoordinate],
options: &RenderedQueryOptions,
) -> Result<Vec<Feature>, Error>
pub fn query_rendered_features( &mut self, geometry: &[ScreenCoordinate], options: &RenderedQueryOptions, ) -> Result<Vec<Feature>, Error>
The features drawn in geometry, a point or a polygon in screen
coordinates. Err for a malformed tile.
pub fn query_rendered_features_at_point( &mut self, point: &ScreenCoordinate, options: &RenderedQueryOptions, ) -> Result<Vec<Feature>, Error>
pub fn query_rendered_features_in_box( &mut self, min: &ScreenCoordinate, max: &ScreenCoordinate, options: &RenderedQueryOptions, ) -> Result<Vec<Feature>, Error>
pub fn query_source_features( &mut self, source_id: &str, options: &SourceQueryOptions, ) -> Result<Vec<Feature>, Error>
Sourcepub fn query_feature_extensions(
&self,
source_id: &str,
feature: &Feature,
extension: &str,
extension_field: &str,
args: Option<&PropertyMap>,
) -> Result<FeatureExtensionValue, Error>
pub fn query_feature_extensions( &self, source_id: &str, feature: &Feature, extension: &str, extension_field: &str, args: Option<&PropertyMap>, ) -> Result<FeatureExtensionValue, Error>
Queries a feature extension: for a GeoJSON source with cluster on,
the “supercluster” extension’s “children”, “leaves” or
“expansion-zoom” of a cluster feature (one with a cluster_id
property). Anything else is a null value. Err for a cluster ID the
source doesn’t have.
Sourcepub fn placed_symbols_data(&self) -> Vec<PlacedSymbolData>
pub fn placed_symbols_data(&self) -> Vec<PlacedSymbolData>
The data of the symbols the last placement placed, when
collect_placed_symbol_data
turned their collection on.
Sourcepub fn dump_debug_logs(&self)
pub fn dump_debug_logs(&self)
Logs every render source’s tiles and the image manager’s state.
Sourcepub fn set_feature_state(
&mut self,
source_id: &str,
source_layer_id: Option<&str>,
feature_id: &str,
state: &FeatureState,
)
pub fn set_feature_state( &mut self, source_id: &str, source_layer_id: Option<&str>, feature_id: &str, state: &FeatureState, )
Merges state into a feature’s state.
An update whose feature state for the source differs from the last
update’s replaces the source’s state with the update’s, undoing what
this and remove_feature_state did. A
renderer that a map drives takes its state from the map’s
set_feature_state.
Sourcepub fn feature_state(
&self,
source_id: &str,
source_layer_id: Option<&str>,
feature_id: &str,
) -> FeatureState
pub fn feature_state( &self, source_id: &str, source_layer_id: Option<&str>, feature_id: &str, ) -> FeatureState
The state of a feature.
Sourcepub fn remove_feature_state(
&mut self,
source_id: &str,
source_layer_id: Option<&str>,
feature_id: Option<&str>,
state_key: Option<&str>,
)
pub fn remove_feature_state( &mut self, source_id: &str, source_layer_id: Option<&str>, feature_id: Option<&str>, state_key: Option<&str>, )
Removes a key of a feature’s state, a feature’s whole state, or a
source layer’s. An update replaces the source’s state as it does for
set_feature_state.
pub fn collect_placed_symbol_data(&mut self, enable: bool)
pub fn set_tile_cache_enabled(&mut self, enable: bool)
Sourcepub fn tile_cache_enabled(&self) -> bool
pub fn tile_cache_enabled(&self) -> bool
Whether the renderer keeps tiles that left the view, to show them again without loading them.
Sourcepub fn lose_custom_layers(&mut self)
pub fn lose_custom_layers(&mut self)
Tells the hosts of the custom layers that the renderer’s graphics objects are lost, so that they forget theirs, and lets go of them. Call it before the renderer goes when its device or target went first.
Sourcepub fn reduce_memory_use(&mut self, gpu: &mut dyn Gpu)
pub fn reduce_memory_use(&mut self, gpu: &mut dyn Gpu)
Lets go of what the orchestrator caches, destroys what it and the
renderer released, and waits for gpu, so that its work finishes
before the app goes to the background.
Sourcepub fn rendering_stats(&self) -> RenderingStats
pub fn rendering_stats(&self) -> RenderingStats
The rendering stats, which count the renderer’s resources until it
destroys them: a buffer or texture counts until the end of the frame
that follows its release, or until
reduce_memory_use.
Sourcepub fn clear_data(&mut self, gpu: &mut dyn Gpu)
pub fn clear_data(&mut self, gpu: &mut dyn Gpu)
Lets go of the map’s data: its sources, tiles and layers, which the
next update loads again. The custom layers that go hear through
gpu that the renderer stopped.
Sourcepub fn tear_down(self, gpu: &mut dyn Gpu) -> RenderingStats
pub fn tear_down(self, gpu: &mut dyn Gpu) -> RenderingStats
Destroys the renderer’s GPU objects on gpu, and tells its custom
layers’ hosts that it stopped. Returns its rendering stats as it
leaves them, with all its resources released.
Auto Trait Implementations§
impl !Freeze for Renderer
impl !RefUnwindSafe for Renderer
impl !Send for Renderer
impl !Sync for Renderer
impl !UnwindSafe for Renderer
impl Forget for Renderer
impl Move for Renderer
impl Unpin for Renderer
impl UnsafeUnpin for Renderer
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<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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§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.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.