skia_safe/gpu/ganesh/
types.rs

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use std::ptr;

use crate::gpu;
use skia_bindings as sb;

pub use skia_bindings::GrBackendApi as BackendApi;
variant_name!(BackendAPI::OpenGL);

#[deprecated(since = "0.80.0", note = "use BackendApi")]
pub use BackendApi as BackendAPI;

pub const METAL_BACKEND: BackendApi = BackendApi::Metal;
pub const VULKAN_BACKEND: BackendApi = BackendApi::Vulkan;
pub const MOCK_BACKEND: BackendApi = BackendApi::Mock;

pub use gpu::Renderable;

pub use gpu::Protected;

pub use skia_bindings::GrSurfaceOrigin as SurfaceOrigin;
variant_name!(SurfaceOrigin::BottomLeft);

// Note: BackendState is in gl/types.rs/

#[repr(C)]
#[allow(dead_code)]
#[derive(Debug)]
pub struct FlushInfo {
    // TODO: wrap access to the following fields in a safe way:
    num_semaphores: usize,
    signal_semaphores: *mut sb::GrBackendSemaphore,
    finished_proc: sb::GrGpuFinishedProc,
    finished_context: sb::GrGpuFinishedContext,
    submitted_proc: sb::GrGpuSubmittedProc,
    submitted_context: sb::GrGpuSubmittedContext,
}

impl Default for FlushInfo {
    fn default() -> Self {
        Self {
            num_semaphores: 0,
            signal_semaphores: ptr::null_mut(),
            finished_proc: None,
            finished_context: ptr::null_mut(),
            submitted_proc: None,
            submitted_context: ptr::null_mut(),
        }
    }
}

native_transmutable!(sb::GrFlushInfo, FlushInfo, flush_info_layout);

pub use sb::GrSemaphoresSubmitted as SemaphoresSubmitted;
variant_name!(SemaphoresSubmitted::Yes);

pub use sb::GrPurgeResourceOptions as PurgeResourceOptions;
variant_name!(PurgeResourceOptions::AllResources);

pub use sb::GrSyncCpu as SyncCpu;
variant_name!(SyncCpu::Yes);

pub use sb::GrMarkFrameBoundary as MarkFrameBoundary;
variant_name!(MarkFrameBoundary::Yes);

#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct SubmitInfo {
    pub sync: SyncCpu,
    pub mark_boundary: MarkFrameBoundary,
    pub frame_id: u64,
}
native_transmutable!(sb::GrSubmitInfo, SubmitInfo, submit_info_layout);

impl Default for SubmitInfo {
    fn default() -> Self {
        Self {
            sync: SyncCpu::No,
            mark_boundary: MarkFrameBoundary::No,
            frame_id: 0,
        }
    }
}

impl From<SyncCpu> for SubmitInfo {
    fn from(sync: SyncCpu) -> Self {
        Self {
            sync,
            ..Self::default()
        }
    }
}

impl From<Option<SyncCpu>> for SubmitInfo {
    fn from(sync_cpu: Option<SyncCpu>) -> Self {
        match sync_cpu {
            Some(sync_cpu) => sync_cpu.into(),
            None => Self::default(),
        }
    }
}