From 1e3a744d2296feb2fd6b5d7da324bb31b6ee17c6 Mon Sep 17 00:00:00 2001 From: Huyen Chau Nguyen Date: Wed, 17 Oct 2018 20:12:28 +0200 Subject: [core] add priorities to resources - priorities can be low or regular - offline downloads should have low priority to not throttle "regular requests" --- src/mbgl/storage/resource.cpp | 32 ++++++++++++++++++++------------ src/mbgl/tile/tile_loader_impl.hpp | 1 + 2 files changed, 21 insertions(+), 12 deletions(-) (limited to 'src/mbgl') diff --git a/src/mbgl/storage/resource.cpp b/src/mbgl/storage/resource.cpp index c51db44548..aca53138ff 100644 --- a/src/mbgl/storage/resource.cpp +++ b/src/mbgl/storage/resource.cpp @@ -39,44 +39,49 @@ static std::string getTileBBox(int32_t x, int32_t y, int8_t z) { util::toString(max.x) + "," + util::toString(max.y)); } -Resource Resource::style(const std::string& url) { +Resource Resource::style(const std::string& url, const Priority priority) { return Resource { Resource::Kind::Style, - url + url, + priority }; } -Resource Resource::source(const std::string& url) { +Resource Resource::source(const std::string& url, const Priority priority) { return Resource { Resource::Kind::Source, - url + url, + priority }; } -Resource Resource::image(const std::string& url) { +Resource Resource::image(const std::string& url, const Priority priority) { return Resource { Resource::Kind::Image, - url + url, + priority }; } -Resource Resource::spriteImage(const std::string& base, float pixelRatio) { +Resource Resource::spriteImage(const std::string& base, float pixelRatio, const Priority priority) { util::URL url(base); return Resource{ Resource::Kind::SpriteImage, base.substr(0, url.path.first + url.path.second) + (pixelRatio > 1 ? "@2x" : "") + ".png" + - base.substr(url.query.first, url.query.second) }; + base.substr(url.query.first, url.query.second), + priority }; } -Resource Resource::spriteJSON(const std::string& base, float pixelRatio) { +Resource Resource::spriteJSON(const std::string& base, float pixelRatio, const Priority priority) { util::URL url(base); return Resource{ Resource::Kind::SpriteJSON, base.substr(0, url.path.first + url.path.second) + (pixelRatio > 1 ? "@2x" : "") + ".json" + - base.substr(url.query.first, url.query.second) }; + base.substr(url.query.first, url.query.second), + priority }; } -Resource Resource::glyphs(const std::string& urlTemplate, const FontStack& fontStack, const std::pair& glyphRange) { +Resource Resource::glyphs(const std::string& urlTemplate, const FontStack& fontStack, const std::pair& glyphRange, const Priority priority) { return Resource { Resource::Kind::Glyphs, util::replaceTokens(urlTemplate, [&](const std::string& token) -> optional { @@ -87,7 +92,8 @@ Resource Resource::glyphs(const std::string& urlTemplate, const FontStack& fontS } else { return {}; } - }) + }), + priority }; } @@ -97,6 +103,7 @@ Resource Resource::tile(const std::string& urlTemplate, int32_t y, int8_t z, Tileset::Scheme scheme, + const Priority priority, LoadingMethod loadingMethod) { bool supportsRatio = urlTemplate.find("{ratio}") != std::string::npos; if (scheme == Tileset::Scheme::TMS) { @@ -126,6 +133,7 @@ Resource Resource::tile(const std::string& urlTemplate, return {}; } }), + priority, Resource::TileData { urlTemplate, uint8_t(supportsRatio && pixelRatio > 1.0 ? 2 : 1), diff --git a/src/mbgl/tile/tile_loader_impl.hpp b/src/mbgl/tile/tile_loader_impl.hpp index 1b29638269..5835858d1a 100644 --- a/src/mbgl/tile/tile_loader_impl.hpp +++ b/src/mbgl/tile/tile_loader_impl.hpp @@ -23,6 +23,7 @@ TileLoader::TileLoader(T& tile_, id.canonical.y, id.canonical.z, tileset.scheme, + Resource::Priority::Regular, Resource::LoadingMethod::CacheOnly)), fileSource(parameters.fileSource) { assert(!request); -- cgit v1.2.1