skia_safe/
lib.rs

1#![macro_use]
2#![allow(clippy::upper_case_acronyms)]
3#![allow(clippy::non_send_fields_in_send_ty)]
4// https://github.com/rust-lang/rust/issues/93367
5#![allow(unknown_lints)]
6#![allow(clippy::too_long_first_doc_paragraph)]
7#![allow(clippy::doc_overindented_list_items)]
8
9mod macros;
10
11pub mod codec;
12#[deprecated(since = "0.33.1", note = "use codec::Result")]
13pub use codec::Result as CodecResult;
14pub use codec::{codecs, Codec, EncodedImageFormat, EncodedOrigin};
15
16mod core;
17#[cfg(feature = "pdf")]
18mod docs;
19mod effects;
20mod encode_;
21#[cfg(feature = "gpu")]
22pub mod gpu;
23mod interop;
24mod modules;
25mod pathops;
26mod prelude;
27pub(crate) mod private;
28pub mod svg;
29pub mod wrapper;
30// TODO: We don't export utils/* into the crate's root yet. Should we?
31pub mod utils;
32
33#[macro_use]
34extern crate bitflags;
35#[macro_use]
36extern crate lazy_static;
37
38// Prelude re-exports
39pub use crate::prelude::{Borrows, ConditionallySend, Handle, RCHandle, RefHandle, Sendable};
40
41/// All Sk* types are accessible via skia_safe::
42pub use crate::core::*;
43#[cfg(feature = "pdf")]
44pub use docs::*;
45pub use effects::*;
46pub use encode_::*;
47#[allow(unused_imports)]
48pub use modules::*;
49pub use pathops::*;
50
51/// Stubs for types that are only available with the `gpu` feature.
52#[allow(unknown_lints, clippy::uninhabited_references)]
53#[cfg(not(feature = "gpu"))]
54pub mod gpu {
55    use std::{
56        ops::{Deref, DerefMut},
57        ptr,
58    };
59
60    use crate::prelude::*;
61
62    #[derive(Debug)]
63    pub enum RecordingContext {}
64
65    impl NativePointerOrNullMut for Option<&mut RecordingContext> {
66        type Native = skia_bindings::GrRecordingContext;
67
68        fn native_ptr_or_null_mut(&mut self) -> *mut skia_bindings::GrRecordingContext {
69            ptr::null_mut()
70        }
71    }
72
73    #[derive(Debug)]
74    pub enum DirectContext {}
75
76    impl Deref for DirectContext {
77        type Target = RecordingContext;
78
79        fn deref(&self) -> &Self::Target {
80            unsafe { transmute_ref(self) }
81        }
82    }
83
84    impl DerefMut for DirectContext {
85        fn deref_mut(&mut self) -> &mut Self::Target {
86            unsafe { transmute_ref_mut(self) }
87        }
88    }
89
90    impl NativePointerOrNullMut for Option<&mut DirectContext> {
91        type Native = skia_bindings::GrDirectContext;
92
93        fn native_ptr_or_null_mut(&mut self) -> *mut skia_bindings::GrDirectContext {
94            ptr::null_mut()
95        }
96    }
97}
98
99#[cfg(test)]
100mod transmutation_tests {
101    use crate::{prelude::NativeTransmutableSliceAccess, Point};
102    use skia_bindings::SkPoint;
103
104    #[test]
105    #[allow(clippy::float_cmp)]
106    fn test_transmutation_of_fixed_size_arrays_to_slice() {
107        let mut points = [Point::default(); 4];
108
109        let points_native = points.native_mut();
110        let native_point = SkPoint { fX: 10.0, fY: 11.0 };
111        points_native[1] = native_point;
112
113        assert_eq!(points[1].x, native_point.fX);
114        assert_eq!(points[1].y, native_point.fY);
115    }
116}