skia_safe/gpu/ganesh/mtl/
backend_context.rs

1use std::fmt;
2
3use crate::{
4    gpu::mtl::Handle,
5    prelude::{self, NativeDrop},
6};
7
8use skia_bindings::{self as sb, GrMtlBackendContext};
9
10pub type BackendContext = prelude::Handle<GrMtlBackendContext>;
11unsafe_send_sync!(BackendContext);
12
13impl NativeDrop for GrMtlBackendContext {
14    fn drop(&mut self) {
15        unsafe { sb::C_GrMtlBackendContext_Destruct(self) }
16    }
17}
18
19impl fmt::Debug for BackendContext {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        f.debug_struct("BackendContext").finish()
22    }
23}
24
25impl BackendContext {
26    /// # Safety
27    ///
28    /// Unsafe because it expects various objects in form of `c_void` pointers.
29    ///
30    /// This function retains all the non-`null` handles passed to it and releases them as soon the
31    /// [BackendContext] is dropped.
32    pub unsafe fn new(device: Handle, queue: Handle) -> Self {
33        BackendContext::construct(|bc| sb::C_GrMtlBackendContext_Construct(bc, device, queue))
34    }
35}