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