mirror of
https://github.com/penpot/penpot.git
synced 2025-06-21 19:16:59 +02:00
✨ Only take N amount of fills
This commit is contained in:
parent
be13704934
commit
e4a1c373bb
3 changed files with 41 additions and 28 deletions
|
@ -762,4 +762,7 @@
|
|||
(cond-> (cfh/text-shape? shape) (patch-text-props props))
|
||||
(cond-> (cfh/frame-shape? shape) (patch-layout-props props)))))
|
||||
|
||||
(def MAX-GRADIENT-STOPS 16)
|
||||
;; FIXME: Get these from the wasm module, and tweak the values
|
||||
;; (we'd probably want 12 stops at most)
|
||||
(def MAX-GRADIENT-STOPS 16)
|
||||
(def MAX-FILLS 8)
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.types.path :as path]
|
||||
[app.common.types.shape :as shp]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cf]
|
||||
|
@ -241,33 +242,24 @@
|
|||
[fills]
|
||||
(h/call wasm/internal-module "_clear_shape_fills")
|
||||
(keep (fn [fill]
|
||||
(let [opacity (or (:fill-opacity fill) 1.0)
|
||||
color (:fill-color fill)
|
||||
gradient (:fill-color-gradient fill)
|
||||
image (:fill-image fill)
|
||||
offset (mem/alloc-bytes sr-fills/FILL-BYTE-SIZE)
|
||||
(let [offset (mem/alloc-bytes sr-fills/FILL-BYTE-SIZE)
|
||||
heap (mem/get-heap-u8)
|
||||
dview (js/DataView. (.-buffer heap))]
|
||||
(cond
|
||||
(some? color)
|
||||
(do
|
||||
(sr-fills/write-solid-fill! offset dview (sr-clr/hex->u32argb color opacity))
|
||||
(h/call wasm/internal-module "_add_shape_fill"))
|
||||
|
||||
(some? gradient)
|
||||
(do
|
||||
(sr-fills/write-gradient-fill! offset dview gradient opacity)
|
||||
(h/call wasm/internal-module "_add_shape_fill"))
|
||||
|
||||
(some? image)
|
||||
(let [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))]
|
||||
(sr-fills/write-image-fill! offset dview id opacity (dm/get-prop image :width) (dm/get-prop image :height))
|
||||
(h/call wasm/internal-module "_add_shape_fill")
|
||||
(when (== cached-image? 0)
|
||||
dview (js/DataView. (.-buffer heap))
|
||||
image (:fill-image fill)]
|
||||
(sr-fills/write-fill! offset dview fill)
|
||||
(h/call wasm/internal-module "_add_shape_fill")
|
||||
;; store image for image fills if not cached
|
||||
(when (some? image)
|
||||
(let [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))))))
|
||||
fills))
|
||||
(take shp/MAX-FILLS fills)))
|
||||
|
||||
(defn set-shape-strokes
|
||||
[strokes]
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
(ns app.render-wasm.serializers.fills
|
||||
(:require
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.types.shape :as shp]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.render-wasm.serializers.color :as clr]))
|
||||
|
||||
(def ^:private GRADIENT-STOP-SIZE 8)
|
||||
|
||||
|
||||
(def GRADIENT-BYTE-SIZE 156)
|
||||
(def SOLID-BYTE-SIZE 4)
|
||||
(def IMAGE-BYTE-SIZE 28)
|
||||
|
@ -14,6 +14,7 @@
|
|||
;; FIXME: get it from the wasm module
|
||||
(def FILL-BYTE-SIZE (+ 4 (max GRADIENT-BYTE-SIZE IMAGE-BYTE-SIZE SOLID-BYTE-SIZE)))
|
||||
|
||||
|
||||
(defn write-solid-fill!
|
||||
[offset dview argb]
|
||||
(.setUint8 dview offset 0x00 true)
|
||||
|
@ -60,4 +61,21 @@
|
|||
stop-offset (:offset stop)]
|
||||
(.setUint32 dview loop-offset argb true)
|
||||
(.setFloat32 dview (+ loop-offset 4) stop-offset true)
|
||||
(recur (rest stops) (+ loop-offset GRADIENT-STOP-SIZE)))))))
|
||||
(recur (rest stops) (+ loop-offset GRADIENT-STOP-SIZE)))))))
|
||||
|
||||
(defn write-fill!
|
||||
[offset dview fill]
|
||||
(let [opacity (or (:fill-opacity fill) 1.0)
|
||||
color (:fill-color fill)
|
||||
gradient (:fill-color-gradient fill)
|
||||
image (:fill-image fill)]
|
||||
(cond
|
||||
(some? color)
|
||||
(write-solid-fill! offset dview (clr/hex->u32argb color opacity))
|
||||
|
||||
(some? gradient)
|
||||
(write-gradient-fill! offset dview gradient opacity)
|
||||
|
||||
(some? image)
|
||||
(let [id (dm/get-prop image :id)]
|
||||
(write-image-fill! offset dview id opacity (dm/get-prop image :width) (dm/get-prop image :height))))))
|
Loading…
Add table
Add a link
Reference in a new issue