skia_safe/gpu/ganesh/mtl/
direct_context.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pub mod direct_contexts {

    use skia_bindings as sb;

    use crate::{
        gpu::{mtl, ContextOptions, DirectContext},
        prelude::*,
    };

    /// Makes a [`DirectContext`] which uses Metal as the backend. The [`mtl::BackendContext`] contains a
    /// MTLDevice and MTLCommandQueue which should be used by the backend. These objects must
    /// have their own ref which will be released when the [`mtl::BackendContext`] is destroyed.
    /// Ganesh will take its own ref on the objects which will be released when the [`DirectContext`]
    /// is destroyed.
    pub fn make_metal<'a>(
        backend: &mtl::BackendContext,
        options: impl Into<Option<&'a ContextOptions>>,
    ) -> Option<DirectContext> {
        DirectContext::from_ptr(unsafe {
            sb::C_GrContext_MakeMetal(backend.native(), options.into().native_ptr_or_null())
        })
    }
}