From 4c46e3189ac96c8ebcbe1caa47227c4e086d12ff Mon Sep 17 00:00:00 2001 From: Andre de la Rocha Date: Tue, 22 Jan 2019 20:28:49 +0100 Subject: Windows QPA: Cache "forcedScreenForGLWindow" to avoid overhead The fix for QTBUG-50371 caused an overhead when you hover over a secondary window like a tool tip, menu or combo box due to the forcedScreenForGLWindow() function being called, which loads dx9.dll and sub-dlls and unloads them afterwards. This fix caches the required info on the first call, and only refreshes it when required by a display/settings change. Fixes: QTBUG-73008 Change-Id: Ie604ba4034ad8041b971f5aa46bd43ae03decd55 Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowswindow.cpp | 30 ++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/plugins/platforms/windows/qwindowswindow.cpp') diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 7efefa9458..54a4f237ff 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -551,12 +551,6 @@ static QScreen *screenForName(const QWindow *w, const QString &name) return winScreen; } -static QScreen *forcedScreenForGLWindow(const QWindow *w) -{ - const QString forceToScreen = GpuDescription::detect().gpuSuitableScreen; - return forceToScreen.isEmpty() ? nullptr : screenForName(w, forceToScreen); -} - static QPoint calcPosition(const QWindow *w, const QWindowCreationContextPtr &context, const QMargins &invMargins) { const QPoint orgPos(context->frameX - invMargins.left(), context->frameY - invMargins.top()); @@ -565,7 +559,7 @@ static QPoint calcPosition(const QWindow *w, const QWindowCreationContextPtr &co return orgPos; // Workaround for QTBUG-50371 - const QScreen *screenForGL = forcedScreenForGLWindow(w); + const QScreen *screenForGL = QWindowsWindow::forcedScreenForGLWindow(w); if (!screenForGL) return orgPos; @@ -1359,6 +1353,28 @@ void QWindowsWindow::setDropSiteEnabled(bool dropEnabled) #endif // QT_CONFIG(clipboard) && QT_CONFIG(draganddrop) } +bool QWindowsWindow::m_screenForGLInitialized = false; + +void QWindowsWindow::displayChanged() +{ + m_screenForGLInitialized = false; +} + +void QWindowsWindow::settingsChanged() +{ + m_screenForGLInitialized = false; +} + +QScreen *QWindowsWindow::forcedScreenForGLWindow(const QWindow *w) +{ + static QString forceToScreen; + if (!m_screenForGLInitialized) { + forceToScreen = GpuDescription::detect().gpuSuitableScreen; + m_screenForGLInitialized = true; + } + return forceToScreen.isEmpty() ? nullptr : screenForName(w, forceToScreen); +} + // Returns topmost QWindowsWindow ancestor even if there are embedded windows in the chain. // Returns this window if it is the topmost ancestor. QWindow *QWindowsWindow::topLevelOf(QWindow *w) -- cgit v1.2.3