From 167d9b64c3ec5c7c4ccb46f1dcd716d52a183449 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 23 Sep 2025 21:37:27 +0100 Subject: [PATCH] LV2 Host: Query ComponentPeer directly for scale factor instead of using a cached value --- .../format_types/juce_LV2PluginFormat.cpp | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp index 5d5ade4b4a..fbfad6cf85 100644 --- a/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp @@ -545,16 +545,29 @@ private: /* Convert from the component's coordinate system to the hosted LV2's coordinate system. */ Rectangle componentToLv2Rect (Rectangle r) const { - return localAreaToGlobal (r) * nativeScaleFactor * getDesktopScaleFactor(); + const auto platformScale = getDesktopScaleFactor() * getPeerScale(); + return (localAreaToGlobal (r.toFloat()) * platformScale).toNearestInt(); } /* Convert from the hosted LV2's coordinate system to the component's coordinate system. */ Rectangle lv2ToComponentRect (Rectangle vr) const { - return getLocalArea (nullptr, vr / (nativeScaleFactor * getDesktopScaleFactor())); + const auto platformScale = getDesktopScaleFactor() * getPeerScale(); + return (getLocalArea (nullptr, vr.toFloat() / platformScale)).toNearestInt(); } - float getEffectiveScale() const { return nativeScaleFactor * userScaleFactor; } + float getPeerScale() const + { + if (auto* peer = getPeer()) + return peer->getPlatformScaleFactor(); + + return 1.0f; + } + + float getEffectiveScale() const + { + return getPeerScale() * userScaleFactor; + } // If possible, try to keep platform-specific handing restricted to the implementation of // ViewComponent. Keep the interface of ViewComponent consistent on all platforms. @@ -660,20 +673,14 @@ private: MessageManager::callAsync ([ref = Component::SafePointer (&window), platformScale] { if (auto* r = ref.getComponent()) - { - if (approximatelyEqual (std::exchange (r->nativeScaleFactor, platformScale), platformScale)) - return; - - r->nativeScaleFactor = platformScale; r->sendScaleFactorToPlugin(); - } }); } }; LogicalResizeListener& resizeListener; int lastWidth = 0, lastHeight = 0; - float nativeScaleFactor = 1.0f, userScaleFactor = 1.0f; + float userScaleFactor = 1.0f; NativeScaleFactorNotifier scaleNotifier { this, ScaleNotifierCallback { *this } }; ViewComponent viewComponent { *this }; LV2_URID floatUrid, scaleFactorUrid;