diff --git a/qtdeclarative/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/qtdeclarative/src/quick/scenegraph/qsgthreadedrenderloop.cpp index da0e8bdc7c7..9b4324b659a 100644 --- a/qtdeclarative/src/quick/scenegraph/qsgthreadedrenderloop.cpp +++ b/qtdeclarative/src/quick/scenegraph/qsgthreadedrenderloop.cpp @@ -45,6 +45,12 @@ #include #include +#ifdef Q_OS_WIN +#include +#include +#include +#endif + #include #include #include @@ -119,6 +125,38 @@ QT_BEGIN_NAMESPACE +namespace { + +#ifdef Q_OS_WIN + +struct QWindowsUser32DLL { + void init(); + inline bool isValid() const { return getWindowDpiAwarenessContext && setThreadDpiAwarenessContext; } + + typedef DPI_AWARENESS_CONTEXT (WINAPI *GetWindowDpiAwarenessContext)(HWND); + typedef DPI_AWARENESS_CONTEXT (WINAPI *SetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); + + GetWindowDpiAwarenessContext getWindowDpiAwarenessContext = nullptr; + SetThreadDpiAwarenessContext setThreadDpiAwarenessContext = nullptr; +}; + +void QWindowsUser32DLL::init() +{ + QSystemLibrary library(QStringLiteral("user32")); + + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 14393)) + { + getWindowDpiAwarenessContext = (GetWindowDpiAwarenessContext)library.resolve("GetWindowDpiAwarenessContext"); + setThreadDpiAwarenessContext = (SetThreadDpiAwarenessContext)library.resolve("SetThreadDpiAwarenessContext"); + } +} + +QWindowsUser32DLL user32DLL; + +#endif + +} + #define QSG_RT_PAD " (RT) %s" static inline int qsgrl_animation_interval() { @@ -300,6 +338,10 @@ public: setStackSize(1024 * 1024); #endif vsyncDelta = qsgrl_animation_interval(); + +#ifdef Q_OS_WIN + user32DLL.init(); +#endif } ~QSGRenderThread() @@ -1011,6 +1053,17 @@ void QSGRenderThread::run() #endif if (window) { + // On Windows we need to ensure to render with the window's DPI awareness, because + // by default every thread uses the process DPI awareness which might differ from the plugin + // window depending on the host. Ableton Live is known to run as DPI_UNAWARE process, but + // can provide DPI_AWARE plugin windows. + #ifdef Q_OS_WIN + if (user32DLL.isValid()) + { + user32DLL.setThreadDpiAwarenessContext(user32DLL.getWindowDpiAwarenessContext((HWND)window->winId())); + } + #endif + if (enableRhi) { ensureRhi();