1 | pub mod backend_formats { |
2 | use skia_bindings as sb; |
3 | |
4 | use crate::{ |
5 | gpu::{gl, BackendFormat}, |
6 | prelude::*, |
7 | }; |
8 | |
9 | pub fn make_gl(format: gl::Enum, target: gl::Enum) -> BackendFormat { |
10 | BackendFormatHandle::construct(|bf: *mut GrBackendFormat| unsafe { |
11 | sb::C_GrBackendFormats_ConstructGL(uninitialized:bf, format, target) |
12 | }) |
13 | .assert_valid() |
14 | } |
15 | |
16 | pub fn as_gl_format(format: &BackendFormat) -> gl::Format { |
17 | unsafe { sb::C_GrBackendFormats_AsGLFormat(format:format.native()) } |
18 | } |
19 | |
20 | pub fn as_gl_format_enum(format: &BackendFormat) -> gl::Enum { |
21 | unsafe { sb::C_GrBackendFormats_AsGLFormatEnum(format:format.native()) } |
22 | } |
23 | } |
24 | |
25 | pub mod backend_textures { |
26 | use skia_bindings as sb; |
27 | |
28 | use crate::{ |
29 | gpu::{gl, BackendTexture, Mipmapped}, |
30 | prelude::*, |
31 | }; |
32 | |
33 | #[allow (clippy::missing_safety_doc)] |
34 | pub unsafe fn make_gl( |
35 | (width, height): (i32, i32), |
36 | mipmapped: Mipmapped, |
37 | gl_info: gl::TextureInfo, |
38 | label: impl AsRef<str>, |
39 | ) -> BackendTexture { |
40 | let str = label.as_ref().as_bytes(); |
41 | BackendTexture::from_ptr(sb::C_GrBackendTextures_newGL( |
42 | width, |
43 | height, |
44 | mipmapped, |
45 | gl_info.native(), |
46 | str.as_ptr() as _, |
47 | str.len(), |
48 | )) |
49 | .unwrap() |
50 | } |
51 | |
52 | pub fn get_gl_texture_info(texture: &BackendTexture) -> Option<gl::TextureInfo> { |
53 | let mut texture_info = gl::TextureInfo::default(); |
54 | unsafe { |
55 | sb::C_GrBackendTextures_GetGLTextureInfo(texture.native(), texture_info.native_mut()) |
56 | } |
57 | .if_true_some(texture_info) |
58 | } |
59 | |
60 | pub fn gl_texture_parameters_modified(texture: &mut BackendTexture) { |
61 | unsafe { sb::C_GrBackendTextures_GLTextureParametersModified(texture.native_mut()) } |
62 | } |
63 | } |
64 | |
65 | pub mod backend_render_targets { |
66 | use skia_bindings as sb; |
67 | |
68 | use crate::{ |
69 | gpu::{gl, BackendRenderTarget}, |
70 | prelude::*, |
71 | }; |
72 | |
73 | pub fn make_gl( |
74 | (width, height): (i32, i32), |
75 | sample_count: impl Into<Option<usize>>, |
76 | stencil_bits: usize, |
77 | info: gl::FramebufferInfo, |
78 | ) -> BackendRenderTarget { |
79 | BackendRenderTarget::construct(|target| unsafe { |
80 | sb::C_GrBackendRenderTargets_ConstructGL( |
81 | target, |
82 | width, |
83 | height, |
84 | sample_count.into().unwrap_or(0).try_into().unwrap(), |
85 | stencil_bits.try_into().unwrap(), |
86 | info.native(), |
87 | ) |
88 | }) |
89 | } |
90 | |
91 | pub fn get_gl_framebuffer_info( |
92 | render_target: &BackendRenderTarget, |
93 | ) -> Option<gl::FramebufferInfo> { |
94 | let mut info = gl::FramebufferInfo::default(); |
95 | unsafe { |
96 | sb::C_GrBackendRenderTargets_GetGLFramebufferInfo( |
97 | render_target.native(), |
98 | info.native_mut(), |
99 | ) |
100 | } |
101 | .if_true_some(info) |
102 | } |
103 | } |
104 | |