Refresh QGuiApplication's devicePixelRatio cache when screens change

Task-number: QTBUG-63548
Change-Id: Id934cda6e15449c00c80a646055899f49580da88
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Steve Mokris 2018-12-08 12:28:02 -05:00
parent b2297e595c
commit ba304af284
3 changed files with 27 additions and 8 deletions

View File

@ -208,6 +208,8 @@ bool QGuiApplicationPrivate::obey_desktop_settings = true;
QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = 0;
qreal QGuiApplicationPrivate::m_maxDevicePixelRatio = 0.0;
static qreal fontSmoothingGamma = 1.7;
extern void qRegisterGuiVariant();
@ -1093,17 +1095,19 @@ QScreen *QGuiApplication::screenAt(const QPoint &point)
*/
qreal QGuiApplication::devicePixelRatio() const
{
// Cache topDevicePixelRatio, iterate through the screen list once only.
static qreal topDevicePixelRatio = 0.0;
if (!qFuzzyIsNull(topDevicePixelRatio)) {
return topDevicePixelRatio;
}
if (!qFuzzyIsNull(QGuiApplicationPrivate::m_maxDevicePixelRatio))
return QGuiApplicationPrivate::m_maxDevicePixelRatio;
topDevicePixelRatio = 1.0; // make sure we never return 0.
QGuiApplicationPrivate::m_maxDevicePixelRatio = 1.0; // make sure we never return 0.
for (QScreen *screen : qAsConst(QGuiApplicationPrivate::screen_list))
topDevicePixelRatio = qMax(topDevicePixelRatio, screen->devicePixelRatio());
QGuiApplicationPrivate::m_maxDevicePixelRatio = qMax(QGuiApplicationPrivate::m_maxDevicePixelRatio, screen->devicePixelRatio());
return topDevicePixelRatio;
return QGuiApplicationPrivate::m_maxDevicePixelRatio;
}
void QGuiApplicationPrivate::resetCachedDevicePixelRatio()
{
m_maxDevicePixelRatio = 0.0;
}
/*!
@ -3000,6 +3004,8 @@ void QGuiApplicationPrivate::processScreenGeometryChange(QWindowSystemInterfaceP
for (QScreen* sibling : siblings)
emit sibling->virtualGeometryChanged(sibling->virtualGeometry());
}
resetCachedDevicePixelRatio();
}
void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e)
@ -3015,6 +3021,8 @@ void QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange(QWindowSystem
s->d_func()->logicalDpi = QDpi(e->dpiX, e->dpiY);
emit s->logicalDotsPerInchChanged(s->logicalDotsPerInch());
resetCachedDevicePixelRatio();
}
void QGuiApplicationPrivate::processScreenRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e)

View File

@ -311,6 +311,8 @@ public:
static void setApplicationState(Qt::ApplicationState state, bool forcePropagate = false);
static void resetCachedDevicePixelRatio();
protected:
virtual void notifyThemeChanged();
bool tryCloseRemainingWindows(QWindowList processedWindows);
@ -330,6 +332,10 @@ private:
bool ownGlobalShareContext;
static QInputDeviceManager *m_inputDeviceManager;
// Cache the maximum device pixel ratio, to iterate through the screen list
// only the first time it's required, or when devices are added or removed.
static qreal m_maxDevicePixelRatio;
};
Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k);

View File

@ -482,6 +482,9 @@ void QPlatformIntegration::screenAdded(QPlatformScreen *ps, bool isPrimary)
} else {
QGuiApplicationPrivate::screen_list.append(screen);
}
QGuiApplicationPrivate::resetCachedDevicePixelRatio();
emit qGuiApp->screenAdded(screen);
if (isPrimary)
@ -499,6 +502,8 @@ void QPlatformIntegration::removeScreen(QScreen *screen)
const bool wasPrimary = (!QGuiApplicationPrivate::screen_list.isEmpty() && QGuiApplicationPrivate::screen_list.at(0) == screen);
QGuiApplicationPrivate::screen_list.removeOne(screen);
QGuiApplicationPrivate::resetCachedDevicePixelRatio();
if (wasPrimary && qGuiApp && !QGuiApplicationPrivate::screen_list.isEmpty())
emit qGuiApp->primaryScreenChanged(QGuiApplicationPrivate::screen_list.at(0));
}