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

namespace mbgl {

class RendererBackend;

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 mbgl