summaryrefslogtreecommitdiff
path: root/include/mbgl/map
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2016-12-06 17:24:32 +0100
committerJesse Bounds <jesse@rebounds.net>2016-12-13 10:03:05 -0800
commit18730d598d29cf876064ce6964ef88ef0351f78f (patch)
tree5ca7d6f7b7e42c3845e251f063885f88bf3ae982 /include/mbgl/map
parent1ab791c3dc15ee5d7bb8045e15a6ea4782b2e337 (diff)
downloadqtlocation-mapboxgl-18730d598d29cf876064ce6964ef88ef0351f78f.tar.gz
[core] use raii to guard backend deactivation
Diffstat (limited to 'include/mbgl/map')
-rw-r--r--include/mbgl/map/backend.hpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/include/mbgl/map/backend.hpp b/include/mbgl/map/backend.hpp
index c11d094906..0468449155 100644
--- a/include/mbgl/map/backend.hpp
+++ b/include/mbgl/map/backend.hpp
@@ -10,6 +10,8 @@ namespace gl {
class Context;
} // namespace gl
+class BackendScope;
+
class Backend {
public:
Backend();
@@ -18,6 +20,14 @@ public:
// Returns the backend's context which manages OpenGL state.
gl::Context& getContext();
+ // Called when the map needs to be rendered; the backend should call Map::render() at some point
+ // in the near future. (Not called for Map::renderStill() mode.)
+ virtual void invalidate() = 0;
+
+ // Notifies a watcher of map x/y/scale/rotation changes.
+ virtual void notifyMapChange(MapChange change);
+
+protected:
// Called when the backend's GL context needs to be made active or inactive. These are called,
// as a matched pair, in four situations:
//
@@ -31,15 +41,24 @@ public:
virtual void activate() = 0;
virtual void deactivate() = 0;
- // Called when the map needs to be rendered; the backend should call Map::render() at some point
- // in the near future. (Not called for Map::renderStill() mode.)
- virtual void invalidate() = 0;
+private:
+ const std::unique_ptr<gl::Context> context;
- // Notifies a watcher of map x/y/scale/rotation changes.
- virtual void notifyMapChange(MapChange change);
+ friend class BackendScope;
+};
+
+class BackendScope {
+public:
+ BackendScope(Backend& backend_) : backend(backend_) {
+ backend.activate();
+ }
+
+ ~BackendScope() {
+ backend.deactivate();
+ }
private:
- const std::unique_ptr<gl::Context> context;
+ Backend& backend;
};
} // namespace mbgl