summaryrefslogtreecommitdiff
path: root/include/mbgl/gfx/backend_scope.hpp
blob: b92334ae0fe0e357b1423dcb30c7cc49a4611af9 (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
#pragma once

namespace mbgl {

class RendererBackend;

namespace gfx {

class BackendScope {
public:
    // There are two types of scopes: Creating an "Implicit" scope tells Mapbox GL that the
    // supporting windowing system has already activated the GL Backend and that no further actions
    // are required. Creating an "Explicit" scope actually enables the GL Backend, and disables it
    // when the BackendScope is destroyed.
    enum class ScopeType : bool {
        Implicit,
        Explicit,
    };

    BackendScope(RendererBackend&, ScopeType = ScopeType::Explicit);
    ~BackendScope();

    // Returns true when there is currently a BackendScope active in this thread.
    static bool exists();

private:
    void activate();
    void deactivate();

    BackendScope* priorScope;
    BackendScope* nextScope;
    RendererBackend& backend;
    const ScopeType scopeType;
    bool activated = false;
};

} // namespace gfx
} // namespace mbgl