skia_safe/gpu/ganesh/gl/
extensions.rs

1use crate::prelude::*;
2use skia_bindings::{self as sb, GrGLExtensions};
3use std::{ffi::CString, fmt};
4
5pub type Extensions = Handle<GrGLExtensions>;
6unsafe_send_sync!(Extensions);
7
8impl NativeDrop for GrGLExtensions {
9    fn drop(&mut self) {
10        unsafe { sb::C_GrGLExtensions_destruct(self) }
11    }
12}
13
14impl NativeClone for GrGLExtensions {
15    fn clone(&self) -> Self {
16        unsafe { sb::GrGLExtensions::new(self) }
17    }
18}
19
20impl fmt::Debug for Extensions {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        f.debug_struct("Extensions")
23            .field("is_initialized", &self.is_initialized())
24            .finish()
25    }
26}
27
28impl Extensions {
29    // TODO: support new() / init?
30
31    pub fn is_initialized(&self) -> bool {
32        self.native().fInitialized
33    }
34
35    pub fn has(&self, extension: impl AsRef<str>) -> bool {
36        let extension = CString::new(extension.as_ref()).unwrap();
37        unsafe { self.native().has(extension.as_ptr()) }
38    }
39
40    pub fn remove(&mut self, extension: impl AsRef<str>) -> bool {
41        let extension = CString::new(extension.as_ref()).unwrap();
42        unsafe { self.native_mut().remove(extension.as_ptr()) }
43    }
44
45    pub fn add(&mut self, extension: impl AsRef<str>) {
46        let extension = CString::new(extension.as_ref()).unwrap();
47        unsafe { self.native_mut().add(extension.as_ptr()) }
48    }
49
50    pub fn reset(&mut self) {
51        unsafe { sb::C_GrGLExtensions_reset(self.native_mut()) }
52    }
53
54    // TODO: dumpJSON()?
55}