diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-05-29 11:07:46 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-05-29 12:04:26 +0300 |
commit | b50aa497cc96e0572adf4b1f2b9fd9a145b3d4f4 (patch) | |
tree | 9741831e38bcce1486d04baa8f29bdee1f8ce634 | |
parent | 5bb0a49dc9533eaf871e18fc2a0ffd2534493df5 (diff) | |
download | qtlocation-mapboxgl-b50aa497cc96e0572adf4b1f2b9fd9a145b3d4f4.tar.gz |
[core] Introduce RenderTileSource
RenderTileSource is a base class for the render sources that provide render tiles.
* Removes repeated code
* Simplifies render source code refactoring and improves readability
-rw-r--r-- | src/core-files.json | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_custom_geometry_source.cpp | 51 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_custom_geometry_source.hpp | 34 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_geojson_source.cpp | 52 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_geojson_source.hpp | 37 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_raster_dem_source.cpp | 40 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_raster_dem_source.hpp | 35 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_raster_source.cpp | 38 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_raster_source.hpp | 25 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_tile_source.cpp | 66 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_tile_source.hpp | 44 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_vector_source.cpp | 52 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_vector_source.hpp | 32 |
13 files changed, 150 insertions, 358 deletions
diff --git a/src/core-files.json b/src/core-files.json index eb581f7959..2c6e521c43 100644 --- a/src/core-files.json +++ b/src/core-files.json @@ -137,6 +137,7 @@ "src/mbgl/renderer/sources/render_image_source.cpp", "src/mbgl/renderer/sources/render_raster_dem_source.cpp", "src/mbgl/renderer/sources/render_raster_source.cpp", + "src/mbgl/renderer/sources/render_tile_source.cpp", "src/mbgl/renderer/sources/render_vector_source.cpp", "src/mbgl/renderer/style_diff.cpp", "src/mbgl/renderer/tile_pyramid.cpp", @@ -651,6 +652,7 @@ "mbgl/renderer/sources/render_image_source.hpp": "src/mbgl/renderer/sources/render_image_source.hpp", "mbgl/renderer/sources/render_raster_dem_source.hpp": "src/mbgl/renderer/sources/render_raster_dem_source.hpp", "mbgl/renderer/sources/render_raster_source.hpp": "src/mbgl/renderer/sources/render_raster_source.hpp", + "mbgl/renderer/sources/render_tile_source.hpp": "src/mbgl/renderer/sources/render_tile_source.hpp", "mbgl/renderer/sources/render_vector_source.hpp": "src/mbgl/renderer/sources/render_vector_source.hpp", "mbgl/renderer/style_diff.hpp": "src/mbgl/renderer/style_diff.hpp", "mbgl/renderer/tile_mask.hpp": "src/mbgl/renderer/tile_mask.hpp", diff --git a/src/mbgl/renderer/sources/render_custom_geometry_source.cpp b/src/mbgl/renderer/sources/render_custom_geometry_source.cpp index d0b8a70d8e..ee7b6e6f14 100644 --- a/src/mbgl/renderer/sources/render_custom_geometry_source.cpp +++ b/src/mbgl/renderer/sources/render_custom_geometry_source.cpp @@ -8,7 +8,7 @@ namespace mbgl { using namespace style; RenderCustomGeometrySource::RenderCustomGeometrySource(Immutable<style::CustomGeometrySource::Impl> impl_) - : RenderSource(impl_) { + : RenderTileSource(std::move(impl_)) { tilePyramid.setObserver(this); } @@ -16,10 +16,6 @@ const style::CustomGeometrySource::Impl& RenderCustomGeometrySource::impl() cons return static_cast<const style::CustomGeometrySource::Impl&>(*baseImpl); } -bool RenderCustomGeometrySource::isLoaded() const { - return tilePyramid.isLoaded(); -} - void RenderCustomGeometrySource::update(Immutable<style::Source::Impl> baseImpl_, const std::vector<Immutable<style::LayerProperties>>& layers, const bool needsRendering, @@ -47,49 +43,4 @@ void RenderCustomGeometrySource::update(Immutable<style::Source::Impl> baseImpl_ }); } -void RenderCustomGeometrySource::upload(gfx::UploadPass& uploadPass) { - tilePyramid.upload(uploadPass); -} - -void RenderCustomGeometrySource::prepare(const SourcePrepareParameters& parameters) { - tilePyramid.prepare(parameters); -} - -void RenderCustomGeometrySource::finishRender(PaintParameters& parameters) { - tilePyramid.finishRender(parameters); -} - -void RenderCustomGeometrySource::updateFadingTiles() { - tilePyramid.updateFadingTiles(); -} - -bool RenderCustomGeometrySource::hasFadingTiles() const { - return tilePyramid.hasFadingTiles(); -} - -std::vector<std::reference_wrapper<RenderTile>> RenderCustomGeometrySource::getRenderTiles() { - return tilePyramid.getRenderTiles(); -} - -std::unordered_map<std::string, std::vector<Feature>> -RenderCustomGeometrySource::queryRenderedFeatures(const ScreenLineString& geometry, - const TransformState& transformState, - const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options, - const mat4& projMatrix) const { - return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix); -} - -std::vector<Feature> RenderCustomGeometrySource::querySourceFeatures(const SourceQueryOptions& options) const { - return tilePyramid.querySourceFeatures(options); -} - -void RenderCustomGeometrySource::reduceMemoryUse() { - tilePyramid.reduceMemoryUse(); -} - -void RenderCustomGeometrySource::dumpDebugLogs() const { - tilePyramid.dumpDebugLogs(); -} - } // namespace mbgl diff --git a/src/mbgl/renderer/sources/render_custom_geometry_source.hpp b/src/mbgl/renderer/sources/render_custom_geometry_source.hpp index b461d92e8b..331ae455e7 100644 --- a/src/mbgl/renderer/sources/render_custom_geometry_source.hpp +++ b/src/mbgl/renderer/sources/render_custom_geometry_source.hpp @@ -1,48 +1,22 @@ #pragma once -#include <mbgl/renderer/render_source.hpp> -#include <mbgl/renderer/tile_pyramid.hpp> +#include <mbgl/renderer/sources/render_tile_source.hpp> #include <mbgl/style/sources/custom_geometry_source_impl.hpp> namespace mbgl { -class RenderCustomGeometrySource : public RenderSource { +class RenderCustomGeometrySource final : public RenderTileSource { public: - RenderCustomGeometrySource(Immutable<style::CustomGeometrySource::Impl>); - - bool isLoaded() const final; + explicit RenderCustomGeometrySource(Immutable<style::CustomGeometrySource::Impl>); void update(Immutable<style::Source::Impl>, const std::vector<Immutable<style::LayerProperties>>&, bool needsRendering, bool needsRelayout, - const TileParameters&) final; - - void upload(gfx::UploadPass&) final; - void prepare(const SourcePrepareParameters&) final; - void finishRender(PaintParameters&) final; - void updateFadingTiles() final; - bool hasFadingTiles() const final; - - std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() final; - - std::unordered_map<std::string, std::vector<Feature>> - queryRenderedFeatures(const ScreenLineString& geometry, - const TransformState& transformState, - const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options, - const mat4& projMatrix) const final; - - std::vector<Feature> - querySourceFeatures(const SourceQueryOptions&) const final; - - void reduceMemoryUse() final; - void dumpDebugLogs() const final; + const TileParameters&) override; private: const style::CustomGeometrySource::Impl& impl() const; - - TilePyramid tilePyramid; }; template <> diff --git a/src/mbgl/renderer/sources/render_geojson_source.cpp b/src/mbgl/renderer/sources/render_geojson_source.cpp index 44d3a3a2bb..e451dab6d3 100644 --- a/src/mbgl/renderer/sources/render_geojson_source.cpp +++ b/src/mbgl/renderer/sources/render_geojson_source.cpp @@ -66,8 +66,7 @@ MAPBOX_ETERNAL_CONSTEXPR const auto extensionGetters = mapbox::eternal::hash_map } // namespace RenderGeoJSONSource::RenderGeoJSONSource(Immutable<style::GeoJSONSource::Impl> impl_) - : RenderSource(impl_) { - tilePyramid.setObserver(this); + : RenderTileSource(std::move(impl_)) { } RenderGeoJSONSource::~RenderGeoJSONSource() = default; @@ -76,10 +75,6 @@ const style::GeoJSONSource::Impl& RenderGeoJSONSource::impl() const { return static_cast<const style::GeoJSONSource::Impl&>(*baseImpl); } -bool RenderGeoJSONSource::isLoaded() const { - return tilePyramid.isLoaded(); -} - void RenderGeoJSONSource::update(Immutable<style::Source::Impl> baseImpl_, const std::vector<Immutable<LayerProperties>>& layers, const bool needsRendering, @@ -123,43 +118,6 @@ void RenderGeoJSONSource::update(Immutable<style::Source::Impl> baseImpl_, }); } -void RenderGeoJSONSource::upload(gfx::UploadPass& parameters) { - tilePyramid.upload(parameters); -} - -void RenderGeoJSONSource::prepare(const SourcePrepareParameters& parameters) { - tilePyramid.prepare(parameters); -} - -void RenderGeoJSONSource::finishRender(PaintParameters& parameters) { - tilePyramid.finishRender(parameters); -} - -void RenderGeoJSONSource::updateFadingTiles() { - tilePyramid.updateFadingTiles(); -} - -bool RenderGeoJSONSource::hasFadingTiles() const { - return tilePyramid.hasFadingTiles(); -} - -std::vector<std::reference_wrapper<RenderTile>> RenderGeoJSONSource::getRenderTiles() { - return tilePyramid.getRenderTiles(); -} - -std::unordered_map<std::string, std::vector<Feature>> -RenderGeoJSONSource::queryRenderedFeatures(const ScreenLineString& geometry, - const TransformState& transformState, - const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options, - const mat4& projMatrix) const { - return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix); -} - -std::vector<Feature> RenderGeoJSONSource::querySourceFeatures(const SourceQueryOptions& options) const { - return tilePyramid.querySourceFeatures(options); -} - mapbox::util::variant<Value, FeatureCollection> RenderGeoJSONSource::queryFeatureExtensions(const Feature& feature, const std::string& extension, @@ -187,12 +145,4 @@ RenderGeoJSONSource::queryFeatureExtensions(const Feature& feature, return extensionIt->second(std::move(jsonData), static_cast<std::uint32_t>(*clusterID), args); } -void RenderGeoJSONSource::reduceMemoryUse() { - tilePyramid.reduceMemoryUse(); -} - -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 index 1ebeb045d8..3896457806 100644 --- a/src/mbgl/renderer/sources/render_geojson_source.hpp +++ b/src/mbgl/renderer/sources/render_geojson_source.hpp @@ -1,7 +1,6 @@ #pragma once -#include <mbgl/renderer/render_source.hpp> -#include <mbgl/renderer/tile_pyramid.hpp> +#include <mbgl/renderer/sources/render_tile_source.hpp> #include <mbgl/style/sources/geojson_source_impl.hpp> namespace mbgl { @@ -10,50 +9,26 @@ namespace style { class GeoJSONData; } // namespace style -class RenderGeoJSONSource : public RenderSource { +class RenderGeoJSONSource final : public RenderTileSource { public: - RenderGeoJSONSource(Immutable<style::GeoJSONSource::Impl>); - ~RenderGeoJSONSource() final; - - bool isLoaded() const final; + explicit RenderGeoJSONSource(Immutable<style::GeoJSONSource::Impl>); + ~RenderGeoJSONSource() override; void update(Immutable<style::Source::Impl>, const std::vector<Immutable<style::LayerProperties>>&, bool needsRendering, bool needsRelayout, - const TileParameters&) final; - - void upload(gfx::UploadPass&) final; - void prepare(const SourcePrepareParameters&) final; - void finishRender(PaintParameters&) final; - void updateFadingTiles() final; - bool hasFadingTiles() const final; - - std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() final; - - std::unordered_map<std::string, std::vector<Feature>> - queryRenderedFeatures(const ScreenLineString& geometry, - const TransformState& transformState, - const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options, - const mat4& projMatrix) const final; - - std::vector<Feature> - querySourceFeatures(const SourceQueryOptions&) const final; + const TileParameters&) override; FeatureExtensionValue queryFeatureExtensions(const Feature& feature, const std::string& extension, const std::string& extensionField, - const optional<std::map<std::string, Value>>& args) const final; - - void reduceMemoryUse() final; - void dumpDebugLogs() const final; + const optional<std::map<std::string, Value>>& args) const override; private: const style::GeoJSONSource::Impl& impl() const; - TilePyramid tilePyramid; std::weak_ptr<style::GeoJSONData> data; }; diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.cpp b/src/mbgl/renderer/sources/render_raster_dem_source.cpp index afe8e060b2..3ec544a845 100644 --- a/src/mbgl/renderer/sources/render_raster_dem_source.cpp +++ b/src/mbgl/renderer/sources/render_raster_dem_source.cpp @@ -10,18 +10,13 @@ namespace mbgl { using namespace style; RenderRasterDEMSource::RenderRasterDEMSource(Immutable<style::RasterSource::Impl> impl_) - : RenderSource(impl_) { - tilePyramid.setObserver(this); + : RenderTileSource(std::move(impl_)) { } const style::RasterSource::Impl& RenderRasterDEMSource::impl() const { return static_cast<const style::RasterSource::Impl&>(*baseImpl); } -bool RenderRasterDEMSource::isLoaded() const { - return tilePyramid.isLoaded(); -} - void RenderRasterDEMSource::update(Immutable<style::Source::Impl> baseImpl_, const std::vector<Immutable<LayerProperties>>& layers, const bool needsRendering, @@ -123,32 +118,12 @@ void RenderRasterDEMSource::onTileChanged(Tile& tile){ } } } - RenderSource::onTileChanged(tile); -} - -void RenderRasterDEMSource::upload(gfx::UploadPass& parameters) { - tilePyramid.upload(parameters); + RenderTileSource::onTileChanged(tile); } void RenderRasterDEMSource::prepare(const SourcePrepareParameters& parameters) { algorithm::updateTileMasks(tilePyramid.getRenderTiles()); - tilePyramid.prepare(parameters); -} - -void RenderRasterDEMSource::finishRender(PaintParameters& parameters) { - tilePyramid.finishRender(parameters); -} - -void RenderRasterDEMSource::updateFadingTiles() { - tilePyramid.updateFadingTiles(); -} - -bool RenderRasterDEMSource::hasFadingTiles() const { - return tilePyramid.hasFadingTiles(); -} - -std::vector<std::reference_wrapper<RenderTile>> RenderRasterDEMSource::getRenderTiles() { - return tilePyramid.getRenderTiles(); + RenderTileSource::prepare(parameters); } std::unordered_map<std::string, std::vector<Feature>> @@ -157,19 +132,12 @@ RenderRasterDEMSource::queryRenderedFeatures(const ScreenLineString&, const std::vector<const RenderLayer*>&, const RenderedQueryOptions&, const mat4&) const { - return std::unordered_map<std::string, std::vector<Feature>> {}; + return std::unordered_map<std::string, std::vector<Feature>>{}; } std::vector<Feature> RenderRasterDEMSource::querySourceFeatures(const SourceQueryOptions&) const { return {}; } -void RenderRasterDEMSource::reduceMemoryUse() { - tilePyramid.reduceMemoryUse(); -} - -void RenderRasterDEMSource::dumpDebugLogs() const { - tilePyramid.dumpDebugLogs(); -} } // namespace mbgl diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.hpp b/src/mbgl/renderer/sources/render_raster_dem_source.hpp index 9167fd1114..dcec53e04a 100644 --- a/src/mbgl/renderer/sources/render_raster_dem_source.hpp +++ b/src/mbgl/renderer/sources/render_raster_dem_source.hpp @@ -1,16 +1,14 @@ #pragma once -#include <mbgl/renderer/render_source.hpp> -#include <mbgl/renderer/tile_pyramid.hpp> +#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 : public RenderSource { +class RenderRasterDEMSource final : public RenderTileSource { public: - RenderRasterDEMSource(Immutable<style::RasterSource::Impl>); - - bool isLoaded() const final; + explicit RenderRasterDEMSource(Immutable<style::RasterSource::Impl>); void update(Immutable<style::Source::Impl>, const std::vector<Immutable<style::LayerProperties>>&, @@ -18,40 +16,27 @@ public: bool needsRelayout, const TileParameters&) final; - void upload(gfx::UploadPass&) final; - void prepare(const SourcePrepareParameters&) final; - void finishRender(PaintParameters&) final; - void updateFadingTiles() final; - bool hasFadingTiles() const final; - - std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() final; + void prepare(const SourcePrepareParameters&) override; std::unordered_map<std::string, std::vector<Feature>> queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, const RenderedQueryOptions& options, - const mat4& projMatrix) const final; + const mat4& projMatrix) const override; std::vector<Feature> - querySourceFeatures(const SourceQueryOptions&) const final; - - void reduceMemoryUse() final; - void dumpDebugLogs() const final; + querySourceFeatures(const SourceQueryOptions&) const override; - uint8_t getMaxZoom() const { - return maxzoom; - }; + uint8_t getMaxZoom() const { return maxzoom; } private: const style::RasterSource::Impl& impl() const; - TilePyramid tilePyramid; optional<Tileset> tileset; - uint8_t maxzoom = 15; + uint8_t maxzoom = util::TERRAIN_RGB_MAXZOOM; -protected: - void onTileChanged(Tile&) final; + void onTileChanged(Tile&) override; }; template <> diff --git a/src/mbgl/renderer/sources/render_raster_source.cpp b/src/mbgl/renderer/sources/render_raster_source.cpp index db410a4e5c..588009faa8 100644 --- a/src/mbgl/renderer/sources/render_raster_source.cpp +++ b/src/mbgl/renderer/sources/render_raster_source.cpp @@ -8,18 +8,13 @@ namespace mbgl { using namespace style; RenderRasterSource::RenderRasterSource(Immutable<style::RasterSource::Impl> impl_) - : RenderSource(impl_) { - tilePyramid.setObserver(this); + : RenderTileSource(std::move(impl_)) { } const style::RasterSource::Impl& RenderRasterSource::impl() const { return static_cast<const style::RasterSource::Impl&>(*baseImpl); } -bool RenderRasterSource::isLoaded() const { - return tilePyramid.isLoaded(); -} - void RenderRasterSource::update(Immutable<style::Source::Impl> baseImpl_, const std::vector<Immutable<LayerProperties>>& layers, const bool needsRendering, @@ -57,29 +52,9 @@ void RenderRasterSource::update(Immutable<style::Source::Impl> baseImpl_, }); } -void RenderRasterSource::upload(gfx::UploadPass& parameters) { - tilePyramid.upload(parameters); -} - void RenderRasterSource::prepare(const SourcePrepareParameters& parameters) { algorithm::updateTileMasks(tilePyramid.getRenderTiles()); - tilePyramid.prepare(parameters); -} - -void RenderRasterSource::finishRender(PaintParameters& parameters) { - tilePyramid.finishRender(parameters); -} - -void RenderRasterSource::updateFadingTiles() { - tilePyramid.updateFadingTiles(); -} - -bool RenderRasterSource::hasFadingTiles() const { - return tilePyramid.hasFadingTiles(); -} - -std::vector<std::reference_wrapper<RenderTile>> RenderRasterSource::getRenderTiles() { - return tilePyramid.getRenderTiles(); + RenderTileSource::prepare(parameters); } std::unordered_map<std::string, std::vector<Feature>> @@ -88,19 +63,12 @@ RenderRasterSource::queryRenderedFeatures(const ScreenLineString&, const std::vector<const RenderLayer*>&, const RenderedQueryOptions&, const mat4&) const { - return std::unordered_map<std::string, std::vector<Feature>> {}; + return std::unordered_map<std::string, std::vector<Feature>>{}; } std::vector<Feature> RenderRasterSource::querySourceFeatures(const SourceQueryOptions&) const { return {}; } -void RenderRasterSource::reduceMemoryUse() { - tilePyramid.reduceMemoryUse(); -} - -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 index bc3bc53d35..ec6d7f2474 100644 --- a/src/mbgl/renderer/sources/render_raster_source.hpp +++ b/src/mbgl/renderer/sources/render_raster_source.hpp @@ -1,48 +1,33 @@ #pragma once -#include <mbgl/renderer/render_source.hpp> -#include <mbgl/renderer/tile_pyramid.hpp> +#include <mbgl/renderer/sources/render_tile_source.hpp> #include <mbgl/style/sources/raster_source_impl.hpp> namespace mbgl { -class RenderRasterSource : public RenderSource { +class RenderRasterSource final : public RenderTileSource { public: - RenderRasterSource(Immutable<style::RasterSource::Impl>); - - bool isLoaded() const final; + 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; - - void upload(gfx::UploadPass&) final; void prepare(const SourcePrepareParameters&) final; - void finishRender(PaintParameters&) final; - void updateFadingTiles() final; - bool hasFadingTiles() const final; - - std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() final; std::unordered_map<std::string, std::vector<Feature>> queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, const std::vector<const RenderLayer*>& layers, const RenderedQueryOptions& options, - const mat4& projMatrix) const final; + const mat4& projMatrix) const override; std::vector<Feature> - querySourceFeatures(const SourceQueryOptions&) const final; - - void reduceMemoryUse() final; - void dumpDebugLogs() const final; + querySourceFeatures(const SourceQueryOptions&) const override; private: const style::RasterSource::Impl& impl() const; - - TilePyramid tilePyramid; optional<Tileset> tileset; }; diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp new file mode 100644 index 0000000000..a906945e4f --- /dev/null +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -0,0 +1,66 @@ +#include <mbgl/renderer/sources/render_tile_source.hpp> +#include <mbgl/renderer/render_tile.hpp> +#include <mbgl/renderer/paint_parameters.hpp> +#include <mbgl/tile/vector_tile.hpp> + +namespace mbgl { + +using namespace style; + +RenderTileSource::RenderTileSource(Immutable<style::Source::Impl> impl_) + : RenderSource(std::move(impl_)) { + tilePyramid.setObserver(this); +} + +RenderTileSource::~RenderTileSource() = default; + +bool RenderTileSource::isLoaded() const { + return tilePyramid.isLoaded(); +} + +void RenderTileSource::upload(gfx::UploadPass& parameters) { + tilePyramid.upload(parameters); +} + +void RenderTileSource::prepare(const SourcePrepareParameters& parameters) { + tilePyramid.prepare(parameters); +} + +void RenderTileSource::finishRender(PaintParameters& parameters) { + tilePyramid.finishRender(parameters); +} + +void RenderTileSource::updateFadingTiles() { + tilePyramid.updateFadingTiles(); +} + +bool RenderTileSource::hasFadingTiles() const { + return tilePyramid.hasFadingTiles(); +} + +std::vector<std::reference_wrapper<RenderTile>> RenderTileSource::getRenderTiles() { + return tilePyramid.getRenderTiles(); +} + +std::unordered_map<std::string, std::vector<Feature>> +RenderTileSource::queryRenderedFeatures(const ScreenLineString& geometry, + const TransformState& transformState, + const std::vector<const RenderLayer*>& layers, + const RenderedQueryOptions& options, + const mat4& projMatrix) const { + return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix); +} + +std::vector<Feature> RenderTileSource::querySourceFeatures(const SourceQueryOptions& options) const { + return tilePyramid.querySourceFeatures(options); +} + +void RenderTileSource::reduceMemoryUse() { + tilePyramid.reduceMemoryUse(); +} + +void RenderTileSource::dumpDebugLogs() const { + tilePyramid.dumpDebugLogs(); +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/sources/render_tile_source.hpp b/src/mbgl/renderer/sources/render_tile_source.hpp new file mode 100644 index 0000000000..c1a1f76242 --- /dev/null +++ b/src/mbgl/renderer/sources/render_tile_source.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include <mbgl/renderer/render_source.hpp> +#include <mbgl/renderer/tile_pyramid.hpp> +#include <mbgl/style/sources/vector_source_impl.hpp> + +namespace mbgl { + +/** + * @brief Base class for render sources that provide render tiles. + */ +class RenderTileSource : public RenderSource { +public: + RenderTileSource(Immutable<style::Source::Impl>); + ~RenderTileSource() override; + + bool isLoaded() const override; + + void upload(gfx::UploadPass&) override; + void prepare(const SourcePrepareParameters&) override; + void finishRender(PaintParameters&) override; + void updateFadingTiles() override; + bool hasFadingTiles() const override; + + std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() override; + + std::unordered_map<std::string, std::vector<Feature>> + queryRenderedFeatures(const ScreenLineString& geometry, + const TransformState& transformState, + const std::vector<const RenderLayer*>& layers, + const RenderedQueryOptions& options, + const mat4& projMatrix) const override; + + std::vector<Feature> + querySourceFeatures(const SourceQueryOptions&) const override; + + void reduceMemoryUse() override; + void dumpDebugLogs() const override; + +protected: + TilePyramid tilePyramid; +}; + +} // namespace mbgl diff --git a/src/mbgl/renderer/sources/render_vector_source.cpp b/src/mbgl/renderer/sources/render_vector_source.cpp index 0d5eb5c89f..53fc4c8299 100644 --- a/src/mbgl/renderer/sources/render_vector_source.cpp +++ b/src/mbgl/renderer/sources/render_vector_source.cpp @@ -8,18 +8,13 @@ namespace mbgl { using namespace style; RenderVectorSource::RenderVectorSource(Immutable<style::VectorSource::Impl> impl_) - : RenderSource(impl_) { - tilePyramid.setObserver(this); + : RenderTileSource(impl_) { } const style::VectorSource::Impl& RenderVectorSource::impl() const { return static_cast<const style::VectorSource::Impl&>(*baseImpl); } -bool RenderVectorSource::isLoaded() const { - return tilePyramid.isLoaded(); -} - void RenderVectorSource::update(Immutable<style::Source::Impl> baseImpl_, const std::vector<Immutable<style::LayerProperties>>& layers, const bool needsRendering, @@ -57,49 +52,4 @@ void RenderVectorSource::update(Immutable<style::Source::Impl> baseImpl_, }); } -void RenderVectorSource::upload(gfx::UploadPass& parameters) { - tilePyramid.upload(parameters); -} - -void RenderVectorSource::prepare(const SourcePrepareParameters& parameters) { - tilePyramid.prepare(parameters); -} - -void RenderVectorSource::finishRender(PaintParameters& parameters) { - tilePyramid.finishRender(parameters); -} - -void RenderVectorSource::updateFadingTiles() { - tilePyramid.updateFadingTiles(); -} - -bool RenderVectorSource::hasFadingTiles() const { - return tilePyramid.hasFadingTiles(); -} - -std::vector<std::reference_wrapper<RenderTile>> RenderVectorSource::getRenderTiles() { - return tilePyramid.getRenderTiles(); -} - -std::unordered_map<std::string, std::vector<Feature>> -RenderVectorSource::queryRenderedFeatures(const ScreenLineString& geometry, - const TransformState& transformState, - const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options, - const mat4& projMatrix) const { - return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix); -} - -std::vector<Feature> RenderVectorSource::querySourceFeatures(const SourceQueryOptions& options) const { - return tilePyramid.querySourceFeatures(options); -} - -void RenderVectorSource::reduceMemoryUse() { - tilePyramid.reduceMemoryUse(); -} - -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 index 2eb33df91b..c1ffdd207c 100644 --- a/src/mbgl/renderer/sources/render_vector_source.hpp +++ b/src/mbgl/renderer/sources/render_vector_source.hpp @@ -1,48 +1,22 @@ #pragma once -#include <mbgl/renderer/render_source.hpp> +#include <mbgl/renderer/sources/render_tile_source.hpp> #include <mbgl/renderer/tile_pyramid.hpp> #include <mbgl/style/sources/vector_source_impl.hpp> namespace mbgl { -class RenderVectorSource : public RenderSource { +class RenderVectorSource final : public RenderTileSource { public: - RenderVectorSource(Immutable<style::VectorSource::Impl>); - - bool isLoaded() const final; + 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; - - void upload(gfx::UploadPass&) final; - void prepare(const SourcePrepareParameters&) final; - void finishRender(PaintParameters&) final; - void updateFadingTiles() final; - bool hasFadingTiles() const final; - - std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() final; - - std::unordered_map<std::string, std::vector<Feature>> - queryRenderedFeatures(const ScreenLineString& geometry, - const TransformState& transformState, - const std::vector<const RenderLayer*>& layers, - const RenderedQueryOptions& options, - const mat4& projMatrix) const final; - - std::vector<Feature> - querySourceFeatures(const SourceQueryOptions&) const final; - - void reduceMemoryUse() final; - void dumpDebugLogs() const final; - private: const style::VectorSource::Impl& impl() const; - - TilePyramid tilePyramid; optional<Tileset> tileset; }; |