From 94330a9fcc09c67af5911ad2081aa4c6e16dfaf3 Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Sat, 18 May 2024 21:09:01 -0500 Subject: [PATCH] remove Send bound on editor handle returned from Editor::spawn --- nih_plug_egui/src/editor.rs | 6 +----- nih_plug_iced/src/editor.rs | 6 +----- nih_plug_vizia/src/editor.rs | 6 +----- src/editor.rs | 2 +- src/wrapper/clap/wrapper.rs | 5 ++++- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/nih_plug_egui/src/editor.rs b/nih_plug_egui/src/editor.rs index 46eb4391..b4f210e6 100644 --- a/nih_plug_egui/src/editor.rs +++ b/nih_plug_egui/src/editor.rs @@ -63,7 +63,7 @@ where &self, parent: ParentWindowHandle, context: Arc, - ) -> Box { + ) -> Box { let build = self.build.clone(); let update = self.update.clone(); let state = self.user_state.clone(); @@ -153,10 +153,6 @@ struct EguiEditorHandle { window: WindowHandle, } -/// The window handle enum stored within 'WindowHandle' contains raw pointers. Is there a way around -/// having this requirement? -unsafe impl Send for EguiEditorHandle {} - impl Drop for EguiEditorHandle { fn drop(&mut self) { self.egui_state.open.store(false, Ordering::Release); diff --git a/nih_plug_iced/src/editor.rs b/nih_plug_iced/src/editor.rs index d2984d27..09c10b02 100644 --- a/nih_plug_iced/src/editor.rs +++ b/nih_plug_iced/src/editor.rs @@ -56,7 +56,7 @@ impl Editor for IcedEditorWrapper { &self, parent: ParentWindowHandle, context: Arc, - ) -> Box { + ) -> Box { let (unscaled_width, unscaled_height) = self.iced_state.size(); let scaling_factor = self.scaling_factor.load(); @@ -157,10 +157,6 @@ struct IcedEditorHandle { window: iced_baseview::WindowHandle, } -/// The window handle enum stored within 'WindowHandle' contains raw pointers. Is there a way around -/// having this requirement? -unsafe impl Send for IcedEditorHandle {} - impl Drop for IcedEditorHandle { fn drop(&mut self) { self.iced_state.open.store(false, Ordering::Release); diff --git a/nih_plug_vizia/src/editor.rs b/nih_plug_vizia/src/editor.rs index a285d868..862b80e3 100644 --- a/nih_plug_vizia/src/editor.rs +++ b/nih_plug_vizia/src/editor.rs @@ -37,7 +37,7 @@ impl Editor for ViziaEditor { &self, parent: ParentWindowHandle, context: Arc, - ) -> Box { + ) -> Box { let app = self.app.clone(); let vizia_state = self.vizia_state.clone(); let theming = self.theming; @@ -165,10 +165,6 @@ struct ViziaEditorHandle { window: WindowHandle, } -/// The window handle enum stored within 'WindowHandle' contains raw pointers. Is there a way around -/// having this requirement? -unsafe impl Send for ViziaEditorHandle {} - impl Drop for ViziaEditorHandle { fn drop(&mut self) { self.vizia_state.open.store(false, Ordering::Release); diff --git a/src/editor.rs b/src/editor.rs index c6bd190e..6107a049 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -38,7 +38,7 @@ pub trait Editor: Send { &self, parent: ParentWindowHandle, context: Arc, - ) -> Box; + ) -> Box; /// Returns the (current) size of the editor in pixels as a `(width, height)` pair. This size /// must be reported in _logical pixels_, i.e. the size before being multiplied by the DPI diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index f34fe6e2..adcdca7d 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -118,7 +118,7 @@ pub struct Wrapper { editor: AtomicRefCell>>>, /// A handle for the currently active editor instance. The plugin should implement `Drop` on /// this handle for its closing behavior. - editor_handle: Mutex>>, + editor_handle: Mutex>>, /// The DPI scaling factor as passed to the [IPlugViewContentScaleSupport::set_scale_factor()] /// function. Defaults to 1.0, and will be kept there on macOS. When reporting and handling size /// the sizes communicated to and from the DAW should be scaled by this factor since NIH-plug's @@ -258,6 +258,9 @@ pub struct Wrapper { background_thread: AtomicRefCell, Self>>>, } +unsafe impl Send for Wrapper

{} +unsafe impl Sync for Wrapper

{} + /// Tasks that can be sent from the plugin to be executed on the main thread in a non-blocking /// realtime-safe way. Instead of using a random thread or the OS' event loop like in the Linux /// implementation, this uses [`clap_host::request_callback()`] instead.