skia_safe/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#![macro_use]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::non_send_fields_in_send_ty)]
// https://github.com/rust-lang/rust/issues/93367
#![allow(unknown_lints)]
#![allow(clippy::too_long_first_doc_paragraph)]

mod macros;

pub mod codec;
#[deprecated(since = "0.33.1", note = "use codec::Result")]
pub use codec::Result as CodecResult;
pub use codec::{codecs, Codec, EncodedImageFormat, EncodedOrigin};

mod core;
mod docs;
mod effects;
mod encode_;
#[cfg(feature = "gpu")]
pub mod gpu;
mod interop;
mod modules;
mod pathops;
mod prelude;
pub(crate) mod private;
pub mod svg;
pub mod wrapper;
// TODO: We don't export utils/* into the crate's root yet. Should we?
pub mod utils;

#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate lazy_static;

// Prelude re-exports
pub use crate::prelude::{Borrows, ConditionallySend, Handle, RCHandle, RefHandle, Sendable};

/// All Sk* types are accessible via skia_safe::
pub use crate::core::*;
pub use docs::*;
pub use effects::*;
pub use encode_::*;
#[allow(unused_imports)]
pub use modules::*;
pub use pathops::*;

/// Stubs for types that are only available with the `gpu` feature.
#[allow(unknown_lints, clippy::uninhabited_references)]
#[cfg(not(feature = "gpu"))]
pub mod gpu {
    use std::{
        ops::{Deref, DerefMut},
        ptr,
    };

    use crate::prelude::*;

    #[derive(Debug)]
    pub enum RecordingContext {}

    impl NativePointerOrNullMut for Option<&mut RecordingContext> {
        type Native = skia_bindings::GrRecordingContext;

        fn native_ptr_or_null_mut(&mut self) -> *mut skia_bindings::GrRecordingContext {
            ptr::null_mut()
        }
    }

    #[derive(Debug)]
    pub enum DirectContext {}

    impl Deref for DirectContext {
        type Target = RecordingContext;

        fn deref(&self) -> &Self::Target {
            unsafe { transmute_ref(self) }
        }
    }

    impl DerefMut for DirectContext {
        fn deref_mut(&mut self) -> &mut Self::Target {
            unsafe { transmute_ref_mut(self) }
        }
    }

    impl NativePointerOrNullMut for Option<&mut DirectContext> {
        type Native = skia_bindings::GrDirectContext;

        fn native_ptr_or_null_mut(&mut self) -> *mut skia_bindings::GrDirectContext {
            ptr::null_mut()
        }
    }
}

#[cfg(test)]
mod transmutation_tests {
    use crate::{prelude::NativeTransmutableSliceAccess, Point};
    use skia_bindings::SkPoint;

    #[test]
    #[allow(clippy::float_cmp)]
    fn test_transmutation_of_fixed_size_arrays_to_slice() {
        let mut points = [Point::default(); 4];

        let points_native = points.native_mut();
        let native_point = SkPoint { fX: 10.0, fY: 11.0 };
        points_native[1] = native_point;

        assert_eq!(points[1].x, native_point.fX);
        assert_eq!(points[1].y, native_point.fY);
    }
}