blob: f3d78714732712e127b6611bbd54e001af804b35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/gfx/renderer_backend.hpp>
#include <mbgl/util/thread_local.hpp>
#include <cassert>
namespace {
mbgl::util::ThreadLocal<mbgl::gfx::BackendScope>& currentScope() {
static mbgl::util::ThreadLocal<mbgl::gfx::BackendScope> backendScope;
return backendScope;
}
} // namespace
namespace mbgl {
namespace gfx {
BackendScope::BackendScope(RendererBackend& backend_, ScopeType scopeType_)
: priorScope(currentScope().get()),
nextScope(nullptr),
backend(backend_),
scopeType(scopeType_) {
if (priorScope) {
assert(priorScope->nextScope == nullptr);
priorScope->nextScope = this;
priorScope->deactivate();
}
activate();
currentScope().set(this);
}
BackendScope::~BackendScope() {
assert(nextScope == nullptr);
deactivate();
if (priorScope) {
priorScope->activate();
currentScope().set(priorScope);
assert(priorScope->nextScope == this);
priorScope->nextScope = nullptr;
} else {
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();
}
} // namespace gfx
} // namespace mbgl
|