diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-11-06 20:39:13 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-11-08 18:02:38 +0200 |
commit | d0ac12309b470eb59690ece3f15773df73a127e1 (patch) | |
tree | cfb7939f6d3ac7f1656966142b8b6f548ab6389f /platform/qt/test/headless_backend_qt.cpp | |
parent | 297c303e88416274d3d2c14b5f6abf1c850c3cf8 (diff) | |
download | qtlocation-mapboxgl-d0ac12309b470eb59690ece3f15773df73a127e1.tar.gz |
[core] Refactor HeadlessBackend
Diffstat (limited to 'platform/qt/test/headless_backend_qt.cpp')
-rw-r--r-- | platform/qt/test/headless_backend_qt.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/platform/qt/test/headless_backend_qt.cpp b/platform/qt/test/headless_backend_qt.cpp index 3f287ae578..f6552c4557 100644 --- a/platform/qt/test/headless_backend_qt.cpp +++ b/platform/qt/test/headless_backend_qt.cpp @@ -1,5 +1,4 @@ #include <mbgl/platform/default/headless_backend.hpp> -#include <mbgl/platform/default/headless_display.hpp> #include <QApplication> #include <QGLContext> @@ -9,8 +8,22 @@ #include <QOpenGLContext> #endif +#include <cassert> + namespace mbgl { +struct QtImpl : public HeadlessBackend::Impl { + void activateContext() final { + widget.makeCurrent(); + } + + void deactivateContext() final { + widget.doneCurrent(); + } + + QGLWidget widget; +}; + gl::glProc HeadlessBackend::initializeExtension(const char* name) { #if QT_VERSION >= 0x050000 QOpenGLContext* thisContext = QOpenGLContext::currentContext(); @@ -21,26 +34,20 @@ gl::glProc HeadlessBackend::initializeExtension(const char* name) { #endif } +bool HeadlessBackend::hasDisplay() { + return true; +}; + void HeadlessBackend::createContext() { + assert(!hasContext()); + 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(); + impl.reset(new QtImpl); } } // namespace mbgl |