[core] Introduce RenderTileSetSource class
Encapsulates the tiles update logic based on the given tile set.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user