This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core] Prefetch low resolution tiles #7741
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"version": 8, | ||
"sources": {}, | ||
"layers": [] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"version": 8, | ||
"name": "Test", | ||
"sources": { | ||
"raster": { | ||
"type": "raster", | ||
"tiles": [ "{z}" ], | ||
"tileSize": 256, | ||
"maxzoom": 20, | ||
"minzoom": 0 | ||
} | ||
}, | ||
"layers": [{ | ||
"id": "background", | ||
"type": "background", | ||
"paint": { | ||
"background-color": "blue" | ||
} | ||
}, { | ||
"id": "raster", | ||
"type": "raster", | ||
"source": "raster" | ||
}] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <mbgl/test/util.hpp> | ||
#include <mbgl/test/stub_file_source.hpp> | ||
|
||
#include <mbgl/gl/headless_backend.hpp> | ||
#include <mbgl/gl/offscreen_view.hpp> | ||
#include <mbgl/map/backend_scope.hpp> | ||
#include <mbgl/map/map.hpp> | ||
#include <mbgl/storage/default_file_source.hpp> | ||
#include <mbgl/style/style.hpp> | ||
#include <mbgl/util/default_thread_pool.hpp> | ||
#include <mbgl/util/image.hpp> | ||
#include <mbgl/util/io.hpp> | ||
#include <mbgl/util/run_loop.hpp> | ||
|
||
#include <algorithm> | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace mbgl; | ||
using namespace mbgl::style; | ||
using namespace std::literals::string_literals; | ||
|
||
TEST(Map, PrefetchTiles) { | ||
util::RunLoop runLoop; | ||
HeadlessBackend backend(test::sharedDisplay()); | ||
BackendScope scope(backend); | ||
OffscreenView view(backend.getContext(), { 512, 512 }); | ||
ThreadPool threadPool(4); | ||
StubFileSource fileSource; | ||
Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still); | ||
|
||
std::vector<int> tiles; | ||
|
||
fileSource.response = [&] (const Resource& res) -> optional<Response> { | ||
Response response; | ||
|
||
auto zoom = std::stoi(res.url); | ||
tiles.push_back(zoom); | ||
|
||
// Return a red tile for prefetched tiles or green to the actual tile. | ||
// The end rendering result should be all green because the map is only | ||
// considered fully rendered when only ideal tiles are shown. | ||
if (zoom == int(map.getZoom()) + 1) { | ||
response.data = std::make_shared<std::string>( | ||
util::read_file("test/fixtures/map/prefetch/tile_green.png")); | ||
} else { | ||
response.data = std::make_shared<std::string>( | ||
util::read_file("test/fixtures/map/prefetch/tile_red.png")); | ||
} | ||
|
||
return { std::move(response) }; | ||
}; | ||
|
||
auto checkTilesForZoom = [&](int zoom, const std::vector<int>& expected) { | ||
tiles.clear(); | ||
|
||
// Force tile reloading. | ||
map.getStyle().loadJSON(util::read_file("test/fixtures/map/prefetch/empty.json")); | ||
map.getStyle().loadJSON(util::read_file("test/fixtures/map/prefetch/style.json")); | ||
|
||
map.setLatLngZoom({ 40.726989, -73.992857 }, zoom); // Manhattan | ||
|
||
// Should always render the ideal tiles (i.e. a green map) | ||
test::checkImage("test/fixtures/map/prefetch", test::render(map, view)); | ||
|
||
ASSERT_TRUE(std::is_permutation(tiles.begin(), tiles.end(), expected.begin())); | ||
ASSERT_FALSE(tiles.empty()); | ||
}; | ||
|
||
// Check defaults, should be 4. | ||
ASSERT_EQ(map.getPrefetchZoomDelta(), 4); | ||
checkTilesForZoom(12, { 13, 13, 13, 13, 13, 13, 13, 13, 13, 9 }); | ||
|
||
// Setting it to 0 disables prefetching. | ||
map.setPrefetchZoomDelta(0); | ||
|
||
// No prefetching, raster tiles will use ideal | ||
// tiles instead of the actual zoom level, that is | ||
// why the zoom levels for non-prefetched tiles are | ||
// not the same. | ||
checkTilesForZoom(10, { 11, 11, 11, 11, 11, 11, 11, 11, 11 }); | ||
|
||
map.setPrefetchZoomDelta(5); | ||
checkTilesForZoom(12, { 13, 13, 13, 13, 13, 13, 13, 13, 13, 8 }); | ||
|
||
// Should clamp at `minzoom`. | ||
map.setPrefetchZoomDelta(20); | ||
checkTilesForZoom(10, { 11, 11, 11, 11, 11, 11, 11, 11, 11, 0 }); | ||
|
||
// Disabled again. | ||
map.setPrefetchZoomDelta(0); | ||
checkTilesForZoom(13, { 14, 14, 14, 14, 14, 14, 14, 14, 14 }); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we merge this call to
updateRenderables
into the other one by merging thepanTiles
intoidealTiles
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capturing from the chat: we have a separated
algorithm::updateRenderables
because we don't create render tiles for pan tiles.