From 2af1de45d7e06126563c7850745faed065f39de5 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 10 May 2019 17:32:55 +0100 Subject: [PATCH] Windows: Fixed a bug with DPI-aware VSTs in Steinberg hosts using the OpenGL renderer --- .../utility/juce_PluginUtilities.cpp | 13 +++---------- .../native/juce_win32_Windowing.cpp | 16 +++++++++++++++- modules/juce_opengl/native/juce_OpenGL_win32.h | 8 ++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/modules/juce_audio_plugin_client/utility/juce_PluginUtilities.cpp b/modules/juce_audio_plugin_client/utility/juce_PluginUtilities.cpp index 9b5ab3706e..e55db48ff5 100644 --- a/modules/juce_audio_plugin_client/utility/juce_PluginUtilities.cpp +++ b/modules/juce_audio_plugin_client/utility/juce_PluginUtilities.cpp @@ -44,18 +44,11 @@ std::function PluginHostType::jucePlugInIsRunningInAudioS bool juce_isRunningInUnity() { return PluginHostType::getPluginLoadedAs() == AudioProcessor::wrapperType_Unity; } #endif -#if JUCE_MODULE_AVAILABLE_juce_opengl && (JucePlugin_Build_VST || JucePlugin_Build_VST3) +#if JUCE_MODULE_AVAILABLE_juce_opengl && JucePlugin_Build_VST bool juce_shouldDoubleScaleNativeGLWindow() { - auto wrapperType = PluginHostType::getPluginLoadedAs(); - auto hostType = getHostType().type; - - if (wrapperType == AudioProcessor::wrapperType_VST) - return hostType == PluginHostType::SteinbergCubase10 || hostType == PluginHostType::AbletonLive10; - else if (wrapperType == AudioProcessor::wrapperType_VST3) - return hostType == PluginHostType::SteinbergCubase10; - - return false; + return PluginHostType::getPluginLoadedAs() == AudioProcessor::wrapperType_VST + && getHostType().type == PluginHostType::AbletonLive10; } #endif diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index f9d819765b..f33c6bcd5e 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -377,6 +377,7 @@ static void setDPIAwareness() getThreadDPIAwarenessContext = (GetThreadDPIAwarenessContextFunc) getUser32Function ("GetThreadDpiAwarenessContext"); getAwarenessFromDPIAwarenessContext = (GetAwarenessFromDpiAwarenessContextFunc) getUser32Function ("GetAwarenessFromDpiAwarenessContext"); setThreadDPIAwarenessContext = (SetThreadDPIAwarenessContextFunc) getUser32Function ("SetThreadDpiAwarenessContext"); + setProcessDPIAwareness = (SetProcessDPIAwarenessFunc) GetProcAddress (shcoreModule, "SetProcessDpiAwareness"); // Only set the DPI awareness context of the process if we are a standalone app if (! JUCEApplicationBase::isStandaloneApp()) @@ -388,7 +389,6 @@ static void setDPIAwareness() && SUCCEEDED (setProcessDPIAwarenessContext (DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2))) return; - setProcessDPIAwareness = (SetProcessDPIAwarenessFunc) GetProcAddress (shcoreModule, "SetProcessDpiAwareness"); enableNonClientDPIScaling = (EnableNonClientDPIScalingFunc) getUser32Function ("EnableNonClientDpiScaling"); if (setProcessDPIAwareness != nullptr && enableNonClientDPIScaling != nullptr @@ -4073,6 +4073,20 @@ JUCE_API bool shouldScaleGLWindow (void* hwnd) return isPerMonitorDPIAwareWindow ((HWND) hwnd); } +#if JUCE_WIN_PER_MONITOR_DPI_AWARE + JUCE_API void setProcessDPIAwarenessIfNecessary (void* hwnd) + { + DPI_Awareness context; + getProcessDPIAwareness (0, &context); + + if (isPerMonitorDPIAwareWindow ((HWND) hwnd) && context != DPI_Awareness::DPI_Awareness_Per_Monitor_Aware + && setProcessDPIAwareness != nullptr) + { + setProcessDPIAwareness (DPI_Awareness::DPI_Awareness_Per_Monitor_Aware); + } + } +#endif + 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 a0811b6a95..8a53b15fd6 100644 --- a/modules/juce_opengl/native/juce_OpenGL_win32.h +++ b/modules/juce_opengl/native/juce_OpenGL_win32.h @@ -36,6 +36,10 @@ extern bool shouldScaleGLWindow (void* hwnd); bool juce_shouldDoubleScaleNativeGLWindow() { return false; } #endif +#if JUCE_WIN_PER_MONITOR_DPI_AWARE + void setProcessDPIAwarenessIfNecessary (void*); +#endif + //============================================================================== class OpenGLContext::NativeContext #if JUCE_WIN_PER_MONITOR_DPI_AWARE @@ -101,6 +105,10 @@ public: bool initialiseOnRenderThread (OpenGLContext& c) { + #if JUCE_WIN_PER_MONITOR_DPI_AWARE + setProcessDPIAwarenessIfNecessary (nativeWindow->getNativeHandle()); + #endif + context = &c; return true; }