From fb3914e3d486c40cef2a989fe22d4952edd9700f Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 8 Oct 2022 23:36:43 +0200 Subject: [PATCH] Implement the thread check extension --- src/common/serialization/clap/README.md | 2 +- .../bridges/clap-impls/host-proxy.cpp | 25 +++++++++++++++++++ src/wine-host/bridges/clap-impls/host-proxy.h | 7 ++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/common/serialization/clap/README.md b/src/common/serialization/clap/README.md index 6102e0c3..a9323c9a 100644 --- a/src/common/serialization/clap/README.md +++ b/src/common/serialization/clap/README.md @@ -30,7 +30,7 @@ Yabridge currently tracks CLAP 1.1.1. The implementation status for CLAP's core | `clap.render` | :x: Not supported yet | | `clap.state` | :heavy_check_mark: | | `clap.tail` | :heavy_check_mark: | -| `clap.thread-check` | :x: Not supported yet | +| `clap.thread-check` | :heavy_check_mark: | | `clap.thread-pool` | :x: Not supported yet | | `clap.timer-support` | :x: Not supported yet | | `clap.voice-info` | :x: Not supported yet | diff --git a/src/wine-host/bridges/clap-impls/host-proxy.cpp b/src/wine-host/bridges/clap-impls/host-proxy.cpp index 371528eb..fd77b9b0 100644 --- a/src/wine-host/bridges/clap-impls/host-proxy.cpp +++ b/src/wine-host/bridges/clap-impls/host-proxy.cpp @@ -72,6 +72,10 @@ clap_host_proxy::clap_host_proxy(ClapBridge& bridge, }), ext_tail_vtable(clap_host_tail_t{ .changed = ext_tail_changed, + }), + ext_thread_check_vtable(clap_host_thread_check_t{ + .is_main_thread = ext_thread_check_is_main_thread, + .is_audio_thread = ext_thread_check_is_audio_thread, }) {} const void* CLAP_ABI @@ -102,6 +106,9 @@ clap_host_proxy::host_get_extension(const struct clap_host* host, } else if (self->supported_extensions_.supports_tail && strcmp(extension_id, CLAP_EXT_TAIL) == 0) { extension_ptr = &self->ext_tail_vtable; + } else if (strcmp(extension_id, CLAP_EXT_THREAD_CHECK) == 0) { + // This extension doesn't require any bridging + extension_ptr = &self->ext_thread_check_vtable; } self->bridge_.logger_.log_extension_query("clap_host::get_extension", @@ -314,3 +321,21 @@ void CLAP_ABI clap_host_proxy::ext_tail_changed(const clap_host_t* host) { self->bridge_.send_audio_thread_message(clap::ext::tail::host::Changed{ .owner_instance_id = self->owner_instance_id()}); } + +bool CLAP_ABI +clap_host_proxy::ext_thread_check_is_main_thread(const clap_host_t* host) { + assert(host && host->host_data); + auto self = static_cast(host->host_data); + + return self->bridge_.main_context_.is_gui_thread(); +} + +bool CLAP_ABI +clap_host_proxy::ext_thread_check_is_audio_thread(const clap_host_t* host) { + assert(host && host->host_data); + auto self = static_cast(host->host_data); + + // We don't keep track of audio threads, but as long as the plugin doesn't + // do audio thread stuff on the GUI thread everything's fine + return !self->bridge_.main_context_.is_gui_thread(); +} diff --git a/src/wine-host/bridges/clap-impls/host-proxy.h b/src/wine-host/bridges/clap-impls/host-proxy.h index 04782047..520d9cb2 100644 --- a/src/wine-host/bridges/clap-impls/host-proxy.h +++ b/src/wine-host/bridges/clap-impls/host-proxy.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "../../common/serialization/clap/plugin-factory.h" @@ -110,6 +111,11 @@ class clap_host_proxy { static void CLAP_ABI ext_tail_changed(const clap_host_t* host); + static bool CLAP_ABI + ext_thread_check_is_main_thread(const clap_host_t* host); + static bool CLAP_ABI + ext_thread_check_is_audio_thread(const clap_host_t* host); + private: ClapBridge& bridge_; size_t owner_instance_id_; @@ -132,6 +138,7 @@ class clap_host_proxy { const clap_host_params_t ext_params_vtable; const clap_host_state_t ext_state_vtable; const clap_host_tail_t ext_tail_vtable; + const clap_host_thread_check_t ext_thread_check_vtable; /** * Keeps track of whether there are pending host callbacks. Used to prevent