1use crate::{
2 gpu,
3 prelude::{self, NativeAccess, NativeDrop, NativePartialEq},
4};
5use skia_bindings::{self as sb, GrMtlSurfaceInfo, GrMtlTextureInfo};
6use std::{fmt, ptr};
7
8pub use skia_bindings::GrMTLHandle as Handle;
9pub use skia_bindings::GrMTLPixelFormat as PixelFormat;
10pub use skia_bindings::GrMTLStorageMode as StorageMode;
11pub use skia_bindings::GrMTLTextureUsage as TextureUsage;
12
13pub type TextureInfo = prelude::Handle<GrMtlTextureInfo>;
14unsafe_send_sync!(TextureInfo);
15
16impl NativeDrop for GrMtlTextureInfo {
17 fn drop(&mut self) {
18 unsafe { sb::C_GrMtlTextureInfo_Destruct(self) }
19 }
20}
21
22impl NativePartialEq for GrMtlTextureInfo {
23 fn eq(&self, other: &Self) -> bool {
24 unsafe { sb::C_GrMtlTextureInfo_Equals(self, other) }
25 }
26}
27
28impl Default for TextureInfo {
29 fn default() -> Self {
30 unsafe { Self::new(ptr::null()) }
31 }
32}
33
34impl fmt::Debug for TextureInfo {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 f&mut DebugStruct<'_, '_>.debug_struct("TextureInfo")
37 .field(name:"texture", &self.texture())
38 .finish()
39 }
40}
41
42impl TextureInfo {
43 /// # Safety
44 ///
45 /// Unsafe because the texture provided must either be `null` or pointing to a Metal texture by
46 /// providing a raw pointer.
47 ///
48 /// This function retains the texture and releases it as soon TextureInfo is dropped.
49 pub unsafe fn new(texture: Handle) -> Self {
50 Self::construct(|ti: *mut {unknown}| sb::C_GrMtlTextureInfo_Construct(ti, texture))
51 }
52
53 pub fn texture(&self) -> Handle {
54 self.native().fTexture.fObject
55 }
56}
57
58#[derive(Copy, Clone, PartialEq, Eq, Debug)]
59#[repr(C)]
60pub struct SurfaceInfo {
61 pub sample_count: u32,
62 pub level_count: u32,
63 pub protected: gpu::Protected,
64
65 pub format: PixelFormat,
66 pub usage: TextureUsage,
67 pub storage_mode: StorageMode,
68}
69
70native_transmutable!(GrMtlSurfaceInfo, SurfaceInfo, surface_info_layout);
71
72impl Default for SurfaceInfo {
73 fn default() -> Self {
74 Self {
75 sample_count: 1,
76 level_count: 0,
77 protected: gpu::Protected::No,
78 format: 0,
79 usage: 0,
80 storage_mode: 0,
81 }
82 }
83}
84
85#[cfg(test)]
86mod tests {
87 use super::TextureInfo;
88
89 #[test]
90 fn default_texture_info() {
91 drop(TextureInfo::default());
92 }
93}
94