summaryrefslogtreecommitdiff
path: root/platform/qt
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 /platform/qt
parent45f4dc0166f2d609d014d2174209fdbe1994c943 (diff)
downloadqtlocation-mapboxgl-5cc390d694fc7510d445310d8eb9e32429a5e67b.tar.gz
[core] separate Backend from View for headless rendering
Diffstat (limited to 'platform/qt')
-rw-r--r--platform/qt/config.cmake2
-rw-r--r--platform/qt/src/qmapboxgl.cpp7
-rw-r--r--platform/qt/src/qmapboxgl_p.hpp6
-rw-r--r--platform/qt/test/headless_backend_qt.cpp46
-rw-r--r--platform/qt/test/headless_view_qt.cpp38
5 files changed, 65 insertions, 34 deletions
diff --git a/platform/qt/config.cmake b/platform/qt/config.cmake
index d8ede6b450..6df311f885 100644
--- a/platform/qt/config.cmake
+++ b/platform/qt/config.cmake
@@ -43,8 +43,10 @@ endmacro()
macro(mbgl_platform_test)
target_sources(mbgl-test
PRIVATE test/src/main.cpp
+ PRIVATE platform/qt/test/headless_backend_qt.cpp
PRIVATE platform/qt/test/headless_view_qt.cpp
PRIVATE platform/qt/test/qmapboxgl.cpp
+ PRIVATE platform/default/headless_backend.cpp
PRIVATE platform/default/headless_display.cpp
PRIVATE platform/default/headless_view.cpp
)
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index d0a05301f8..73a1771908 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -813,7 +813,7 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
settings.cacheDatabaseMaximumSize()))
, threadPool(4)
, mapObj(std::make_unique<mbgl::Map>(
- *this, *fileSourceObj, threadPool,
+ *this, *this, getPixelRatio(), *fileSourceObj, threadPool,
static_cast<mbgl::MapMode>(settings.mapMode()),
static_cast<mbgl::GLContextMode>(settings.contextMode()),
static_cast<mbgl::ConstrainMode>(settings.constrainMode()),
@@ -845,6 +845,11 @@ float QMapboxGLPrivate::getPixelRatio() const
return pixelRatio;
}
+void QMapboxGLPrivate::bind()
+{
+ MBGL_CHECK_ERROR(glBindFramebuffer(GL_FRAMEBUFFER, 0));
+}
+
std::array<uint16_t, 2> QMapboxGLPrivate::getSize() const
{
return {{ static_cast<uint16_t>(size.width()), static_cast<uint16_t>(size.height()) }};
diff --git a/platform/qt/src/qmapboxgl_p.hpp b/platform/qt/src/qmapboxgl_p.hpp
index c35ac4e7ba..5a228896dc 100644
--- a/platform/qt/src/qmapboxgl_p.hpp
+++ b/platform/qt/src/qmapboxgl_p.hpp
@@ -3,6 +3,7 @@
#include "qmapboxgl.hpp"
#include <mbgl/map/map.hpp>
+#include <mbgl/map/backend.hpp>
#include <mbgl/map/view.hpp>
#include <mbgl/platform/default/thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
@@ -11,7 +12,7 @@
#include <QObject>
#include <QSize>
-class QMapboxGLPrivate : public QObject, public mbgl::View
+class QMapboxGLPrivate : public QObject, public mbgl::View, public mbgl::Backend
{
Q_OBJECT
@@ -20,7 +21,8 @@ public:
virtual ~QMapboxGLPrivate();
// mbgl::View implementation.
- float getPixelRatio() const final;
+ float getPixelRatio() const;
+ void bind() final;
std::array<uint16_t, 2> getSize() const final;
std::array<uint16_t, 2> getFramebufferSize() const final;
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
diff --git a/platform/qt/test/headless_view_qt.cpp b/platform/qt/test/headless_view_qt.cpp
index 03ecb741ab..133b4a2371 100644
--- a/platform/qt/test/headless_view_qt.cpp
+++ b/platform/qt/test/headless_view_qt.cpp
@@ -1,6 +1,7 @@
-#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/default/headless_view.hpp>
+#include <mbgl/gl/gl.hpp>
+
#include <QApplication>
#include <QGLContext>
#include <QGLWidget>
@@ -9,30 +10,13 @@
#include <QOpenGLContext>
#endif
-namespace mbgl {
-
-gl::glProc HeadlessView::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 HeadlessView::createContext() {
- static const char* argv[] = { "mbgl" };
- static int argc = 1;
- static auto* app = new QApplication(argc, const_cast<char**>(argv));
-
- Q_UNUSED(app);
+#include <cassert>
- glContext = new QGLWidget;
-}
+namespace mbgl {
-void HeadlessView::destroyContext() {
- delete glContext;
+void HeadlessView::bindFramebuffer() {
+ assert(fbo);
+ MBGL_CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo));
}
void HeadlessView::resizeFramebuffer() {
@@ -95,12 +79,4 @@ void HeadlessView::clearBuffers() {
}
}
-void HeadlessView::activateContext() {
- glContext->makeCurrent();
-}
-
-void HeadlessView::deactivateContext() {
- glContext->doneCurrent();
-}
-
} // namespace mbgl