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

Commit

Permalink
[core] Prefetch low resolution tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpsantos committed Jun 29, 2017
1 parent 1df45a5 commit ab849f4
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
15 changes: 15 additions & 0 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ class Map : private util::noncopyable {

AnnotationIDs queryPointAnnotations(const ScreenBox&);

// Tile prefetching
//
// When loading a map area, if `FixedPrefetch` is set to any positive number, the map will
// request first the tile for the prefetch `zoom` level if the `zoom` level is within the
// tile source range and if it is lower than the current zoom level, in a attempt to display
// a map as quick as possible. `DynamicPrefetch` works similarly, but will prefetch a tile
// at `zoom = (getZoom() - delta)`, constrained at the lowest zoom level for the source.
//
// If both are set, only a tile for the fixed zoom is requested.
void setFixedPrefetchZoom(optional<uint8_t> zoom);
optional<uint8_t> getFixedPrefetchZoom() const;

void setDynamicPrefetchZoomDelta(optional<uint8_t> delta);
optional<uint8_t> getDynamicPrefetchZoomDelta() const;

// Memory
void onLowMemory();

Expand Down
24 changes: 23 additions & 1 deletion src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class Map::Impl : public style::Observer,
std::unique_ptr<RenderStyle> renderStyle;

bool cameraMutated = false;

optional<uint8_t> fixedPrefetchZoom;
optional<uint8_t> dynamicPrefetchZoomDelta;

bool loading = false;

util::AsyncTask asyncInvalidate;
Expand Down Expand Up @@ -243,7 +247,9 @@ void Map::Impl::render(View& view) {
style->impl->getLayerImpls(),
scheduler,
fileSource,
annotationManager
annotationManager,
fixedPrefetchZoom,
dynamicPrefetchZoomDelta
});

bool loaded = style->impl->isLoaded() && renderStyle->isLoaded();
Expand Down Expand Up @@ -821,6 +827,22 @@ bool Map::isFullyLoaded() const {
return impl->style->impl->isLoaded() && impl->renderStyle && impl->renderStyle->isLoaded();
}

void Map::setFixedPrefetchZoom(optional<uint8_t> zoom) {
impl->fixedPrefetchZoom = zoom;
}

optional<uint8_t> Map::getFixedPrefetchZoom() const {
return impl->fixedPrefetchZoom;
}

void Map::setDynamicPrefetchZoomDelta(optional<uint8_t> delta) {
impl->dynamicPrefetchZoomDelta = delta;
}

optional<uint8_t> Map::getDynamicPrefetchZoomDelta() const {
return impl->dynamicPrefetchZoomDelta;
}

void Map::onLowMemory() {
if (impl->painter) {
BackendScope guard(impl->backend);
Expand Down
4 changes: 3 additions & 1 deletion src/mbgl/renderer/render_style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ void RenderStyle::update(const UpdateParameters& parameters) {
parameters.mode,
parameters.annotationManager,
*imageManager,
*glyphManager
*glyphManager,
parameters.fixedPrefetchZoom,
parameters.dynamicPrefetchZoomDelta
};

glyphManager->setURL(parameters.glyphURL);
Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/renderer/tile_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class TileParameters {
AnnotationManager& annotationManager;
ImageManager& imageManager;
GlyphManager& glyphManager;
const optional<uint8_t> fixedPrefetchZoom = {};
const optional<uint8_t> dynamicPrefetchZoomDelta = {};
};

} // namespace mbgl
30 changes: 28 additions & 2 deletions src/mbgl/renderer/tile_pyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,32 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer
// 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;

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

if (overscaledZoom >= zoomRange.min) {
int32_t idealZoom = std::min<int32_t>(zoomRange.max, overscaledZoom);

// Make sure we're not reparsing overzoomed raster tiles.
if (type == SourceType::Raster) {
tileZoom = idealZoom;

// FIXME: Prefetching is only enabled for raster
// tiles until we fix #7026.

// Request lower zoom level tiles (if configure to do so) in an attempt
// to show something on the screen faster at the cost of a little of bandwidth.
if (parameters.fixedPrefetchZoom) {
panZoom = std::max<int32_t>(std::min<int32_t>(*parameters.fixedPrefetchZoom, tileZoom), zoomRange.min);
} else if (parameters.dynamicPrefetchZoomDelta) {
panZoom = std::max<int32_t>(tileZoom - *parameters.dynamicPrefetchZoomDelta, zoomRange.min);
}

if (panZoom < tileZoom) {
panTiles = util::tileCover(parameters.transformState, panZoom);
}
}

idealTiles = util::tileCover(parameters.transformState, idealZoom);
Expand All @@ -109,8 +127,10 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer
std::set<OverscaledTileID> retain;

auto retainTileFn = [&](Tile& tile, Resource::Necessity necessity) -> void {
retain.emplace(tile.id);
tile.setNecessity(necessity);
if (retain.emplace(tile.id).second) {
tile.setNecessity(necessity);
}

if (needsRelayout) {
tile.setLayers(layers);
}
Expand Down Expand Up @@ -138,6 +158,12 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer
};

renderTiles.clear();

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

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

Expand Down
3 changes: 3 additions & 0 deletions src/mbgl/renderer/update_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class UpdateParameters {
Scheduler& scheduler;
FileSource& fileSource;
AnnotationManager& annotationManager;

const optional<uint8_t> fixedPrefetchZoom = {};
const optional<uint8_t> dynamicPrefetchZoomDelta = {};
};

} // namespace mbgl

0 comments on commit ab849f4

Please sign in to comment.