[core] Nestable BackendScope

This commit is contained in:
John Firebaugh
2017-02-17 10:57:21 -08:00
parent 3ef9e26593
commit 694159c49e
6 changed files with 47 additions and 14 deletions

View File

@@ -104,11 +104,13 @@ set(MBGL_CORE_FILES
# map
include/mbgl/map/backend.hpp
include/mbgl/map/backend_scope.hpp
include/mbgl/map/camera.hpp
include/mbgl/map/map.hpp
include/mbgl/map/mode.hpp
include/mbgl/map/view.hpp
src/mbgl/map/backend.cpp
src/mbgl/map/backend_scope.cpp
src/mbgl/map/change.hpp
src/mbgl/map/map.cpp
src/mbgl/map/transform.cpp

View File

@@ -47,18 +47,4 @@ private:
friend class BackendScope;
};
class BackendScope {
public:
BackendScope(Backend& backend_) : backend(backend_) {
backend.activate();
}
~BackendScope() {
backend.deactivate();
}
private:
Backend& backend;
};
} // namespace mbgl

View File

@@ -0,0 +1,17 @@
#pragma once
namespace mbgl {
class Backend;
class BackendScope {
public:
BackendScope(Backend&);
~BackendScope();
private:
Backend* priorBackend;
Backend& backend;
};
} // namespace mbgl

View File

@@ -16,6 +16,7 @@
#include <mbgl/util/logging.hpp>
#include <mbgl/gl/extension.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/map/backend_scope.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/shared_thread_pool.hpp>

View File

@@ -0,0 +1,26 @@
#include <mbgl/map/backend_scope.hpp>
#include <mbgl/map/backend.hpp>
#include <mbgl/util/thread_local.hpp>
namespace mbgl {
static util::ThreadLocal<Backend> currentBackend;
BackendScope::BackendScope(Backend& backend_)
: priorBackend(currentBackend.get()),
backend(backend_) {
backend.activate();
currentBackend.set(&backend);
}
BackendScope::~BackendScope() {
if (priorBackend) {
priorBackend->activate();
currentBackend.set(priorBackend);
} else {
backend.deactivate();
currentBackend.set(nullptr);
}
}
} // namespace mbgl

View File

@@ -2,6 +2,7 @@
#include <mbgl/map/camera.hpp>
#include <mbgl/map/view.hpp>
#include <mbgl/map/backend.hpp>
#include <mbgl/map/backend_scope.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/annotation/annotation_manager.hpp>