summaryrefslogtreecommitdiffstats
path: root/third_party/rust/metal/src/capturemanager.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/metal/src/capturemanager.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/metal/src/capturemanager.rs')
-rw-r--r--third_party/rust/metal/src/capturemanager.rs113
1 files changed, 113 insertions, 0 deletions
diff --git a/third_party/rust/metal/src/capturemanager.rs b/third_party/rust/metal/src/capturemanager.rs
new file mode 100644
index 0000000000..7c9c407cb1
--- /dev/null
+++ b/third_party/rust/metal/src/capturemanager.rs
@@ -0,0 +1,113 @@
+// Copyright 2018 GFX developers
+//
+// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
+// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
+// http://opensource.org/licenses/MIT>, at your option. This file may not be
+// copied, modified, or distributed except according to those terms.
+
+use super::*;
+use std::ffi::CStr;
+
+/// See <https://developer.apple.com/documentation/metal/mtlcapturescope>
+pub enum MTLCaptureScope {}
+
+foreign_obj_type! {
+ type CType = MTLCaptureScope;
+ pub struct CaptureScope;
+}
+
+impl CaptureScopeRef {
+ pub fn begin_scope(&self) {
+ unsafe { msg_send![self, beginScope] }
+ }
+
+ pub fn end_scope(&self) {
+ unsafe { msg_send![self, endScope] }
+ }
+
+ pub fn label(&self) -> &str {
+ unsafe {
+ let label = msg_send![self, label];
+ crate::nsstring_as_str(label)
+ }
+ }
+}
+
+/// See <https://developer.apple.com/documentation/metal/mtlcapturemanager>
+pub enum MTLCaptureManager {}
+
+foreign_obj_type! {
+ type CType = MTLCaptureManager;
+ pub struct CaptureManager;
+}
+
+impl CaptureManager {
+ pub fn shared<'a>() -> &'a CaptureManagerRef {
+ unsafe {
+ let class = class!(MTLCaptureManager);
+ msg_send![class, sharedCaptureManager]
+ }
+ }
+}
+
+impl CaptureManagerRef {
+ pub fn new_capture_scope_with_device(&self, device: &DeviceRef) -> CaptureScope {
+ unsafe { msg_send![self, newCaptureScopeWithDevice: device] }
+ }
+
+ pub fn new_capture_scope_with_command_queue(
+ &self,
+ command_queue: &CommandQueueRef,
+ ) -> CaptureScope {
+ unsafe { msg_send![self, newCaptureScopeWithCommandQueue: command_queue] }
+ }
+
+ pub fn default_capture_scope(&self) -> Option<&CaptureScopeRef> {
+ unsafe { msg_send![self, defaultCaptureScope] }
+ }
+
+ pub fn set_default_capture_scope(&self, scope: &CaptureScopeRef) {
+ unsafe { msg_send![self, setDefaultCaptureScope: scope] }
+ }
+
+ /// Starts capturing with the capture session defined by a descriptor object.
+ ///
+ /// This function will panic if Metal capture is not enabled. Capture can be enabled by
+ /// either:
+ /// 1. Running from Xcode
+ /// 2. Setting the environment variable `METAL_CAPTURE_ENABLED=1`
+ /// 3. Adding an info.plist file containing the `MetalCaptureEnabled` key set to `YES`
+ pub fn start_capture(&self, descriptor: &CaptureDescriptorRef) -> Result<(), String> {
+ unsafe {
+ Ok(try_objc! { err =>
+ msg_send![self, startCaptureWithDescriptor: descriptor
+ error: &mut err]
+ })
+ }
+ }
+
+ pub fn start_capture_with_device(&self, device: &DeviceRef) {
+ unsafe { msg_send![self, startCaptureWithDevice: device] }
+ }
+
+ pub fn start_capture_with_command_queue(&self, command_queue: &CommandQueueRef) {
+ unsafe { msg_send![self, startCaptureWithCommandQueue: command_queue] }
+ }
+
+ pub fn start_capture_with_scope(&self, scope: &CaptureScopeRef) {
+ unsafe { msg_send![self, startCaptureWithScope: scope] }
+ }
+
+ pub fn stop_capture(&self) {
+ unsafe { msg_send![self, stopCapture] }
+ }
+
+ pub fn is_capturing(&self) -> bool {
+ unsafe { msg_send![self, isCapturing] }
+ }
+
+ /// See <https://developer.apple.com/documentation/metal/mtlcapturemanager/3237260-supportsdestination?language=objc>
+ pub fn supports_destination(&self, destination: MTLCaptureDestination) -> bool {
+ unsafe { msg_send![self, supportsDestination: destination] }
+ }
+}