Add a function to check for SCK availability at runtime
Firefox uses this to decide whether to skip creating a
DesktopAndCursorComposer, since the Mac MouseCursorMonitor is quite
expensive.
Bug: webrtc:367915807
Change-Id: Idfb4c113391620c48f1e548bd5d876b7b3565d7d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/365082
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: Johannes Kron <kron@webrtc.org>
Commit-Queue: Andreas Pehrson <apehrson@mozilla.com>
Cr-Commit-Position: refs/heads/main@{#44195}
diff --git a/modules/desktop_capture/mac/screen_capturer_sck.h b/modules/desktop_capture/mac/screen_capturer_sck.h
index 2c5241d..105cbf0 100644
--- a/modules/desktop_capture/mac/screen_capturer_sck.h
+++ b/modules/desktop_capture/mac/screen_capturer_sck.h
@@ -18,6 +18,9 @@
namespace webrtc {
+// Returns true if the ScreenCaptureKit capturer is available.
+bool ScreenCapturerSckAvailable();
+
// A DesktopCapturer implementation that uses ScreenCaptureKit.
std::unique_ptr<DesktopCapturer> CreateScreenCapturerSck(
const DesktopCaptureOptions& options);
diff --git a/modules/desktop_capture/mac/screen_capturer_sck.mm b/modules/desktop_capture/mac/screen_capturer_sck.mm
index fbec429..098a169 100644
--- a/modules/desktop_capture/mac/screen_capturer_sck.mm
+++ b/modules/desktop_capture/mac/screen_capturer_sck.mm
@@ -374,13 +374,22 @@
[SCShareableContent getShareableContentWithCompletionHandler:handler];
}
+bool ScreenCapturerSckAvailable() {
+ static bool available = ([] {
+ if (@available(macOS 14.0, *)) {
+ return true;
+ }
+ return false;
+ })();
+ return available;
+}
+
std::unique_ptr<DesktopCapturer> CreateScreenCapturerSck(
const DesktopCaptureOptions& options) {
if (@available(macOS 14.0, *)) {
return std::make_unique<ScreenCapturerSck>(options);
- } else {
- return nullptr;
}
+ return nullptr;
}
} // namespace webrtc