summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rwxr-xr-xplatform/android/src/android_renderer_backend.cpp2
-rw-r--r--platform/default/include/mbgl/gfx/headless_backend.hpp9
-rw-r--r--platform/default/src/mbgl/gfx/headless_frontend.cpp6
-rw-r--r--platform/default/src/mbgl/gl/headless_backend.cpp12
-rw-r--r--platform/glfw/glfw_backend.hpp7
-rw-r--r--platform/glfw/glfw_gl_backend.cpp12
-rw-r--r--platform/glfw/glfw_view.cpp9
-rw-r--r--platform/glfw/glfw_view.hpp2
-rw-r--r--platform/glfw/main.cpp2
-rw-r--r--platform/node/src/node_mapbox_gl_native.cpp13
10 files changed, 60 insertions, 14 deletions
diff --git a/platform/android/src/android_renderer_backend.cpp b/platform/android/src/android_renderer_backend.cpp
index 3fba0b83da..e2d0648385 100755
--- a/platform/android/src/android_renderer_backend.cpp
+++ b/platform/android/src/android_renderer_backend.cpp
@@ -59,7 +59,7 @@ void AndroidRendererBackend::updateAssumedState() {
void AndroidRendererBackend::markContextLost() {
if (context) {
- getGLContext().setCleanupOnDestruction(false);
+ getContext<gl::Context>().setCleanupOnDestruction(false);
}
}
diff --git a/platform/default/include/mbgl/gfx/headless_backend.hpp b/platform/default/include/mbgl/gfx/headless_backend.hpp
index de9283dcdf..325422323a 100644
--- a/platform/default/include/mbgl/gfx/headless_backend.hpp
+++ b/platform/default/include/mbgl/gfx/headless_backend.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/gfx/renderable.hpp>
+#include <mbgl/gfx/backend.hpp>
#include <mbgl/gfx/renderer_backend.hpp>
#include <mbgl/util/image.hpp>
@@ -15,8 +16,12 @@ namespace gfx {
class HeadlessBackend : public gfx::Renderable {
public:
// Factory.
- static std::unique_ptr<HeadlessBackend> make(Size = { 256, 256 }, gfx::ContextMode = gfx::ContextMode::Unique);
-
+ static std::unique_ptr<HeadlessBackend>
+ Create(const Size size = { 256, 256 },
+ const gfx::ContextMode contextMode = gfx::ContextMode::Unique) {
+ return Backend::Create<HeadlessBackend, Size, gfx::ContextMode>(size, contextMode);
+ }
+
virtual PremultipliedImage readStillImage() = 0;
virtual RendererBackend* getRendererBackend() = 0;
void setSize(Size);
diff --git a/platform/default/src/mbgl/gfx/headless_frontend.cpp b/platform/default/src/mbgl/gfx/headless_frontend.cpp
index 025abdd87a..0e97c40e49 100644
--- a/platform/default/src/mbgl/gfx/headless_frontend.cpp
+++ b/platform/default/src/mbgl/gfx/headless_frontend.cpp
@@ -23,9 +23,9 @@ HeadlessFrontend::HeadlessFrontend(Size size_,
const gfx::ContextMode contextMode,
const optional<std::string> localFontFamily)
: size(size_),
- pixelRatio(pixelRatio_),
- backend(gfx::HeadlessBackend::make( { static_cast<uint32_t>(size.width * pixelRatio),
- static_cast<uint32_t>(size.height * pixelRatio) }, contextMode)),
+ pixelRatio(pixelRatio_),
+ backend(gfx::HeadlessBackend::Create({ static_cast<uint32_t>(size.width * pixelRatio),
+ static_cast<uint32_t>(size.height * pixelRatio) }, contextMode)),
asyncInvalidate([this] {
if (renderer && updateParameters) {
gfx::BackendScope guard { *getBackend() };
diff --git a/platform/default/src/mbgl/gl/headless_backend.cpp b/platform/default/src/mbgl/gl/headless_backend.cpp
index c81952fadc..732e4babae 100644
--- a/platform/default/src/mbgl/gl/headless_backend.cpp
+++ b/platform/default/src/mbgl/gl/headless_backend.cpp
@@ -79,20 +79,22 @@ void HeadlessBackend::updateAssumedState() {
PremultipliedImage HeadlessBackend::readStillImage() {
return static_cast<gl::Context&>(getContext()).readFramebuffer<PremultipliedImage>(size);
}
-
+
RendererBackend* HeadlessBackend::getRendererBackend() {
return this;
}
} // namespace gl
-#ifndef OVERRIDE_HEADLESS_BACKEND_FACTORY
-// Default factory implementation.
-std::unique_ptr<gfx::HeadlessBackend> gfx::HeadlessBackend::make(Size size, gfx::ContextMode contextMode) {
+namespace gfx {
+
+template <>
+std::unique_ptr<gfx::HeadlessBackend>
+Backend::Create<gfx::Backend::Type::OpenGL>(const Size size, const gfx::ContextMode contextMode) {
return std::make_unique<gl::HeadlessBackend>(size, contextMode);
}
-#endif
+} // namespace gfx
} // namespace mbgl
diff --git a/platform/glfw/glfw_backend.hpp b/platform/glfw/glfw_backend.hpp
index 1a2c89ac7a..867e60d79e 100644
--- a/platform/glfw/glfw_backend.hpp
+++ b/platform/glfw/glfw_backend.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/util/size.hpp>
+#include <mbgl/gfx/backend.hpp>
namespace mbgl {
namespace gfx {
@@ -8,6 +9,8 @@ class RendererBackend;
} // namespace gfx
} // namespace mbgl
+struct GLFWwindow;
+
class GLFWBackend {
public:
explicit GLFWBackend() = default;
@@ -15,6 +18,10 @@ public:
GLFWBackend& operator=(const GLFWBackend&) = delete;
virtual ~GLFWBackend() = default;
+ static std::unique_ptr<GLFWBackend> Create(GLFWwindow* window, bool capFrameRate) {
+ return mbgl::gfx::Backend::Create<GLFWBackend, GLFWwindow*, bool>(window, capFrameRate);
+ }
+
virtual mbgl::gfx::RendererBackend& getRendererBackend() = 0;
virtual mbgl::Size getSize() const = 0;
virtual void setSize(mbgl::Size) = 0;
diff --git a/platform/glfw/glfw_gl_backend.cpp b/platform/glfw/glfw_gl_backend.cpp
index 4d9d87dd72..d0975fc08f 100644
--- a/platform/glfw/glfw_gl_backend.cpp
+++ b/platform/glfw/glfw_gl_backend.cpp
@@ -72,3 +72,15 @@ void GLFWGLBackend::setSize(const mbgl::Size newSize) {
void GLFWGLBackend::swap() {
glfwSwapBuffers(window);
}
+
+namespace mbgl {
+namespace gfx {
+
+template <>
+std::unique_ptr<GLFWBackend>
+Backend::Create<mbgl::gfx::Backend::Type::OpenGL>(GLFWwindow* window, bool capFrameRate) {
+ return std::make_unique<GLFWGLBackend>(window, capFrameRate);
+}
+
+} // namespace gfx
+} // namespace mbgl
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index 91e2345bb6..82519e6ac2 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -1,5 +1,5 @@
#include "glfw_view.hpp"
-#include "glfw_gl_backend.hpp"
+#include "glfw_backend.hpp"
#include "glfw_renderer_frontend.hpp"
#include "ny_route.hpp"
@@ -17,6 +17,7 @@
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/renderer/renderer.hpp>
+#include <mbgl/gfx/backend.hpp>
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/map/camera.hpp>
@@ -76,6 +77,10 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
#endif
+ if (mbgl::gfx::Backend::GetType() != mbgl::gfx::Backend::Type::OpenGL) {
+ glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
+ }
+
glfwWindowHint(GLFW_RED_BITS, 8);
glfwWindowHint(GLFW_GREEN_BITS, 8);
glfwWindowHint(GLFW_BLUE_BITS, 8);
@@ -100,7 +105,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
glfwGetWindowSize(window, &width, &height);
- backend = std::make_unique<GLFWGLBackend>(window, benchmark);
+ backend = GLFWBackend::Create(window, benchmark);
pixelRatio = static_cast<float>(backend->getSize().width) / width;
diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp
index 1f27bb4421..3322932dde 100644
--- a/platform/glfw/glfw_view.hpp
+++ b/platform/glfw/glfw_view.hpp
@@ -17,7 +17,7 @@ class RendererBackend;
class GLFWView : public mbgl::MapObserver {
public:
- GLFWView(bool fullscreen = false, bool benchmark = false);
+ GLFWView(bool fullscreen, bool benchmark);
~GLFWView() override;
float getPixelRatio() const;
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp
index 04cff3962a..a5001d1204 100644
--- a/platform/glfw/main.cpp
+++ b/platform/glfw/main.cpp
@@ -2,6 +2,7 @@
#include "glfw_renderer_frontend.hpp"
#include "settings_json.hpp"
+#include <mbgl/gfx/backend.hpp>
#include <mbgl/util/default_styles.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
@@ -42,6 +43,7 @@ int main(int argc, char *argv[]) {
args::Flag benchmarkFlag(argumentParser, "benchmark", "Toggle benchmark", {'b', "benchmark"});
args::Flag offlineFlag(argumentParser, "offline", "Toggle offline", {'o', "offline"});
+ args::ValueFlag<std::string> backendValue(argumentParser, "Backend", "Rendering backend", {"backend"});
args::ValueFlag<std::string> styleValue(argumentParser, "URL", "Map stylesheet", {'s', "style"});
args::ValueFlag<std::string> cacheDBValue(argumentParser, "file", "Cache database file name", {'c', "cache"});
args::ValueFlag<double> lonValue(argumentParser, "degrees", "Longitude", {'x', "lon"});
diff --git a/platform/node/src/node_mapbox_gl_native.cpp b/platform/node/src/node_mapbox_gl_native.cpp
index 96e96e4298..9b4437b0aa 100644
--- a/platform/node/src/node_mapbox_gl_native.cpp
+++ b/platform/node/src/node_mapbox_gl_native.cpp
@@ -6,12 +6,23 @@
#pragma GCC diagnostic pop
#include <mbgl/util/run_loop.hpp>
+#include <mbgl/gfx/backend.hpp>
#include "node_map.hpp"
#include "node_logging.hpp"
#include "node_request.hpp"
#include "node_expression.hpp"
+
+void SetBackendType(const Nan::FunctionCallbackInfo<v8::Value>& info) {
+ if (info.Length() < 1 || info[0]->IsUndefined()) {
+ return Nan::ThrowTypeError("Requires a render backend name");
+ }
+
+ const std::string backendName { *Nan::Utf8String(info[0]) };
+ (void)backendName;
+}
+
void RegisterModule(v8::Local<v8::Object> target, v8::Local<v8::Object> module) {
// This has the effect of:
// a) Ensuring that the static local variable is initialized before any thread contention.
@@ -19,6 +30,8 @@ void RegisterModule(v8::Local<v8::Object> target, v8::Local<v8::Object> module)
static mbgl::util::RunLoop nodeRunLoop;
nodeRunLoop.stop();
+ Nan::SetMethod(target, "setBackendType", SetBackendType);
+
node_mbgl::NodeMap::Init(target);
node_mbgl::NodeRequest::Init();
node_mbgl::NodeExpression::Init(target);