skia_safe/gpu/ganesh/
types.rs

1use std::ptr;
2
3use crate::gpu;
4use crate::gpu::GpuStatsFlags;
5use skia_bindings as sb;
6
7pub use skia_bindings::GrBackendApi as BackendApi;
8variant_name!(BackendAPI::OpenGL);
9
10#[deprecated(since = "0.80.0", note = "use BackendApi")]
11pub use BackendApi as BackendAPI;
12
13pub const METAL_BACKEND: BackendApi = BackendApi::Metal;
14pub const VULKAN_BACKEND: BackendApi = BackendApi::Vulkan;
15pub const MOCK_BACKEND: BackendApi = BackendApi::Mock;
16
17pub use gpu::Renderable;
18
19pub use gpu::Protected;
20
21pub use skia_bindings::GrSurfaceOrigin as SurfaceOrigin;
22variant_name!(SurfaceOrigin::BottomLeft);
23
24// Note: BackendState is in gl/types.rs/
25
26#[repr(C)]
27#[allow(dead_code)]
28#[derive(Debug)]
29pub 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
41impl 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
56native_transmutable!(sb::GrFlushInfo, FlushInfo, flush_info_layout);
57
58pub use sb::GrSemaphoresSubmitted as SemaphoresSubmitted;
59variant_name!(SemaphoresSubmitted::Yes);
60
61pub use sb::GrPurgeResourceOptions as PurgeResourceOptions;
62variant_name!(PurgeResourceOptions::AllResources);
63
64pub use sb::GrSyncCpu as SyncCpu;
65variant_name!(SyncCpu::Yes);
66
67pub use sb::GrMarkFrameBoundary as MarkFrameBoundary;
68variant_name!(MarkFrameBoundary::Yes);
69
70#[repr(C)]
71#[derive(Copy, Clone, Debug)]
72pub struct SubmitInfo {
73    pub sync: SyncCpu,
74    pub mark_boundary: MarkFrameBoundary,
75    pub frame_id: u64,
76}
77native_transmutable!(sb::GrSubmitInfo, SubmitInfo, submit_info_layout);
78
79impl 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
89impl From<SyncCpu> for SubmitInfo {
90    fn from(sync: SyncCpu) -> Self {
91        Self {
92            sync,
93            ..Self::default()
94        }
95    }
96}
97
98impl From<Option<SyncCpu>> for SubmitInfo {
99    fn from(sync_cpu: Option<SyncCpu>) -> Self {
100        match sync_cpu {
101            Some(sync_cpu) => sync_cpu.into(),
102            None => Self::default(),
103        }
104    }
105}