objc2_metal_kit/generated/
MTKView.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-app-kit")]
7#[cfg(target_os = "macos")]
8use objc2_app_kit::*;
9#[cfg(feature = "objc2-core-foundation")]
10use objc2_core_foundation::*;
11#[cfg(feature = "objc2-core-graphics")]
12use objc2_core_graphics::*;
13use objc2_foundation::*;
14use objc2_metal::*;
15#[cfg(feature = "objc2-quartz-core")]
16use objc2_quartz_core::*;
17
18use crate::*;
19
20extern_class!(
21    /// View for rendering metal content
22    ///
23    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalkit/mtkview?language=objc)
24    #[unsafe(super(NSView, NSResponder, NSObject))]
25    #[thread_kind = MainThreadOnly]
26    #[derive(Debug, PartialEq, Eq, Hash)]
27    #[cfg(feature = "objc2-app-kit")]
28    #[cfg(target_os = "macos")]
29    pub struct MTKView;
30);
31
32#[cfg(all(feature = "objc2-app-kit", feature = "objc2-quartz-core"))]
33#[cfg(target_os = "macos")]
34extern_conformance!(
35    unsafe impl CALayerDelegate for MTKView {}
36);
37
38#[cfg(feature = "objc2-app-kit")]
39#[cfg(target_os = "macos")]
40extern_conformance!(
41    unsafe impl NSAccessibility for MTKView {}
42);
43
44#[cfg(feature = "objc2-app-kit")]
45#[cfg(target_os = "macos")]
46extern_conformance!(
47    unsafe impl NSAccessibilityElementProtocol for MTKView {}
48);
49
50#[cfg(feature = "objc2-app-kit")]
51#[cfg(target_os = "macos")]
52extern_conformance!(
53    unsafe impl NSAnimatablePropertyContainer for MTKView {}
54);
55
56#[cfg(feature = "objc2-app-kit")]
57#[cfg(target_os = "macos")]
58extern_conformance!(
59    unsafe impl NSAppearanceCustomization for MTKView {}
60);
61
62#[cfg(feature = "objc2-app-kit")]
63#[cfg(target_os = "macos")]
64extern_conformance!(
65    unsafe impl NSCoding for MTKView {}
66);
67
68#[cfg(feature = "objc2-app-kit")]
69#[cfg(target_os = "macos")]
70extern_conformance!(
71    unsafe impl NSDraggingDestination for MTKView {}
72);
73
74#[cfg(feature = "objc2-app-kit")]
75#[cfg(target_os = "macos")]
76extern_conformance!(
77    unsafe impl NSObjectProtocol for MTKView {}
78);
79
80#[cfg(feature = "objc2-app-kit")]
81#[cfg(target_os = "macos")]
82extern_conformance!(
83    unsafe impl NSUserInterfaceItemIdentification for MTKView {}
84);
85
86#[cfg(feature = "objc2-app-kit")]
87#[cfg(target_os = "macos")]
88impl MTKView {
89    extern_methods!(
90        #[cfg(feature = "objc2-core-foundation")]
91        /// Initalize the view with a frame and device
92        ///
93        /// Parameter `frameRect`: The frame rectangle for the created view object.
94        ///
95        /// Parameter `device`: The MTLDevice to be used by the view to create Metal objects
96        #[unsafe(method(initWithFrame:device:))]
97        #[unsafe(method_family = init)]
98        pub fn initWithFrame_device(
99            this: Allocated<Self>,
100            frame_rect: CGRect,
101            device: Option<&ProtocolObject<dyn MTLDevice>>,
102        ) -> Retained<Self>;
103
104        /// Returns a view initalized from data in a given unarchiver
105        ///
106        /// Parameter `coder`: An unarchiver object
107        ///
108        /// # Safety
109        ///
110        /// `coder` possibly has further requirements.
111        #[unsafe(method(initWithCoder:))]
112        #[unsafe(method_family = init)]
113        pub unsafe fn initWithCoder(this: Allocated<Self>, coder: &NSCoder) -> Retained<Self>;
114
115        /// The delegate handling common view operations
116        #[unsafe(method(delegate))]
117        #[unsafe(method_family = none)]
118        pub fn delegate(&self) -> Option<Retained<ProtocolObject<dyn MTKViewDelegate>>>;
119
120        /// Setter for [`delegate`][Self::delegate].
121        ///
122        /// This is a [weak property][objc2::topics::weak_property].
123        #[unsafe(method(setDelegate:))]
124        #[unsafe(method_family = none)]
125        pub fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn MTKViewDelegate>>);
126
127        /// The MTLDevice used to create Metal objects
128        ///
129        /// This must be explicitly set by the application unless it was passed into the initializer. Defaults to nil
130        #[unsafe(method(device))]
131        #[unsafe(method_family = none)]
132        pub fn device(&self) -> Option<Retained<ProtocolObject<dyn MTLDevice>>>;
133
134        /// Setter for [`device`][Self::device].
135        #[unsafe(method(setDevice:))]
136        #[unsafe(method_family = none)]
137        pub fn setDevice(&self, device: Option<&ProtocolObject<dyn MTLDevice>>);
138
139        #[cfg(feature = "objc2-quartz-core")]
140        /// The drawable to be used for the current frame.
141        ///
142        /// currentDrawable is updated at the end -draw (i.e. after the delegate's drawInMTKView method is called)
143        #[unsafe(method(currentDrawable))]
144        #[unsafe(method_family = none)]
145        pub fn currentDrawable(&self) -> Option<Retained<ProtocolObject<dyn CAMetalDrawable>>>;
146
147        /// If the currentDrawable can be used for sampling or texture read operations
148        ///
149        /// This defaults to YES. This property controls whether or not the returned drawables' MTLTextures may only be used for framebuffer attachments (YES) or whether they may also be used for texture sampling and pixel read/write operations (NO). A value of YES allows the CAMetalLayer to allocate the MTLTexture objects in ways that are optimized for display purposes that makes them unsuitable for sampling. The recommended value for most applications is YES.
150        #[unsafe(method(framebufferOnly))]
151        #[unsafe(method_family = none)]
152        pub fn framebufferOnly(&self) -> bool;
153
154        /// Setter for [`framebufferOnly`][Self::framebufferOnly].
155        #[unsafe(method(setFramebufferOnly:))]
156        #[unsafe(method_family = none)]
157        pub fn setFramebufferOnly(&self, framebuffer_only: bool);
158
159        /// The usage flags set on the depth attachment.
160        ///
161        /// This property controls the texture usage flags set on the MTKView's depth-stencil attachment on creation.  This value defaults to MTLTextureUsageRenderTarget. The recommended value for most applications is MTLTextureUsageRenderTarget. Changing this value re-creates the depth attachment, but any data currently in the depth attachment will be lost.
162        #[unsafe(method(depthStencilAttachmentTextureUsage))]
163        #[unsafe(method_family = none)]
164        pub fn depthStencilAttachmentTextureUsage(&self) -> MTLTextureUsage;
165
166        /// Setter for [`depthStencilAttachmentTextureUsage`][Self::depthStencilAttachmentTextureUsage].
167        #[unsafe(method(setDepthStencilAttachmentTextureUsage:))]
168        #[unsafe(method_family = none)]
169        pub fn setDepthStencilAttachmentTextureUsage(
170            &self,
171            depth_stencil_attachment_texture_usage: MTLTextureUsage,
172        );
173
174        /// The texture usage flags for the multisample color attachment.
175        ///
176        /// This property controls the texture usage flags set on the the multisample color attachment attachment.  This value defaults to MTLTextureUsageRenderTarget. The recommended value for most applications is MTLTextureUsageRenderTarget. Changing this value re-creates the multisample color attachment, but any data currently in the multisample color attachment will be lost.
177        #[unsafe(method(multisampleColorAttachmentTextureUsage))]
178        #[unsafe(method_family = none)]
179        pub fn multisampleColorAttachmentTextureUsage(&self) -> MTLTextureUsage;
180
181        /// Setter for [`multisampleColorAttachmentTextureUsage`][Self::multisampleColorAttachmentTextureUsage].
182        #[unsafe(method(setMultisampleColorAttachmentTextureUsage:))]
183        #[unsafe(method_family = none)]
184        pub fn setMultisampleColorAttachmentTextureUsage(
185            &self,
186            multisample_color_attachment_texture_usage: MTLTextureUsage,
187        );
188
189        /// If the layer should be presented synchronously
190        ///
191        /// Defaults to NO. When NO, changes to the layer's render buffer appear on-screen asynchronously to normal layer updates. When YES, changes to the MTL content are sent to the screen via the standard CATransaction mechanisms.
192        #[unsafe(method(presentsWithTransaction))]
193        #[unsafe(method_family = none)]
194        pub fn presentsWithTransaction(&self) -> bool;
195
196        /// Setter for [`presentsWithTransaction`][Self::presentsWithTransaction].
197        #[unsafe(method(setPresentsWithTransaction:))]
198        #[unsafe(method_family = none)]
199        pub fn setPresentsWithTransaction(&self, presents_with_transaction: bool);
200
201        /// The pixelFormat for the drawable's texture.
202        #[unsafe(method(colorPixelFormat))]
203        #[unsafe(method_family = none)]
204        pub fn colorPixelFormat(&self) -> MTLPixelFormat;
205
206        /// Setter for [`colorPixelFormat`][Self::colorPixelFormat].
207        #[unsafe(method(setColorPixelFormat:))]
208        #[unsafe(method_family = none)]
209        pub fn setColorPixelFormat(&self, color_pixel_format: MTLPixelFormat);
210
211        /// The pixelFormat used to create depthStencilTexture
212        #[unsafe(method(depthStencilPixelFormat))]
213        #[unsafe(method_family = none)]
214        pub fn depthStencilPixelFormat(&self) -> MTLPixelFormat;
215
216        /// Setter for [`depthStencilPixelFormat`][Self::depthStencilPixelFormat].
217        #[unsafe(method(setDepthStencilPixelFormat:))]
218        #[unsafe(method_family = none)]
219        pub fn setDepthStencilPixelFormat(&self, depth_stencil_pixel_format: MTLPixelFormat);
220
221        /// The storage mode for the depthStencilTexture. Defaults to MTLStorageModePrivate.
222        #[unsafe(method(depthStencilStorageMode))]
223        #[unsafe(method_family = none)]
224        pub fn depthStencilStorageMode(&self) -> MTLStorageMode;
225
226        /// Setter for [`depthStencilStorageMode`][Self::depthStencilStorageMode].
227        #[unsafe(method(setDepthStencilStorageMode:))]
228        #[unsafe(method_family = none)]
229        pub fn setDepthStencilStorageMode(&self, depth_stencil_storage_mode: MTLStorageMode);
230
231        /// The sample count used to to create multisampleColorTexture
232        ///
233        /// This defaults to 1.  If sampleCount is greater than 1 a multisampled color texture will be created and the currentDrawable's texture will be set as the resolve texture in the currentRenderPassDescriptor and the store action will be set to MTLStoreActionMultisampleResolve
234        #[unsafe(method(sampleCount))]
235        #[unsafe(method_family = none)]
236        pub fn sampleCount(&self) -> NSUInteger;
237
238        /// Setter for [`sampleCount`][Self::sampleCount].
239        #[unsafe(method(setSampleCount:))]
240        #[unsafe(method_family = none)]
241        pub fn setSampleCount(&self, sample_count: NSUInteger);
242
243        /// The clear color value used to generate the currentRenderPassDescriptor
244        ///
245        /// This defaults to (0.0, 0.0, 0.0, 1.0)
246        #[unsafe(method(clearColor))]
247        #[unsafe(method_family = none)]
248        pub fn clearColor(&self) -> MTLClearColor;
249
250        /// Setter for [`clearColor`][Self::clearColor].
251        #[unsafe(method(setClearColor:))]
252        #[unsafe(method_family = none)]
253        pub fn setClearColor(&self, clear_color: MTLClearColor);
254
255        /// The clear depth value used to generate the currentRenderPassDescriptor
256        ///
257        /// This defaults to 1.0
258        #[unsafe(method(clearDepth))]
259        #[unsafe(method_family = none)]
260        pub fn clearDepth(&self) -> c_double;
261
262        /// Setter for [`clearDepth`][Self::clearDepth].
263        #[unsafe(method(setClearDepth:))]
264        #[unsafe(method_family = none)]
265        pub fn setClearDepth(&self, clear_depth: c_double);
266
267        /// The clear stencil value used to generate currentRenderPassDescriptor
268        ///
269        /// This defaults to 0
270        #[unsafe(method(clearStencil))]
271        #[unsafe(method_family = none)]
272        pub fn clearStencil(&self) -> u32;
273
274        /// Setter for [`clearStencil`][Self::clearStencil].
275        #[unsafe(method(setClearStencil:))]
276        #[unsafe(method_family = none)]
277        pub fn setClearStencil(&self, clear_stencil: u32);
278
279        /// A packed depth and stencil texture to be attached to a MTLRenderPassDescriptor
280        ///
281        /// The view will generate the depth buffer using the specified depthPixelFormat.  This will be nil if depthStencilPixelFormat is MTLPixelFormatInvalid.
282        #[unsafe(method(depthStencilTexture))]
283        #[unsafe(method_family = none)]
284        pub fn depthStencilTexture(&self) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;
285
286        /// A multisample color texture that will be resolved into the currentDrawable's texture
287        ///
288        /// The view will generate the multisample color buffer using the specified colorPixelFormat.  This will be nil if sampleCount is less than or equal to 1.
289        #[unsafe(method(multisampleColorTexture))]
290        #[unsafe(method_family = none)]
291        pub fn multisampleColorTexture(&self) -> Option<Retained<ProtocolObject<dyn MTLTexture>>>;
292
293        /// Release the depthStencilTexture and multisampleColorTexture
294        ///
295        /// Can be called by the app to release the textures in order to conserve memory when it goes into the background.   The view will recreate multisampleColorTexture or depthStencilTexture upon the next access of the respective properties.  Both multisampleColorTexture and depthStencilTexture will be recreated in the access to currentRenderPassDescriptor.
296        #[unsafe(method(releaseDrawables))]
297        #[unsafe(method_family = none)]
298        pub fn releaseDrawables(&self);
299
300        /// A render pass descriptor generated from the currentDrawable's texture and the view's depth, stencil, and sample buffers and clear values.
301        ///
302        /// This is a convience property.  The view does not use this descriptor and there is no requirement for an app to use this descriptor.
303        #[unsafe(method(currentRenderPassDescriptor))]
304        #[unsafe(method_family = none)]
305        pub fn currentRenderPassDescriptor(&self) -> Option<Retained<MTLRenderPassDescriptor>>;
306
307        /// A render pass descriptor generated from the currentDrawable's texture and the view's depth, stencil, and sample buffers and clear values.
308        ///
309        /// This is a convience property.  The view does not use this descriptor and there is no requirement for an app to use this descriptor.
310        #[unsafe(method(currentMTL4RenderPassDescriptor))]
311        #[unsafe(method_family = none)]
312        pub fn currentMTL4RenderPassDescriptor(&self)
313            -> Option<Retained<MTL4RenderPassDescriptor>>;
314
315        /// The rate you want the view to redraw its contents.
316        ///
317        /// When your application sets its preferred frame rate, the view chooses a frame rate as close to that as possible based on the capabilities of the screen the view is displayed on. The actual frame rate chosen is usually a factor of the maximum refresh rate of the screen to provide a consistent frame rate. For example, if the maximum refresh rate of the screen is 60 frames per second, that is also the highest frame rate the view sets as the actual frame rate. However, if you ask for a lower frame rate, it might choose 30, 20, 15 or some other factor to be the actual frame rate. Your application should choose a frame rate that it can consistently maintain. The default value is 60 frames per second.
318        #[unsafe(method(preferredFramesPerSecond))]
319        #[unsafe(method_family = none)]
320        pub fn preferredFramesPerSecond(&self) -> NSInteger;
321
322        /// Setter for [`preferredFramesPerSecond`][Self::preferredFramesPerSecond].
323        #[unsafe(method(setPreferredFramesPerSecond:))]
324        #[unsafe(method_family = none)]
325        pub fn setPreferredFramesPerSecond(&self, preferred_frames_per_second: NSInteger);
326
327        /// Controls whether the view responds to setNeedsDisplay.
328        ///
329        /// If true, then the view behaves similarily to a UIView or NSView, responding to calls to setNeedsDisplay. When the view has been marked for display, the view is automatically redisplayed on each pass through the application’s event loop. Setting enableSetNeedsDisplay to true will also pause the MTKView's internal render loop and updates will instead be event driven. The default value is false.
330        #[unsafe(method(enableSetNeedsDisplay))]
331        #[unsafe(method_family = none)]
332        pub fn enableSetNeedsDisplay(&self) -> bool;
333
334        /// Setter for [`enableSetNeedsDisplay`][Self::enableSetNeedsDisplay].
335        #[unsafe(method(setEnableSetNeedsDisplay:))]
336        #[unsafe(method_family = none)]
337        pub fn setEnableSetNeedsDisplay(&self, enable_set_needs_display: bool);
338
339        /// Controls whether to resize the drawable as the view changes size.
340        ///
341        /// If true, the size of the currentDrawable's texture, depthStencilTexture, and multisampleColorTexture will automatically resize as the view resizes.  If false, these textures will take on the size of drawableSize and drawableSize will not change. The default value is true.
342        #[unsafe(method(autoResizeDrawable))]
343        #[unsafe(method_family = none)]
344        pub fn autoResizeDrawable(&self) -> bool;
345
346        /// Setter for [`autoResizeDrawable`][Self::autoResizeDrawable].
347        #[unsafe(method(setAutoResizeDrawable:))]
348        #[unsafe(method_family = none)]
349        pub fn setAutoResizeDrawable(&self, auto_resize_drawable: bool);
350
351        #[cfg(feature = "objc2-core-foundation")]
352        /// The current size of drawable textures
353        ///
354        /// The size currentDrawable's texture, depthStencilTexture, and multisampleColorTexture.  If autoResizeDrawable is true this value will be updated as the view's size changes. If autoResizeDrawable is false, this can be set to fix the size of the drawable textures.
355        #[unsafe(method(drawableSize))]
356        #[unsafe(method_family = none)]
357        pub fn drawableSize(&self) -> CGSize;
358
359        #[cfg(feature = "objc2-core-foundation")]
360        /// Setter for [`drawableSize`][Self::drawableSize].
361        #[unsafe(method(setDrawableSize:))]
362        #[unsafe(method_family = none)]
363        pub fn setDrawableSize(&self, drawable_size: CGSize);
364
365        #[cfg(feature = "objc2-core-foundation")]
366        /// The preferred drawable size reported by the backing NSView to match a NSView's native resolution.
367        ///
368        /// this value can be observed via key-value observation to determine if the current native drawable size has changed.
369        #[unsafe(method(preferredDrawableSize))]
370        #[unsafe(method_family = none)]
371        pub fn preferredDrawableSize(&self) -> CGSize;
372
373        /// The preferred device is updated per-frame by the system in order to identify the most efficient GPU for presentation (e.g. the one being used for compositing).
374        ///
375        /// This value is determined by the underlying CAMetalLayer and this property is a convenience accessor for it.
376        #[unsafe(method(preferredDevice))]
377        #[unsafe(method_family = none)]
378        pub fn preferredDevice(&self) -> Option<Retained<ProtocolObject<dyn MTLDevice>>>;
379
380        /// Controls whether the draw methods should countinue at preferredFramesPerSecond
381        ///
382        /// If true, the delegate will receive drawInMTKView: messages or the subclass will receive drawRect: messages at a rate of preferredFramesPerSecond based on an internal timer. The default value is false.
383        #[unsafe(method(isPaused))]
384        #[unsafe(method_family = none)]
385        pub fn isPaused(&self) -> bool;
386
387        /// Setter for [`isPaused`][Self::isPaused].
388        #[unsafe(method(setPaused:))]
389        #[unsafe(method_family = none)]
390        pub fn setPaused(&self, paused: bool);
391
392        #[cfg(feature = "objc2-core-graphics")]
393        /// The colorspace of the rendered frames. '
394        ///
395        /// If nil, no colormatching occurs.  If non-nil, the rendered content will be colormatched to the colorspace of the context containing this layer (typically the display's colorspace).  This property aliases the olorspace property or the view's CAMetalLayer
396        #[unsafe(method(colorspace))]
397        #[unsafe(method_family = none)]
398        pub fn colorspace(&self) -> Option<Retained<CGColorSpace>>;
399
400        #[cfg(feature = "objc2-core-graphics")]
401        /// Setter for [`colorspace`][Self::colorspace].
402        #[unsafe(method(setColorspace:))]
403        #[unsafe(method_family = none)]
404        pub fn setColorspace(&self, colorspace: Option<&CGColorSpace>);
405
406        /// Manually ask the view to draw new contents. This causes the view to call either the drawInMTKView (delegate) or drawRect (subclass) method.
407        ///
408        /// Manually ask the view to draw new contents. This causes the view to call either the drawInMTKView (delegate) or drawRect (subclass) method. This should be used when the view's paused proprety is set to true and enableSetNeedsDisplay is set to false.
409        #[unsafe(method(draw))]
410        #[unsafe(method_family = none)]
411        pub fn draw(&self);
412    );
413}
414
415/// Methods declared on superclass `NSView`.
416#[cfg(feature = "objc2-app-kit")]
417#[cfg(target_os = "macos")]
418impl MTKView {
419    extern_methods!(
420        #[unsafe(method(initWithFrame:))]
421        #[unsafe(method_family = init)]
422        pub fn initWithFrame(this: Allocated<Self>, frame_rect: NSRect) -> Retained<Self>;
423    );
424}
425
426/// Methods declared on superclass `NSResponder`.
427#[cfg(feature = "objc2-app-kit")]
428#[cfg(target_os = "macos")]
429impl MTKView {
430    extern_methods!(
431        #[unsafe(method(init))]
432        #[unsafe(method_family = init)]
433        pub fn init(this: Allocated<Self>) -> Retained<Self>;
434    );
435}
436
437/// Methods declared on superclass `NSObject`.
438#[cfg(feature = "objc2-app-kit")]
439#[cfg(target_os = "macos")]
440impl MTKView {
441    extern_methods!(
442        #[unsafe(method(new))]
443        #[unsafe(method_family = new)]
444        pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
445    );
446}
447
448extern_protocol!(
449    /// Allows an object to render into the view and respond to resize events
450    ///
451    /// See also [Apple's documentation](https://developer.apple.com/documentation/metalkit/mtkviewdelegate?language=objc)
452    pub unsafe trait MTKViewDelegate: NSObjectProtocol + MainThreadOnly {
453        #[cfg(all(feature = "objc2-app-kit", feature = "objc2-core-foundation"))]
454        #[cfg(target_os = "macos")]
455        /// Called whenever the drawableSize of the view will change
456        ///
457        /// Delegate can recompute view and projection matricies or regenerate any buffers to be compatible with the new view size or resolution
458        ///
459        /// Parameter `view`: MTKView which called this method
460        ///
461        /// Parameter `size`: New drawable size in pixels
462        #[unsafe(method(mtkView:drawableSizeWillChange:))]
463        #[unsafe(method_family = none)]
464        fn mtkView_drawableSizeWillChange(&self, view: &MTKView, size: CGSize);
465
466        #[cfg(feature = "objc2-app-kit")]
467        #[cfg(target_os = "macos")]
468        /// Called on the delegate when it is asked to render into the view
469        ///
470        /// Called on the delegate when it is asked to render into the view
471        #[unsafe(method(drawInMTKView:))]
472        #[unsafe(method_family = none)]
473        fn drawInMTKView(&self, view: &MTKView);
474    }
475);