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