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