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

Commit

Permalink
[core] Add setMaxOverscaleFactorForParentTiles
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshalamov committed Apr 1, 2020
1 parent 09a5ee2 commit 9d593f2
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 14 deletions.
14 changes: 14 additions & 0 deletions include/mbgl/style/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ class Source : public mbgl::util::noncopyable {
virtual void loadDescription(FileSource&) = 0;
void setPrefetchZoomDelta(optional<uint8_t> delta) noexcept;
optional<uint8_t> getPrefetchZoomDelta() const noexcept;

// Sets a limit for how much a parent tile can be overscaled.
//
// When a set of tiles for a current zoom level is being rendered and some of the
// ideal tiles that cover the screen are not yet loaded, parent tile could be
// used instead. This might introduce unwanted rendering side-effects, especially
// for raster tiles that are overscaled multiple times.
//
// For example, an overscale factor of 3 would mean that on zoom level 3, the
// minimum zoom level of a parent tile that could be used in place of an ideal
// tile during rendering would be zoom 0. By default, no limit is set, so any
// parent tile may be used.
void setMaxOverscaleFactorForParentTiles(optional<uint8_t> overscaleFactor) noexcept;
optional<uint8_t> getMaxOverscaleFactorForParentTiles() const noexcept;
void dumpDebugLogs() const;

virtual bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const = 0;
Expand Down
9 changes: 8 additions & 1 deletion src/mbgl/algorithm/update_renderables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <mbgl/tile/tile_id.hpp>
#include <mbgl/tile/tile_necessity.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/range.hpp>

#include <unordered_set>
Expand All @@ -20,7 +21,8 @@ void updateRenderables(GetTileFn getTile,
RenderTileFn renderTile,
const IdealTileIDs& idealTileIDs,
const Range<uint8_t>& zoomRange,
const uint8_t dataTileZoom) {
const uint8_t dataTileZoom,
const optional<uint8_t>& maxParentOverscaleFactor = nullopt) {
std::unordered_set<OverscaledTileID> checked;
bool covered;
int32_t overscaledZ;
Expand Down Expand Up @@ -86,6 +88,11 @@ void updateRenderables(GetTileFn getTile,
for (overscaledZ = dataTileZoom - 1; overscaledZ >= zoomRange.min; --overscaledZ) {
const auto parentDataTileID = idealDataTileID.scaledTo(overscaledZ);

// Request / render parent tile only if it's overscale factor is less than defined maximum.
if (maxParentOverscaleFactor && (dataTileZoom - overscaledZ) > *maxParentOverscaleFactor) {
break;
}

if (checked.find(parentDataTileID) != checked.end()) {
// Break parent tile ascent, this route has been checked by another child
// tile before.
Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/annotation/render_annotation_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ void RenderAnnotationSource::update(Immutable<style::Source::Impl> baseImpl_,
{0, 16},
optional<LatLngBounds>{},
[&](const OverscaledTileID& tileID) { return std::make_unique<AnnotationTile>(tileID, parameters); },
baseImpl->getPrefetchZoomDelta());
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
}

std::unordered_map<std::string, std::vector<Feature>>
Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/renderer/sources/render_custom_geometry_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void RenderCustomGeometrySource::update(Immutable<style::Source::Impl> baseImpl_
return std::make_unique<CustomGeometryTile>(
tileID, impl().id, parameters, impl().getTileOptions(), *tileLoader);
},
baseImpl->getPrefetchZoomDelta());
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
}

} // namespace mbgl
3 changes: 2 additions & 1 deletion src/mbgl/renderer/sources/render_geojson_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ void RenderGeoJSONSource::update(Immutable<style::Source::Impl> baseImpl_,
[&, data_](const OverscaledTileID& tileID) {
return std::make_unique<GeoJSONTile>(tileID, impl().id, parameters, data_);
},
baseImpl->getPrefetchZoomDelta());
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
}

mapbox::util::variant<Value, FeatureCollection>
Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/renderer/sources/render_raster_dem_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ void RenderRasterDEMSource::updateInternal(const Tileset& tileset,
tileset.zoomRange,
tileset.bounds,
[&](const OverscaledTileID& tileID) { return std::make_unique<RasterDEMTile>(tileID, parameters, tileset); },
baseImpl->getPrefetchZoomDelta());
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
algorithm::updateTileMasks(tilePyramid.getRenderedTiles());
}

Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/renderer/sources/render_raster_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void RenderRasterSource::updateInternal(const Tileset& tileset,
tileset.zoomRange,
tileset.bounds,
[&](const OverscaledTileID& tileID) { return std::make_unique<RasterTile>(tileID, parameters, tileset); },
baseImpl->getPrefetchZoomDelta());
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
algorithm::updateTileMasks(tilePyramid.getRenderedTiles());
}

Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/renderer/sources/render_vector_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ void RenderVectorSource::updateInternal(const Tileset& tileset,
[&](const OverscaledTileID& tileID) {
return std::make_unique<VectorTile>(tileID, baseImpl->id, parameters, tileset);
},
baseImpl->getPrefetchZoomDelta());
baseImpl->getPrefetchZoomDelta(),
baseImpl->getMaxOverscaleFactorForParentTiles());
}

} // namespace mbgl
26 changes: 20 additions & 6 deletions src/mbgl/renderer/tile_pyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
const Range<uint8_t> zoomRange,
optional<LatLngBounds> bounds,
std::function<std::unique_ptr<Tile>(const OverscaledTileID&)> createTile,
optional<uint8_t> sourcePrefetchZoomDelta) {
const optional<uint8_t>& sourcePrefetchZoomDelta,
const optional<uint8_t>& maxParentTileOverscaleFactor) {
// If we need a relayout, abandon any cached tiles; they're now stale.
if (needsRelayout) {
cache.clear();
Expand Down Expand Up @@ -177,13 +178,26 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
renderedTiles.clear();

if (!panTiles.empty()) {
algorithm::updateRenderables(getTileFn, createTileFn, retainTileFn,
[](const UnwrappedTileID&, Tile&) {}, panTiles, zoomRange, panZoom);
algorithm::updateRenderables(
getTileFn,
createTileFn,
retainTileFn,
[](const UnwrappedTileID&, Tile&) {},
panTiles,
zoomRange,
panZoom,
maxParentTileOverscaleFactor);
}

algorithm::updateRenderables(getTileFn, createTileFn, retainTileFn, renderTileFn,
idealTiles, zoomRange, tileZoom);

algorithm::updateRenderables(getTileFn,
createTileFn,
retainTileFn,
renderTileFn,
idealTiles,
zoomRange,
tileZoom,
maxParentTileOverscaleFactor);

for (auto previouslyRenderedTile : previouslyRenderedTiles) {
Tile& tile = previouslyRenderedTile.second;
tile.markRenderedPreviously();
Expand Down
3 changes: 2 additions & 1 deletion src/mbgl/renderer/tile_pyramid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class TilePyramid {
Range<uint8_t> zoomRange,
optional<LatLngBounds> bounds,
std::function<std::unique_ptr<Tile>(const OverscaledTileID&)> createTile,
optional<uint8_t> sourcePrefetchZoomDelta);
const optional<uint8_t>& sourcePrefetchZoomDelta,
const optional<uint8_t>& maxParentTileOverscaleFactor);

const std::map<UnwrappedTileID, std::reference_wrapper<Tile>>& getRenderedTiles() const { return renderedTiles; }
Tile* getTile(const OverscaledTileID&);
Expand Down
12 changes: 12 additions & 0 deletions src/mbgl/style/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ optional<uint8_t> Source::getPrefetchZoomDelta() const noexcept {
return baseImpl->getPrefetchZoomDelta();
}

void Source::setMaxOverscaleFactorForParentTiles(optional<uint8_t> overscaleFactor) noexcept {
if (getMaxOverscaleFactorForParentTiles() == overscaleFactor) return;
auto newImpl = createMutable();
newImpl->setMaxOverscaleFactorForParentTiles(std::move(overscaleFactor));
baseImpl = std::move(newImpl);
observer->onSourceChanged(*this);
}

optional<uint8_t> Source::getMaxOverscaleFactorForParentTiles() const noexcept {
return baseImpl->getMaxOverscaleFactorForParentTiles();
}

void Source::dumpDebugLogs() const {
Log::Info(Event::General, "Source::id: %s", getID().c_str());
Log::Info(Event::General, "Source::loaded: %d", loaded);
Expand Down
21 changes: 21 additions & 0 deletions src/mbgl/style/source_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
#include <mbgl/style/source_impl.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/logging.hpp>

namespace mbgl {
namespace style {

namespace {
void WarnIfOverscaleFactorCapsPrefetchDelta(const optional<uint8_t>& overscale, const optional<uint8_t>& prefetch) {
const uint8_t prefetchDelta = std::max<uint8_t>(util::DEFAULT_PREFETCH_ZOOM_DELTA, prefetch.value_or(0u));
if (overscale && *overscale < prefetchDelta) {
Log::Warning(Event::Style, "Parent tile overscale factor will cap prefetch delta to %d", int(*overscale));
}
}
} // namespace

Source::Impl::Impl(SourceType type_, std::string id_)
: type(type_),
id(std::move(id_)) {
}

void Source::Impl::setPrefetchZoomDelta(optional<uint8_t> delta) noexcept {
prefetchZoomDelta = std::move(delta);
WarnIfOverscaleFactorCapsPrefetchDelta(maxOverscaleFactor, prefetchZoomDelta);
}

optional<uint8_t> Source::Impl::getPrefetchZoomDelta() const noexcept {
return prefetchZoomDelta;
}

void Source::Impl::setMaxOverscaleFactorForParentTiles(optional<uint8_t> overscaleFactor) noexcept {
maxOverscaleFactor = std::move(overscaleFactor);
WarnIfOverscaleFactorCapsPrefetchDelta(maxOverscaleFactor, prefetchZoomDelta);
}

optional<uint8_t> Source::Impl::getMaxOverscaleFactorForParentTiles() const noexcept {
return maxOverscaleFactor;
}

} // namespace style
} // namespace mbgl
3 changes: 3 additions & 0 deletions src/mbgl/style/source_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ class Source::Impl {
virtual optional<std::string> getAttribution() const = 0;
void setPrefetchZoomDelta(optional<uint8_t> delta) noexcept;
optional<uint8_t> getPrefetchZoomDelta() const noexcept;
void setMaxOverscaleFactorForParentTiles(optional<uint8_t> overscaleFactor) noexcept;
optional<uint8_t> getMaxOverscaleFactorForParentTiles() const noexcept;

const SourceType type;
const std::string id;
optional<uint8_t> prefetchZoomDelta;
optional<uint8_t> maxOverscaleFactor;

protected:
Impl(SourceType, std::string);
Expand Down

0 comments on commit 9d593f2

Please sign in to comment.