Experiment further

This commit is contained in:
Dennis Kobert 2023-05-12 18:07:05 +02:00 committed by Keavon Chambers
parent 685ccb3822
commit 42d45ed0d9
6 changed files with 15087 additions and 603 deletions

15646
frontend/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -32,9 +32,9 @@
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
"@parcel/config-default": "^2.8.3",
"@parcel/transformer-inline-string": "^2.8.3",
"@parcel/transformer-webmanifest": "^2.8.3",
"@parcel/config-default": "=2.7.0",
"@parcel/transformer-inline-string": "=2.7.0",
"@parcel/transformer-webmanifest": "=2.7.0",
"@types/license-checker-webpack-plugin": "^0.2.1",
"@types/node": "^18.16.2",
"@types/webpack": "^5.28.1",
@ -42,7 +42,7 @@
"concurrently": "^8.0.1",
"license-checker-webpack-plugin": "^0.2.1",
"parcel-transformer-svelte3-plus": "^0.2.9",
"parcel": "^2.8.3",
"parcel": "=2.7.0",
"postcss": "^8.4.23",
"process": "^0.11.10",
"sass": "^1.62.1",

View file

@ -1,7 +1,9 @@
import wasm_bindgen from '../../wasm/pkg/graphite_wasm.js'
import "reflect-metadata";
"use strict";
//import "reflect-metadata";
//import wasm_bindgen from '../../wasm/pkg/graphite_wasm.js'
//importScripts('./pkg/graphite_wasm.js')
const { child_entry_point } = wasm_bindgen;
//const { child_entry_point } = wasm_bindgen;
self.onmessage = async event => {
// We expect a message with three elements [module, memory, ptr], where:
@ -15,18 +17,26 @@ self.onmessage = async event => {
// or a module object); the second is the memory block to use, and if you
// don't provide one (like we didn't in "index.js") then a new one will be
// allocated for you.
console.log('worker.js: onmessage', event.data);
debugger;
const url = new URL('../../wasm/pkg/graphite_wasm_bg.wasm', import.meta.url);
let init = await wasm_bindgen(url, event.data[1]).catch(err => {
/*
const bindgen_url = new URL('../../wasm/pkg/graphite_wasm.js', import.meta.url);
let wasm_bindgen = importScripts(bindgen_url);
console.log('worker.js: onmessage', event.data);
*/
let wasm_bindgen = await import('../../wasm/pkg/graphite_wasm.js').catch(err => { });;
// const url = new URL('./pkg/graphite_wasm_bg.wasm', import.meta.url);
let init = await wasm_bindgen('/pkg/graphite_wasm_bg.wasm', event.data[1]).catch(err => {
// Propagate to main `onerror`:
setTimeout(() => {
throw err;
});
// Rethrow to keep promise rejected and prevent execution of further commands:
throw err;
// "tauri:build-wasm": "wasm-pack build ./wasm --release --target=web -- --features tauri",
});
/*
child_entry_point(event.data[2]);
// Clean up thread resources. Depending on what you're doing with the thread, this might
@ -38,5 +48,6 @@ self.onmessage = async event => {
// Free memory (stack, thread-locals) held (in the wasm linear memory) by the thread.
init.__wbindgen_thread_destroy();
// Tell the browser to stop the thread.
*/
close();
};

View file

@ -14,6 +14,7 @@ license = "Apache-2.0"
tauri = ["ron"]
gpu = ["editor/gpu"]
default = []
no-modules = []
[lib]
crate-type = ["cdylib", "rlib"]

View file

@ -9,7 +9,10 @@ extern "C" {
pub static PERFORMANCE: web_sys::Performance;
}
#[wasm_bindgen(module = "/../src/wasm-communication/editor.ts")]
//#[wasm_bindgen(module = "/../src/wasm-communication/editor.ts")]
//#[wasm_bindgen]
#[cfg_attr(feature = "no-modules", wasm_bindgen)]
#[cfg_attr(not(feature = "no-modules"), wasm_bindgen(module = "/../src/wasm-communication/editor.ts"))]
extern "C" {
fn spawnWorker() -> web_sys::Worker;
}
@ -55,7 +58,7 @@ pub fn spawn(f: impl FnOnce() + Send + 'static) -> Result<web_sys::Worker, JsVal
// Double-boxing because `dyn FnOnce` is unsized and so `Box<dyn FnOnce()>` has
// an undefined layout (although I think in practice its a pointer and a length?).
let ptr = Box::into_raw(Box::new(Box::new(f) as Box<dyn FnOnce()>));
let w = spawnWorker();
let w = unsafe { spawnWorker() };
// See `worker.js` for the format of this message.
let msg: js_sys::Array = [&wasm_bindgen::module(), &wasm_bindgen::memory().as_ref(), &JsValue::from(ptr as u32)].into_iter().collect();

View file

@ -31,7 +31,8 @@ pub fn set_random_seed(seed: u64) {
/// We directly interface with the updateImage JS function for massively increased performance over serializing and deserializing.
/// This avoids creating a json with a list millions of numbers long.
#[wasm_bindgen(module = "/../src/wasm-communication/editor.ts")]
#[cfg_attr(feature = "no-modules", wasm_bindgen)]
#[cfg_attr(not(feature = "no-modules"), wasm_bindgen(module = "/../src/wasm-communication/editor.ts"))]
extern "C" {
fn updateImage(path: Vec<u64>, mime: String, imageData: &[u8], transform: js_sys::Float64Array, document_id: u64);
fn fetchImage(path: Vec<u64>, mime: String, document_id: u64, identifier: String);
@ -167,7 +168,7 @@ impl JsEditorHandle {
} else {
js_sys::Float64Array::default()
};
updateImage(image.path, image.mime, &image.image_data, transform, document_id);
unsafe { updateImage(image.path, image.mime, &image.image_data, transform, document_id) };
}
#[cfg(feature = "tauri")]
fetchImage(image.path.clone(), image.mime, document_id, format!("http://localhost:3001/image/{:?}_{}", &image.path, document_id));