1 | use std::ptr; |
2 | |
3 | use crate::gpu; |
4 | use crate::gpu::GpuStatsFlags; |
5 | use skia_bindings as sb; |
6 | |
7 | pub use skia_bindings::GrBackendApi as BackendApi; |
8 | variant_name!(BackendAPI::OpenGL); |
9 | |
10 | #[deprecated (since = "0.80.0" , note = "use BackendApi" )] |
11 | pub use BackendApi as BackendAPI; |
12 | |
13 | pub const METAL_BACKEND: BackendApi = BackendApi::Metal; |
14 | pub const VULKAN_BACKEND: BackendApi = BackendApi::Vulkan; |
15 | pub const MOCK_BACKEND: BackendApi = BackendApi::Mock; |
16 | |
17 | pub use gpu::Renderable; |
18 | |
19 | pub use gpu::Protected; |
20 | |
21 | pub use skia_bindings::GrSurfaceOrigin as SurfaceOrigin; |
22 | variant_name!(SurfaceOrigin::BottomLeft); |
23 | |
24 | // Note: BackendState is in gl/types.rs/ |
25 | |
26 | #[repr (C)] |
27 | #[allow (dead_code)] |
28 | #[derive (Debug)] |
29 | pub struct FlushInfo { |
30 | // TODO: wrap access to the following fields in a safe way: |
31 | num_semaphores: usize, |
32 | gpu_stats_flags: GpuStatsFlags, |
33 | signal_semaphores: *mut sb::GrBackendSemaphore, |
34 | finished_proc: sb::GrGpuFinishedProc, |
35 | finished_with_stats_proc: sb::GrGpuFinishedWithStatsProc, |
36 | finished_context: sb::GrGpuFinishedContext, |
37 | submitted_proc: sb::GrGpuSubmittedProc, |
38 | submitted_context: sb::GrGpuSubmittedContext, |
39 | } |
40 | |
41 | impl Default for FlushInfo { |
42 | fn default() -> Self { |
43 | Self { |
44 | num_semaphores: 0, |
45 | gpu_stats_flags: GpuStatsFlags::NONE, |
46 | signal_semaphores: ptr::null_mut(), |
47 | finished_proc: None, |
48 | finished_with_stats_proc: None, |
49 | finished_context: ptr::null_mut(), |
50 | submitted_proc: None, |
51 | submitted_context: ptr::null_mut(), |
52 | } |
53 | } |
54 | } |
55 | |
56 | native_transmutable!(sb::GrFlushInfo, FlushInfo, flush_info_layout); |
57 | |
58 | pub use sb::GrSemaphoresSubmitted as SemaphoresSubmitted; |
59 | variant_name!(SemaphoresSubmitted::Yes); |
60 | |
61 | pub use sb::GrPurgeResourceOptions as PurgeResourceOptions; |
62 | variant_name!(PurgeResourceOptions::AllResources); |
63 | |
64 | pub use sb::GrSyncCpu as SyncCpu; |
65 | variant_name!(SyncCpu::Yes); |
66 | |
67 | pub use sb::GrMarkFrameBoundary as MarkFrameBoundary; |
68 | variant_name!(MarkFrameBoundary::Yes); |
69 | |
70 | #[repr (C)] |
71 | #[derive (Copy, Clone, Debug)] |
72 | pub struct SubmitInfo { |
73 | pub sync: SyncCpu, |
74 | pub mark_boundary: MarkFrameBoundary, |
75 | pub frame_id: u64, |
76 | } |
77 | native_transmutable!(sb::GrSubmitInfo, SubmitInfo, submit_info_layout); |
78 | |
79 | impl Default for SubmitInfo { |
80 | fn default() -> Self { |
81 | Self { |
82 | sync: SyncCpu::No, |
83 | mark_boundary: MarkFrameBoundary::No, |
84 | frame_id: 0, |
85 | } |
86 | } |
87 | } |
88 | |
89 | impl From<SyncCpu> for SubmitInfo { |
90 | fn from(sync: SyncCpu) -> Self { |
91 | Self { |
92 | sync, |
93 | ..Self::default() |
94 | } |
95 | } |
96 | } |
97 | |
98 | impl From<Option<SyncCpu>> for SubmitInfo { |
99 | fn from(sync_cpu: Option<SyncCpu>) -> Self { |
100 | match sync_cpu { |
101 | Some(sync_cpu: GrSyncCpu) => sync_cpu.into(), |
102 | None => Self::default(), |
103 | } |
104 | } |
105 | } |
106 | |