mirror of
https://github.com/penpot/penpot.git
synced 2025-06-20 19:37:30 +02:00
Merge pull request #6623 from penpot/ladybenko-11106-send-all-fills
✨ Send all fills of a shape in a single wasm call
This commit is contained in:
commit
bbac5d050e
3 changed files with 43 additions and 20 deletions
|
@ -240,26 +240,36 @@
|
||||||
|
|
||||||
(defn set-shape-fills
|
(defn set-shape-fills
|
||||||
[fills]
|
[fills]
|
||||||
(h/call wasm/internal-module "_clear_shape_fills")
|
(let [fills (take shp/MAX-FILLS fills)
|
||||||
(keep (fn [fill]
|
image-fills (filter :fill-image fills)
|
||||||
(let [offset (mem/alloc-bytes sr-fills/FILL-BYTE-SIZE)
|
offset (mem/alloc-bytes (* (count fills) sr-fills/FILL-BYTE-SIZE))
|
||||||
heap (mem/get-heap-u8)
|
heap (mem/get-heap-u8)
|
||||||
dview (js/DataView. (.-buffer heap))
|
dview (js/DataView. (.-buffer heap))]
|
||||||
image (:fill-image fill)]
|
|
||||||
(sr-fills/write-fill! offset dview fill)
|
;; write fill data to heap
|
||||||
(h/call wasm/internal-module "_add_shape_fill")
|
(loop [fills (seq fills)
|
||||||
;; store image for image fills if not cached
|
current-offset 0]
|
||||||
(when (some? image)
|
(when-not (empty? fills)
|
||||||
(let [id (dm/get-prop image :id)
|
(let [fill (first fills)]
|
||||||
buffer (uuid/get-u32 id)
|
(sr-fills/write-fill! offset dview fill)
|
||||||
cached-image? (h/call wasm/internal-module "_is_image_cached"
|
(recur (rest fills) (+ current-offset sr-fills/FILL-BYTE-SIZE)))))
|
||||||
(aget buffer 0)
|
|
||||||
(aget buffer 1)
|
;; send fills to wasm
|
||||||
(aget buffer 2)
|
(h/call wasm/internal-module "_set_shape_fills")
|
||||||
(aget buffer 3))]
|
|
||||||
(when (zero? cached-image?)
|
;; load images for image fills if not cached
|
||||||
(store-image id))))))
|
(keep (fn [fill]
|
||||||
(take shp/MAX-FILLS fills)))
|
(let [image (:fill-image fill)
|
||||||
|
id (dm/get-prop image :id)
|
||||||
|
buffer (uuid/get-u32 id)
|
||||||
|
cached-image? (h/call wasm/internal-module "_is_image_cached"
|
||||||
|
(aget buffer 0)
|
||||||
|
(aget buffer 1)
|
||||||
|
(aget buffer 2)
|
||||||
|
(aget buffer 3))]
|
||||||
|
(when (zero? cached-image?)
|
||||||
|
(store-image id))))
|
||||||
|
image-fills)))
|
||||||
|
|
||||||
(defn set-shape-strokes
|
(defn set-shape-strokes
|
||||||
[strokes]
|
[strokes]
|
||||||
|
|
|
@ -495,6 +495,10 @@ impl Shape {
|
||||||
self.fills.iter()
|
self.fills.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_fills(&mut self, fills: Vec<Fill>) {
|
||||||
|
self.fills = fills;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_fill(&mut self, f: Fill) {
|
pub fn add_fill(&mut self, f: Fill) {
|
||||||
self.fills.push(f);
|
self.fills.push(f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,15 @@ pub fn parse_fills_from_bytes(buffer: &[u8], num_fills: usize) -> Vec<shapes::Fi
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn set_shape_fills() {
|
||||||
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
|
let bytes = mem::bytes();
|
||||||
|
let fills = parse_fills_from_bytes(&bytes, bytes.len() / RAW_FILL_DATA_SIZE);
|
||||||
|
shape.set_fills(fills);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn add_shape_fill() {
|
pub extern "C" fn add_shape_fill() {
|
||||||
with_current_shape!(state, |shape: &mut Shape| {
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue