From 5daba7b43475b539b4337b559fd35aba668ad498 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 12 Jun 2017 15:11:44 -0700 Subject: [PATCH 1/4] [core] Skip calculations when we already know we need rendering or layout --- src/mbgl/renderer/render_style.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mbgl/renderer/render_style.cpp b/src/mbgl/renderer/render_style.cpp index 9b0b512bf9e..c8918fc2eeb 100644 --- a/src/mbgl/renderer/render_style.cpp +++ b/src/mbgl/renderer/render_style.cpp @@ -203,14 +203,15 @@ void RenderStyle::update(const UpdateParameters& parameters) { continue; } - if (getRenderLayer(layer->id)->needsRendering(zoomHistory.lastZoom)) { + if (!needsRendering && getRenderLayer(layer->id)->needsRendering(zoomHistory.lastZoom)) { needsRendering = true; } - if (hasLayoutDifference(layerDiff, layer->id) || + if (!needsRelayout && ( + hasLayoutDifference(layerDiff, layer->id) || !imageDiff.added.empty() || !imageDiff.removed.empty() || - !imageDiff.changed.empty()) { + !imageDiff.changed.empty())) { needsRelayout = true; } From c266c01687c9684db9d1a8270ffa2afe7bd75057 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 12 Jun 2017 15:21:15 -0700 Subject: [PATCH 2/4] [core] Obey "transition" property from style and its default value --- include/mbgl/util/constants.hpp | 2 +- src/mbgl/renderer/painter.cpp | 4 ++-- src/mbgl/renderer/render_style.cpp | 2 +- src/mbgl/style/parser.cpp | 15 +++++++++++++++ src/mbgl/style/parser.hpp | 2 ++ src/mbgl/style/style.cpp | 1 + 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp index 0f2779e33b5..14aaa752bc1 100644 --- a/include/mbgl/util/constants.hpp +++ b/include/mbgl/util/constants.hpp @@ -40,7 +40,7 @@ constexpr float MAX_ZOOM_F = MAX_ZOOM; constexpr uint64_t DEFAULT_MAX_CACHE_SIZE = 50 * 1024 * 1024; -constexpr Duration DEFAULT_FADE_DURATION = Milliseconds(300); +constexpr Duration DEFAULT_TRANSITION_DURATION = Milliseconds(300); constexpr Seconds CLOCK_SKEW_RETRY_TIMEOUT { 30 }; constexpr UnitBezier DEFAULT_TRANSITION_EASE = { 0, 0, 0.25, 1 }; diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 1f55c168a6e..edec98047d2 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -115,7 +115,7 @@ Painter::Painter(gl::Context& context_, Painter::~Painter() = default; bool Painter::needsAnimation() const { - return frameHistory.needsAnimation(util::DEFAULT_FADE_DURATION); + return frameHistory.needsAnimation(util::DEFAULT_TRANSITION_DURATION); } void Painter::cleanup() { @@ -159,7 +159,7 @@ void Painter::render(RenderStyle& style, const FrameData& frame_, View& view) { } frameHistory.record(frame.timePoint, state.getZoom(), - frame.mapMode == MapMode::Continuous ? util::DEFAULT_FADE_DURATION : Milliseconds(0)); + frame.mapMode == MapMode::Continuous ? util::DEFAULT_TRANSITION_DURATION : Milliseconds(0)); // - UPLOAD PASS ------------------------------------------------------------------------------- diff --git a/src/mbgl/renderer/render_style.cpp b/src/mbgl/renderer/render_style.cpp index c8918fc2eeb..589a4936218 100644 --- a/src/mbgl/renderer/render_style.cpp +++ b/src/mbgl/renderer/render_style.cpp @@ -88,7 +88,7 @@ void RenderStyle::update(const UpdateParameters& parameters) { const PropertyEvaluationParameters evaluationParameters { zoomHistory, parameters.mode == MapMode::Continuous ? parameters.timePoint : Clock::time_point::max(), - parameters.mode == MapMode::Continuous ? util::DEFAULT_FADE_DURATION : Duration::zero() + parameters.mode == MapMode::Continuous ? util::DEFAULT_TRANSITION_DURATION : Duration::zero() }; const TileParameters tileParameters { diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index 725feb3fc20..467b44632c8 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -86,6 +86,10 @@ StyleParseResult Parser::parse(const std::string& json) { } } + if (document.HasMember("transition")) { + parseTransition(document["transition"]); + } + if (document.HasMember("light")) { parseLight(document["light"]); } @@ -115,6 +119,17 @@ StyleParseResult Parser::parse(const std::string& json) { return nullptr; } +void Parser::parseTransition(const JSValue& value) { + conversion::Error error; + optional converted = conversion::convert(value, error); + if (!converted) { + Log::Warning(Event::ParseStyle, error.message); + return; + } + + transition = std::move(*converted); +} + void Parser::parseLight(const JSValue& value) { conversion::Error error; optional converted = conversion::convert(value, error); diff --git a/src/mbgl/style/parser.hpp b/src/mbgl/style/parser.hpp index 32b8a7a8bcb..401b5ff513a 100644 --- a/src/mbgl/style/parser.hpp +++ b/src/mbgl/style/parser.hpp @@ -32,6 +32,7 @@ class Parser { std::vector> sources; std::vector> layers; + TransitionOptions transition; Light light; std::string name; @@ -44,6 +45,7 @@ class Parser { std::vector fontStacks() const; private: + void parseTransition(const JSValue&); void parseLight(const JSValue&); void parseSources(const JSValue&); void parseLayers(const JSValue&); diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 27ca58e85da..94e003df516 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -57,6 +57,7 @@ void Style::setJSON(const std::string& json) { images.clear(); transitionOptions = {}; + transitionOptions.duration = util::DEFAULT_TRANSITION_DURATION; Parser parser; auto error = parser.parse(json); From 6490e5d074d2d6eddc8df13e3618b169019848a2 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 12 Jun 2017 15:12:28 -0700 Subject: [PATCH 3/4] [core] Implement "smart setStyle" --- src/mbgl/map/map.cpp | 149 +++++++++-------------------------- test/api/api_misuse.test.cpp | 28 ------- 2 files changed, 38 insertions(+), 139 deletions(-) diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index e685251b803..0df9f11112b 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -165,6 +165,8 @@ Map::Impl::Impl(Map& map_, renderStill(); } }) { + style = std::make_unique