summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMike Morris <michael.patrick.morris@gmail.com>2014-10-03 18:31:38 -0400
committerMike Morris <michael.patrick.morris@gmail.com>2014-10-03 18:31:38 -0400
commit0f1d33f5ee29adf9b62c912339935fdde44b0b98 (patch)
treeb2d811270a7c364306371f460a56c5540106d2d1 /common
parentc4c4b3318a89c0a7548040f7182fb043704e230f (diff)
downloadqtlocation-mapboxgl-0f1d33f5ee29adf9b62c912339935fdde44b0b98.tar.gz
break out HeadlessDisplay from HeadlessView, ref #478
Diffstat (limited to 'common')
-rw-r--r--common/headless_display.cpp65
-rw-r--r--common/headless_display.hpp32
-rw-r--r--common/headless_view.cpp60
-rw-r--r--common/headless_view.hpp24
4 files changed, 121 insertions, 60 deletions
diff --git a/common/headless_display.cpp b/common/headless_display.cpp
new file mode 100644
index 0000000000..580d3ef587
--- /dev/null
+++ b/common/headless_display.cpp
@@ -0,0 +1,65 @@
+#include "headless_view.hpp"
+
+#include <stdexcept>
+
+namespace mbgl {
+
+HeadlessDisplay::HeadlessDisplay() {
+#if MBGL_USE_CGL
+ // TODO: test if OpenGL 4.1 with GL_ARB_ES2_compatibility is supported
+ // If it is, use kCGLOGLPVersion_3_2_Core and enable that extension.
+ CGLPixelFormatAttribute attributes[] = {
+ kCGLPFAOpenGLProfile,
+ (CGLPixelFormatAttribute) kCGLOGLPVersion_Legacy,
+ kCGLPFAAccelerated,
+ (CGLPixelFormatAttribute) 0
+ };
+
+ GLint num;
+ CGLError error = CGLChoosePixelFormat(attributes, &pixelFormat, &num);
+ if (error) {
+ fprintf(stderr, "Error pixel format: %s\n", CGLErrorString(error));
+ return;
+ }
+#endif
+
+#if MBGL_USE_GLX
+ x_display = XOpenDisplay(0);
+
+ if (x_display == nullptr) {
+ throw std::runtime_error("Failed to open X display");
+ }
+
+ static int pixelFormat[] = {
+ GLX_RGBA,
+ GLX_DOUBLEBUFFER,
+ GLX_RED_SIZE, 8,
+ GLX_GREEN_SIZE, 8,
+ GLX_BLUE_SIZE, 8,
+ GLX_ALPHA_SIZE, 8,
+ GLX_DEPTH_SIZE, 24,
+ GLX_STENCIL_SIZE, 8,
+ None
+ };
+
+ x_info = glXChooseVisual(x_display, DefaultScreen(x_display), pixelFormat);
+
+ if (x_info == nullptr) {
+ throw std::runtime_error("Error pixel format");
+ }
+#endif
+}
+
+HeadlessDisplay::~HeadlessDisplay() {
+#if MBGL_USE_CGL
+ CGLDestroyPixelFormat(pixelFormat);
+#endif
+
+#if MBGL_USE_GLX
+ XFree(x_info);
+ XCloseDisplay(x_display);
+#endif
+}
+
+}
+
diff --git a/common/headless_display.hpp b/common/headless_display.hpp
new file mode 100644
index 0000000000..4fc03da083
--- /dev/null
+++ b/common/headless_display.hpp
@@ -0,0 +1,32 @@
+#ifndef MBGL_COMMON_HEADLESS_DISPLAY
+#define MBGL_COMMON_HEADLESS_DISPLAY
+
+#ifdef __APPLE__
+#define MBGL_USE_CGL 1
+#else
+#include <GL/glx.h>
+#define MBGL_USE_GLX 1
+#endif
+
+#include <mbgl/platform/gl.hpp>
+
+namespace mbgl {
+
+class HeadlessDisplay {
+public:
+ HeadlessDisplay();
+ ~HeadlessDisplay();
+
+#if MBGL_USE_CGL
+ CGLPixelFormatObj pixelFormat;
+#endif
+
+#if MBGL_USE_GLX
+ Display *x_display = nullptr;
+ XVisualInfo *x_info = nullptr;
+#endif
+};
+
+}
+
+#endif
diff --git a/common/headless_view.cpp b/common/headless_view.cpp
index 10888f7a76..47cf3bd661 100644
--- a/common/headless_view.cpp
+++ b/common/headless_view.cpp
@@ -1,31 +1,21 @@
#include "headless_view.hpp"
-#include <mbgl/util/timer.hpp>
#include <stdexcept>
namespace mbgl {
-HeadlessView::HeadlessView() {
-#if MBGL_USE_CGL
- // TODO: test if OpenGL 4.1 with GL_ARB_ES2_compatibility is supported
- // If it is, use kCGLOGLPVersion_3_2_Core and enable that extension.
- CGLPixelFormatAttribute attributes[] = {
- kCGLPFAOpenGLProfile,
- (CGLPixelFormatAttribute) kCGLOGLPVersion_Legacy,
- kCGLPFAAccelerated,
- (CGLPixelFormatAttribute) 0
- };
-
- CGLPixelFormatObj pixelFormat;
- GLint num;
- CGLError error = CGLChoosePixelFormat(attributes, &pixelFormat, &num);
- if (error) {
- fprintf(stderr, "Error pixel format: %s\n", CGLErrorString(error));
- return;
- }
+HeadlessView::HeadlessView() : display_(new HeadlessDisplay()) {
+ createContext();
+}
+
+HeadlessView::HeadlessView(HeadlessDisplay *display)
+ : display_(display) {
+ createContext();
+}
- error = CGLCreateContext(pixelFormat, NULL, &gl_context);
- CGLDestroyPixelFormat(pixelFormat);
+void HeadlessView::createContext() {
+#if MBGL_USE_CGL
+ CGLError error = CGLCreateContext(display_->pixelFormat, NULL, &gl_context);
if (error) {
fprintf(stderr, "Error creating GL context object\n");
return;
@@ -39,29 +29,8 @@ HeadlessView::HeadlessView() {
#endif
#if MBGL_USE_GLX
- x_display = XOpenDisplay(0);
-
- if (x_display == nullptr) {
- throw std::runtime_error("Failed to open X display");
- }
-
- static int pixelFormat[] = {
- GLX_RGBA,
- GLX_DOUBLEBUFFER,
- GLX_RED_SIZE, 8,
- GLX_GREEN_SIZE, 8,
- GLX_BLUE_SIZE, 8,
- GLX_ALPHA_SIZE, 8,
- GLX_DEPTH_SIZE, 24,
- GLX_STENCIL_SIZE, 8,
- None
- };
-
- x_info = glXChooseVisual(x_display, DefaultScreen(x_display), pixelFormat);
-
- if (x_info == nullptr) {
- throw std::runtime_error("Error pixel format");
- }
+ x_display = display_->x_display;
+ x_info = display_->x_info;
gl_context = glXCreateContext(x_display, x_info, 0, GL_TRUE);
if (gl_context == nullptr) {
@@ -70,7 +39,6 @@ HeadlessView::HeadlessView() {
#endif
}
-
void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
clear_buffers();
@@ -171,8 +139,6 @@ HeadlessView::~HeadlessView() {
#if MBGL_USE_GLX
glXDestroyContext(x_display, gl_context);
- XFree(x_info);
- XCloseDisplay(x_display);
#endif
}
diff --git a/common/headless_view.hpp b/common/headless_view.hpp
index c8475a2516..d1b09ce700 100644
--- a/common/headless_view.hpp
+++ b/common/headless_view.hpp
@@ -1,24 +1,20 @@
-#ifndef MBGL_COMMON_HEADLESS_CGL
-#define MBGL_COMMON_HEADLESS_CGL
-
-#ifdef __APPLE__
-#define MBGL_USE_CGL 1
-#else
-#include <GL/glx.h>
-#define MBGL_USE_GLX 1
-#endif
+#ifndef MBGL_COMMON_HEADLESS_VIEW
+#define MBGL_COMMON_HEADLESS_VIEW
+
+#include "headless_display.hpp"
#include <mbgl/map/view.hpp>
-#include <mbgl/platform/gl.hpp>
-#include <mbgl/util/time.hpp>
namespace mbgl {
class HeadlessView : public View {
public:
HeadlessView();
+ HeadlessView(HeadlessDisplay *display);
~HeadlessView();
+ void createContext();
+
void resize(uint16_t width, uint16_t height, float pixelRatio);
void notify_map_change(MapChange change, timestamp delay = 0);
@@ -32,6 +28,8 @@ private:
private:
+ HeadlessDisplay *display_;
+
#if MBGL_USE_CGL
CGLContextObj gl_context;
GLuint fbo = 0;
@@ -40,9 +38,9 @@ private:
#endif
#if MBGL_USE_GLX
- GLXContext gl_context = nullptr;
- XVisualInfo *x_info = nullptr;
Display *x_display = nullptr;
+ XVisualInfo *x_info = nullptr;
+ GLXContext gl_context = nullptr;
Pixmap x_pixmap = 0;
GLXPixmap glx_pixmap = 0;
#endif