Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] TilePyramid::update accepts source impl
Browse files Browse the repository at this point in the history
  • Loading branch information
pozdnyakov committed Apr 20, 2020
1 parent 20f159c commit 41b7aa5
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 79 deletions.
6 changes: 2 additions & 4 deletions src/mbgl/annotation/render_annotation_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ void RenderAnnotationSource::update(Immutable<style::Source::Impl> baseImpl_,
needsRendering,
needsRelayout,
parameters,
SourceType::Annotations,
*baseImpl,
util::tileSize,
// Zoom level 16 is typically sufficient for annotations.
// See https://github.com/mapbox/mapbox-gl-native/issues/10197
{0, 16},
optional<LatLngBounds>{},
[&](const OverscaledTileID& tileID) { return std::make_unique<AnnotationTile>(tileID, parameters); },
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
[&](const OverscaledTileID& tileID) { return std::make_unique<AnnotationTile>(tileID, parameters); });
}

std::unordered_map<std::string, std::vector<Feature>>
Expand Down
27 changes: 12 additions & 15 deletions src/mbgl/renderer/sources/render_custom_geometry_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,18 @@ void RenderCustomGeometrySource::update(Immutable<style::Source::Impl> baseImpl_
return;
}

tilePyramid.update(
layers,
needsRendering,
needsRelayout,
parameters,
SourceType::CustomVector,
util::tileSize,
impl().getZoomRange(),
{},
[&](const OverscaledTileID& tileID) {
return std::make_unique<CustomGeometryTile>(
tileID, impl().id, parameters, impl().getTileOptions(), *tileLoader);
},
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
tilePyramid.update(layers,
needsRendering,
needsRelayout,
parameters,
*baseImpl,
util::tileSize,
impl().getZoomRange(),
{},
[&](const OverscaledTileID& tileID) {
return std::make_unique<CustomGeometryTile>(
tileID, impl().id, parameters, impl().getTileOptions(), *tileLoader);
});
}

} // namespace mbgl
25 changes: 11 additions & 14 deletions src/mbgl/renderer/sources/render_geojson_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,17 @@ void RenderGeoJSONSource::update(Immutable<style::Source::Impl> baseImpl_,

if (!data_) return;

tilePyramid.update(
layers,
needsRendering,
needsRelayout,
parameters,
SourceType::GeoJSON,
util::tileSize,
impl().getZoomRange(),
optional<LatLngBounds>{},
[&, data_](const OverscaledTileID& tileID) {
return std::make_unique<GeoJSONTile>(tileID, impl().id, parameters, data_);
},
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
tilePyramid.update(layers,
needsRendering,
needsRelayout,
parameters,
*baseImpl,
util::tileSize,
impl().getZoomRange(),
optional<LatLngBounds>{},
[&, data_](const OverscaledTileID& tileID) {
return std::make_unique<GeoJSONTile>(tileID, impl().id, parameters, data_);
});
}

mapbox::util::variant<Value, FeatureCollection>
Expand Down
6 changes: 2 additions & 4 deletions src/mbgl/renderer/sources/render_raster_dem_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ void RenderRasterDEMSource::updateInternal(const Tileset& tileset,
needsRendering,
needsRelayout,
parameters,
SourceType::RasterDEM,
*baseImpl,
impl().getTileSize(),
tileset.zoomRange,
tileset.bounds,
[&](const OverscaledTileID& tileID) { return std::make_unique<RasterDEMTile>(tileID, parameters, tileset); },
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
[&](const OverscaledTileID& tileID) { return std::make_unique<RasterDEMTile>(tileID, parameters, tileset); });
algorithm::updateTileMasks(tilePyramid.getRenderedTiles());
}

Expand Down
6 changes: 2 additions & 4 deletions src/mbgl/renderer/sources/render_raster_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ void RenderRasterSource::updateInternal(const Tileset& tileset,
needsRendering,
needsRelayout,
parameters,
SourceType::Raster,
*baseImpl,
impl().getTileSize(),
tileset.zoomRange,
tileset.bounds,
[&](const OverscaledTileID& tileID) { return std::make_unique<RasterTile>(tileID, parameters, tileset); },
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
[&](const OverscaledTileID& tileID) { return std::make_unique<RasterTile>(tileID, parameters, tileset); });
algorithm::updateTileMasks(tilePyramid.getRenderedTiles());
}

Expand Down
25 changes: 11 additions & 14 deletions src/mbgl/renderer/sources/render_vector_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ void RenderVectorSource::updateInternal(const Tileset& tileset,
const bool needsRendering,
const bool needsRelayout,
const TileParameters& parameters) {
tilePyramid.update(
layers,
needsRendering,
needsRelayout,
parameters,
SourceType::Vector,
util::tileSize,
tileset.zoomRange,
tileset.bounds,
[&](const OverscaledTileID& tileID) {
return std::make_unique<VectorTile>(tileID, baseImpl->id, parameters, tileset);
},
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
tilePyramid.update(layers,
needsRendering,
needsRelayout,
parameters,
*baseImpl,
util::tileSize,
tileset.zoomRange,
tileset.bounds,
[&](const OverscaledTileID& tileID) {
return std::make_unique<VectorTile>(tileID, baseImpl->id, parameters, tileset);
});
}

} // namespace mbgl
10 changes: 6 additions & 4 deletions src/mbgl/renderer/tile_pyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
const bool needsRendering,
const bool needsRelayout,
const TileParameters& parameters,
const SourceType type,
const style::Source::Impl& sourceImpl,
const uint16_t tileSize,
const Range<uint8_t> zoomRange,
optional<LatLngBounds> bounds,
std::function<std::unique_ptr<Tile>(const OverscaledTileID&)> createTile,
const optional<uint8_t>& sourcePrefetchZoomDelta,
const optional<uint8_t>& maxParentTileOverscaleFactor) {
std::function<std::unique_ptr<Tile>(const OverscaledTileID&)> createTile) {
// If we need a relayout, abandon any cached tiles; they're now stale.
if (needsRelayout) {
cache.clear();
Expand All @@ -86,11 +84,15 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l

handleWrapJump(parameters.transformState.getLatLng().longitude());

const auto type = sourceImpl.type;
// Determine the overzooming/underzooming amounts and required tiles.
int32_t overscaledZoom = util::coveringZoomLevel(parameters.transformState.getZoom(), type, tileSize);
int32_t tileZoom = overscaledZoom;
int32_t panZoom = zoomRange.max;

const optional<uint8_t>& sourcePrefetchZoomDelta = sourceImpl.getPrefetchZoomDelta();
const optional<uint8_t>& maxParentTileOverscaleFactor = sourceImpl.getMaxOverscaleFactorForParentTiles();

std::vector<OverscaledTileID> idealTiles;
std::vector<OverscaledTileID> panTiles;

Expand Down
15 changes: 7 additions & 8 deletions src/mbgl/renderer/tile_pyramid.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once

#include <mbgl/tile/tile_id.hpp>
#include <mbgl/tile/tile_observer.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/tile/tile_cache.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/tile/tile_observer.hpp>

#include <mbgl/util/mat4.hpp>
#include <mbgl/util/feature.hpp>
Expand Down Expand Up @@ -37,13 +38,11 @@ class TilePyramid {
bool needsRendering,
bool needsRelayout,
const TileParameters&,
style::SourceType type,
const style::Source::Impl&,
uint16_t tileSize,
Range<uint8_t> zoomRange,
optional<LatLngBounds> bounds,
std::function<std::unique_ptr<Tile>(const OverscaledTileID&)> createTile,
const optional<uint8_t>& sourcePrefetchZoomDelta,
const optional<uint8_t>& maxParentTileOverscaleFactor);
std::function<std::unique_ptr<Tile>(const OverscaledTileID&)> createTile);

const std::map<UnwrappedTileID, std::reference_wrapper<Tile>>& getRenderedTiles() const { return renderedTiles; }
Tile* getTile(const OverscaledTileID&);
Expand Down
21 changes: 9 additions & 12 deletions test/style/source.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,18 +767,15 @@ class FakeTileSource : public RenderTileSetSource {
const bool needsRendering,
const bool needsRelayout,
const TileParameters& parameters) override {
tilePyramid.update(
layers,
needsRendering,
needsRelayout,
parameters,
SourceType::Vector,
util::tileSize,
tileset.zoomRange,
tileset.bounds,
[&](const OverscaledTileID& tileID) { return std::make_unique<FakeTile>(*this, tileID); },
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
tilePyramid.update(layers,
needsRendering,
needsRelayout,
parameters,
*baseImpl,
util::tileSize,
tileset.zoomRange,
tileset.bounds,
[&](const OverscaledTileID& tileID) { return std::make_unique<FakeTile>(*this, tileID); });
}

const optional<Tileset>& getTileset() const override {
Expand Down

0 comments on commit 41b7aa5

Please sign in to comment.