mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 19:06:18 +00:00
🎉 Support for debugging cache texture
This commit is contained in:
parent
434e27bbe8
commit
5eebc17ce2
@ -31,6 +31,9 @@
|
|||||||
[app.main.errors :as errors]
|
[app.main.errors :as errors]
|
||||||
[app.main.repo :as rp]
|
[app.main.repo :as rp]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
[app.render-wasm.helpers :as wasm.h]
|
||||||
|
[app.render-wasm.mem :as wasm.mem]
|
||||||
|
[app.render-wasm.wasm :as wasm]
|
||||||
[app.util.debug :as dbg]
|
[app.util.debug :as dbg]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.http :as http]
|
[app.util.http :as http]
|
||||||
@ -117,6 +120,43 @@
|
|||||||
(js/console.log str (json/->js val))
|
(js/console.log str (json/->js val))
|
||||||
val))
|
val))
|
||||||
|
|
||||||
|
(defn- wasm-read-len-prefixed-utf8
|
||||||
|
"Reads a `[u32 byte_len][utf8 bytes...]` buffer returned by WASM and frees it.
|
||||||
|
Returns a JS string (possibly empty)."
|
||||||
|
[ptr]
|
||||||
|
(when (and ptr (not (zero? ptr)))
|
||||||
|
(let [heap-u8 (wasm.mem/get-heap-u8)
|
||||||
|
heap-u32 (wasm.mem/get-heap-u32)
|
||||||
|
len (aget heap-u32 (wasm.mem/->offset-32 ptr))
|
||||||
|
start (+ ptr 4)
|
||||||
|
end (+ start len)
|
||||||
|
decoder (js/TextDecoder. "utf-8")
|
||||||
|
text (.decode decoder (.subarray heap-u8 start end))]
|
||||||
|
(wasm.mem/free)
|
||||||
|
text)))
|
||||||
|
|
||||||
|
(defn ^:export wasmCacheConsole
|
||||||
|
"Logs the current render-wasm cache surface as an image in the JS console."
|
||||||
|
[]
|
||||||
|
(let [module wasm/internal-module
|
||||||
|
f (when module (unchecked-get module "_debug_cache_console"))]
|
||||||
|
(if (fn? f)
|
||||||
|
(wasm.h/call module "_debug_cache_console")
|
||||||
|
(js/console.warn "[debug] render-wasm module not ready or missing _debug_cache_console"))))
|
||||||
|
|
||||||
|
(defn ^:export wasmCacheBase64
|
||||||
|
"Returns the cache surface PNG base64 (empty string if missing/empty)."
|
||||||
|
[]
|
||||||
|
(let [module wasm/internal-module
|
||||||
|
f (when module (unchecked-get module "_debug_cache_base64"))]
|
||||||
|
(if (fn? f)
|
||||||
|
(let [ptr (wasm.h/call module "_debug_cache_base64")
|
||||||
|
s (or (wasm-read-len-prefixed-utf8 ptr) "")]
|
||||||
|
s)
|
||||||
|
(do
|
||||||
|
(js/console.warn "[debug] render-wasm module not ready or missing _debug_cache_base64")
|
||||||
|
""))))
|
||||||
|
|
||||||
(when (exists? js/window)
|
(when (exists? js/window)
|
||||||
(set! (.-dbg ^js js/window) json/->js)
|
(set! (.-dbg ^js js/window) json/->js)
|
||||||
(set! (.-pp ^js js/window) pprint))
|
(set! (.-pp ^js js/window) pprint))
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
use super::{tiles, RenderState, SurfaceId};
|
use super::{tiles, RenderState, SurfaceId};
|
||||||
|
use crate::with_state_mut;
|
||||||
|
use crate::STATE;
|
||||||
|
use macros::wasm_error;
|
||||||
use skia_safe::{self as skia, Rect};
|
use skia_safe::{self as skia, Rect};
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
@ -210,3 +213,13 @@ pub fn console_debug_surface_rect(render_state: &mut RenderState, id: SurfaceId,
|
|||||||
run_script!(format!("console.log('%c ', 'font-size: 1px; background: url(data:image/png;base64,{base64_image}) no-repeat; padding: 100px; background-size: contain;')"))
|
run_script!(format!("console.log('%c ', 'font-size: 1px; background: url(data:image/png;base64,{base64_image}) no-repeat; padding: 100px; background-size: contain;')"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
#[wasm_error]
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
pub extern "C" fn debug_cache_console() -> Result<()> {
|
||||||
|
with_state_mut!(state, {
|
||||||
|
console_debug_surface(state.render_state_mut(), SurfaceId::Cache);
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user