diff --git a/src/detail/vst3/plugview.cpp b/src/detail/vst3/plugview.cpp index da49a465..209f3977 100644 --- a/src/detail/vst3/plugview.cpp +++ b/src/detail/vst3/plugview.cpp @@ -1,6 +1,7 @@ #include "plugview.h" #include #include +#include #include WrappedView::WrappedView(const clap_plugin_t* plugin, const clap_plugin_gui_t* gui, @@ -103,6 +104,8 @@ tresult PLUGIN_API WrappedView::isPlatformTypeSupported(FIDString type) tresult PLUGIN_API WrappedView::attached(void* parent, FIDString /*type*/) { + _main_thread_id = std::this_thread::get_id(); + #if WIN _window = {CLAP_WINDOW_API_WIN32, {parent}}; #endif @@ -259,6 +262,12 @@ tresult PLUGIN_API WrappedView::checkSizeConstraint(ViewRect* rect) bool WrappedView::request_resize(uint32_t width, uint32_t height) { + if (_main_thread_id != std::this_thread::get_id()) + { + resize_request = {width, height}; + return true; + } + auto oldrect = _rect; _rect.right = _rect.left + (int32)width; _rect.bottom = _rect.top + (int32)height; @@ -268,6 +277,7 @@ bool WrappedView::request_resize(uint32_t width, uint32_t height) _rect = oldrect; return false; } + return true; } tresult WrappedView::setContentScaleFactor(IPlugViewContentScaleSupport::ScaleFactor factor) diff --git a/src/detail/vst3/plugview.h b/src/detail/vst3/plugview.h index 8039770f..ac8872f0 100644 --- a/src/detail/vst3/plugview.h +++ b/src/detail/vst3/plugview.h @@ -13,6 +13,8 @@ #include #include #include +#include +#include using namespace Steinberg; @@ -94,6 +96,22 @@ class WrappedView : public Steinberg::IPlugView, // wrapper needed interfaces bool request_resize(uint32_t width, uint32_t height); + // processed in ClapAsVst3::onIdle() + struct GuiResizeRequest + { + bool operator==(GuiResizeRequest const& other) const + { + return w == other.w && h == other.h; + } + bool operator!=(GuiResizeRequest const& other) const + { + return w != other.w || h != other.h; + } + uint32_t w, h; + }; + constexpr static GuiResizeRequest invalid_size = {(uint32_t)-1, (uint32_t)-1}; + std::atomic resize_request{invalid_size}; + private: void ensure_ui(); void drop_ui(); @@ -107,6 +125,7 @@ class WrappedView : public Steinberg::IPlugView, ViewRect _rect = {0, 0, 0, 0}; bool _created = false; bool _attached = false; + std::thread::id _main_thread_id{}; #if LIN public: diff --git a/src/wrapasvst3.cpp b/src/wrapasvst3.cpp index 8328d0a6..91c5fa81 100644 --- a/src/wrapasvst3.cpp +++ b/src/wrapasvst3.cpp @@ -9,6 +9,7 @@ #include "detail/vst3/process.h" #include "detail/vst3/parameter.h" #include "detail/clap/fsutil.h" +#include #include #include @@ -1292,6 +1293,15 @@ void ClapAsVst3::onIdle() _plugin->_plugin->on_main_thread(_plugin->_plugin); } + if (_wrappedview) + { + if (auto const size = _wrappedview->resize_request.exchange(WrappedView::invalid_size); + size != WrappedView::invalid_size) + { + _wrappedview->request_resize(size.w, size.h); + } + } + #if LIN if (!_iRunLoop) // don't process timers if we have a runloop. // (but if we don't have a runloop on linux onIdle isn't called