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
8mod macros;
9
10pub mod codec;
11#[deprecated(since = "0.33.1", note = "use codec::Result")]
12pub use codec::Result as CodecResult;
13pub use codec::{codecs, Codec, EncodedImageFormat, EncodedOrigin};
14
15mod core;
16mod docs;
17mod effects;
18mod encode_;
19#[cfg(feature = "gpu")]
20pub mod gpu;
21mod interop;
22mod modules;
23mod pathops;
24mod prelude;
25pub mod wrapper;
26// The module private may contain types that leak.
27pub mod private;
28pub mod svg;
29// TODO: We don't export utils/* into the crate's root yet. Should we?
30pub mod utils;
31
32#[macro_use]
33extern crate bitflags;
34#[macro_use]
35extern crate lazy_static;
36
37// Prelude re-exports
38pub use crate::prelude::{Borrows, ConditionallySend, Handle, RCHandle, RefHandle, Sendable};
39
40/// All Sk* types are accessible via skia_safe::
41pub use crate::core::*;
42pub use docs::*;
43pub use effects::*;
44pub use encode_::*;
45#[allow(unused_imports)]
46pub use modules::*;
47pub 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"))]
52pub 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)]
98mod 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