summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/qt/app/mapwindow.cpp4
-rw-r--r--platform/qt/src/qmapboxgl.cpp27
-rw-r--r--platform/qt/src/qquickmapboxglrenderer.cpp3
3 files changed, 17 insertions, 17 deletions
diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp
index 29524ef72f..35f56a0bef 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 e901f6fcd4..dd4cab056d 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -13,6 +13,7 @@
#if QT_VERSION >= 0x050000
#include <QGuiApplication>
+#include <QWindow>
#else
#include <QCoreApplication>
#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<uint16_t, 2> QMapboxGLPrivate::getSize() const
@@ -656,12 +665,8 @@ std::array<uint16_t, 2> QMapboxGLPrivate::getSize() const
std::array<uint16_t, 2> QMapboxGLPrivate::getFramebufferSize() const
{
-#if QT_VERSION >= 0x050000
- return {{ static_cast<uint16_t>(size.width() * qApp->devicePixelRatio()),
- static_cast<uint16_t>(size.height() * qApp->devicePixelRatio()) }};
-#else
- return getSize();
-#endif
+ return {{ static_cast<uint16_t>(size.width() * getPixelRatio()),
+ static_cast<uint16_t>(size.height() * getPixelRatio()) }};
}
void QMapboxGLPrivate::invalidate()
diff --git a/platform/qt/src/qquickmapboxglrenderer.cpp b/platform/qt/src/qquickmapboxglrenderer.cpp
index 45549cd400..6212c4f128 100644
--- a/platform/qt/src/qquickmapboxglrenderer.cpp
+++ b/platform/qt/src/qquickmapboxglrenderer.cpp
@@ -3,7 +3,6 @@
#include <QMapboxGL>
#include <QQuickMapboxGL>
-#include <QGuiApplication>
#include <QSize>
#include <QOpenGLFramebufferObject>
#include <QOpenGLFramebufferObjectFormat>
@@ -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);