Serialize stroke solid fills as bytes (wasm)

This commit is contained in:
Belén Albeza 2025-04-29 16:26:20 +02:00
parent 093fa18839
commit 5ae125db94
2 changed files with 11 additions and 5 deletions

View file

@ -297,8 +297,12 @@
(store-image id))) (store-image id)))
(some? color) (some? color)
(let [rgba (sr-clr/hex->u32argb color opacity)] (let [size sr-fills/SOLID-BYTE-SIZE
(h/call wasm/internal-module "_add_shape_stroke_solid_fill" rgba))))) offset (mem/alloc-bytes size)
heap (mem/get-heap-u32)
argb (sr-clr/hex->u32argb color opacity)]
(sr-fills/write-solid-fill! offset heap argb)
(h/call wasm/internal-module "_add_shape_stroke_solid_fill")))))
strokes)) strokes))
(defn set-shape-path-attrs (defn set-shape-path-attrs

View file

@ -34,11 +34,13 @@ pub extern "C" fn add_shape_outer_stroke(width: f32, style: u8, cap_start: u8, c
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn add_shape_stroke_solid_fill(raw_color: u32) { pub extern "C" fn add_shape_stroke_solid_fill() {
with_current_shape!(state, |shape: &mut Shape| { with_current_shape!(state, |shape: &mut Shape| {
let color = skia::Color::new(raw_color); let bytes = mem::bytes();
let solid_color =
shapes::SolidColor::try_from(&bytes[..]).expect("Invalid solid color data");
shape shape
.set_stroke_fill(shapes::Fill::Solid(shapes::SolidColor(color))) .set_stroke_fill(shapes::Fill::Solid(solid_color))
.expect("could not add stroke solid fill"); .expect("could not add stroke solid fill");
}); });
} }