summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/backend.cpp2
-rw-r--r--src/mbgl/map/backend_scope.cpp19
-rw-r--r--src/mbgl/map/map.cpp3
3 files changed, 19 insertions, 5 deletions
diff --git a/src/mbgl/map/backend.cpp b/src/mbgl/map/backend.cpp
index 2a171cdb76..a1a2f8f3a8 100644
--- a/src/mbgl/map/backend.cpp
+++ b/src/mbgl/map/backend.cpp
@@ -1,4 +1,5 @@
#include <mbgl/map/backend.hpp>
+#include <mbgl/map/backend_scope.hpp>
#include <mbgl/gl/context.hpp>
#include <cassert>
@@ -9,6 +10,7 @@ Backend::Backend() : context(std::make_unique<gl::Context>()) {
}
gl::Context& Backend::getContext() {
+ assert(BackendScope::exists());
return *context;
}
diff --git a/src/mbgl/map/backend_scope.cpp b/src/mbgl/map/backend_scope.cpp
index 98775ceadb..824ad4498b 100644
--- a/src/mbgl/map/backend_scope.cpp
+++ b/src/mbgl/map/backend_scope.cpp
@@ -8,15 +8,19 @@ namespace mbgl {
static util::ThreadLocal<BackendScope> currentScope;
-BackendScope::BackendScope(Backend& backend_)
+BackendScope::BackendScope(Backend& backend_, ScopeType scopeType_)
: priorScope(currentScope.get()),
nextScope(nullptr),
- backend(backend_) {
+ backend(backend_),
+ scopeType(scopeType_) {
if (priorScope) {
assert(priorScope->nextScope == nullptr);
priorScope->nextScope = this;
}
- backend.activate();
+ if (scopeType == ScopeType::Explicit) {
+ backend.activate();
+ }
+
currentScope.set(this);
}
@@ -28,9 +32,16 @@ BackendScope::~BackendScope() {
assert(priorScope->nextScope == this);
priorScope->nextScope = nullptr;
} else {
- backend.deactivate();
+ if (scopeType == ScopeType::Explicit) {
+ backend.deactivate();
+ }
+
currentScope.set(nullptr);
}
}
+bool BackendScope::exists() {
+ return currentScope.get();
+}
+
} // namespace mbgl
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 4c787eb660..a883a69282 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -267,8 +267,9 @@ void Map::Impl::render(View& view) {
updateFlags = Update::Nothing;
+ gl::Context& context = backend.getContext();
if (!painter) {
- painter = std::make_unique<Painter>(backend.getContext(), transform.getState(), pixelRatio, programCacheDir);
+ painter = std::make_unique<Painter>(context, transform.getState(), pixelRatio, programCacheDir);
}
if (mode == MapMode::Continuous) {