Added operator implementations for mbgl::Update enum class

This commit is contained in:
Bruno de Oliveira Abinader
2015-08-13 06:53:40 +03:00
parent 5abb18a99c
commit ac9d5886f0
6 changed files with 36 additions and 30 deletions

View File

@@ -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<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
}
#endif
inline Update& operator|=(Update& lhs, const Update& rhs) {
lhs = lhs | rhs;
return lhs;
}
inline bool operator& (const Update& lhs, const Update& rhs) {
return static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs);
}
} // namespace mbgl
#endif // MBGL_MAP_UPDATE

View File

@@ -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<UpdateType>(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

View File

@@ -33,7 +33,6 @@ namespace mbgl {
MapContext::MapContext(View& view_, FileSource& fileSource, MapData& data_)
: view(view_),
data(data_),
updated(static_cast<UpdateType>(Update::Nothing)),
asyncUpdate(std::make_unique<uv::async>(util::RunLoop::getLoop(), [this] { update(); })),
texturePool(std::make_unique<TexturePool>()),
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<UpdateType>(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<UpdateType>(Update::DefaultTransition);
updated |= static_cast<UpdateType>(Update::Classes);
updated |= static_cast<UpdateType>(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<TileID, TileID::
}
}
updated |= static_cast<UpdateType>(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<UpdateType>(Update::Nothing);
updateFlags = Update::Nothing;
}
if (updated == static_cast<UpdateType>(Update::Nothing)) {
if (updateFlags == Update::Nothing) {
return;
}
data.setAnimationTime(Clock::now());
if (updated & static_cast<UpdateType>(Update::Classes)) {
if (updateFlags & Update::Classes) {
style->cascade();
}
if (updated & static_cast<UpdateType>(Update::Classes) ||
updated & static_cast<UpdateType>(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<UpdateType>(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<UpdateType>(Update::RenderStill);
updateFlags |= Update::RenderStill;
asyncUpdate->send();
}
@@ -400,7 +396,7 @@ void MapContext::setSprite(const std::string& name, std::shared_ptr<const Sprite
void MapContext::onTileDataChanged() {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
updated |= static_cast<UpdateType>(Update::Repaint);
updateFlags |= Update::Repaint;
asyncUpdate->send();
}

View File

@@ -81,7 +81,7 @@ private:
util::GLObjectStore glObjectStore;
UpdateType updated { static_cast<UpdateType>(Update::Nothing) };
Update updateFlags = Update::Nothing;
std::unique_ptr<uv::async> asyncUpdate;
std::unique_ptr<TexturePool> texturePool;

View File

@@ -377,8 +377,8 @@ void Transform::startTransition(std::function<Update(double)> frame,
transitionFinishFn = finish;
}
UpdateType Transform::updateTransitions(const TimePoint& now) {
return static_cast<UpdateType>(transitionFrameFn ? transitionFrameFn(now) : Update::Nothing);
Update Transform::updateTransitions(const TimePoint& now) {
return transitionFrameFn ? transitionFrameFn(now) : Update::Nothing;
}
void Transform::cancelTransitions() {

View File

@@ -42,7 +42,7 @@ public:
double getAngle() const;
// Transitions
UpdateType updateTransitions(const TimePoint& now);
Update updateTransitions(const TimePoint& now);
void cancelTransitions();
// Gesture