skia_safe/gpu/ganesh/gl/
backend_surface.rs1pub mod backend_formats {
2 use skia_bindings as sb;
3
4 use crate::{
5 gpu::{BackendFormat, gl},
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::{BackendTexture, Mipmapped, gl},
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(unsafe {
58 sb::C_GrBackendTextures_newGL(
59 width,
60 height,
61 mipmapped,
62 gl_info.native(),
63 str.as_ptr() as _,
64 str.len(),
65 )
66 })
67 .unwrap()
68 }
69
70 pub fn get_gl_texture_info(texture: &BackendTexture) -> Option<gl::TextureInfo> {
71 let mut texture_info = gl::TextureInfo::default();
72 unsafe {
73 sb::C_GrBackendTextures_GetGLTextureInfo(texture.native(), texture_info.native_mut())
74 }
75 .then_some(texture_info)
76 }
77
78 pub fn gl_texture_parameters_modified(texture: &mut BackendTexture) {
79 unsafe { sb::C_GrBackendTextures_GLTextureParametersModified(texture.native_mut()) }
80 }
81}
82
83pub mod backend_render_targets {
84 use skia_bindings as sb;
85
86 use crate::{
87 gpu::{BackendRenderTarget, gl},
88 prelude::*,
89 };
90
91 pub fn make_gl(
92 (width, height): (i32, i32),
93 sample_count: impl Into<Option<usize>>,
94 stencil_bits: usize,
95 info: gl::FramebufferInfo,
96 ) -> BackendRenderTarget {
97 BackendRenderTarget::construct(|target| unsafe {
98 sb::C_GrBackendRenderTargets_ConstructGL(
99 target,
100 width,
101 height,
102 sample_count.into().unwrap_or(0).try_into().unwrap(),
103 stencil_bits.try_into().unwrap(),
104 info.native(),
105 )
106 })
107 }
108
109 pub fn get_gl_framebuffer_info(
110 render_target: &BackendRenderTarget,
111 ) -> Option<gl::FramebufferInfo> {
112 let mut info = gl::FramebufferInfo::default();
113 unsafe {
114 sb::C_GrBackendRenderTargets_GetGLFramebufferInfo(
115 render_target.native(),
116 info.native_mut(),
117 )
118 }
119 .then_some(info)
120 }
121}