mirror of
https://github.com/penpot/penpot.git
synced 2025-05-24 16:16:13 +02:00
✨ Render with dpr
This commit is contained in:
parent
5ce6cbff6f
commit
db9c93f3bf
6 changed files with 115 additions and 92 deletions
|
@ -270,7 +270,6 @@
|
|||
offset-y (if selecting-first-level-frame?
|
||||
(:y first-shape)
|
||||
(:y selected-frame))
|
||||
|
||||
rule-area-size (/ rulers/ruler-area-size zoom)
|
||||
preview-blend (-> refs/workspace-preview-blend
|
||||
(mf/deref))]
|
||||
|
@ -291,7 +290,7 @@
|
|||
|
||||
(mf/with-effect [vport]
|
||||
(when @canvas-init?
|
||||
(wasm.api/resize-canvas (:width vport) (:height vport))))
|
||||
(wasm.api/resize-viewbox (:width vport) (:height vport))))
|
||||
|
||||
(mf/with-effect [base-objects canvas-init?]
|
||||
(when @canvas-init?
|
||||
|
@ -351,8 +350,8 @@
|
|||
:ref canvas-ref
|
||||
:class (stl/css :render-shapes)
|
||||
:key (dm/str "render" page-id)
|
||||
:width (:width vport 0)
|
||||
:height (:height vport 0)
|
||||
:width (* wasm.api/dpr (:width vport 0))
|
||||
:height (* wasm.api/dpr (:height vport 0))
|
||||
:style {:background-color background
|
||||
:pointer-events "none"}}]
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
(defonce internal-module #js {})
|
||||
(defonce use-dpr? (contains? cf/flags :render-wasm-dpr))
|
||||
|
||||
(def dpr
|
||||
(if use-dpr? js/window.devicePixelRatio 1.0))
|
||||
|
||||
;; This should never be called from the outside.
|
||||
;; This function receives a "time" parameter that we're not using but maybe in the future could be useful (it is the time since
|
||||
;; the window started rendering elements so it could be useful to measure time between frames).
|
||||
|
@ -170,31 +173,31 @@
|
|||
:stencil true
|
||||
:alpha true})
|
||||
|
||||
|
||||
(defn clear-canvas
|
||||
[]
|
||||
;; TODO: perform corresponding cleaning
|
||||
)
|
||||
|
||||
(defn resize-canvas
|
||||
(defn resize-viewbox
|
||||
[width height]
|
||||
(h/call internal-module "_resize_canvas" width height))
|
||||
(h/call internal-module "_resize_viewbox" width height))
|
||||
|
||||
(defn assign-canvas
|
||||
[canvas]
|
||||
(let [gl (unchecked-get internal-module "GL")
|
||||
context (.getContext ^js canvas "webgl2" canvas-options)
|
||||
dpr (when use-dpr? js/window.devicePixelRatio)
|
||||
|
||||
;; Register the context with emscripten
|
||||
handle (.registerContext ^js gl context #js {"majorVersion" 2})]
|
||||
(.makeContextCurrent ^js gl handle)
|
||||
|
||||
;; Initialize Wasm Render Engine
|
||||
(h/call internal-module "_init" (.-width ^js canvas) (.-height ^js canvas))
|
||||
(h/call internal-module "_set_render_options" 0x01 (or dpr 0))
|
||||
(h/call internal-module "_init" (/ (.-width ^js canvas) dpr) (/ (.-height ^js canvas) dpr))
|
||||
(h/call internal-module "_set_render_options" 0x01 dpr))
|
||||
|
||||
(set! (.-width canvas) (.-clientWidth ^js canvas))
|
||||
(set! (.-height canvas) (.-clientHeight ^js canvas))))
|
||||
(set! (.-width canvas) (* dpr (.-clientWidth ^js canvas)))
|
||||
(set! (.-height canvas) (* dpr (.-clientHeight ^js canvas))))
|
||||
|
||||
(defonce module
|
||||
(if (exists? js/dynamicImport)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue