summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/sources
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/renderer/sources')
-rw-r--r--src/mbgl/renderer/sources/render_geojson_source.cpp95
-rw-r--r--src/mbgl/renderer/sources/render_geojson_source.hpp59
-rw-r--r--src/mbgl/renderer/sources/render_raster_source.cpp87
-rw-r--r--src/mbgl/renderer/sources/render_raster_source.hpp55
-rw-r--r--src/mbgl/renderer/sources/render_vector_source.cpp91
-rw-r--r--src/mbgl/renderer/sources/render_vector_source.hpp55
6 files changed, 442 insertions, 0 deletions
diff --git a/src/mbgl/renderer/sources/render_geojson_source.cpp b/src/mbgl/renderer/sources/render_geojson_source.cpp
new file mode 100644
index 0000000000..7e36b44ea4
--- /dev/null
+++ b/src/mbgl/renderer/sources/render_geojson_source.cpp
@@ -0,0 +1,95 @@
+#include <mbgl/renderer/sources/render_geojson_source.hpp>
+#include <mbgl/renderer/render_tile.hpp>
+#include <mbgl/tile/geojson_tile.hpp>
+
+#include <mbgl/algorithm/generate_clip_ids.hpp>
+#include <mbgl/algorithm/generate_clip_ids_impl.hpp>
+
+namespace mbgl {
+
+using namespace style;
+
+RenderGeoJSONSource::RenderGeoJSONSource(const style::GeoJSONSource::Impl& impl_)
+ : RenderSource(impl_),
+ impl(impl_) {
+ tilePyramid.setObserver(this);
+}
+
+bool RenderGeoJSONSource::isLoaded() const {
+ return tilePyramid.isLoaded();
+}
+
+void RenderGeoJSONSource::invalidateTiles() {
+ tilePyramid.invalidateTiles();
+}
+
+void RenderGeoJSONSource::startRender(algorithm::ClipIDGenerator& generator, const mat4& projMatrix, const mat4& clipMatrix, const TransformState& transform) {
+ generator.update(tilePyramid.getRenderTiles());
+ tilePyramid.startRender(projMatrix, clipMatrix, transform);
+}
+
+void RenderGeoJSONSource::finishRender(Painter& painter) {
+ tilePyramid.finishRender(painter);
+}
+
+std::map<UnwrappedTileID, RenderTile>& RenderGeoJSONSource::getRenderTiles() {
+ return tilePyramid.getRenderTiles();
+}
+
+void RenderGeoJSONSource::updateTiles(const UpdateParameters& parameters) {
+ GeoJSONData* data_ = impl.getData();
+
+ if (!data_) {
+ return;
+ }
+
+ if (data_ != data) {
+ data = data_;
+ tilePyramid.cache.clear();
+
+ for (auto const& item : tilePyramid.tiles) {
+ static_cast<GeoJSONTile*>(item.second.get())->updateData(data->getTile(item.first.canonical));
+ }
+ }
+
+ tilePyramid.updateTiles(parameters,
+ SourceType::GeoJSON,
+ util::tileSize,
+ impl.getZoomRange(),
+ [&] (const OverscaledTileID& tileID) {
+ return std::make_unique<GeoJSONTile>(tileID, impl.id, parameters, data->getTile(tileID.canonical));
+ });
+}
+
+void RenderGeoJSONSource::removeTiles() {
+ tilePyramid.removeTiles();
+}
+
+void RenderGeoJSONSource::reloadTiles() {
+ tilePyramid.reloadTiles();
+}
+
+std::unordered_map<std::string, std::vector<Feature>>
+RenderGeoJSONSource::queryRenderedFeatures(const ScreenLineString& geometry,
+ const TransformState& transformState,
+ const RenderedQueryOptions& options) const {
+ return tilePyramid.queryRenderedFeatures(geometry, transformState, options);
+}
+
+std::vector<Feature> RenderGeoJSONSource::querySourceFeatures(const SourceQueryOptions& options) const {
+ return tilePyramid.querySourceFeatures(options);
+}
+
+void RenderGeoJSONSource::setCacheSize(size_t size) {
+ tilePyramid.setCacheSize(size);
+}
+
+void RenderGeoJSONSource::onLowMemory() {
+ tilePyramid.onLowMemory();
+}
+
+void RenderGeoJSONSource::dumpDebugLogs() const {
+ tilePyramid.dumpDebugLogs();
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_geojson_source.hpp b/src/mbgl/renderer/sources/render_geojson_source.hpp
new file mode 100644
index 0000000000..3476b63afd
--- /dev/null
+++ b/src/mbgl/renderer/sources/render_geojson_source.hpp
@@ -0,0 +1,59 @@
+#pragma once
+
+#include <mbgl/renderer/render_source.hpp>
+#include <mbgl/renderer/tile_pyramid.hpp>
+#include <mbgl/style/sources/geojson_source_impl.hpp>
+
+namespace mbgl {
+
+namespace style {
+class GeoJSONData;
+} // namespace style
+
+class RenderGeoJSONSource : public RenderSource {
+public:
+ RenderGeoJSONSource(const style::GeoJSONSource::Impl&);
+
+ bool isLoaded() const final;
+
+ // Called when the camera has changed. May load new tiles, unload obsolete tiles, or
+ // trigger re-placement of existing complete tiles.
+ void updateTiles(const style::UpdateParameters&) final;
+
+ // Removes all tiles (by putting them into the cache).
+ void removeTiles() final;
+
+ // Remove all tiles and clear the cache.
+ void invalidateTiles() final;
+
+ // Request that all loaded tiles re-run the layout operation on the existing source
+ // data with fresh style information.
+ void reloadTiles() final;
+
+ void startRender(algorithm::ClipIDGenerator&,
+ const mat4& projMatrix,
+ const mat4& clipMatrix,
+ const TransformState&) final;
+ void finishRender(Painter&) final;
+
+ std::map<UnwrappedTileID, RenderTile>& getRenderTiles() final;
+
+ std::unordered_map<std::string, std::vector<Feature>>
+ queryRenderedFeatures(const ScreenLineString& geometry,
+ const TransformState& transformState,
+ const RenderedQueryOptions& options) const final;
+
+ std::vector<Feature>
+ querySourceFeatures(const SourceQueryOptions&) const final;
+
+ void setCacheSize(size_t) final;
+ void onLowMemory() final;
+ void dumpDebugLogs() const final;
+
+private:
+ const style::GeoJSONSource::Impl& impl;
+ TilePyramid tilePyramid;
+ style::GeoJSONData* data;
+};
+
+} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_raster_source.cpp b/src/mbgl/renderer/sources/render_raster_source.cpp
new file mode 100644
index 0000000000..75a2189053
--- /dev/null
+++ b/src/mbgl/renderer/sources/render_raster_source.cpp
@@ -0,0 +1,87 @@
+#include <mbgl/renderer/sources/render_raster_source.hpp>
+#include <mbgl/renderer/render_tile.hpp>
+#include <mbgl/tile/raster_tile.hpp>
+
+namespace mbgl {
+
+using namespace style;
+
+RenderRasterSource::RenderRasterSource(const style::RasterSource::Impl& impl_)
+ : RenderSource(impl_),
+ impl(impl_) {
+ tilePyramid.setObserver(this);
+}
+
+bool RenderRasterSource::isLoaded() const {
+ return tilePyramid.isLoaded();
+}
+
+void RenderRasterSource::invalidateTiles() {
+ tilePyramid.invalidateTiles();
+}
+
+void RenderRasterSource::startRender(algorithm::ClipIDGenerator&, const mat4& projMatrix, const mat4& clipMatrix, const TransformState& transform) {
+ tilePyramid.startRender(projMatrix, clipMatrix, transform);
+}
+
+void RenderRasterSource::finishRender(Painter& painter) {
+ tilePyramid.finishRender(painter);
+}
+
+std::map<UnwrappedTileID, RenderTile>& RenderRasterSource::getRenderTiles() {
+ return tilePyramid.getRenderTiles();
+}
+
+void RenderRasterSource::updateTiles(const UpdateParameters& parameters) {
+ optional<Tileset> tileset = impl.getTileset();
+
+ if (!tileset) {
+ return;
+ }
+
+ if (tileURLTemplates != tileset->tiles) {
+ tileURLTemplates = tileset->tiles;
+ tilePyramid.invalidateTiles();
+ }
+
+ tilePyramid.updateTiles(parameters,
+ SourceType::Raster,
+ impl.getTileSize(),
+ tileset->zoomRange,
+ [&] (const OverscaledTileID& tileID) {
+ return std::make_unique<RasterTile>(tileID, parameters, *tileset);
+ });
+}
+
+void RenderRasterSource::removeTiles() {
+ tilePyramid.removeTiles();
+}
+
+void RenderRasterSource::reloadTiles() {
+ tilePyramid.reloadTiles();
+}
+
+std::unordered_map<std::string, std::vector<Feature>>
+RenderRasterSource::queryRenderedFeatures(const ScreenLineString&,
+ const TransformState&,
+ const RenderedQueryOptions&) const {
+ return {};
+}
+
+std::vector<Feature> RenderRasterSource::querySourceFeatures(const SourceQueryOptions&) const {
+ return {};
+}
+
+void RenderRasterSource::setCacheSize(size_t size) {
+ tilePyramid.setCacheSize(size);
+}
+
+void RenderRasterSource::onLowMemory() {
+ tilePyramid.onLowMemory();
+}
+
+void RenderRasterSource::dumpDebugLogs() const {
+ tilePyramid.dumpDebugLogs();
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_raster_source.hpp b/src/mbgl/renderer/sources/render_raster_source.hpp
new file mode 100644
index 0000000000..6b95be363f
--- /dev/null
+++ b/src/mbgl/renderer/sources/render_raster_source.hpp
@@ -0,0 +1,55 @@
+#pragma once
+
+#include <mbgl/renderer/render_source.hpp>
+#include <mbgl/renderer/tile_pyramid.hpp>
+#include <mbgl/style/sources/raster_source_impl.hpp>
+
+namespace mbgl {
+
+class RenderRasterSource : public RenderSource {
+public:
+ RenderRasterSource(const style::RasterSource::Impl&);
+
+ bool isLoaded() const final;
+
+ // Called when the camera has changed. May load new tiles, unload obsolete tiles, or
+ // trigger re-placement of existing complete tiles.
+ void updateTiles(const style::UpdateParameters&) final;
+
+ // Removes all tiles (by putting them into the cache).
+ void removeTiles() final;
+
+ // Remove all tiles and clear the cache.
+ void invalidateTiles() final;
+
+ // Request that all loaded tiles re-run the layout operation on the existing source
+ // data with fresh style information.
+ void reloadTiles() final;
+
+ void startRender(algorithm::ClipIDGenerator&,
+ const mat4& projMatrix,
+ const mat4& clipMatrix,
+ const TransformState&) final;
+ void finishRender(Painter&) final;
+
+ std::map<UnwrappedTileID, RenderTile>& getRenderTiles() final;
+
+ std::unordered_map<std::string, std::vector<Feature>>
+ queryRenderedFeatures(const ScreenLineString& geometry,
+ const TransformState& transformState,
+ const RenderedQueryOptions& options) const final;
+
+ std::vector<Feature>
+ querySourceFeatures(const SourceQueryOptions&) const final;
+
+ void setCacheSize(size_t) final;
+ void onLowMemory() final;
+ void dumpDebugLogs() const final;
+
+private:
+ const style::RasterSource::Impl& impl;
+ TilePyramid tilePyramid;
+ optional<std::vector<std::string>> tileURLTemplates;
+};
+
+} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_vector_source.cpp b/src/mbgl/renderer/sources/render_vector_source.cpp
new file mode 100644
index 0000000000..3d7e09fd2a
--- /dev/null
+++ b/src/mbgl/renderer/sources/render_vector_source.cpp
@@ -0,0 +1,91 @@
+#include <mbgl/renderer/sources/render_vector_source.hpp>
+#include <mbgl/renderer/render_tile.hpp>
+#include <mbgl/tile/vector_tile.hpp>
+
+#include <mbgl/algorithm/generate_clip_ids.hpp>
+#include <mbgl/algorithm/generate_clip_ids_impl.hpp>
+
+namespace mbgl {
+
+using namespace style;
+
+RenderVectorSource::RenderVectorSource(const style::VectorSource::Impl& impl_)
+ : RenderSource(impl_),
+ impl(impl_) {
+ tilePyramid.setObserver(this);
+}
+
+bool RenderVectorSource::isLoaded() const {
+ return tilePyramid.isLoaded();
+}
+
+void RenderVectorSource::invalidateTiles() {
+ tilePyramid.invalidateTiles();
+}
+
+void RenderVectorSource::startRender(algorithm::ClipIDGenerator& generator, const mat4& projMatrix, const mat4& clipMatrix, const TransformState& transform) {
+ generator.update(tilePyramid.getRenderTiles());
+ tilePyramid.startRender(projMatrix, clipMatrix, transform);
+}
+
+void RenderVectorSource::finishRender(Painter& painter) {
+ tilePyramid.finishRender(painter);
+}
+
+std::map<UnwrappedTileID, RenderTile>& RenderVectorSource::getRenderTiles() {
+ return tilePyramid.getRenderTiles();
+}
+
+void RenderVectorSource::updateTiles(const UpdateParameters& parameters) {
+ optional<Tileset> tileset = impl.getTileset();
+
+ if (!tileset) {
+ return;
+ }
+
+ if (tileURLTemplates != tileset->tiles) {
+ tileURLTemplates = tileset->tiles;
+ tilePyramid.invalidateTiles();
+ }
+
+ tilePyramid.updateTiles(parameters,
+ SourceType::Vector,
+ util::tileSize,
+ tileset->zoomRange,
+ [&] (const OverscaledTileID& tileID) {
+ return std::make_unique<VectorTile>(tileID, impl.id, parameters, *tileset);
+ });
+}
+
+void RenderVectorSource::removeTiles() {
+ tilePyramid.removeTiles();
+}
+
+void RenderVectorSource::reloadTiles() {
+ tilePyramid.reloadTiles();
+}
+
+std::unordered_map<std::string, std::vector<Feature>>
+RenderVectorSource::queryRenderedFeatures(const ScreenLineString& geometry,
+ const TransformState& transformState,
+ const RenderedQueryOptions& options) const {
+ return tilePyramid.queryRenderedFeatures(geometry, transformState, options);
+}
+
+std::vector<Feature> RenderVectorSource::querySourceFeatures(const SourceQueryOptions& options) const {
+ return tilePyramid.querySourceFeatures(options);
+}
+
+void RenderVectorSource::setCacheSize(size_t size) {
+ tilePyramid.setCacheSize(size);
+}
+
+void RenderVectorSource::onLowMemory() {
+ tilePyramid.onLowMemory();
+}
+
+void RenderVectorSource::dumpDebugLogs() const {
+ tilePyramid.dumpDebugLogs();
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_vector_source.hpp b/src/mbgl/renderer/sources/render_vector_source.hpp
new file mode 100644
index 0000000000..0f40c14cf5
--- /dev/null
+++ b/src/mbgl/renderer/sources/render_vector_source.hpp
@@ -0,0 +1,55 @@
+#pragma once
+
+#include <mbgl/renderer/render_source.hpp>
+#include <mbgl/renderer/tile_pyramid.hpp>
+#include <mbgl/style/sources/vector_source_impl.hpp>
+
+namespace mbgl {
+
+class RenderVectorSource : public RenderSource {
+public:
+ RenderVectorSource(const style::VectorSource::Impl&);
+
+ bool isLoaded() const final;
+
+ // Called when the camera has changed. May load new tiles, unload obsolete tiles, or
+ // trigger re-placement of existing complete tiles.
+ void updateTiles(const style::UpdateParameters&) final;
+
+ // Removes all tiles (by putting them into the cache).
+ void removeTiles() final;
+
+ // Remove all tiles and clear the cache.
+ void invalidateTiles() final;
+
+ // Request that all loaded tiles re-run the layout operation on the existing source
+ // data with fresh style information.
+ void reloadTiles() final;
+
+ void startRender(algorithm::ClipIDGenerator&,
+ const mat4& projMatrix,
+ const mat4& clipMatrix,
+ const TransformState&) final;
+ void finishRender(Painter&) final;
+
+ std::map<UnwrappedTileID, RenderTile>& getRenderTiles() final;
+
+ std::unordered_map<std::string, std::vector<Feature>>
+ queryRenderedFeatures(const ScreenLineString& geometry,
+ const TransformState& transformState,
+ const RenderedQueryOptions& options) const final;
+
+ std::vector<Feature>
+ querySourceFeatures(const SourceQueryOptions&) const final;
+
+ void setCacheSize(size_t) final;
+ void onLowMemory() final;
+ void dumpDebugLogs() const final;
+
+private:
+ const style::VectorSource::Impl& impl;
+ TilePyramid tilePyramid;
+ optional<std::vector<std::string>> tileURLTemplates;
+};
+
+} // namespace mbgl