summaryrefslogtreecommitdiff
path: root/include/mbgl/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/renderer')
-rw-r--r--include/mbgl/renderer/backend_scope.hpp35
-rw-r--r--include/mbgl/renderer/query.hpp43
-rw-r--r--include/mbgl/renderer/renderer.hpp55
-rw-r--r--include/mbgl/renderer/renderer_backend.hpp92
-rw-r--r--include/mbgl/renderer/renderer_frontend.hpp31
5 files changed, 256 insertions, 0 deletions
diff --git a/include/mbgl/renderer/backend_scope.hpp b/include/mbgl/renderer/backend_scope.hpp
new file mode 100644
index 0000000000..73bafc84c7
--- /dev/null
+++ b/include/mbgl/renderer/backend_scope.hpp
@@ -0,0 +1,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
diff --git a/include/mbgl/renderer/query.hpp b/include/mbgl/renderer/query.hpp
new file mode 100644
index 0000000000..4cadf4f017
--- /dev/null
+++ b/include/mbgl/renderer/query.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+#include <mbgl/util/optional.hpp>
+#include <mbgl/style/filter.hpp>
+
+#include <string>
+#include <vector>
+
+namespace mbgl {
+
+/**
+ * Options for query rendered features.
+ */
+class RenderedQueryOptions {
+public:
+ RenderedQueryOptions(optional<std::vector<std::string>> layerIDs_ = {},
+ optional<style::Filter> filter_ = {})
+ : layerIDs(std::move(layerIDs_)),
+ filter(std::move(filter_)) {}
+
+ /** layerIDs to include in the query */
+ optional<std::vector<std::string>> layerIDs;
+
+ optional<style::Filter> filter;
+};
+
+/**
+ * Options for query source features
+ */
+class SourceQueryOptions {
+public:
+ SourceQueryOptions(optional<std::vector<std::string>> sourceLayers_ = {},
+ optional<style::Filter> filter_ = {})
+ : sourceLayers(std::move(sourceLayers_)),
+ filter(std::move(filter_)) {}
+
+ // Required for VectorSource, ignored for GeoJSONSource
+ optional<std::vector<std::string>> sourceLayers;
+
+ optional<style::Filter> filter;
+};
+
+} // namespace mbgl
diff --git a/include/mbgl/renderer/renderer.hpp b/include/mbgl/renderer/renderer.hpp
new file mode 100644
index 0000000000..be8abb2c29
--- /dev/null
+++ b/include/mbgl/renderer/renderer.hpp
@@ -0,0 +1,55 @@
+#pragma once
+
+#include <mbgl/map/mode.hpp>
+#include <mbgl/renderer/query.hpp>
+#include <mbgl/annotation/annotation.hpp>
+#include <mbgl/util/geo.hpp>
+#include <mbgl/util/geo.hpp>
+
+#include <functional>
+#include <memory>
+#include <string>
+#include <vector>
+
+namespace mbgl {
+
+class FileSource;
+class RendererBackend;
+class RendererObserver;
+class RenderedQueryOptions;
+class Scheduler;
+class SourceQueryOptions;
+class UpdateParameters;
+
+class Renderer {
+public:
+ Renderer(RendererBackend&, float pixelRatio_, FileSource&, Scheduler&,
+ GLContextMode = GLContextMode::Unique,
+ const optional<std::string> programCacheDir = {});
+ ~Renderer();
+
+ void markContextLost();
+
+ void setObserver(RendererObserver*);
+
+ void render(const UpdateParameters&);
+
+ // Feature queries
+ std::vector<Feature> queryRenderedFeatures(const ScreenLineString&, const RenderedQueryOptions& options = {}) const;
+ std::vector<Feature> queryRenderedFeatures(const ScreenCoordinate& point, const RenderedQueryOptions& options = {}) const;
+ std::vector<Feature> queryRenderedFeatures(const ScreenBox& box, const RenderedQueryOptions& options = {}) const;
+ std::vector<Feature> querySourceFeatures(const std::string& sourceID, const SourceQueryOptions& options = {}) const;
+ AnnotationIDs queryPointAnnotations(const ScreenBox& box) const;
+
+ // Debug
+ void dumpDebugLogs();
+
+ // Memory
+ void onLowMemory();
+
+private:
+ class Impl;
+ std::unique_ptr<Impl> impl;
+};
+
+} // namespace mbgl
diff --git a/include/mbgl/renderer/renderer_backend.hpp b/include/mbgl/renderer/renderer_backend.hpp
new file mode 100644
index 0000000000..295838c71b
--- /dev/null
+++ b/include/mbgl/renderer/renderer_backend.hpp
@@ -0,0 +1,92 @@
+#pragma once
+
+#include <mbgl/renderer/backend_scope.hpp>
+#include <mbgl/util/image.hpp>
+#include <mbgl/util/size.hpp>
+#include <mbgl/util/util.hpp>
+
+#include <memory>
+#include <mutex>
+
+namespace mbgl {
+
+namespace gl {
+class Context;
+using ProcAddress = void (*)();
+using FramebufferID = uint32_t;
+} // namespace gl
+
+// The RendererBackend is used by the Renderer to facilitate
+// the actual rendering.
+class RendererBackend {
+public:
+ RendererBackend();
+ virtual ~RendererBackend();
+
+ // Returns the backend's context which manages OpenGL state.
+ gl::Context& getContext();
+
+ // Called prior to rendering to update the internally assumed OpenGL state.
+ virtual void updateAssumedState() = 0;
+
+ // Called when this backend is used for rendering. Implementations should ensure that a renderable
+ // object is bound and glClear/glDraw* calls can be done. They should also make sure that
+ // calling .bind() repeatedly is a no-op and that the appropriate gl::Context values are
+ // set to the current state.
+ virtual void bind() = 0;
+
+ virtual Size getFramebufferSize() const = 0;
+
+protected:
+ // Called with the name of an OpenGL extension that should be loaded. RendererBackend implementations
+ // must call the API-specific version that obtains the function pointer for this function,
+ // or a null pointer if unsupported/unavailable.
+ virtual gl::ProcAddress initializeExtension(const char*) = 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 CustomLayerDeinitializeFunction during RenderCustomLayer destruction)
+ // 2. When renderering through Renderer::render()
+ // (Including calling CustomLayerDeinitializeFunction for newly added custom layers and
+ // CustomLayerDeinitializeFunction on layer removal)
+ virtual void activate() = 0;
+ virtual void deactivate() = 0;
+
+ // Reads the color pixel data from the currently bound framebuffer.
+ PremultipliedImage readFramebuffer(const Size&) const;
+
+ // A constant to signal that a framebuffer is bound, but with an unknown ID.
+ static constexpr const gl::FramebufferID ImplicitFramebufferBinding =
+ std::numeric_limits<gl::FramebufferID>::max();
+
+ // Tells the renderer that OpenGL state has already been set by the windowing toolkit.
+ // It sets the internal assumed state to the supplied values.
+ void assumeFramebufferBinding(gl::FramebufferID fbo);
+ void assumeViewport(int32_t x, int32_t y, const Size&);
+ void assumeScissorTest(bool);
+
+ // Returns true when assumed framebuffer binding hasn't changed from the implicit binding.
+ bool implicitFramebufferBound();
+
+ // Triggers an OpenGL state update if the internal assumed state doesn't match the
+ // supplied values.
+ void setFramebufferBinding(gl::FramebufferID fbo);
+ void setViewport(int32_t x, int32_t y, const Size&);
+ void setScissorTest(bool);
+
+protected:
+ std::unique_ptr<gl::Context> context;
+
+private:
+ std::once_flag initialized;
+
+ friend class BackendScope;
+};
+
+MBGL_CONSTEXPR bool operator==(const RendererBackend& a, const RendererBackend& b) {
+ return &a == &b;
+}
+
+} // namespace mbgl
diff --git a/include/mbgl/renderer/renderer_frontend.hpp b/include/mbgl/renderer/renderer_frontend.hpp
new file mode 100644
index 0000000000..f72b0ccdde
--- /dev/null
+++ b/include/mbgl/renderer/renderer_frontend.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <memory>
+
+namespace mbgl {
+
+class RendererObserver;
+class UpdateParameters;
+
+// The RenderFrontend is the bridge between the Map and
+// platform used to update and observer the Renderer
+//
+// It hides any threading specifics and always replies on
+// the original thread.
+class RendererFrontend {
+public:
+
+ virtual ~RendererFrontend() = default;
+
+ // Must synchronously clean up the Renderer if set
+ virtual void reset() = 0;
+
+ // Implementer must bind the renderer observer to the renderer in a
+ // appropriate manner so that the callbacks occur on the main thread
+ virtual void setObserver(RendererObserver&) = 0;
+
+ // Coalescing updates is up to the implementer
+ virtual void update(std::shared_ptr<UpdateParameters>) = 0;
+};
+
+} // namespace mbgl