1 // Copyright 2016 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 
10 use block::Block;
11 
12 #[repr(u32)]
13 #[allow(non_camel_case_types)]
14 pub enum MTLCommandBufferStatus {
15     NotEnqueued = 0,
16     Enqueued = 1,
17     Committed = 2,
18     Scheduled = 3,
19     Completed = 4,
20     Error = 5,
21 }
22 
23 #[repr(u32)]
24 #[allow(non_camel_case_types)]
25 pub enum MTLCommandBufferError {
26     None = 0,
27     Internal = 1,
28     Timeout = 2,
29     PageFault = 3,
30     Blacklisted = 4,
31     NotPermitted = 7,
32     OutOfMemory = 8,
33     InvalidResource = 9,
34     Memoryless = 10,
35     DeviceRemoved = 11,
36 }
37 
38 #[repr(u32)]
39 #[allow(non_camel_case_types)]
40 pub enum MTLDispatchType {
41     Serial = 0,
42     Concurrent = 1,
43 }
44 
45 type _MTLCommandBufferHandler = Block<(MTLCommandBuffer), ()>;
46 
47 pub enum MTLCommandBuffer {}
48 
49 foreign_obj_type! {
50     type CType = MTLCommandBuffer;
51     pub struct CommandBuffer;
52     pub struct CommandBufferRef;
53 }
54 
55 impl CommandBufferRef {
label(&self) -> &str56     pub fn label(&self) -> &str {
57         unsafe {
58             let label = msg_send![self, label];
59             crate::nsstring_as_str(label)
60         }
61     }
62 
set_label(&self, label: &str)63     pub fn set_label(&self, label: &str) {
64         unsafe {
65             let nslabel = crate::nsstring_from_str(label);
66             let () = msg_send![self, setLabel: nslabel];
67         }
68     }
69 
enqueue(&self)70     pub fn enqueue(&self) {
71         unsafe { msg_send![self, enqueue] }
72     }
73 
commit(&self)74     pub fn commit(&self) {
75         unsafe { msg_send![self, commit] }
76     }
77 
status(&self) -> MTLCommandBufferStatus78     pub fn status(&self) -> MTLCommandBufferStatus {
79         unsafe { msg_send![self, status] }
80     }
81 
present_drawable(&self, drawable: &DrawableRef)82     pub fn present_drawable(&self, drawable: &DrawableRef) {
83         unsafe { msg_send![self, presentDrawable: drawable] }
84     }
85 
wait_until_completed(&self)86     pub fn wait_until_completed(&self) {
87         unsafe { msg_send![self, waitUntilCompleted] }
88     }
89 
wait_until_scheduled(&self)90     pub fn wait_until_scheduled(&self) {
91         unsafe { msg_send![self, waitUntilScheduled] }
92     }
93 
new_blit_command_encoder(&self) -> &BlitCommandEncoderRef94     pub fn new_blit_command_encoder(&self) -> &BlitCommandEncoderRef {
95         unsafe { msg_send![self, blitCommandEncoder] }
96     }
97 
new_compute_command_encoder(&self) -> &ComputeCommandEncoderRef98     pub fn new_compute_command_encoder(&self) -> &ComputeCommandEncoderRef {
99         unsafe { msg_send![self, computeCommandEncoder] }
100     }
101 
new_render_command_encoder( &self, descriptor: &RenderPassDescriptorRef, ) -> &RenderCommandEncoderRef102     pub fn new_render_command_encoder(
103         &self,
104         descriptor: &RenderPassDescriptorRef,
105     ) -> &RenderCommandEncoderRef {
106         unsafe { msg_send![self, renderCommandEncoderWithDescriptor: descriptor] }
107     }
108 
new_parallel_render_command_encoder( &self, descriptor: &RenderPassDescriptorRef, ) -> &ParallelRenderCommandEncoderRef109     pub fn new_parallel_render_command_encoder(
110         &self,
111         descriptor: &RenderPassDescriptorRef,
112     ) -> &ParallelRenderCommandEncoderRef {
113         unsafe { msg_send![self, parallelRenderCommandEncoderWithDescriptor: descriptor] }
114     }
115 
compute_command_encoder_with_dispatch_type( &self, ty: MTLDispatchType, ) -> &ComputeCommandEncoderRef116     pub fn compute_command_encoder_with_dispatch_type(
117         &self,
118         ty: MTLDispatchType,
119     ) -> &ComputeCommandEncoderRef {
120         unsafe { msg_send![self, computeCommandEncoderWithDispatchType: ty] }
121     }
122 }
123