mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
🐛 Fix problem with thumbnails in parallel
This commit is contained in:
@@ -60,10 +60,10 @@
|
||||
(defn render-thumbnail
|
||||
[file-id revn]
|
||||
(if (features/active-feature? @st/state "render-wasm/v1")
|
||||
(->> (mw/ask! {:cmd :thumbnails/generate-for-file-wasm
|
||||
(mw/ask! {:cmd :thumbnails/generate-for-file-wasm
|
||||
:revn revn
|
||||
:file-id file-id
|
||||
:width thumbnail-width}))
|
||||
:width thumbnail-width})
|
||||
(->> (mw/ask! {:cmd :thumbnails/generate-for-file
|
||||
:revn revn
|
||||
:file-id file-id
|
||||
|
||||
@@ -128,11 +128,12 @@
|
||||
|
||||
(defn update-text-rect!
|
||||
[id]
|
||||
(when wasm/context-initialized?
|
||||
(mw/emit!
|
||||
{:cmd :index/update-text-rect
|
||||
:page-id (:current-page-id @st/state)
|
||||
:shape-id id
|
||||
:dimensions (get-text-dimensions id)}))
|
||||
:dimensions (get-text-dimensions id)})))
|
||||
|
||||
|
||||
(defn- ensure-text-content
|
||||
@@ -198,6 +199,7 @@
|
||||
(defn set-shape-children
|
||||
[children]
|
||||
(perf/begin-measure "set-shape-children")
|
||||
(let [children (into [] (filter uuid?) children)]
|
||||
(case (count children)
|
||||
0
|
||||
(h/call wasm/internal-module "_set_children_0")
|
||||
@@ -261,7 +263,7 @@
|
||||
(mem.h32/write-uuid offset heap id))
|
||||
offset
|
||||
children)
|
||||
(h/call wasm/internal-module "_set_children")))
|
||||
(h/call wasm/internal-module "_set_children"))))
|
||||
(perf/end-measure "set-shape-children")
|
||||
nil)
|
||||
|
||||
@@ -1031,8 +1033,9 @@
|
||||
(into full-acc full)))
|
||||
{:thumbnails thumbnails-acc :full full-acc}))]
|
||||
(perf/end-measure "set-objects")
|
||||
(process-pending shapes thumbnails full render-callback
|
||||
(process-pending shapes thumbnails full noop-fn
|
||||
(fn []
|
||||
(when render-callback (render-callback))
|
||||
(ug/dispatch! (ug/event "penpot:wasm:set-objects")))))))
|
||||
|
||||
(defn clear-focus-mode
|
||||
|
||||
@@ -83,12 +83,13 @@
|
||||
|
||||
(defn update-text-layout
|
||||
[id]
|
||||
(when wasm/context-initialized?
|
||||
(let [shape-id-buffer (uuid/get-u32 id)]
|
||||
(h/call wasm/internal-module "_update_shape_text_layout_for"
|
||||
(aget shape-id-buffer 0)
|
||||
(aget shape-id-buffer 1)
|
||||
(aget shape-id-buffer 2)
|
||||
(aget shape-id-buffer 3))))
|
||||
(aget shape-id-buffer 3)))))
|
||||
|
||||
;; IMPORTANT: Only TTF fonts can be stored.
|
||||
(defn- store-font-buffer
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
[app.common.logging :as log]
|
||||
[app.common.types.color :as cc]
|
||||
[app.common.uri :as u]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cf]
|
||||
[app.main.fonts :as fonts]
|
||||
[app.main.render :as render]
|
||||
@@ -125,16 +126,27 @@
|
||||
|
||||
(def thumbnail-aspect-ratio (/ 2 3))
|
||||
|
||||
(defmethod impl/handler :thumbnails/generate-for-file-wasm
|
||||
[{:keys [file-id revn width] :as message} _]
|
||||
(defn render-canvas-blob
|
||||
[canvas width height background-color]
|
||||
(-> (.convertToBlob canvas)
|
||||
(p/then
|
||||
(fn [blob]
|
||||
(rds/renderToStaticMarkup
|
||||
(mf/element
|
||||
svg-wrapper
|
||||
#js {:data-uri (blob->uri blob)
|
||||
:width width
|
||||
:height height
|
||||
:background background-color}))))))
|
||||
|
||||
(defn process-wasm-thumbnail
|
||||
[{:keys [id file-id revn width] :as message}]
|
||||
(->> (rx/from @init-wasm)
|
||||
(rx/mapcat #(request-data-for-thumbnail file-id revn false))
|
||||
(rx/mapcat
|
||||
(fn [{:keys [page] :as file}]
|
||||
(rx/create
|
||||
(fn [subs]
|
||||
(try
|
||||
(let [background-color (or (:background page) cc/canvas)
|
||||
height (* width thumbnail-aspect-ratio)
|
||||
canvas (js/OffscreenCanvas. width height)
|
||||
@@ -155,28 +167,34 @@
|
||||
(wasm.api/render-sync-shape (:id frame))
|
||||
(wasm.api/render-sync))
|
||||
|
||||
(-> (.convertToBlob canvas)
|
||||
(p/then
|
||||
(fn [blob]
|
||||
(let [data
|
||||
(rds/renderToStaticMarkup
|
||||
(mf/element
|
||||
svg-wrapper
|
||||
#js {:data-uri (blob->uri blob)
|
||||
:width width
|
||||
:height height
|
||||
:background background-color}))]
|
||||
(rx/push! subs {:data data :file-id file-id :revn revn}))))
|
||||
(p/catch #(do (.error js/console %)
|
||||
(rx/error! subs %)))
|
||||
(-> (render-canvas-blob canvas width height background-color)
|
||||
(p/then #(rx/push! subs {:id id :data % :file-id file-id :revn revn}))
|
||||
(p/catch #(rx/error! subs %))
|
||||
(p/finally #(rx/end! subs))))))
|
||||
|
||||
(do (rx/error! subs "Error loading webgl context")
|
||||
(rx/end! subs)))
|
||||
(rx/end! subs))
|
||||
|
||||
nil)
|
||||
nil)))))))
|
||||
|
||||
(catch :default err
|
||||
(.error js/console err)
|
||||
(rx/error! subs err)
|
||||
(rx/end! subs)))))))))
|
||||
(defonce thumbs-subject (rx/subject))
|
||||
|
||||
(defonce thumbs-stream
|
||||
(->> thumbs-subject
|
||||
(rx/mapcat process-wasm-thumbnail)
|
||||
(rx/share)))
|
||||
|
||||
(defmethod impl/handler :thumbnails/generate-for-file-wasm
|
||||
[message _]
|
||||
(rx/create
|
||||
(fn [subs]
|
||||
(let [id (uuid/next)
|
||||
sid
|
||||
(->> thumbs-stream
|
||||
(rx/filter #(= id (:id %)))
|
||||
(rx/subs!
|
||||
#(do
|
||||
(rx/push! subs %)
|
||||
(rx/end! subs))))]
|
||||
(rx/push! thumbs-subject (assoc message :id id))
|
||||
|
||||
#(rx/dispose! sid)))))
|
||||
|
||||
@@ -291,9 +291,10 @@ pub extern "C" fn set_shape_text_content() {
|
||||
let bytes = mem::bytes();
|
||||
with_current_shape_mut!(state, |shape: &mut Shape| {
|
||||
let raw_text_data = RawParagraph::try_from(&bytes).unwrap();
|
||||
shape
|
||||
.add_paragraph(raw_text_data.into())
|
||||
.expect("Failed to add paragraph");
|
||||
|
||||
if let Err(_) = shape.add_paragraph(raw_text_data.into()) {
|
||||
println!("Error with set_shape_text_content on {:?}", shape.id);
|
||||
}
|
||||
});
|
||||
mem::free_bytes();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user