From 21e4029acf757898da8695474f94642f9858acd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 4 Jan 2016 12:30:13 +0100 Subject: [PATCH] [core] use stale styles This adds support for using cached styles that are stale. They're treated like changing styles; when the refreshed style changed compared to the one we've already had, we're swapping out the entire style, which might cause a slight flicker. --- platform/linux/scripts/after_script.sh | 4 +- src/mbgl/map/map_context.cpp | 15 +++--- src/mbgl/style/style.cpp | 3 ++ test/fixtures/stale/0-0-0.vector.pbf | Bin 0 -> 482553 bytes test/fixtures/stale/stale_style/expected.png | Bin 0 -> 13447 bytes test/fixtures/stale/streets.json | 14 +++++ test/fixtures/stale/style.json | 25 +++++++++ test/storage/cache_stale.cpp | 51 +++++++++++++++++++ test/storage/server.js | 3 ++ test/test.gypi | 1 + 10 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 test/fixtures/stale/0-0-0.vector.pbf create mode 100644 test/fixtures/stale/stale_style/expected.png create mode 100644 test/fixtures/stale/streets.json create mode 100644 test/fixtures/stale/style.json create mode 100644 test/storage/cache_stale.cpp diff --git a/platform/linux/scripts/after_script.sh b/platform/linux/scripts/after_script.sh index f8e4bc348..b5397f1df 100755 --- a/platform/linux/scripts/after_script.sh +++ b/platform/linux/scripts/after_script.sh @@ -10,6 +10,6 @@ if [ ! -z "${AWS_ACCESS_KEY_ID}" ] && [ ! -z "${AWS_SECRET_ACCESS_KEY}" ] ; then REPO_NAME=$(basename $TRAVIS_REPO_SLUG) - aws s3 cp --recursive --acl public-read test/fixtures/annotations \ - s3://mapbox/$REPO_NAME/render-tests/$TRAVIS_JOB_NUMBER/annotations + aws s3 cp --recursive --acl public-read --exclude "*" --include "*/actual.png" test/fixtures \ + s3://mapbox/$REPO_NAME/render-tests/$TRAVIS_JOB_NUMBER fi diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 6f12e968b..eb17e20ae 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -105,12 +105,6 @@ void MapContext::setStyleURL(const std::string& url) { FileSource* fs = util::ThreadContext::getFileSource(); styleRequest = fs->request({ Resource::Kind::Style, styleURL }, [this, base](Response res) { - if (res.stale) { - // Only handle fresh responses. - return; - } - styleRequest = nullptr; - if (res.error) { if (res.error->reason == Response::Error::Reason::NotFound && util::mapbox::isMapboxURL(styleURL)) { @@ -120,9 +114,11 @@ void MapContext::setStyleURL(const std::string& url) { data.loading = false; } } else { - loadStyleJSON(*res.data, base); + // We got a new stylesheet; only update when it's different from the previous one. + if (styleJSON != *res.data) { + loadStyleJSON(*res.data, base); + } } - }); } @@ -132,7 +128,7 @@ void MapContext::setStyleJSON(const std::string& json, const std::string& base) } styleURL.clear(); - styleJSON = json; + styleJSON.clear(); style = std::make_unique