summaryrefslogtreecommitdiff
path: root/include/mbgl/platform
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-10-06 13:23:50 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-10-25 13:52:36 -0700
commit5cc390d694fc7510d445310d8eb9e32429a5e67b (patch)
tree7a24706f919ac3e8154be8b4ce33aed5bf42188d /include/mbgl/platform
parent45f4dc0166f2d609d014d2174209fdbe1994c943 (diff)
downloadqtlocation-mapboxgl-5cc390d694fc7510d445310d8eb9e32429a5e67b.tar.gz
[core] separate Backend from View for headless rendering
Diffstat (limited to 'include/mbgl/platform')
-rw-r--r--include/mbgl/platform/default/glfw_view.hpp34
-rw-r--r--include/mbgl/platform/default/headless_backend.hpp78
-rw-r--r--include/mbgl/platform/default/headless_display.hpp9
-rw-r--r--include/mbgl/platform/default/headless_view.hpp74
4 files changed, 115 insertions, 80 deletions
diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp
index 8662a90bf3..a115d03d7f 100644
--- a/include/mbgl/platform/default/glfw_view.hpp
+++ b/include/mbgl/platform/default/glfw_view.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/mbgl.hpp>
+#include <mbgl/map/backend.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/timer.hpp>
#include <mbgl/util/geometry.hpp>
@@ -11,20 +12,36 @@
#define GL_GLEXT_PROTOTYPES
#include <GLFW/glfw3.h>
-class GLFWView : public mbgl::View {
+class GLFWView : public mbgl::View, public mbgl::Backend {
public:
GLFWView(bool fullscreen = false, bool benchmark = false);
~GLFWView() override;
- float getPixelRatio() const override;
+ float getPixelRatio() const;
+
+ // Callback called when the user presses the key mapped to style change.
+ // The expected action is to set a new style, different to the current one.
+ void setChangeStyleCallback(std::function<void()> callback);
+
+ void setShouldClose();
+
+ void setWindowTitle(const std::string&);
+
+ void run();
+
+private:
+ // mbgl::View implementation
+ void initialize(mbgl::Map*) override;
+ void bind() override;
std::array<uint16_t, 2> getSize() const override;
std::array<uint16_t, 2> getFramebufferSize() const override;
- void initialize(mbgl::Map*) override;
+ // mbgl::Backend implementation
void activate() override;
void deactivate() override;
void invalidate() override;
+ // Window callbacks
static void onKey(GLFWwindow *window, int key, int scancode, int action, int mods);
static void onScroll(GLFWwindow *window, double xoffset, double yoffset);
static void onWindowResize(GLFWwindow *window, int width, int height);
@@ -32,21 +49,12 @@ public:
static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers);
static void onMouseMove(GLFWwindow *window, double x, double y);
- // Callback called when the user presses the key mapped to style change.
- // The expected action is to set a new style, different to the current one.
- void setChangeStyleCallback(std::function<void()> callback);
-
- void setShouldClose();
-
- void setWindowTitle(const std::string&);
-
- void run();
+ // Internal
void report(float duration);
void setMapChangeCallback(std::function<void(mbgl::MapChange)> callback);
void notifyMapChange(mbgl::MapChange change) override;
-private:
mbgl::Color makeRandomColor() const;
mbgl::Point<double> makeRandomPoint() const;
static std::shared_ptr<const mbgl::SpriteImage>
diff --git a/include/mbgl/platform/default/headless_backend.hpp b/include/mbgl/platform/default/headless_backend.hpp
new file mode 100644
index 0000000000..2f4886a365
--- /dev/null
+++ b/include/mbgl/platform/default/headless_backend.hpp
@@ -0,0 +1,78 @@
+#pragma once
+
+#include <mbgl/gl/implementation.hpp>
+
+#if MBGL_USE_QT
+class QGLWidget;
+#elif MBGL_USE_CGL
+#include <OpenGL/OpenGL.h>
+#elif MBGL_USE_GLX
+typedef struct _XDisplay Display;
+typedef struct __GLXcontextRec* GLXContext;
+typedef struct __GLXFBConfigRec* GLXFBConfig;
+typedef long unsigned int XID;
+typedef XID GLXPbuffer;
+#endif
+
+#include <mbgl/map/backend.hpp>
+#include <mbgl/gl/extension.hpp>
+
+#include <memory>
+#include <functional>
+
+namespace mbgl {
+
+class HeadlessDisplay;
+
+class HeadlessBackend : public Backend {
+public:
+ HeadlessBackend();
+ HeadlessBackend(std::shared_ptr<HeadlessDisplay>);
+ ~HeadlessBackend() override;
+
+ void invalidate() override;
+ void activate() override;
+ void deactivate() override;
+ void notifyMapChange(MapChange) override;
+
+ void setMapChangeCallback(std::function<void(MapChange)>&& cb) { mapChangeCallback = std::move(cb); }
+
+private:
+ void activateContext();
+ void deactivateContext();
+
+private:
+ // Implementation specific functions
+ static gl::glProc initializeExtension(const char*);
+ void createContext();
+ void destroyContext();
+
+ std::shared_ptr<HeadlessDisplay> display;
+
+ bool extensionsLoaded = false;
+ bool active = false;
+
+#if MBGL_USE_QT
+ QGLWidget* glContext = nullptr;
+#endif
+
+#if MBGL_USE_CGL
+ CGLContextObj glContext = nullptr;
+#endif
+
+#if MBGL_USE_EAGL
+ void *glContext = nullptr;
+#endif
+
+#if MBGL_USE_GLX
+ Display *xDisplay = nullptr;
+ GLXFBConfig *fbConfigs = nullptr;
+ GLXContext glContext = nullptr;
+ GLXPbuffer glxPbuffer = 0;
+#endif
+
+ std::function<void(MapChange)> mapChangeCallback;
+
+};
+
+} // namespace mbgl
diff --git a/include/mbgl/platform/default/headless_display.hpp b/include/mbgl/platform/default/headless_display.hpp
index edcc905221..f43e61340f 100644
--- a/include/mbgl/platform/default/headless_display.hpp
+++ b/include/mbgl/platform/default/headless_display.hpp
@@ -1,6 +1,13 @@
#pragma once
-#include <mbgl/platform/default/headless_view.hpp>
+#include <mbgl/gl/implementation.hpp>
+
+#if MBGL_USE_CGL
+#include <OpenGL/OpenGL.h>
+#elif MBGL_USE_GLX
+typedef struct _XDisplay Display;
+typedef struct __GLXFBConfigRec* GLXFBConfig;
+#endif
namespace mbgl {
diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp
index 23f1e8251a..27af4fc9d9 100644
--- a/include/mbgl/platform/default/headless_view.hpp
+++ b/include/mbgl/platform/default/headless_view.hpp
@@ -1,95 +1,37 @@
#pragma once
-#if defined(__QT__)
-#define MBGL_USE_QT 1
-class QGLWidget;
-#elif defined(__APPLE__)
-#include <TargetConditionals.h>
-#if TARGET_OS_IOS
-#define MBGL_USE_EAGL 1
-#else
-#define MBGL_USE_CGL 1
-#endif
-#else
-#define GL_GLEXT_PROTOTYPES
-#define MBGL_USE_GLX 1
-typedef struct _XDisplay Display;
-typedef struct __GLXcontextRec* GLXContext;
-typedef struct __GLXFBConfigRec* GLXFBConfig;
-typedef long unsigned int XID;
-typedef XID GLXPbuffer;
-#endif
-
-#include <mbgl/mbgl.hpp>
-#include <mbgl/gl/gl.hpp>
+#include <mbgl/map/view.hpp>
#include <mbgl/gl/types.hpp>
-#include <mbgl/gl/extension.hpp>
-
-#include <memory>
-#include <thread>
namespace mbgl {
-class HeadlessDisplay;
-
class HeadlessView : public View {
public:
- HeadlessView(float pixelRatio, uint16_t width = 256, uint16_t height = 256);
- HeadlessView(std::shared_ptr<HeadlessDisplay> display, float pixelRatio, uint16_t width = 256, uint16_t height = 256);
+ HeadlessView(float pixelRatio = 1, uint16_t width = 256, uint16_t height = 256);
~HeadlessView() override;
- float getPixelRatio() const override;
+ void bind() override;
+
std::array<uint16_t, 2> getSize() const override;
std::array<uint16_t, 2> getFramebufferSize() const override;
- void invalidate() override;
- void activate() override;
- void deactivate() override;
- void notifyMapChange(MapChange) override;
PremultipliedImage readStillImage(std::array<uint16_t, 2> size = {{ 0, 0 }}) override;
+ float getPixelRatio() const;
+
void resize(uint16_t width, uint16_t height);
- void setMapChangeCallback(std::function<void(MapChange)>&& cb) { mapChangeCallback = std::move(cb); }
private:
- // Implementation specific functions
- static gl::glProc initializeExtension(const char*);
- void createContext();
- void destroyContext();
void clearBuffers();
void resizeFramebuffer();
- void activateContext();
- void deactivateContext();
+ void bindFramebuffer();
- std::shared_ptr<HeadlessDisplay> display;
+private:
const float pixelRatio;
std::array<uint16_t, 2> dimensions;
bool needsResize = false;
- bool extensionsLoaded = false;
- bool active = false;
-
-#if MBGL_USE_QT
- QGLWidget* glContext = nullptr;
-#endif
-
-#if MBGL_USE_CGL
- CGLContextObj glContext = nullptr;
-#endif
-
-#if MBGL_USE_EAGL
- void *glContext = nullptr;
-#endif
-
-#if MBGL_USE_GLX
- Display *xDisplay = nullptr;
- GLXFBConfig *fbConfigs = nullptr;
- GLXContext glContext = nullptr;
- GLXPbuffer glxPbuffer = 0;
-#endif
-
- std::function<void(MapChange)> mapChangeCallback;
gl::FramebufferID fbo = 0;
gl::RenderbufferID fboDepthStencil = 0;