Debian Codegraph @

third_party/rust/metal/src/capturemanager.rs

raw
1 // Copyright 2018 GFX developers
2 //
3 // Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4 // http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5 // http://opensource.org/licenses/MIT>, at your option. This file may not be
6 // copied, modified, or distributed except according to those terms.
7
8 use super::*;
9 use std::ffi::CStr;
10
11 /// See <https://developer.apple.com/documentation/metal/mtlcapturescope>
12 pub enum MTLCaptureScope {}
13
14 foreign_obj_type! {
15 type CType = MTLCaptureScope;
16 pub struct CaptureScope;
17 }
18
19 impl CaptureScopeRef {
20 pub fn begin_scope(&self) {
21 unsafe { msg_send![self, beginScope] }
22 }
23
24 pub fn end_scope(&self) {
25 unsafe { msg_send![self, endScope] }
26 }
27
28 pub fn label(&self) -> &str {
29 unsafe {
30 let label = msg_send![self, label];
31 crate::nsstring_as_str(label)
32 }
33 }
34 }
35
36 /// See <https://developer.apple.com/documentation/metal/mtlcapturemanager>
37 pub enum MTLCaptureManager {}
38
39 foreign_obj_type! {
40 type CType = MTLCaptureManager;
41 pub struct CaptureManager;
42 }
43
44 impl CaptureManager {
45 pub fn shared<'a>() -> &'a CaptureManagerRef {
46 unsafe {
47 let class = class!(MTLCaptureManager);
48 msg_send![class, sharedCaptureManager]
49 }
50 }
51 }
52
53 impl CaptureManagerRef {
54 pub fn new_capture_scope_with_device(&self, device: &DeviceRef) -> CaptureScope {
55 unsafe { msg_send![self, newCaptureScopeWithDevice: device] }
56 }
57
58 pub fn new_capture_scope_with_command_queue(
59 &self,
60 command_queue: &CommandQueueRef,
61 ) -> CaptureScope {
62 unsafe { msg_send![self, newCaptureScopeWithCommandQueue: command_queue] }
63 }
64
65 pub fn default_capture_scope(&self) -> Option<&CaptureScopeRef> {
66 unsafe { msg_send![self, defaultCaptureScope] }
67 }
68
69 pub fn set_default_capture_scope(&self, scope: &CaptureScopeRef) {
70 unsafe { msg_send![self, setDefaultCaptureScope: scope] }
71 }
72
73 /// Starts capturing with the capture session defined by a descriptor object.
74 ///
75 /// This function will panic if Metal capture is not enabled. Capture can be enabled by
76 /// either:
77 /// 1. Running from Xcode
78 /// 2. Setting the environment variable `METAL_CAPTURE_ENABLED=1`
79 /// 3. Adding an info.plist file containing the `MetalCaptureEnabled` key set to `YES`
80 pub fn start_capture(&self, descriptor: &CaptureDescriptorRef) -> Result<(), String> {
81 #[allow(clippy::unit_arg)]
82 unsafe {
83 Ok(try_objc! { err =>
84 msg_send![self, startCaptureWithDescriptor: descriptor
85 error: &mut err]
86 })
87 }
88 }
89
90 pub fn start_capture_with_device(&self, device: &DeviceRef) {
91 unsafe { msg_send![self, startCaptureWithDevice: device] }
92 }
93
94 pub fn start_capture_with_command_queue(&self, command_queue: &CommandQueueRef) {
95 unsafe { msg_send![self, startCaptureWithCommandQueue: command_queue] }
96 }
97
98 pub fn start_capture_with_scope(&self, scope: &CaptureScopeRef) {
99 unsafe { msg_send![self, startCaptureWithScope: scope] }
100 }
101
102 pub fn stop_capture(&self) {
103 unsafe { msg_send![self, stopCapture] }
104 }
105
106 pub fn is_capturing(&self) -> bool {
107 unsafe { msg_send![self, isCapturing] }
108 }
109
110 /// See <https://developer.apple.com/documentation/metal/mtlcapturemanager/3237260-supportsdestination?language=objc>
111 pub fn supports_destination(&self, destination: MTLCaptureDestination) -> bool {
112 unsafe { msg_send![self, supportsDestination: destination] }
113 }
114 }