Files
MapLibreParticleLab/include/mbgl/map/backend_scope.hpp
Ivo van Dongen 733661948c [core] BackendScope prevent double (de-)activation
- Guards against duplicate activations by checking wether the backend of the prior scope is the same as the current ones
- Makes sure that only the most outer backend scope deactivates by tracking activation state
2017-07-19 17:34:07 +02:00

36 lines
899 B
C++

#pragma once
namespace mbgl {
class Backend;
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(Backend&, 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;
Backend& backend;
const ScopeType scopeType;
bool activated = false;
};
} // namespace mbgl