From 97c100b9c1b436d16d7bba45b0c3814c80879949 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 15 Oct 2018 15:54:29 +0100 Subject: [PATCH] Windows: Added a workaround for non-DPI aware windows having an incorrect scale factor when using the OpenGL renderer --- .../juce_gui_basics/native/juce_win32_Windowing.cpp | 5 +++++ modules/juce_opengl/native/juce_OpenGL_win32.h | 9 +++++++++ modules/juce_opengl/opengl/juce_OpenGLContext.cpp | 13 ++++++------- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 91fe905e32..cf7a1ed834 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -4020,6 +4020,11 @@ JUCE_API ComponentPeer* createNonRepaintingEmbeddedWindowsPeer (Component& compo (HWND) parentHWND, true); } +JUCE_API bool shouldScaleGLWindow (void* hwnd) +{ + return isPerMonitorDPIAwareWindow ((HWND) hwnd); +} + JUCE_IMPLEMENT_SINGLETON (HWNDComponentPeer::WindowClassHolder) //============================================================================== diff --git a/modules/juce_opengl/native/juce_OpenGL_win32.h b/modules/juce_opengl/native/juce_OpenGL_win32.h index 3f3f5c31be..15ed2154ba 100644 --- a/modules/juce_opengl/native/juce_OpenGL_win32.h +++ b/modules/juce_opengl/native/juce_OpenGL_win32.h @@ -28,6 +28,7 @@ namespace juce { extern ComponentPeer* createNonRepaintingEmbeddedWindowsPeer (Component&, void* parent); +extern bool shouldScaleGLWindow (void* hwnd); //============================================================================== class OpenGLContext::NativeContext @@ -160,6 +161,14 @@ public: } #endif + double getWindowScaleFactor (const Rectangle& screenBounds) + { + if (nativeWindow != nullptr && shouldScaleGLWindow (nativeWindow->getNativeHandle())) + return Desktop::getInstance().getDisplays().findDisplayForRect (screenBounds).scale; + + return 1.0; + } + private: struct DummyComponent : public Component { diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index aef2086e1e..a45d714d35 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -280,15 +280,14 @@ public: { if (auto* peer = component.getPeer()) { - lastScreenBounds = component.getTopLevelComponent()->getScreenBounds(); - - auto newScale = Desktop::getInstance().getDisplays().findDisplayForRect (lastScreenBounds).scale; + #if JUCE_WINDOWS + auto newScale = nativeContext->getWindowScaleFactor (component.getTopLevelComponent()->getScreenBounds()); + #else + auto newScale = Desktop::getInstance().getDisplays().findDisplayForRect (component.getTopLevelComponent()->getScreenBounds()).scale; + #endif auto localBounds = component.getLocalBounds(); - - auto newArea = peer->getComponent().getLocalArea (&component, localBounds) - .withZeroOrigin() - * newScale; + auto newArea = peer->getComponent().getLocalArea (&component, localBounds).withZeroOrigin() * newScale; if (scale != newScale || viewportArea != newArea) {