diff --git a/include/mbgl/map/update.hpp b/include/mbgl/map/update.hpp index d5978d80b6d..fe9250efcff 100644 --- a/include/mbgl/map/update.hpp +++ b/include/mbgl/map/update.hpp @@ -5,9 +5,7 @@ namespace mbgl { -using UpdateType = uint32_t; - -enum class Update : UpdateType { +enum class Update : uint32_t { Nothing = 0, Dimensions = 1 << 1, DefaultTransition = 1 << 2, @@ -17,6 +15,19 @@ enum class Update : UpdateType { Repaint = 1 << 6, }; +inline Update operator| (const Update& lhs, const Update& rhs) { + return Update(static_cast(lhs) | static_cast(rhs)); +} + +inline Update& operator|=(Update& lhs, const Update& rhs) { + lhs = lhs | rhs; + return lhs; } -#endif +inline bool operator& (const Update& lhs, const Update& rhs) { + return static_cast(lhs) & static_cast(rhs); +} + +} // namespace mbgl + +#endif // MBGL_MAP_UPDATE diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index a7015695c1e..9bfb0484192 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -71,19 +71,18 @@ void Map::renderSync() { } void Map::nudgeTransitions() { - UpdateType update_ = transform->updateTransitions(Clock::now()); + Update flags = transform->updateTransitions(Clock::now()); if (data->getNeedsRepaint()) { - update_ |= static_cast(Update::Repaint); + flags |= Update::Repaint; } - update(Update(update_)); + update(flags); } -void Map::update(Update update_) { - if (update_ == Update::Dimensions) { +void Map::update(Update flags) { + if (flags & Update::Dimensions) { transform->resize(view.getSize()); } - - context->invoke(&MapContext::triggerUpdate, transform->getState(), update_); + context->invoke(&MapContext::triggerUpdate, transform->getState(), flags); } #pragma mark - Style diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index c14a61b8b7e..bbcfa37b46a 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -33,7 +33,6 @@ namespace mbgl { MapContext::MapContext(View& view_, FileSource& fileSource, MapData& data_) : view(view_), data(data_), - updated(static_cast(Update::Nothing)), asyncUpdate(std::make_unique(util::RunLoop::getLoop(), [this] { update(); })), texturePool(std::make_unique()), viewInvalidated(false) { @@ -84,9 +83,9 @@ void MapContext::pause() { view.activate(); } -void MapContext::triggerUpdate(const TransformState& state, const Update u) { +void MapContext::triggerUpdate(const TransformState& state, const Update flags) { transformState = state; - updated |= static_cast(u); + updateFlags |= flags; asyncUpdate->send(); } @@ -138,9 +137,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base) // force style cascade, causing all pending transitions to complete. style->cascade(); - updated |= static_cast(Update::DefaultTransition); - updated |= static_cast(Update::Classes); - updated |= static_cast(Update::Zoom); + updateFlags |= Update::DefaultTransition | Update::Classes | Update::Zoom; asyncUpdate->send(); auto staleTiles = data.getAnnotationManager()->resetStaleTiles(); @@ -245,7 +242,7 @@ void MapContext::updateAnnotationTiles(const std::unordered_set(Update::Classes); + updateFlags |= Update::Classes; asyncUpdate->send(); annotationManager->resetStaleTiles(); @@ -255,21 +252,20 @@ void MapContext::update() { assert(util::ThreadContext::currentlyOn(util::ThreadType::Map)); if (!style) { - updated = static_cast(Update::Nothing); + updateFlags = Update::Nothing; } - if (updated == static_cast(Update::Nothing)) { + if (updateFlags == Update::Nothing) { return; } data.setAnimationTime(Clock::now()); - if (updated & static_cast(Update::Classes)) { + if (updateFlags & Update::Classes) { style->cascade(); } - if (updated & static_cast(Update::Classes) || - updated & static_cast(Update::Zoom)) { + if (updateFlags & Update::Classes || updateFlags & Update::Zoom) { style->recalculate(transformState.getNormalizedZoom()); } @@ -281,7 +277,7 @@ void MapContext::update() { renderSync(transformState, frameData); } - updated = static_cast(Update::Nothing); + updateFlags = Update::Nothing; } void MapContext::renderStill(const TransformState& state, const FrameData& frame, Map::StillImageCallback fn) { @@ -314,7 +310,7 @@ void MapContext::renderStill(const TransformState& state, const FrameData& frame transformState = state; frameData = frame; - updated |= static_cast(Update::RenderStill); + updateFlags |= Update::RenderStill; asyncUpdate->send(); } @@ -400,7 +396,7 @@ void MapContext::setSprite(const std::string& name, std::shared_ptr(Update::Repaint); + updateFlags |= Update::Repaint; asyncUpdate->send(); } diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index 215f5d377a6..5964c6686ee 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -81,7 +81,7 @@ class MapContext : public Style::Observer { util::GLObjectStore glObjectStore; - UpdateType updated { static_cast(Update::Nothing) }; + Update updateFlags = Update::Nothing; std::unique_ptr asyncUpdate; std::unique_ptr texturePool; diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 29ca54d78be..580b5ca15f4 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -377,8 +377,8 @@ void Transform::startTransition(std::function frame, transitionFinishFn = finish; } -UpdateType Transform::updateTransitions(const TimePoint& now) { - return static_cast(transitionFrameFn ? transitionFrameFn(now) : Update::Nothing); +Update Transform::updateTransitions(const TimePoint& now) { + return transitionFrameFn ? transitionFrameFn(now) : Update::Nothing; } void Transform::cancelTransitions() { diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index f4a78bbcb5c..57dc8c4534f 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -42,7 +42,7 @@ class Transform : private util::noncopyable { double getAngle() const; // Transitions - UpdateType updateTransitions(const TimePoint& now); + Update updateTransitions(const TimePoint& now); void cancelTransitions(); // Gesture