From 11b4672b55578f714ddd9d7ff6654c6ec4174593 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 2 Aug 2022 17:42:47 +0100 Subject: [PATCH] VST3 Client: Fix occasional incorrect scaling in Ableton Live when rendering with OpenGL This patch fixes an issue where closing and reopening a plugin editor in Live could cause it to display at the wrong scale when using OpenGL. --- .../VST3/juce_VST3_Wrapper.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index b80ae5a5bb..e54935a679 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -1734,9 +1734,6 @@ private: #if JUCE_MAC if (getHostType().type == PluginHostType::SteinbergCubase10) cubase10Workaround.reset (new Cubase10WindowResizeWorkaround (*this)); - #else - if (! approximatelyEqual (editorScaleFactor, ec.lastScaleFactorReceived)) - setContentScaleFactor (ec.lastScaleFactorReceived); #endif } @@ -1784,12 +1781,25 @@ private: createContentWrapperComponentIfNeeded(); #if JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD + // If the plugin was last opened at a particular scale, try to reapply that scale here. + // Note that we do this during attach(), rather than in JuceVST3Editor(). During the + // constructor, we don't have a host plugFrame, so + // ContentWrapperComponent::resizeHostWindow() won't do anything, and the content + // wrapper component will be left at the wrong size. + if (! approximatelyEqual (editorScaleFactor, owner->lastScaleFactorReceived)) + setContentScaleFactor (owner->lastScaleFactorReceived); + + // Check the host scale factor *before* calling addToDesktop, so that the initial + // window size during addToDesktop is correct for the current platform scale factor. + #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE + component->checkHostWindowScaleFactor(); + #endif + component->setOpaque (true); component->addToDesktop (0, (void*) systemWindow); component->setVisible (true); #if JUCE_WINDOWS && JUCE_WIN_PER_MONITOR_DPI_AWARE - component->checkHostWindowScaleFactor(); component->startTimer (500); #endif