1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#[cfg(feature = "vulkan")]
use crate::gpu::vk;
use crate::gpu::BackendAPI;
use crate::prelude::*;
use skia_bindings as sb;
use skia_bindings::GrBackendDrawableInfo;

pub type BackendDrawableInfo = Handle<GrBackendDrawableInfo>;

impl NativeDrop for GrBackendDrawableInfo {
    fn drop(&mut self) {
        unsafe { sb::C_GrBackendDrawableInfo_destruct(self) }
    }
}

impl Handle<GrBackendDrawableInfo> {
    pub fn new() -> BackendDrawableInfo {
        Self::construct(|di| unsafe { sb::C_GrBackendDrawableInfo_Construct(di) })
    }

    #[cfg(feature = "vulkan")]
    pub fn from_vk(info: &vk::DrawableInfo) -> BackendDrawableInfo {
        Self::construct(|di| unsafe { sb::C_GrBackendDrawableInfo_Construct2(di, info.native()) })
    }

    pub fn is_valid(&self) -> bool {
        unsafe { sb::C_GrBackendDrawableInfo_isValid(self.native()) }
    }

    pub fn backend(&self) -> BackendAPI {
        BackendAPI::from_native(unsafe { sb::C_GrBackendDrawableInfo_backend(self.native()) })
    }

    #[cfg(feature = "vulkan")]
    pub fn get_vk_drawable_info(&self) -> Option<vk::DrawableInfo> {
        unsafe {
            let mut di = vk::DrawableInfo::default();
            sb::C_GrBackendDrawableInfo_getVkDrawableInfo(self.native(), di.native_mut())
                .if_true_some(di)
        }
    }
}