| 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 | |
| 9 | mod macros; |
| 10 | |
| 11 | pub mod codec; |
| 12 | #[deprecated (since = "0.33.1" , note = "use codec::Result" )] |
| 13 | pub use codec::Result as CodecResult; |
| 14 | pub use codec::{codecs, Codec, EncodedImageFormat, EncodedOrigin}; |
| 15 | |
| 16 | mod core; |
| 17 | mod docs; |
| 18 | mod effects; |
| 19 | mod encode_; |
| 20 | #[cfg (feature = "gpu" )] |
| 21 | pub mod gpu; |
| 22 | mod interop; |
| 23 | mod modules; |
| 24 | mod pathops; |
| 25 | mod prelude; |
| 26 | pub(crate) mod private; |
| 27 | pub mod svg; |
| 28 | pub mod wrapper; |
| 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 | |