From c1dde52c73061a49d576454a9ab4739e72561ca6 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Fri, 13 May 2016 15:35:54 +0300 Subject: [PATCH] [Qt] Fix map aspect ratio Take QGuiApplication::devicePixelRatio() in consideration when resizing the map. Fixes #4889. --- platform/qt/app/mapwindow.cpp | 9 ++++++--- platform/qt/src/qmapboxgl.cpp | 9 +++++++++ platform/qt/src/qquickmapboxglrenderer.cpp | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp index 3e0b373db..7a431f980 100644 --- a/platform/qt/app/mapwindow.cpp +++ b/platform/qt/app/mapwindow.cpp @@ -149,13 +149,16 @@ void MapWindow::initializeGL() void MapWindow::resizeGL(int w, int h) { - m_map.resize(QSize(w, h)); + QSize size(w, h); +#if QT_VERSION >= 0x050000 + size /= qApp->devicePixelRatio(); +#endif + m_map.resize(size); + glViewport(0, 0, size.width(), size.height()); } void MapWindow::paintGL() { - glViewport(0, 0, width(), height()); - m_frameDraws++; m_map.render(); } diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index e0f57cc0d..32e0f43c8 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -11,7 +11,12 @@ #include #include +#if QT_VERSION >= 0x050000 +#include +#else #include +#endif + #include #include #include @@ -636,8 +641,12 @@ QMapboxGLPrivate::~QMapboxGLPrivate() float QMapboxGLPrivate::getPixelRatio() const { +#if QT_VERSION >= 0x050000 + return qApp->devicePixelRatio(); +#else // FIXME: Should handle pixel ratio. return 1.0; +#endif } std::array QMapboxGLPrivate::getSize() const diff --git a/platform/qt/src/qquickmapboxglrenderer.cpp b/platform/qt/src/qquickmapboxglrenderer.cpp index 6212c4f12..45549cd40 100644 --- a/platform/qt/src/qquickmapboxglrenderer.cpp +++ b/platform/qt/src/qquickmapboxglrenderer.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -27,7 +28,7 @@ QQuickMapboxGLRenderer::~QQuickMapboxGLRenderer() QOpenGLFramebufferObject* QQuickMapboxGLRenderer::createFramebufferObject(const QSize &size) { - m_map->resize(size); + m_map->resize(size / qApp->devicePixelRatio()); QOpenGLFramebufferObjectFormat format; format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);