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
use crate::prelude::*;
use crate::{scalar, BlurStyle, Color, NativeFlattenable, Paint, Rect, Vector};
use skia_bindings as sb;
use skia_bindings::{SkDrawLooper, SkDrawLooper_BlurShadowRec, SkFlattenable, SkRefCntBase};

pub type DrawLooper = RCHandle<SkDrawLooper>;

impl NativeRefCountedBase for SkDrawLooper {
    type Base = SkRefCntBase;

    fn ref_counted_base(&self) -> &Self::Base {
        &self._base._base._base
    }
}

impl NativeFlattenable for SkDrawLooper {
    fn native_flattenable(&self) -> &SkFlattenable {
        &self._base
    }

    fn native_deserialize(data: &[u8]) -> *mut Self {
        unsafe { sb::C_SkDrawLooper_Deserialize(data.as_ptr() as _, data.len()) }
    }
}

#[derive(Clone, PartialEq, Default, Debug)]
#[repr(C)]
pub struct BlurShadowRec {
    pub sigma: scalar,
    pub offset: Vector,
    pub color: Color,
    pub blur: BlurStyle,
}

impl NativeTransmutable<SkDrawLooper_BlurShadowRec> for BlurShadowRec {}
#[test]
fn test_blur_shadow_rec_layout() {
    BlurShadowRec::test_layout()
}

impl RCHandle<SkDrawLooper> {
    // TODO: Context
    // TODO: makeContext

    pub fn can_compute_fast_bounds(&self, paint: &Paint) -> bool {
        unsafe { self.native().canComputeFastBounds(paint.native()) }
    }

    pub fn compute_fast_bounds(&self, paint: &Paint, src: impl AsRef<Rect>) -> Rect {
        let mut r = Rect::default();
        unsafe {
            self.native()
                .computeFastBounds(paint.native(), src.as_ref().native(), r.native_mut())
        };
        r
    }

    pub fn as_a_blur_shadow(&self) -> Option<BlurShadowRec> {
        let mut br = BlurShadowRec::default();
        unsafe { sb::C_SkDrawLooper_asABlurShadow(self.native(), br.native_mut()) }.if_true_some(br)
    }

    // TODO: apply
}