Merge pull request #5371 from penpot/ladybenko-9337-pixel-ratio

Device pixel ratio
This commit is contained in:
Aitor Moreno 2024-11-28 11:46:41 +01:00 committed by GitHub
commit 9a9815ebfa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 208 additions and 138 deletions

View file

@ -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"}}]

View file

@ -16,6 +16,10 @@
(defonce internal-frame-id nil)
(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
@ -169,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")
init-fn (unchecked-get internal-module "_init")
context (.getContext ^js canvas "webgl2" canvas-options)
;; Register the context with emscripten
handle (.registerContext ^js gl context #js {"majorVersion" 2})]
(.makeContextCurrent ^js gl handle)
;; Initialize Skia
(^function init-fn (.-width ^js canvas)
(.-height ^js canvas)
1)
(set! (.-width canvas) (.-clientWidth ^js canvas))
(set! (.-height canvas) (.-clientHeight ^js canvas))))
;; Initialize Wasm Render Engine
(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) (* dpr (.-clientWidth ^js canvas)))
(set! (.-height canvas) (* dpr (.-clientHeight ^js canvas))))
(defonce module
(if (exists? js/dynamicImport)