🎉 Render wasm blur support

This commit is contained in:
Alejandro Alonso 2025-01-09 13:51:12 +01:00
parent d500058aa9
commit 7cc33b1a1a
8 changed files with 117 additions and 11 deletions

View file

@ -0,0 +1,38 @@
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum BlurType {
None,
Layer,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Blur {
pub hidden: bool,
pub blur_type: BlurType,
pub value: f32,
}
impl From<u8> for BlurType {
fn from(value: u8) -> Self {
match value {
1 => BlurType::Layer,
_ => BlurType::None,
}
}
}
impl Blur {
pub fn default() -> Self {
Blur {
blur_type: BlurType::None,
hidden: true,
value: 0.,
}
}
pub fn new(blur_type: u8, hidden: bool, value: f32) -> Self {
Blur {
blur_type: BlurType::from(blur_type),
hidden,
value,
}
}
}

View file

@ -1,7 +1,7 @@
use skia_safe as skia;
use uuid::Uuid;
use super::{Fill, Image, Kind, Path, Shape, Stroke, StrokeCap, StrokeKind};
use super::{BlurType, Fill, Image, Kind, Path, Shape, Stroke, StrokeCap, StrokeKind};
use crate::math::Rect;
use crate::render::{ImageStore, Renderable};
@ -70,6 +70,22 @@ impl Renderable for Shape {
self.children.clone()
}
}
fn image_filter(&self, scale: f32) -> Option<skia::ImageFilter> {
if !self.blur.hidden {
match self.blur.blur_type {
BlurType::None => None,
BlurType::Layer => skia::image_filters::blur(
(self.blur.value * scale, self.blur.value * scale),
None,
None,
None,
),
}
} else {
None
}
}
}
fn render_fill(