summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/backend_scope.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/renderer/backend_scope.cpp')
-rw-r--r--src/mbgl/renderer/backend_scope.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/mbgl/renderer/backend_scope.cpp b/src/mbgl/renderer/backend_scope.cpp
index 5d57421c48..fafeaabb39 100644
--- a/src/mbgl/renderer/backend_scope.cpp
+++ b/src/mbgl/renderer/backend_scope.cpp
@@ -16,30 +16,49 @@ BackendScope::BackendScope(RendererBackend& backend_, ScopeType scopeType_)
if (priorScope) {
assert(priorScope->nextScope == nullptr);
priorScope->nextScope = this;
+ priorScope->deactivate();
}
- if (scopeType == ScopeType::Explicit) {
- backend.activate();
- }
+
+ activate();
currentScope.set(this);
}
BackendScope::~BackendScope() {
assert(nextScope == nullptr);
+ deactivate();
+
if (priorScope) {
- priorScope->backend.activate();
+ priorScope->activate();
currentScope.set(priorScope);
assert(priorScope->nextScope == this);
priorScope->nextScope = nullptr;
} else {
- if (scopeType == ScopeType::Explicit) {
- backend.deactivate();
- }
-
currentScope.set(nullptr);
}
}
+void BackendScope::activate() {
+ if (scopeType == ScopeType::Explicit &&
+ !(priorScope && this->backend == priorScope->backend) &&
+ !(nextScope && this->backend == nextScope->backend)) {
+ // Only activate when set to Explicit and
+ // only once per RenderBackend
+ backend.activate();
+ activated = true;
+ }
+}
+
+void BackendScope::deactivate() {
+ if (activated &&
+ !(nextScope && this->backend == nextScope->backend)) {
+ // Only deactivate when set to Explicit and
+ // only once per RenderBackend
+ backend.deactivate();
+ activated = false;
+ }
+}
+
bool BackendScope::exists() {
return currentScope.get();
}