summaryrefslogtreecommitdiff
path: root/platform/qt/test/headless_backend_qt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/qt/test/headless_backend_qt.cpp')
-rw-r--r--platform/qt/test/headless_backend_qt.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/platform/qt/test/headless_backend_qt.cpp b/platform/qt/test/headless_backend_qt.cpp
new file mode 100644
index 0000000000..3f287ae578
--- /dev/null
+++ b/platform/qt/test/headless_backend_qt.cpp
@@ -0,0 +1,46 @@
+#include <mbgl/platform/default/headless_backend.hpp>
+#include <mbgl/platform/default/headless_display.hpp>
+
+#include <QApplication>
+#include <QGLContext>
+#include <QGLWidget>
+
+#if QT_VERSION >= 0x050000
+#include <QOpenGLContext>
+#endif
+
+namespace mbgl {
+
+gl::glProc HeadlessBackend::initializeExtension(const char* name) {
+#if QT_VERSION >= 0x050000
+ QOpenGLContext* thisContext = QOpenGLContext::currentContext();
+ return thisContext->getProcAddress(name);
+#else
+ const QGLContext* thisContext = QGLContext::currentContext();
+ return reinterpret_cast<mbgl::gl::glProc>(thisContext->getProcAddress(name));
+#endif
+}
+
+void HeadlessBackend::createContext() {
+ static const char* argv[] = { "mbgl" };
+ static int argc = 1;
+ static auto* app = new QApplication(argc, const_cast<char**>(argv));
+
+ Q_UNUSED(app);
+
+ glContext = new QGLWidget;
+}
+
+void HeadlessBackend::destroyContext() {
+ delete glContext;
+}
+
+void HeadlessBackend::activateContext() {
+ glContext->makeCurrent();
+}
+
+void HeadlessBackend::deactivateContext() {
+ glContext->doneCurrent();
+}
+
+} // namespace mbgl