summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2015-07-12 22:00:32 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2015-07-14 16:44:42 +0300
commit7023ea061c79468843178a636cb83e8c5044a1e5 (patch)
tree9c791066beb13b0f7585a8ed0ed2eb0fba5fee33
parent77a91f64d8afb08a6d3e48da4348f6e9f7c67e69 (diff)
downloadqtlocation-mapboxgl-7023ea061c79468843178a636cb83e8c5044a1e5.tar.gz
Unify time point for Mapcontext::update
- Let style classes cascade use the same time point as the one used to recalculate style. - Cleaned up MapContext::update to return early whenever possible. - Cleaned up MapContext::loadStyleJSON to avoid redundant calls to style classes cascade.
-rw-r--r--src/mbgl/map/map_context.cpp48
-rw-r--r--src/mbgl/map/map_context.hpp3
-rw-r--r--src/mbgl/style/style.cpp4
-rw-r--r--src/mbgl/style/style.hpp2
4 files changed, 25 insertions, 32 deletions
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index 4447ecc4f0..fc700581d9 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -131,10 +131,10 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
style->setJSON(json, base);
- style->cascade(data.getClasses());
- style->setDefaultTransitionDuration(data.getDefaultTransitionDuration());
style->setObserver(this);
+ updated |= static_cast<UpdateType>(Update::DefaultTransitionDuration);
+ updated |= static_cast<UpdateType>(Update::Classes);
updated |= static_cast<UpdateType>(Update::Zoom);
asyncUpdate->send();
@@ -240,45 +240,43 @@ void MapContext::updateAnnotationTiles(const std::unordered_set<TileID, TileID::
}
}
- cascadeClasses();
-
updated |= static_cast<UpdateType>(Update::Classes);
asyncUpdate->send();
annotationManager->resetStaleTiles();
}
-void MapContext::cascadeClasses() {
- style->cascade(data.getClasses());
-}
-
void MapContext::update() {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
- const auto now = Clock::now();
+ if (!style) {
+ updated = static_cast<UpdateType>(Update::Nothing);
+ return;
+ }
+
+ TimePoint now = Clock::now();
+
data.setAnimationTime(now);
- if (style) {
- if (updated & static_cast<UpdateType>(Update::DefaultTransitionDuration)) {
- style->setDefaultTransitionDuration(data.getDefaultTransitionDuration());
- }
+ if (updated & static_cast<UpdateType>(Update::DefaultTransitionDuration)) {
+ style->setDefaultTransitionDuration(data.getDefaultTransitionDuration());
+ }
- if (updated & static_cast<UpdateType>(Update::Classes)) {
- cascadeClasses();
- }
+ if (updated & static_cast<UpdateType>(Update::Classes)) {
+ style->cascade(data.getClasses(), now);
+ }
- if (updated & static_cast<UpdateType>(Update::Classes) ||
+ if (updated & static_cast<UpdateType>(Update::Classes) ||
updated & static_cast<UpdateType>(Update::Zoom)) {
- style->recalculate(transformState.getNormalizedZoom(), now);
- }
+ style->recalculate(transformState.getNormalizedZoom(), now);
+ }
- style->update(transformState, *texturePool);
+ style->update(transformState, *texturePool);
- if (data.mode == MapMode::Continuous) {
- view.invalidate();
- } else if (callback && style->isLoaded()) {
- renderSync(transformState, frameData);
- }
+ if (data.mode == MapMode::Continuous) {
+ view.invalidate();
+ } else if (callback && style->isLoaded()) {
+ renderSync(transformState, frameData);
}
updated = static_cast<UpdateType>(Update::Nothing);
diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp
index 2e60d8eae0..8c8c90ff8b 100644
--- a/src/mbgl/map/map_context.hpp
+++ b/src/mbgl/map/map_context.hpp
@@ -72,9 +72,6 @@ public:
void onResourceLoadingFailed(std::exception_ptr error) override;
private:
- // Style-related updates.
- void cascadeClasses();
-
// Update the state indicated by the accumulated Update flags, then render.
void update();
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index e091c92f53..4e0c41185a 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -86,9 +86,7 @@ void Style::update(const TransformState& transform,
}
}
-void Style::cascade(const std::vector<std::string>& classes) {
- TimePoint now = Clock::now();
-
+void Style::cascade(const std::vector<std::string>& classes, TimePoint now) {
for (const auto& layer : layers) {
layer->setClasses(classes, now, defaultTransition);
}
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index d6b762a830..850c066592 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -54,7 +54,7 @@ public:
// a tile is ready so observers can render the tile.
void update(const TransformState&, TexturePool&);
- void cascade(const std::vector<std::string>&);
+ void cascade(const std::vector<std::string>&, TimePoint now);
void recalculate(float z, TimePoint now);
void setDefaultTransitionDuration(Duration);