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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// A render source is the renderer's side of a style source: what every one
// has is `RenderSourceBase`, what each type does the `RenderSource` trait. A
// source's tiles are in the renderer's tile store, which the source's
// methods are given.
use std::sync::Arc;
use mln_style::Source;
use mln_util::error::Error;
use crate::bucket::UploadNeeds;
use crate::gfx::context::Context;
use crate::layer_type::ErasedEvaluatedLayer;
use crate::paint_parameters::TransformParameters;
use crate::registry::Registry;
use crate::render_tile::RenderTile;
use crate::sources::render_image_source::ImageSourceRenderData;
use crate::tile::job::SourceKey;
use crate::tile::store::TileStore;
use crate::tile_parameters::TileParameters;
pub(crate) struct RenderTileParameters<'a> {
pub(crate) transform: &'a TransformParameters,
/// Whether a layer of the frame draws the source's tiles in
/// [`TileOrder::ByY`], which `update_render_tiles` then sorts them in.
pub(crate) sort_by_y: bool,
}
/// What every render source has, whatever its type.
pub(crate) struct RenderSourceBase {
pub(crate) style_source: Source,
pub(crate) enabled: bool,
}
impl RenderSourceBase {
pub(crate) fn new(style_source: Source) -> Self {
RenderSourceBase { style_source, enabled: false }
}
}
/// An order a layer draws its source's tiles in.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum TileOrder {
/// By tile id, without the tiles held for fade.
ById,
/// By opposite y position, so that the lower of two tiles' overlapping
/// symbols draw over the higher's.
ByY,
}
pub(crate) trait RenderSource {
fn base(&self) -> &RenderSourceBase;
fn is_loaded(&self, store: &TileStore) -> bool;
fn update(
&mut self,
store: &mut TileStore,
style_source: Source,
layers: &[Arc<dyn ErasedEvaluatedLayer>],
needs_rendering: bool,
needs_relayout: bool,
parameters: &TileParameters<'_>,
);
/// Makes the source's render tiles of the frame.
fn update_render_tiles(&mut self, store: &mut TileStore, parameters: &RenderTileParameters<'_>);
/// Readies the buckets the frame draws, before its layers make their
/// draws, which read what `needs` says, uploading their indexes through
/// `context`.
fn upload(&mut self, store: &mut TileStore, context: &mut Context, needs: UploadNeeds);
/// Releases the render data from the last `update_render_tiles` while
/// the source is disabled.
fn release_render_data(&mut self) {}
/// The source's tiles in the tile store, for a source with tiles.
fn tiles(&self) -> Option<SourceKey> {
None
}
/// The source's render tiles, as of the last `update_render_tiles`.
fn render_tiles(&self) -> &[RenderTile] {
&[]
}
/// The source's tiles in `order`, as indexes into `render_tiles`, as of
/// the last `update_render_tiles`; `None` for a source without tiles.
fn tile_order(&self, _order: TileOrder) -> Option<&[usize]> {
None
}
/// An image source's image, as the layers that draw it read it; `None`
/// for other sources.
fn image_render_data(&self) -> Option<ImageSourceRenderData<'_>> {
None
}
/// Queries a feature extension; sources without extensions return a null
/// value.
fn query_feature_extensions(
&self,
_feature: &mln_util::feature::Feature,
_extension: &str,
_extension_field: &str,
_args: Option<&feature::PropertyMap>,
) -> Result<crate::query::FeatureExtensionValue, Error> {
Ok(crate::query::FeatureExtensionValue::default())
}
fn set_fast_pfor_enabled(&mut self, _enable: bool) {}
fn dump_debug_logs(&self);
/// The deepest zoom the source has tiles of; `None` for a source without
/// tiles.
fn max_zoom(&self) -> Option<u8>;
fn is_enabled(&self) -> bool {
self.base().enabled
}
}
/// Creates the render source of a style source through its type in
/// `registry`, whose tiles, if it has any, `store` keeps. `None` for a type
/// that the registry lacks, which breaks the contract that a map and its
/// renderer register the same types.
pub(crate) fn create(registry: &Registry, source: &Source, store: &mut TileStore) -> Option<Box<dyn RenderSource>> {
let name = source.info().name;
let render_source = registry.source_type(name).map(|source_type| source_type.create_render_source(source, store));
debug_assert!(render_source.is_some(), "the renderer's registry has no source type '{name}'");
render_source
}