skia_safe/gpu/ganesh/gl/
types.rs1use crate::{gpu, prelude::*};
2use skia_bindings::{self as sb, GrGLFramebufferInfo, GrGLSurfaceInfo, GrGLTextureInfo};
3
4pub use skia_bindings::GrGLFormat as Format;
5variant_name!(Format::ALPHA8);
6pub use skia_bindings::GrGLStandard as Standard;
7variant_name!(Standard::GLES);
8pub use skia_bindings::GrGLenum as Enum;
9pub use skia_bindings::GrGLuint as UInt;
10
11#[derive(Copy, Clone, Eq, Debug)]
12#[repr(C)]
13pub struct TextureInfo {
14 pub target: Enum,
15 pub id: Enum,
16 pub format: Enum,
17 pub protected: gpu::Protected,
18}
19
20native_transmutable!(GrGLTextureInfo, TextureInfo);
21
22impl Default for TextureInfo {
23 fn default() -> Self {
24 Self {
25 target: 0,
26 id: 0,
27 format: 0,
28 protected: gpu::Protected::No,
29 }
30 }
31}
32
33impl PartialEq for TextureInfo {
34 fn eq(&self, other: &Self) -> bool {
35 unsafe { sb::C_GrGLTextureInfo_Equals(self.native(), other.native()) }
36 }
37}
38
39impl TextureInfo {
40 pub fn from_target_and_id(target: Enum, id: Enum) -> Self {
41 Self {
42 target,
43 id,
44 ..Default::default()
45 }
46 }
47
48 pub fn is_protected(&self) -> bool {
49 self.protected == gpu::Protected::Yes
50 }
51}
52
53#[derive(Copy, Clone, PartialEq, Eq, Debug)]
54#[repr(C)]
55pub struct FramebufferInfo {
56 pub fboid: UInt,
57 pub format: Enum,
58 pub protected: gpu::Protected,
59}
60
61native_transmutable!(GrGLFramebufferInfo, FramebufferInfo);
62
63impl Default for FramebufferInfo {
64 fn default() -> Self {
65 Self {
66 fboid: 0,
67 format: 0,
68 protected: gpu::Protected::No,
69 }
70 }
71}
72
73impl FramebufferInfo {
74 pub fn from_fboid(fboid: UInt) -> Self {
75 Self {
76 fboid,
77 ..Default::default()
78 }
79 }
80
81 pub fn is_protected(&self) -> bool {
82 self.protected == gpu::Protected::Yes
83 }
84}
85
86#[derive(Copy, Clone, PartialEq, Eq, Debug)]
87#[repr(C)]
88pub struct SurfaceInfo {
89 pub sample_count: u32,
90 pub level_count: u32,
91 pub protected: gpu::Protected,
92
93 pub target: Enum,
94 pub format: Enum,
95}
96
97native_transmutable!(GrGLSurfaceInfo, SurfaceInfo);
98
99impl Default for SurfaceInfo {
100 fn default() -> Self {
101 Self {
102 sample_count: 1,
103 level_count: 0,
104 protected: gpu::Protected::No,
105 target: 0,
106 format: 0,
107 }
108 }
109}
110
111bitflags! {
112 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
113 pub struct BackendState: u32 {
114 const RENDER_TARGET = sb::GrGLBackendState_kRenderTarget_GrGLBackendState as _;
115 const TEXTURE_BINDING = sb::GrGLBackendState_kTextureBinding_GrGLBackendState as _;
116 const VIEW = sb::GrGLBackendState_kView_GrGLBackendState as _;
117 const BLEND = sb::GrGLBackendState_kBlend_GrGLBackendState as _;
118 const MSAA_ENABLE = sb::GrGLBackendState_kMSAAEnable_GrGLBackendState as _;
119 const VERTEX = sb::GrGLBackendState_kVertex_GrGLBackendState as _;
120 const STENCIL = sb::GrGLBackendState_kStencil_GrGLBackendState as _;
121 const PIXEL_STORE = sb::GrGLBackendState_kPixelStore_GrGLBackendState as _;
122 const PROGRAM = sb::GrGLBackendState_kProgram_GrGLBackendState as _;
123 const FIXED_FUNCTION = sb::GrGLBackendState_kFixedFunction_GrGLBackendState as _;
124 const MISC = sb::GrGLBackendState_kMisc_GrGLBackendState as _;
125 }
126}
127
128#[cfg(test)]
131mod tests {
132 use super::{Enum, Format};
133
134 #[test]
135 fn test_support_from_format_to_enum_and_back() {
136 let e: Enum = Format::ALPHA8.into();
137 let f: Format = e.into();
138 assert_eq!(f, Format::ALPHA8);
139 }
140
141 #[test]
142 fn test_all_formats_exhaustive() {
143 use Format::*;
144 let x = ALPHA8;
145 match x {
149 Unknown => {}
150 RGBA8 => {}
151 R8 => {}
152 ALPHA8 => {}
153 LUMINANCE8 => {}
154 LUMINANCE8_ALPHA8 => {}
155 BGRA8 => {}
156 RGB565 => {}
157 RGBA16F => {}
158 R16F => {}
159 RGB8 => {}
160 RGBX8 => {}
161 RG8 => {}
162 RGB10_A2 => {}
163 RGBA4 => {}
164 SRGB8_ALPHA8 => {}
165 COMPRESSED_ETC1_RGB8 => {}
166 COMPRESSED_RGB8_ETC2 => {}
167 COMPRESSED_RGB8_BC1 => {}
168 COMPRESSED_RGBA8_BC1 => {}
169 R16 => {}
170 RG16 => {}
171 RGBA16 => {}
172 RG16F => {}
173 LUMINANCE16F => {}
174 STENCIL_INDEX8 => {}
175 STENCIL_INDEX16 => {}
176 DEPTH24_STENCIL8 => {}
177 }
178 }
179
180 #[test]
181 fn test_format_last_color_and_last_exists() {
182 let _ = Format::Last;
183 let _ = Format::LastColorFormat;
184 }
185}