1#[cfg(feature = "vulkan")]
2use crate::gpu::vk;
3use crate::{gpu::BackendAPI, prelude::*};
4use skia_bindings::{self as sb, GrBackendDrawableInfo};
5use std::fmt;
6
7pub type BackendDrawableInfo = Handle<GrBackendDrawableInfo>;
8unsafe_send_sync!(BackendDrawableInfo);
9
10impl NativeDrop for GrBackendDrawableInfo {
11 fn drop(&mut self) {
12 unsafe { sb::C_GrBackendDrawableInfo_destruct(self) }
13 }
14}
15
16impl fmt::Debug for BackendDrawableInfo {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 let mut d: DebugStruct<'_, '_> = f.debug_struct(name:"BackendDrawableInfo");
19 d.field(name:"is_valid", &self.is_valid());
20 d.field(name:"backend", &self.backend());
21 #[cfg(feature = "vulkan")]
22 d.field("vk_drawable_info", &self.get_vk_drawable_info());
23 d.finish()
24 }
25}
26
27impl BackendDrawableInfo {
28 pub fn new() -> Self {
29 Self::construct(|di| unsafe { sb::C_GrBackendDrawableInfo_Construct(di) })
30 }
31
32 #[cfg(feature = "vulkan")]
33 pub fn from_vk(info: &vk::DrawableInfo) -> Self {
34 Self::construct(|di| unsafe { sb::C_GrBackendDrawableInfo_Construct2(di, info.native()) })
35 }
36
37 pub fn is_valid(&self) -> bool {
38 unsafe { sb::C_GrBackendDrawableInfo_isValid(self.native()) }
39 }
40
41 pub fn backend(&self) -> BackendAPI {
42 unsafe { sb::C_GrBackendDrawableInfo_backend(self.native()) }
43 }
44
45 #[cfg(feature = "vulkan")]
46 pub fn get_vk_drawable_info(&self) -> Option<vk::DrawableInfo> {
47 unsafe {
48 let mut di = vk::DrawableInfo::default();
49 sb::C_GrBackendDrawableInfo_getVkDrawableInfo(self.native(), di.native_mut())
50 .if_true_some(di)
51 }
52 }
53}
54