1use std::fmt;
2
3use skia_bindings::{self as sb, SkFlattenable, SkMaskFilter, SkRefCntBase};
4
5use crate::{prelude::*, scalar, BlurStyle, NativeFlattenable};
6
7/// MaskFilter is the base class for object that perform transformations on the mask before drawing
8/// it. An example subclass is Blur.
9pub type MaskFilter = RCHandle<SkMaskFilter>;
10unsafe_send_sync!(MaskFilter);
11
12impl NativeBase<SkRefCntBase> for SkMaskFilter {}
13impl NativeBase<SkFlattenable> for SkMaskFilter {}
14
15impl NativeRefCountedBase for SkMaskFilter {
16 type Base = SkRefCntBase;
17}
18
19impl NativeFlattenable for SkMaskFilter {
20 fn native_flattenable(&self) -> &SkFlattenable {
21 self.base()
22 }
23
24 fn native_deserialize(data: &[u8]) -> *mut Self {
25 unsafe { sb::C_SkMaskFilter_Deserialize(data.as_ptr() as _, length:data.len()) }
26 }
27}
28
29impl fmt::Debug for MaskFilter {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 f.debug_struct(name:"MaskFilter").finish()
32 }
33}
34
35impl MaskFilter {
36 /// Create a blur mask filter.
37 ///
38 /// - `style` The [`BlurStyle`] to use
39 /// - `sigma` Standard deviation of the Gaussian blur to apply. Must be > 0.
40 /// - `respect_ctm` if `true` the blur's sigma is modified by the `ctm`.
41 ///
42 /// Returns the new blur mask filter
43 pub fn blur(
44 style: BlurStyle,
45 sigma: scalar,
46 respect_ctm: impl Into<Option<bool>>,
47 ) -> Option<Self> {
48 Self::from_ptr(unsafe {
49 sb::C_SkMaskFilter_MakeBlur(style, sigma, respectCTM:respect_ctm.into().unwrap_or(true))
50 })
51 }
52}
53