1 | pub mod backend_formats { |
2 | use skia_bindings as sb; |
3 | |
4 | use crate::{ |
5 | gpu::{mtl, BackendFormat}, |
6 | prelude::*, |
7 | }; |
8 | |
9 | pub fn make_mtl(format: mtl::PixelFormat) -> BackendFormat { |
10 | BackendFormatHandle::construct(|bf: *mut GrBackendFormat| unsafe { sb::C_GrBackendFormats_ConstructMtl(bf, format) }) |
11 | .assert_valid() |
12 | } |
13 | |
14 | pub fn as_mtl_format(backend_format: &BackendFormat) -> Option<mtl::PixelFormat> { |
15 | let pixel_format = unsafe { sb::C_GrBackendFormats_AsMtlFormat(backend_format.native()) }; |
16 | // Mtl's PixelFormat == 0 is invalid. |
17 | (pixel_format != 0).if_true_some(pixel_format) |
18 | } |
19 | } |
20 | |
21 | pub mod backend_textures { |
22 | use skia_bindings as sb; |
23 | |
24 | use crate::{ |
25 | gpu::{self, mtl, BackendTexture}, |
26 | prelude::*, |
27 | }; |
28 | |
29 | #[allow (clippy::missing_safety_doc)] |
30 | pub unsafe fn make_mtl( |
31 | (width, height): (i32, i32), |
32 | mipmapped: gpu::Mipmapped, |
33 | mtl_info: &mtl::TextureInfo, |
34 | label: impl AsRef<str>, |
35 | ) -> BackendTexture { |
36 | let label = label.as_ref().as_bytes(); |
37 | BackendTexture::from_native_if_valid(sb::C_GrBackendTextures_newMtl( |
38 | width, |
39 | height, |
40 | mipmapped, |
41 | mtl_info.native(), |
42 | label.as_ptr() as _, |
43 | label.len(), |
44 | )) |
45 | .unwrap() |
46 | } |
47 | |
48 | pub fn get_mtl_texture_info(texture: &BackendTexture) -> Option<mtl::TextureInfo> { |
49 | unsafe { |
50 | let mut texture_info = mtl::TextureInfo::default(); |
51 | sb::C_GrBackendTextures_GetMtlTextureInfo(texture.native(), texture_info.native_mut()) |
52 | .if_true_some(texture_info) |
53 | } |
54 | } |
55 | } |
56 | |
57 | pub mod backend_render_targets { |
58 | use skia_bindings as sb; |
59 | |
60 | use crate::{ |
61 | gpu::{mtl, BackendRenderTarget}, |
62 | prelude::*, |
63 | }; |
64 | |
65 | pub fn make_mtl( |
66 | (width, height): (i32, i32), |
67 | mtl_info: &mtl::TextureInfo, |
68 | ) -> BackendRenderTarget { |
69 | BackendRenderTarget::construct(|target| unsafe { |
70 | sb::C_GrBackendRenderTargets_ConstructMtl(target, width, height, mtl_info.native()) |
71 | }) |
72 | } |
73 | |
74 | pub fn get_mtl_texture_info(render_target: &BackendRenderTarget) -> Option<mtl::TextureInfo> { |
75 | let mut info = mtl::TextureInfo::default(); |
76 | unsafe { |
77 | sb::C_GrBackendRenderTargets_GetMtlTextureInfo( |
78 | render_target.native(), |
79 | info.native_mut(), |
80 | ) |
81 | } |
82 | .if_true_some(info) |
83 | } |
84 | } |
85 | |