summaryrefslogtreecommitdiff
path: root/platform/qt/test/headless_backend_qt.cpp
blob: 1992cab2fa8583ebb34f4a82ee43826edb7cf0bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <mbgl/gl/headless_backend.hpp>

#include <QApplication>
#include <QGLContext>
#include <QGLWidget>

#if QT_VERSION >= 0x050000
#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();
        return thisContext->getProcAddress(name);
#else
        const QGLContext* thisContext = QGLContext::currentContext();
        return reinterpret_cast<mbgl::gl::glProc>(thisContext->getProcAddress(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);

    impl.reset(new QtImpl);
}

} // namespace mbgl