🎉 Serialize radial fills in one go

This commit is contained in:
Belén Albeza 2025-04-15 11:53:09 +02:00
parent 5765d1c56c
commit dc3d802d3d
4 changed files with 65 additions and 33 deletions

View file

@ -242,24 +242,11 @@
(sr-fills/serialize-linear-fill gradient opacity heap offset)
(h/call wasm/internal-module "_add_shape_linear_fill"))
:radial
(let [stops (:stops gradient)
size (gradient-stop-get-entries-size stops)
(let [size (gradient-byte-size gradient)
offset (mem/alloc-bytes size)
heap (mem/get-heap-u8)
mem (js/Uint8Array. (.-buffer heap) offset size)]
(h/call wasm/internal-module "_add_shape_radial_fill"
(:start-x gradient)
(:start-y gradient)
(:end-x gradient)
(:end-y gradient)
opacity
(:width gradient))
(.set mem (js/Uint8Array. (clj->js (flatten (map (fn [stop]
(let [[r g b a] (sr-clr/rgba-bytes-from-hex (:color stop) (:opacity stop))
offset (:offset stop)]
[r g b a (* 100 offset)]))
stops)))))
(h/call wasm/internal-module "_add_shape_fill_stops")))
heap (mem/get-heap-u32)]
(sr-fills/serialize-radial-fill gradient opacity heap offset)
(h/call wasm/internal-module "_add_shape_radial_fill")))
(some? image)
(let [id (dm/get-prop image :id)
@ -301,13 +288,15 @@
size (gradient-stop-get-entries-size stops)
offset (mem/alloc-bytes size)
heap (mem/get-heap-u8)]
(if (= (:type gradient) :linear)
(case (:type gradient)
:linear
(h/call wasm/internal-module "_add_shape_stroke_linear_fill"
(:start-x gradient)
(:start-y gradient)
(:end-x gradient)
(:end-y gradient)
opacity)
:radial
(h/call wasm/internal-module "_add_shape_stroke_radial_fill"
(:start-x gradient)
(:start-y gradient)

View file

@ -35,4 +35,21 @@
(.setFloat32 dview (+ offset 12) end-y true)
(.setFloat32 dview (+ offset 16) opacity true)
(.setFloat32 dview (+ offset 20) width true)
(serialize-gradient-stops stops heap (+ offset GRADIENT-BASE-SIZE))))
(defn serialize-radial-fill
[gradient opacity heap offset]
(let [dview (js/DataView. (.-buffer heap))
start-x (dm/get-prop gradient :start-x)
start-y (dm/get-prop gradient :start-y)
end-x (dm/get-prop gradient :end-x)
end-y (dm/get-prop gradient :end-y)
stops (dm/get-prop gradient :stops)
width (dm/get-prop gradient :width)]
(.setFloat32 dview offset start-x true)
(.setFloat32 dview (+ offset 4) start-y true)
(.setFloat32 dview (+ offset 8) end-x true)
(.setFloat32 dview (+ offset 12) end-y true)
(.setFloat32 dview (+ offset 16) opacity true)
(.setFloat32 dview (+ offset 20) width true)
(serialize-gradient-stops stops heap (+ offset GRADIENT-BASE-SIZE))))