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