1 | use std::fmt; |
2 | |
3 | use crate::{ |
4 | gpu::mtl::Handle, |
5 | prelude::{self, NativeDrop}, |
6 | }; |
7 | |
8 | use skia_bindings::{self as sb, GrMtlBackendContext}; |
9 | |
10 | pub type BackendContext = prelude::Handle<GrMtlBackendContext>; |
11 | unsafe_send_sync!(BackendContext); |
12 | |
13 | impl NativeDrop for GrMtlBackendContext { |
14 | fn drop(&mut self) { |
15 | unsafe { sb::C_GrMtlBackendContext_Destruct(self) } |
16 | } |
17 | } |
18 | |
19 | impl fmt::Debug for BackendContext { |
20 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
21 | f.debug_struct(name:"BackendContext" ).finish() |
22 | } |
23 | } |
24 | |
25 | impl 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: *mut {unknown}| sb::C_GrMtlBackendContext_Construct(bc, device, queue)) |
34 | } |
35 | } |
36 | |