1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! What a renderer reports to the map it renders: frames, resource errors,
//! missing images, glyph and tile activity. The renderer pushes the events
//! into the map's [`RendererEvents`] queue, and the map handles them when it
//! drains the queue.
use std::sync::Arc;
pub use mln_gfx::rendering_stats::RenderingStats;
use mln_style::error::Error;
use mln_style::time::Instant;
use crate::camera::Elevation;
use crate::exec::event_queue::EventQueue;
pub use crate::text::font_stack::FontStack;
pub use crate::text::glyph::GlyphRange;
use crate::tile::OverscaledTileID;
pub use crate::tile_store::TileOperation;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum RenderMode {
Partial,
Full,
}
/// An event of a renderer.
#[derive(Clone, Debug)]
pub enum RendererEvent {
/// The renderer needs a new frame, as when a tile arrived.
Invalidate,
/// A resource failed to load or parse.
ResourceError(Error),
/// The renderer is about to draw its first frame.
RenderMapStarted,
/// The renderer is about to draw a frame.
RenderFrameStarted,
/// The renderer drew a frame.
RenderFrameFinished {
/// `Full` when everything the frame shows has loaded and its camera
/// stood as it would on the terrain's current ground
/// ([`UpdateParameters::elevation`]), though some of it may have
/// failed to draw (`error`).
///
/// [`UpdateParameters::elevation`]: crate::UpdateParameters::elevation
mode: RenderMode,
/// The frame has transitions still running.
needs_repaint: bool,
/// When, without `needs_repaint`, the map changes next though
/// nothing asks for a frame before: a frame then places the symbols
/// again.
repaint_at: Option<Instant>,
placement_changed: bool,
/// The still image request of the update that the frame drew, or 0
/// when the update requested none. Only a frame of the request's own
/// updates completes it, not one of an earlier update that a renderer
/// on another thread drew late.
still_image_request_id: u64,
/// The [`update_id`] of the update that the frame drew.
///
/// [`update_id`]: crate::UpdateParameters::update_id
update_id: u64,
/// The context's counters after the frame.
stats: Arc<RenderingStats>,
/// Why the frame failed on the GPU, if it did
/// ([`DrawnFrame::error`](crate::DrawnFrame::error)): its image
/// lacks what failed. Boxed, so that the events don't grow for it.
error: Option<Box<Error>>,
},
/// The ground of the terrain changed: the tiles that draw it, or the DEM
/// data they read; or it comes again for an update that carried a
/// ground that differs from it at the view's center. `None` once terrain
/// stops drawing, and for an update that carries a ground while terrain
/// doesn't draw. It comes before the frame of its update finishes. The
/// map's camera stands on it, and the map answers it with an update that
/// carries it ([`UpdateParameters::elevation`]), which a still image
/// waits for.
///
/// [`UpdateParameters::elevation`]: crate::UpdateParameters::elevation
TerrainElevation(Option<Arc<dyn Elevation>>),
/// The renderer drew its first frame with everything loaded.
RenderMapFinished,
/// A layer uses an image that the style lacks. The renderer lays out
/// without it until an update adds it.
StyleImageMissing(String),
/// These images were requested before, and no layer uses them anymore.
UnusedStyleImages(Vec<String>),
GlyphsRequested {
font_stack: FontStack,
range: GlyphRange,
},
GlyphsLoaded {
font_stack: FontStack,
range: GlyphRange,
},
/// A glyph range of a font stack failed to load or parse.
GlyphsError {
font_stack: FontStack,
range: GlyphRange,
error: Error,
},
/// A tile of the source `source_id` went through `op`: a request, a
/// response, the start or end of its parse, an error or a cancel.
TileAction {
op: TileOperation,
id: OverscaledTileID,
source_id: String,
},
}
/// The queue a renderer pushes its events to.
pub type RendererEvents = EventQueue<RendererEvent>;
// A renderer on another thread than its map sends it the events.
const _: () = {
const fn assert_send<T: Send>() {}
assert_send::<RendererEvent>();
};