diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp index 29524ef72..35f56a0be 100644 --- a/platform/qt/app/mapwindow.cpp +++ b/platform/qt/app/mapwindow.cpp @@ -157,11 +157,7 @@ void MapWindow::initializeGL() void MapWindow::resizeGL(int w, int 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() diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index e901f6fcd..dd4cab056 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -13,6 +13,7 @@ #if QT_VERSION >= 0x050000 #include +#include #else #include #endif @@ -493,9 +494,12 @@ void QMapboxGL::rotateBy(const QPointF &first, const QPointF &second) void QMapboxGL::resize(const QSize& size) { - if (d_ptr->size == size) return; + QSize converted = size / d_ptr->getPixelRatio(); + if (d_ptr->size == converted) return; - d_ptr->size = size; + glViewport(0, 0, size.width(), size.height()); + + d_ptr->size = converted; d_ptr->mapObj->update(mbgl::Update::Dimensions); } @@ -642,11 +646,16 @@ QMapboxGLPrivate::~QMapboxGLPrivate() float QMapboxGLPrivate::getPixelRatio() const { #if QT_VERSION >= 0x050000 - return qApp->devicePixelRatio(); + // QWindow is the most reliable pixel ratio because QGuiApplication returns + // the maximum pixel ratio of all available QScreen objects - this is not + // valid for cases e.g. where two or more QScreen objects with different + // pixel ratios are present and the window shows on the screen with lower + // pixel ratio. + static const float pixelRatio = QGuiApplication::allWindows().first()->devicePixelRatio(); #else - // FIXME: Should handle pixel ratio. - return 1.0; + static const float pixelRatio = 1.0; #endif + return pixelRatio; } std::array QMapboxGLPrivate::getSize() const @@ -656,12 +665,8 @@ std::array QMapboxGLPrivate::getSize() const std::array QMapboxGLPrivate::getFramebufferSize() const { -#if QT_VERSION >= 0x050000 - return {{ static_cast(size.width() * qApp->devicePixelRatio()), - static_cast(size.height() * qApp->devicePixelRatio()) }}; -#else - return getSize(); -#endif + return {{ static_cast(size.width() * getPixelRatio()), + static_cast(size.height() * getPixelRatio()) }}; } void QMapboxGLPrivate::invalidate() diff --git a/platform/qt/src/qquickmapboxglrenderer.cpp b/platform/qt/src/qquickmapboxglrenderer.cpp index 45549cd40..6212c4f12 100644 --- a/platform/qt/src/qquickmapboxglrenderer.cpp +++ b/platform/qt/src/qquickmapboxglrenderer.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -28,7 +27,7 @@ QQuickMapboxGLRenderer::~QQuickMapboxGLRenderer() QOpenGLFramebufferObject* QQuickMapboxGLRenderer::createFramebufferObject(const QSize &size) { - m_map->resize(size / qApp->devicePixelRatio()); + m_map->resize(size); QOpenGLFramebufferObjectFormat format; format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);