summaryrefslogtreecommitdiff
path: root/include/mbgl/gfx
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2019-04-01 16:56:24 +0200
committerKonstantin Käfer <mail@kkaefer.com>2019-04-05 11:49:17 +0200
commit66c020034e8260e5e071481e68ab61cd264723ba (patch)
treeb5263772d72175474d91ce2daa9dc037b99fab0d /include/mbgl/gfx
parenta782a6d15b80dd83105604f3f779f6c83ba222e5 (diff)
downloadqtlocation-mapboxgl-66c020034e8260e5e071481e68ab61cd264723ba.tar.gz
[core] refactor RendererBackend
Diffstat (limited to 'include/mbgl/gfx')
-rw-r--r--include/mbgl/gfx/backend_scope.hpp3
-rw-r--r--include/mbgl/gfx/renderer_backend.hpp57
2 files changed, 58 insertions, 2 deletions
diff --git a/include/mbgl/gfx/backend_scope.hpp b/include/mbgl/gfx/backend_scope.hpp
index b92334ae0f..ae42123e97 100644
--- a/include/mbgl/gfx/backend_scope.hpp
+++ b/include/mbgl/gfx/backend_scope.hpp
@@ -1,11 +1,10 @@
#pragma once
namespace mbgl {
+namespace gfx {
class RendererBackend;
-namespace gfx {
-
class BackendScope {
public:
// There are two types of scopes: Creating an "Implicit" scope tells Mapbox GL that the
diff --git a/include/mbgl/gfx/renderer_backend.hpp b/include/mbgl/gfx/renderer_backend.hpp
new file mode 100644
index 0000000000..032c7021da
--- /dev/null
+++ b/include/mbgl/gfx/renderer_backend.hpp
@@ -0,0 +1,57 @@
+#pragma once
+
+#include <mbgl/util/util.hpp>
+
+#include <memory>
+#include <mutex>
+
+namespace mbgl {
+namespace gfx {
+
+class Context;
+class Renderable;
+class BackendScope;
+
+// TODO: Rename to "Device"
+class RendererBackend {
+protected:
+ explicit RendererBackend();
+
+public:
+ virtual ~RendererBackend();
+ RendererBackend(const RendererBackend&) = delete;
+ RendererBackend& operator=(const RendererBackend&) = delete;
+
+ // Returns the device's context.
+ Context& getContext();
+
+ // Returns a reference to the default surface that should be rendered on.
+ virtual Renderable& getDefaultRenderable() = 0;
+
+protected:
+ virtual std::unique_ptr<Context> createContext() = 0;
+
+ // Called when the backend's GL context needs to be made active or inactive. These are called,
+ // as a matched pair, exclusively through BackendScope, in two situations:
+ //
+ // 1. When releasing GL resources during Renderer destruction
+ // (Including calling CustomLayerHost::deinitialize during RenderCustomLayer destruction)
+ // 2. When renderering through Renderer::render()
+ // (Including calling CustomLayerHost::initialize for newly added custom layers and
+ // CustomLayerHost::deinitialize on layer removal)
+ virtual void activate() = 0;
+ virtual void deactivate() = 0;
+
+protected:
+ std::unique_ptr<Context> context;
+ std::once_flag initialized;
+
+ friend class BackendScope;
+};
+
+MBGL_CONSTEXPR bool operator==(const RendererBackend& a, const RendererBackend& b) {
+ return &a == &b;
+}
+
+} // namespace gfx
+} // namespace mbgl