summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/renderer/sources/render_raster_dem_source.cpp42
-rw-r--r--src/mbgl/renderer/sources/render_raster_dem_source.hpp22
-rw-r--r--src/mbgl/renderer/sources/render_raster_source.cpp44
-rw-r--r--src/mbgl/renderer/sources/render_raster_source.hpp18
-rw-r--r--src/mbgl/renderer/sources/render_tile_source.cpp42
-rw-r--r--src/mbgl/renderer/sources/render_tile_source.hpp29
-rw-r--r--src/mbgl/renderer/sources/render_vector_source.cpp44
-rw-r--r--src/mbgl/renderer/sources/render_vector_source.hpp16
8 files changed, 132 insertions, 125 deletions
diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.cpp b/src/mbgl/renderer/sources/render_raster_dem_source.cpp
index b86b0bba7b..fb6e343670 100644
--- a/src/mbgl/renderer/sources/render_raster_dem_source.cpp
+++ b/src/mbgl/renderer/sources/render_raster_dem_source.cpp
@@ -11,50 +11,32 @@ namespace mbgl {
using namespace style;
RenderRasterDEMSource::RenderRasterDEMSource(Immutable<style::RasterSource::Impl> impl_)
- : RenderTileSource(std::move(impl_)) {
+ : RenderTileSetSource(std::move(impl_)) {
}
const style::RasterSource::Impl& RenderRasterDEMSource::impl() const {
return static_cast<const style::RasterSource::Impl&>(*baseImpl);
}
-void RenderRasterDEMSource::update(Immutable<style::Source::Impl> baseImpl_,
- const std::vector<Immutable<LayerProperties>>& layers,
- const bool needsRendering,
- const bool needsRelayout,
- const TileParameters& parameters) {
- std::swap(baseImpl, baseImpl_);
-
- enabled = needsRendering;
-
- const optional<Tileset>& implTileset = impl().tileset;
- // In Continuous mode, keep the existing tiles if the new tileset is not
- // yet available, thus providing smart style transitions without flickering.
- // In other modes, allow clearing the tile pyramid first, before the early
- // return in order to avoid render tests being flaky.
- bool canUpdateTileset = implTileset || parameters.mode != MapMode::Continuous;
- if (canUpdateTileset && tileset != implTileset) {
- tileset = implTileset;
- maxzoom = tileset->zoomRange.max;
- // TODO: this removes existing buckets, and will cause flickering.
- // Should instead refresh tile data in place.
- tilePyramid.clearAll();
- }
-
- if (!implTileset) {
- return;
- }
+const optional<Tileset>& RenderRasterDEMSource::getTileset() const {
+ return impl().tileset;
+}
+void RenderRasterDEMSource::updateInternal(const Tileset& tileset,
+ const std::vector<Immutable<LayerProperties>>& layers,
+ const bool needsRendering,
+ const bool needsRelayout,
+ const TileParameters& parameters) {
tilePyramid.update(layers,
needsRendering,
needsRelayout,
parameters,
SourceType::RasterDEM,
impl().getTileSize(),
- tileset->zoomRange,
- tileset->bounds,
+ tileset.zoomRange,
+ tileset.bounds,
[&] (const OverscaledTileID& tileID) {
- return std::make_unique<RasterDEMTile>(tileID, parameters, *tileset);
+ return std::make_unique<RasterDEMTile>(tileID, parameters, tileset);
});
algorithm::updateTileMasks(tilePyramid.getRenderedTiles());
}
diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.hpp b/src/mbgl/renderer/sources/render_raster_dem_source.hpp
index dd74f4d7e7..72a3779e99 100644
--- a/src/mbgl/renderer/sources/render_raster_dem_source.hpp
+++ b/src/mbgl/renderer/sources/render_raster_dem_source.hpp
@@ -2,20 +2,13 @@
#include <mbgl/renderer/sources/render_tile_source.hpp>
#include <mbgl/style/sources/raster_source_impl.hpp>
-#include <mbgl/util/constants.hpp>
namespace mbgl {
-class RenderRasterDEMSource final : public RenderTileSource {
+class RenderRasterDEMSource final : public RenderTileSetSource {
public:
explicit RenderRasterDEMSource(Immutable<style::RasterSource::Impl>);
- void update(Immutable<style::Source::Impl>,
- const std::vector<Immutable<style::LayerProperties>>&,
- bool needsRendering,
- bool needsRelayout,
- const TileParameters&) final;
-
std::unordered_map<std::string, std::vector<Feature>>
queryRenderedFeatures(const ScreenLineString& geometry,
const TransformState& transformState,
@@ -26,13 +19,16 @@ public:
std::vector<Feature>
querySourceFeatures(const SourceQueryOptions&) const override;
- uint8_t getMaxZoom() const override { return maxzoom; }
-
private:
- const style::RasterSource::Impl& impl() const;
+ // RenderTileSetSource overrides
+ void updateInternal(const Tileset&,
+ const std::vector<Immutable<style::LayerProperties>>&,
+ bool needsRendering,
+ bool needsRelayout,
+ const TileParameters&) override;
+ const optional<Tileset>& getTileset() const override;
- optional<Tileset> tileset;
- uint8_t maxzoom = util::TERRAIN_RGB_MAXZOOM;
+ const style::RasterSource::Impl& impl() const;
void onTileChanged(Tile&) override;
};
diff --git a/src/mbgl/renderer/sources/render_raster_source.cpp b/src/mbgl/renderer/sources/render_raster_source.cpp
index 310a4cbc57..408f8a4e11 100644
--- a/src/mbgl/renderer/sources/render_raster_source.cpp
+++ b/src/mbgl/renderer/sources/render_raster_source.cpp
@@ -9,50 +9,32 @@ namespace mbgl {
using namespace style;
RenderRasterSource::RenderRasterSource(Immutable<style::RasterSource::Impl> impl_)
- : RenderTileSource(std::move(impl_)) {
+ : RenderTileSetSource(std::move(impl_)) {
}
-const style::RasterSource::Impl& RenderRasterSource::impl() const {
+inline const style::RasterSource::Impl& RenderRasterSource::impl() const {
return static_cast<const style::RasterSource::Impl&>(*baseImpl);
}
-void RenderRasterSource::update(Immutable<style::Source::Impl> baseImpl_,
- const std::vector<Immutable<LayerProperties>>& layers,
- const bool needsRendering,
- const bool needsRelayout,
- const TileParameters& parameters) {
- std::swap(baseImpl, baseImpl_);
-
- enabled = needsRendering;
-
- const optional<Tileset>& implTileset = impl().tileset;
- // In Continuous mode, keep the existing tiles if the new tileset is not
- // yet available, thus providing smart style transitions without flickering.
- // In other modes, allow clearing the tile pyramid first, before the early
- // return in order to avoid render tests being flaky.
- bool canUpdateTileset = implTileset || parameters.mode != MapMode::Continuous;
- if (canUpdateTileset && tileset != implTileset) {
- tileset = implTileset;
-
- // TODO: this removes existing buckets, and will cause flickering.
- // Should instead refresh tile data in place.
- tilePyramid.clearAll();
- }
-
- if (!implTileset) {
- return;
- }
+const optional<Tileset>& RenderRasterSource::getTileset() const {
+ return impl().tileset;
+}
+void RenderRasterSource::updateInternal(const Tileset& tileset,
+ const std::vector<Immutable<LayerProperties>>& layers,
+ const bool needsRendering,
+ const bool needsRelayout,
+ const TileParameters& parameters) {
tilePyramid.update(layers,
needsRendering,
needsRelayout,
parameters,
SourceType::Raster,
impl().getTileSize(),
- tileset->zoomRange,
- tileset->bounds,
+ tileset.zoomRange,
+ tileset.bounds,
[&] (const OverscaledTileID& tileID) {
- return std::make_unique<RasterTile>(tileID, parameters, *tileset);
+ return std::make_unique<RasterTile>(tileID, parameters, tileset);
});
algorithm::updateTileMasks(tilePyramid.getRenderedTiles());
}
diff --git a/src/mbgl/renderer/sources/render_raster_source.hpp b/src/mbgl/renderer/sources/render_raster_source.hpp
index 0071dddec9..0760b7fa2b 100644
--- a/src/mbgl/renderer/sources/render_raster_source.hpp
+++ b/src/mbgl/renderer/sources/render_raster_source.hpp
@@ -5,15 +5,11 @@
namespace mbgl {
-class RenderRasterSource final : public RenderTileSource {
+class RenderRasterSource final : public RenderTileSetSource {
public:
explicit RenderRasterSource(Immutable<style::RasterSource::Impl>);
- void update(Immutable<style::Source::Impl>,
- const std::vector<Immutable<style::LayerProperties>>&,
- bool needsRendering,
- bool needsRelayout,
- const TileParameters&) final;
+private:
void prepare(const SourcePrepareParameters&) final;
std::unordered_map<std::string, std::vector<Feature>>
@@ -26,9 +22,15 @@ public:
std::vector<Feature>
querySourceFeatures(const SourceQueryOptions&) const override;
-private:
+ // RenderTileSetSource overrides
+ void updateInternal(const Tileset&,
+ const std::vector<Immutable<style::LayerProperties>>&,
+ bool needsRendering,
+ bool needsRelayout,
+ const TileParameters&) override;
+ const optional<Tileset>& getTileset() const override;
+
const style::RasterSource::Impl& impl() const;
- optional<Tileset> tileset;
};
} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp
index 6ee2eca1b1..ef3f34f595 100644
--- a/src/mbgl/renderer/sources/render_tile_source.cpp
+++ b/src/mbgl/renderer/sources/render_tile_source.cpp
@@ -4,8 +4,10 @@
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/renderer/render_tree.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
+#include <mbgl/renderer/tile_parameters.hpp>
#include <mbgl/renderer/tile_render_data.hpp>
#include <mbgl/tile/vector_tile.hpp>
+#include <mbgl/util/constants.hpp>
#include <mbgl/util/math.hpp>
namespace mbgl {
@@ -139,4 +141,44 @@ void RenderTileSource::dumpDebugLogs() const {
tilePyramid.dumpDebugLogs();
}
+// RenderTileSetSource implementation
+
+RenderTileSetSource::RenderTileSetSource(Immutable<style::Source::Impl> impl_)
+ : RenderTileSource(std::move(impl_)) {
+}
+
+RenderTileSetSource::~RenderTileSetSource() = default;
+
+uint8_t RenderTileSetSource::getMaxZoom() const {
+ return cachedTileset ? cachedTileset->zoomRange.max : util::TERRAIN_RGB_MAXZOOM;
+}
+
+void RenderTileSetSource::update(Immutable<style::Source::Impl> baseImpl_,
+ const std::vector<Immutable<style::LayerProperties>>& layers,
+ const bool needsRendering,
+ const bool needsRelayout,
+ const TileParameters& parameters) {
+ std::swap(baseImpl, baseImpl_);
+
+ enabled = needsRendering;
+
+ const optional<Tileset>& implTileset = getTileset();
+ // In Continuous mode, keep the existing tiles if the new cachedTileset is not
+ // yet available, thus providing smart style transitions without flickering.
+ // In other modes, allow clearing the tile pyramid first, before the early
+ // return in order to avoid render tests being flaky.
+ bool canUpdateTileset = implTileset || parameters.mode != MapMode::Continuous;
+ if (canUpdateTileset && cachedTileset != implTileset) {
+ cachedTileset = implTileset;
+
+ // TODO: this removes existing buckets, and will cause flickering.
+ // Should instead refresh tile data in place.
+ tilePyramid.clearAll();
+ }
+
+ if (!implTileset) return;
+
+ updateInternal(*cachedTileset, layers, needsRendering, needsRelayout, parameters);
+}
+
} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_tile_source.hpp b/src/mbgl/renderer/sources/render_tile_source.hpp
index f961c20561..7edff726d5 100644
--- a/src/mbgl/renderer/sources/render_tile_source.hpp
+++ b/src/mbgl/renderer/sources/render_tile_source.hpp
@@ -11,7 +11,6 @@ namespace mbgl {
*/
class RenderTileSource : public RenderSource {
public:
- RenderTileSource(Immutable<style::Source::Impl>);
~RenderTileSource() override;
bool isLoaded() const override;
@@ -39,6 +38,7 @@ public:
void dumpDebugLogs() const override;
protected:
+ RenderTileSource(Immutable<style::Source::Impl>);
TilePyramid tilePyramid;
Immutable<std::vector<RenderTile>> renderTiles;
mutable RenderTiles filteredRenderTiles;
@@ -46,4 +46,31 @@ protected:
float bearing = 0.0f;
};
+/**
+ * @brief Base class for render sources that use tile sets.
+ */
+class RenderTileSetSource : public RenderTileSource {
+protected:
+ RenderTileSetSource(Immutable<style::Source::Impl>);
+ ~RenderTileSetSource() override;
+
+ virtual void updateInternal(const Tileset&,
+ const std::vector<Immutable<style::LayerProperties>>&,
+ bool needsRendering,
+ bool needsRelayout,
+ const TileParameters&) = 0;
+ // Returns tileset from the current impl.
+ virtual const optional<Tileset>& getTileset() const = 0;
+
+private:
+ uint8_t getMaxZoom() const final;
+ void update(Immutable<style::Source::Impl>,
+ const std::vector<Immutable<style::LayerProperties>>&,
+ bool needsRendering,
+ bool needsRelayout,
+ const TileParameters&) final;
+
+ optional<Tileset> cachedTileset;
+};
+
} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_vector_source.cpp b/src/mbgl/renderer/sources/render_vector_source.cpp
index 7035be9cf2..6e4fdede10 100644
--- a/src/mbgl/renderer/sources/render_vector_source.cpp
+++ b/src/mbgl/renderer/sources/render_vector_source.cpp
@@ -9,50 +9,28 @@ namespace mbgl {
using namespace style;
RenderVectorSource::RenderVectorSource(Immutable<style::VectorSource::Impl> impl_)
- : RenderTileSource(impl_) {
+ : RenderTileSetSource(std::move(impl_)) {
}
-const style::VectorSource::Impl& RenderVectorSource::impl() const {
- return static_cast<const style::VectorSource::Impl&>(*baseImpl);
+const optional<Tileset>& RenderVectorSource::getTileset() const {
+ return static_cast<const style::VectorSource::Impl&>(*baseImpl).tileset;
}
-void RenderVectorSource::update(Immutable<style::Source::Impl> baseImpl_,
- const std::vector<Immutable<style::LayerProperties>>& layers,
- const bool needsRendering,
- const bool needsRelayout,
- const TileParameters& parameters) {
- std::swap(baseImpl, baseImpl_);
-
- enabled = needsRendering;
-
- const optional<Tileset>& implTileset = impl().tileset;
- // In Continuous mode, keep the existing tiles if the new tileset is not
- // yet available, thus providing smart style transitions without flickering.
- // In other modes, allow clearing the tile pyramid first, before the early
- // return in order to avoid render tests being flaky.
- bool canUpdateTileset = implTileset || parameters.mode != MapMode::Continuous;
- if (canUpdateTileset && tileset != implTileset) {
- tileset = implTileset;
-
- // TODO: this removes existing buckets, and will cause flickering.
- // Should instead refresh tile data in place.
- tilePyramid.clearAll();
- }
-
- if (!implTileset) {
- return;
- }
-
+void RenderVectorSource::updateInternal(const Tileset& tileset,
+ const std::vector<Immutable<style::LayerProperties>>& layers,
+ const bool needsRendering,
+ const bool needsRelayout,
+ const TileParameters& parameters) {
tilePyramid.update(layers,
needsRendering,
needsRelayout,
parameters,
SourceType::Vector,
util::tileSize,
- tileset->zoomRange,
- tileset->bounds,
+ tileset.zoomRange,
+ tileset.bounds,
[&] (const OverscaledTileID& tileID) {
- return std::make_unique<VectorTile>(tileID, impl().id, parameters, *tileset);
+ return std::make_unique<VectorTile>(tileID, baseImpl->id, parameters, tileset);
});
}
diff --git a/src/mbgl/renderer/sources/render_vector_source.hpp b/src/mbgl/renderer/sources/render_vector_source.hpp
index d5ac443e1c..b83402ddb4 100644
--- a/src/mbgl/renderer/sources/render_vector_source.hpp
+++ b/src/mbgl/renderer/sources/render_vector_source.hpp
@@ -6,18 +6,16 @@
namespace mbgl {
-class RenderVectorSource final : public RenderTileSource {
+class RenderVectorSource final : public RenderTileSetSource {
public:
explicit RenderVectorSource(Immutable<style::VectorSource::Impl>);
-
- void update(Immutable<style::Source::Impl>,
- const std::vector<Immutable<style::LayerProperties>>&,
- bool needsRendering,
- bool needsRelayout,
- const TileParameters&) final;
private:
- const style::VectorSource::Impl& impl() const;
- optional<Tileset> tileset;
+ void updateInternal(const Tileset&,
+ const std::vector<Immutable<style::LayerProperties>>&,
+ bool needsRendering,
+ bool needsRelayout,
+ const TileParameters&) override;
+ const optional<Tileset>& getTileset() const override;
};
} // namespace mbgl