1 | use std::fmt; |
2 | |
3 | use skia_bindings::{self as sb, skgpu_MutableTextureState, SkRefCntBase}; |
4 | |
5 | use super::BackendApi; |
6 | use crate::prelude::*; |
7 | |
8 | pub type MutableTextureState = RCHandle<skgpu_MutableTextureState>; |
9 | unsafe_send_sync!(MutableTextureState); |
10 | |
11 | impl NativeRefCountedBase for skgpu_MutableTextureState { |
12 | type Base = SkRefCntBase; |
13 | } |
14 | |
15 | impl Default for MutableTextureState { |
16 | fn default() -> Self { |
17 | MutableTextureState::from_ptr(unsafe { sb::C_MutableTextureState_Construct() }).unwrap() |
18 | } |
19 | } |
20 | |
21 | impl fmt::Debug for MutableTextureState { |
22 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
23 | let mut str: DebugStruct<'_, '_> = f.debug_struct(name:"MutableTextureState" ); |
24 | #[cfg (feature = "vulkan" )] |
25 | { |
26 | str.field("image_layout" , &self.vk_image_layout()) |
27 | .field("queue_family_index" , &self.queue_family_index()); |
28 | } |
29 | str.field(name:"backend" , &self.backend()).finish() |
30 | } |
31 | } |
32 | |
33 | impl MutableTextureState { |
34 | pub fn copied(&self) -> Self { |
35 | MutableTextureState::from_ptr(unsafe { |
36 | sb::C_MutableTextureState_CopyConstruct(self.native()) |
37 | }) |
38 | .unwrap() |
39 | } |
40 | |
41 | #[cfg (feature = "vulkan" )] |
42 | pub fn new_vk(layout: crate::gpu::vk::ImageLayout, queue_family_index: u32) -> Self { |
43 | crate::gpu::vk::mutable_texture_states::new_vulkan(layout, queue_family_index) |
44 | } |
45 | |
46 | #[cfg (feature = "vulkan" )] |
47 | pub fn vk_image_layout(&self) -> sb::VkImageLayout { |
48 | unsafe { sb::C_MutableTextureState_getVkImageLayout(self.native()) } |
49 | } |
50 | |
51 | #[cfg (feature = "vulkan" )] |
52 | pub fn queue_family_index(&self) -> u32 { |
53 | unsafe { sb::C_MutableTextureState_getQueueFamilyIndex(self.native()) } |
54 | } |
55 | |
56 | pub fn backend(&self) -> BackendApi { |
57 | unsafe { sb::C_MutableTextureState_backend(self.native()) } |
58 | } |
59 | } |
60 | |