Serialize solid fills as bytes (wasm)

This commit is contained in:
Belén Albeza 2025-04-29 16:20:45 +02:00
parent 81f18ad7f4
commit 093fa18839
7 changed files with 73 additions and 24 deletions

View file

@ -217,8 +217,12 @@
image (:fill-image fill)]
(cond
(some? color)
(let [rgba (sr-clr/hex->u32argb color opacity)]
(h/call wasm/internal-module "_add_shape_solid_fill" rgba))
(let [size sr-fills/SOLID-BYTE-SIZE
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_solid_fill"))
(some? gradient)
(let [size sr-fills/GRADIENT-BYTE-SIZE

View file

@ -2,6 +2,14 @@
(:require
[app.render-wasm.serializers.color :as clr]))
(def SOLID-BYTE-SIZE 4)
(defn write-solid-fill!
[offset heap-u32 argb]
(let [dview (js/DataView. (.-buffer heap-u32))]
(.setUint32 dview offset argb true)
(+ offset 4)))
(def ^:private GRADIENT-STOP-SIZE 8)
(def ^:private GRADIENT-BASE-SIZE 28)
;; TODO: Define in shape model
@ -11,8 +19,8 @@
(+ GRADIENT-BASE-SIZE (* MAX-GRADIENT-STOPS GRADIENT-STOP-SIZE)))
(defn write-gradient-fill!
[offset heap gradient opacity]
(let [dview (js/DataView. (.-buffer heap))
[offset heap-u32 gradient opacity]
(let [dview (js/DataView. (.-buffer heap-u32))
start-x (:start-x gradient)
start-y (:start-y gradient)
end-x (:end-x gradient)