diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-05-03 14:53:03 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-05-05 08:56:36 -0700 |
commit | 66da7594263b657b78aff54a16905184505e275e (patch) | |
tree | 3f940c3852ff7a7d4f2b885c742e4fac06c84abc | |
parent | fd104dd3c229ce42d149a143260407cd259b716c (diff) | |
download | qtlocation-mapboxgl-66da7594263b657b78aff54a16905184505e275e.tar.gz |
[core] Reduce use of RecalculateStyle
* Don't use it to track zoom changes. Instead, Style::update can use the zoom history to check for a change in zoom from the previous frame.
* Don't use it to track active property transitions. Style already knows which layers/light have an active transition, and can re-evaluate only those that do.
This leaves layer property changes as the only use of RecalculateStyle.
-rw-r--r-- | src/mbgl/map/map.cpp | 32 | ||||
-rw-r--r-- | src/mbgl/map/transform.cpp | 18 | ||||
-rw-r--r-- | src/mbgl/map/transform.hpp | 7 | ||||
-rw-r--r-- | src/mbgl/map/zoom_history.hpp | 31 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 13 |
5 files changed, 48 insertions, 53 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 5d52fc130b..bba6d50a98 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -231,9 +231,7 @@ void Map::Impl::render(View& view) { ? Clock::now() : Clock::time_point::max(); - auto flags = transform.updateTransitions(timePoint); - - updateFlags |= flags; + transform.updateTransitions(timePoint); if (style->loaded && updateFlags & Update::AnnotationStyle) { annotationManager->updateStyle(*style); @@ -297,16 +295,10 @@ void Map::Impl::render(View& view) { } } - if (style->hasTransitions()) { - flags |= Update::RecalculateStyle; - } else if (painter->needsAnimation()) { - flags |= Update::Repaint; - } - - // Only schedule an update if we need to paint another frame due to transitions or + // Schedule an update if we need to paint another frame due to transitions or // animations that are still in progress - if (flags != Update::Nothing) { - onUpdate(flags); + if (style->hasTransitions() || painter->needsAnimation() || transform.inTransition()) { + onUpdate(Update::Repaint); } } else if (stillImageRequest && style->isLoaded()) { FrameData frameData { timePoint, @@ -409,7 +401,7 @@ void Map::Impl::loadStyleJSON(const std::string& json) { map.setPitch(map.getDefaultPitch()); } - onUpdate(Update::Classes | Update::RecalculateStyle | Update::AnnotationStyle); + onUpdate(Update::Classes | Update::AnnotationStyle); } std::string Map::getStyleURL() const { @@ -457,19 +449,19 @@ CameraOptions Map::getCameraOptions(const EdgeInsets& padding) const { void Map::jumpTo(const CameraOptions& camera) { impl->cameraMutated = true; impl->transform.jumpTo(camera); - impl->onUpdate(camera.zoom ? Update::RecalculateStyle : Update::Repaint); + impl->onUpdate(Update::Repaint); } void Map::easeTo(const CameraOptions& camera, const AnimationOptions& animation) { impl->cameraMutated = true; impl->transform.easeTo(camera, animation); - impl->onUpdate(camera.zoom ? Update::RecalculateStyle : Update::Repaint); + impl->onUpdate(Update::Repaint); } void Map::flyTo(const CameraOptions& camera, const AnimationOptions& animation) { impl->cameraMutated = true; impl->transform.flyTo(camera, animation); - impl->onUpdate(Update::RecalculateStyle); + impl->onUpdate(Update::Repaint); } #pragma mark - Position @@ -510,7 +502,7 @@ void Map::resetPosition(const EdgeInsets& padding) { camera.padding = padding; camera.zoom = 0; impl->transform.jumpTo(camera); - impl->onUpdate(Update::RecalculateStyle); + impl->onUpdate(Update::Repaint); } @@ -524,13 +516,13 @@ void Map::setZoom(double zoom, const AnimationOptions& animation) { void Map::setZoom(double zoom, optional<ScreenCoordinate> anchor, const AnimationOptions& animation) { impl->cameraMutated = true; impl->transform.setZoom(zoom, anchor, animation); - impl->onUpdate(Update::RecalculateStyle); + impl->onUpdate(Update::Repaint); } void Map::setZoom(double zoom, const EdgeInsets& padding, const AnimationOptions& animation) { impl->cameraMutated = true; impl->transform.setZoom(zoom, padding, animation); - impl->onUpdate(Update::RecalculateStyle); + impl->onUpdate(Update::Repaint); } double Map::getZoom() const { @@ -545,7 +537,7 @@ void Map::setLatLngZoom(const LatLng& latLng, double zoom, const AnimationOption void Map::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInsets& padding, const AnimationOptions& animation) { impl->cameraMutated = true; impl->transform.setLatLngZoom(latLng, zoom, padding, animation); - impl->onUpdate(Update::RecalculateStyle); + impl->onUpdate(Update::Repaint); } CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, const EdgeInsets& padding) const { diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 0480ce4d9d..9f3a2a83d2 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -122,8 +122,6 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim const double scale = state.zoomScale(zoom); pitch = util::clamp(pitch, state.min_pitch, state.max_pitch); - Update update = state.getZoom() == zoom ? Update::Repaint : Update::RecalculateStyle; - // Minimize rotation by taking the shorter path around the circle. angle = _normalizeAngle(angle, state.angle); state.angle = _normalizeAngle(state.angle, angle); @@ -153,7 +151,6 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim if (!padding.isFlush()) { state.moveLatLng(frameLatLng, center); } - return update; }, duration); } @@ -313,7 +310,6 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima if (!padding.isFlush()) { state.moveLatLng(frameLatLng, center); } - return Update::RecalculateStyle; }, duration); } @@ -533,7 +529,7 @@ ViewportMode Transform::getViewportMode() const { void Transform::startTransition(const CameraOptions& camera, const AnimationOptions& animation, - std::function<Update(double)> frame, + std::function<void(double)> frame, const Duration& duration) { if (transitionFinishFn) { transitionFinishFn(); @@ -555,12 +551,11 @@ void Transform::startTransition(const CameraOptions& camera, transitionFrameFn = [isAnimated, animation, frame, anchor, anchorLatLng, this](const TimePoint now) { float t = isAnimated ? (std::chrono::duration<float>(now - transitionStart) / transitionDuration) : 1.0; - Update result; if (t >= 1.0) { - result = frame(1.0); + frame(1.0); } else { util::UnitBezier ease = animation.easing ? *animation.easing : util::DEFAULT_TRANSITION_EASE; - result = frame(ease.solve(t, 0.001)); + frame(ease.solve(t, 0.001)); } if (anchor) state.moveLatLng(anchorLatLng, *anchor); @@ -579,7 +574,6 @@ void Transform::startTransition(const CameraOptions& camera, // we can only return after this point. transitionFrameFn = nullptr; } - return result; }; transitionFinishFn = [isAnimated, animation, this] { @@ -601,8 +595,10 @@ bool Transform::inTransition() const { return transitionFrameFn != nullptr; } -Update Transform::updateTransitions(const TimePoint& now) { - return transitionFrameFn ? transitionFrameFn(now) : Update::Nothing; +void Transform::updateTransitions(const TimePoint& now) { + if (transitionFrameFn) { + transitionFrameFn(now); + } } void Transform::cancelTransitions() { diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index 2c59a6c1aa..af2f821602 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -4,7 +4,6 @@ #include <mbgl/map/map_observer.hpp> #include <mbgl/map/mode.hpp> #include <mbgl/map/transform_state.hpp> -#include <mbgl/map/update.hpp> #include <mbgl/util/chrono.hpp> #include <mbgl/util/geo.hpp> #include <mbgl/util/noncopyable.hpp> @@ -128,7 +127,7 @@ public: // Transitions bool inTransition() const; - Update updateTransitions(const TimePoint& now); + void updateTransitions(const TimePoint& now); TimePoint getTransitionStart() const { return transitionStart; } Duration getTransitionDuration() const { return transitionDuration; } void cancelTransitions(); @@ -153,12 +152,12 @@ private: void startTransition(const CameraOptions&, const AnimationOptions&, - std::function<Update(double)>, + std::function<void(double)>, const Duration&); TimePoint transitionStart; Duration transitionDuration; - std::function<Update(const TimePoint)> transitionFrameFn; + std::function<void(const TimePoint)> transitionFrameFn; std::function<void()> transitionFinishFn; }; diff --git a/src/mbgl/map/zoom_history.hpp b/src/mbgl/map/zoom_history.hpp index 8c88ea6507..308846b1e3 100644 --- a/src/mbgl/map/zoom_history.hpp +++ b/src/mbgl/map/zoom_history.hpp @@ -12,25 +12,30 @@ struct ZoomHistory { TimePoint lastIntegerZoomTime; bool first = true; - void update(float z, const TimePoint& now) { + bool update(float z, const TimePoint& now) { if (first) { first = false; - lastIntegerZoom = std::floor(z); lastIntegerZoomTime = TimePoint(Duration::zero()); lastZoom = z; + return true; + } else { + if (std::floor(lastZoom) < std::floor(z)) { + lastIntegerZoom = std::floor(z); + lastIntegerZoomTime = now; + } else if (std::floor(lastZoom) > std::floor(z)) { + lastIntegerZoom = std::floor(z + 1); + lastIntegerZoomTime = now; + } + + if (z != lastZoom) { + lastZoom = z; + return true; + } + + return false; } - - if (std::floor(lastZoom) < std::floor(z)) { - lastIntegerZoom = std::floor(z); - lastIntegerZoomTime = now; - - } else if (std::floor(lastZoom) > std::floor(z)) { - lastIntegerZoom = std::floor(z + 1); - lastIntegerZoomTime = now; - } - - lastZoom = z; } }; + } // namespace mbgl diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 1fc738cb84..d2821751be 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -329,7 +329,7 @@ double Style::getDefaultPitch() const { } void Style::update(const UpdateParameters& parameters) { - zoomHistory.update(parameters.transformState.getZoom(), parameters.timePoint); + bool zoomChanged = zoomHistory.update(parameters.transformState.getZoom(), parameters.timePoint); std::vector<ClassID> classIDs; for (const auto& className : classes) { @@ -358,11 +358,14 @@ void Style::update(const UpdateParameters& parameters) { parameters.annotationManager, *this); - if (parameters.updateFlags & Update::Classes) { + const bool cascade = parameters.updateFlags & Update::Classes; + const bool evaluate = cascade || zoomChanged || parameters.updateFlags & Update::RecalculateStyle; + + if (cascade) { transitioningLight = TransitioningLight(*light, std::move(transitioningLight), cascadeParameters); } - if (parameters.updateFlags & Update::RecalculateStyle) { + if (evaluate || transitioningLight.hasTransition()) { evaluatedLight = EvaluatedLight(transitioningLight, evaluationParameters); } @@ -371,11 +374,11 @@ void Style::update(const UpdateParameters& parameters) { } for (const auto& layer : renderLayers) { - if (parameters.updateFlags & Update::Classes) { + if (cascade) { layer->cascade(cascadeParameters); } - if (parameters.updateFlags & Update::Classes || parameters.updateFlags & Update::RecalculateStyle) { + if (evaluate || layer->hasTransition()) { layer->evaluate(evaluationParameters); } |