Compare commits
2 Commits
109af8793b
...
03e596b219
Author | SHA1 | Date |
---|---|---|
mars | 03e596b219 | |
mars | b9416b922f |
|
@ -20,6 +20,7 @@ allsorts = "0.10"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
bytemuck = "1"
|
bytemuck = "1"
|
||||||
canary-script = { path = "crates/script" }
|
canary-script = { path = "crates/script" }
|
||||||
|
log = "0.4"
|
||||||
lyon = "1"
|
lyon = "1"
|
||||||
ouroboros = "^0.15"
|
ouroboros = "^0.15"
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
|
|
|
@ -13,8 +13,10 @@ required-features = ["service"]
|
||||||
anyhow = { version = "1", optional = true }
|
anyhow = { version = "1", optional = true }
|
||||||
byteorder = "1.4"
|
byteorder = "1.4"
|
||||||
canary = { path = "../..", optional = true }
|
canary = { path = "../..", optional = true }
|
||||||
|
env_logger = { version = "0.10", optional = true }
|
||||||
futures-util = { version = "0.3", optional = true, features = ["io"] }
|
futures-util = { version = "0.3", optional = true, features = ["io"] }
|
||||||
glium = { version = "0.32", optional = true}
|
glium = { version = "0.32", optional = true}
|
||||||
|
log = "0.4"
|
||||||
mio = { version = "0.8", features = ["net", "os-poll"], optional = true }
|
mio = { version = "0.8", features = ["net", "os-poll"], optional = true }
|
||||||
mio-signals = { version = "0.2", optional = true }
|
mio-signals = { version = "0.2", optional = true }
|
||||||
parking_lot = { version = "0.12", optional = true}
|
parking_lot = { version = "0.12", optional = true}
|
||||||
|
@ -24,4 +26,4 @@ slab = { version = "0.4", optional = true}
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
async = ["dep:futures-util"]
|
async = ["dep:futures-util"]
|
||||||
service = ["dep:anyhow", "dep:canary", "dep:glium", "dep:mio", "dep:mio-signals", "dep:parking_lot", "dep:slab"]
|
service = ["dep:anyhow", "dep:canary", "dep:env_logger", "dep:glium", "dep:mio", "dep:mio-signals", "dep:parking_lot", "dep:slab"]
|
||||||
|
|
|
@ -8,6 +8,7 @@ use ipc::Ipc;
|
||||||
use window::{WindowMessage, WindowStore};
|
use window::{WindowMessage, WindowStore};
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
|
env_logger::init();
|
||||||
let event_loop = EventLoopBuilder::<WindowMessage>::with_user_event().build();
|
let event_loop = EventLoopBuilder::<WindowMessage>::with_user_event().build();
|
||||||
let window_sender = event_loop.create_proxy();
|
let window_sender = event_loop.create_proxy();
|
||||||
let (ipc, ipc_sender) = Ipc::new(window_sender)?;
|
let (ipc, ipc_sender) = Ipc::new(window_sender)?;
|
||||||
|
|
|
@ -19,11 +19,13 @@ pub mod wasmtime;
|
||||||
/// Currently, only ever creates [wasmtime::WasmtimeBackend].
|
/// Currently, only ever creates [wasmtime::WasmtimeBackend].
|
||||||
pub fn make_default_backend() -> anyhow::Result<Box<dyn Backend>> {
|
pub fn make_default_backend() -> anyhow::Result<Box<dyn Backend>> {
|
||||||
let backend = wasmtime::WasmtimeBackend::new()?;
|
let backend = wasmtime::WasmtimeBackend::new()?;
|
||||||
|
log::info!("Created default ({}) backend", backend.name());
|
||||||
Ok(Box::new(backend))
|
Ok(Box::new(backend))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A WebAssembly runtime backend.
|
/// A WebAssembly runtime backend.
|
||||||
pub trait Backend {
|
pub trait Backend {
|
||||||
|
fn name(&self) -> &'static str;
|
||||||
fn load_module(&self, abi: Arc<ScriptAbi>, module: &[u8]) -> anyhow::Result<Arc<dyn Instance>>;
|
fn load_module(&self, abi: Arc<ScriptAbi>, module: &[u8]) -> anyhow::Result<Arc<dyn Instance>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
use std::collections::{hash_map::DefaultHasher, HashMap};
|
use std::collections::{hash_map::DefaultHasher, HashMap};
|
||||||
use std::hash::Hasher;
|
use std::hash::Hasher;
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
use super::{Arc, Backend, Instance, PanelId, ScriptAbi};
|
use super::{Arc, Backend, Instance, PanelId, ScriptAbi};
|
||||||
use crate::DrawCommand;
|
use crate::DrawCommand;
|
||||||
|
@ -24,6 +25,8 @@ pub struct WasmtimeBackend {
|
||||||
|
|
||||||
impl WasmtimeBackend {
|
impl WasmtimeBackend {
|
||||||
pub fn new() -> anyhow::Result<Self> {
|
pub fn new() -> anyhow::Result<Self> {
|
||||||
|
log::info!("Creating wasmtime backend");
|
||||||
|
|
||||||
let mut config = wasmtime::Config::new();
|
let mut config = wasmtime::Config::new();
|
||||||
config.wasm_simd(true);
|
config.wasm_simd(true);
|
||||||
config.wasm_bulk_memory(true);
|
config.wasm_bulk_memory(true);
|
||||||
|
@ -40,20 +43,33 @@ impl WasmtimeBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Backend for WasmtimeBackend {
|
impl Backend for WasmtimeBackend {
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"wasmtime"
|
||||||
|
}
|
||||||
|
|
||||||
fn load_module(&self, abi: Arc<ScriptAbi>, module: &[u8]) -> anyhow::Result<Arc<dyn Instance>> {
|
fn load_module(&self, abi: Arc<ScriptAbi>, module: &[u8]) -> anyhow::Result<Arc<dyn Instance>> {
|
||||||
|
let start = Instant::now();
|
||||||
|
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
hasher.write(module);
|
hasher.write(module);
|
||||||
let hashed = hasher.finish();
|
let hashed = hasher.finish();
|
||||||
|
let fmt_hash = format!("{:x}", hashed);
|
||||||
|
|
||||||
|
log::debug!("Loading module (hash: {})", fmt_hash);
|
||||||
|
|
||||||
let prehasher = DefaultPrehasher::new();
|
let prehasher = DefaultPrehasher::new();
|
||||||
let prehashed = prehasher.prehash(hashed);
|
let prehashed = prehasher.prehash(hashed);
|
||||||
let mut cache = self.module_cache.lock();
|
let mut cache = self.module_cache.lock();
|
||||||
|
|
||||||
let module = if let Some(module) = cache.get(&prehashed) {
|
let module = if let Some(module) = cache.get(&prehashed) {
|
||||||
|
log::debug!("Module load cache hit (hash: {})", fmt_hash);
|
||||||
module
|
module
|
||||||
} else {
|
} else {
|
||||||
|
log::debug!("Module load cache miss; building (hash: {})", fmt_hash);
|
||||||
|
let start = Instant::now();
|
||||||
let module = wasmtime::Module::new(&self.engine, module)?;
|
let module = wasmtime::Module::new(&self.engine, module)?;
|
||||||
cache.insert(prehashed, module);
|
cache.insert(prehashed, module);
|
||||||
|
log::debug!("Built module in {:?} (hash: {})", start.elapsed(), fmt_hash);
|
||||||
cache.get(&prehashed).unwrap()
|
cache.get(&prehashed).unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -80,6 +96,12 @@ impl Backend for WasmtimeBackend {
|
||||||
|
|
||||||
let instance = Arc::new(instance);
|
let instance = Arc::new(instance);
|
||||||
|
|
||||||
|
log::debug!(
|
||||||
|
"Loaded module in {:?} (hash: {})",
|
||||||
|
start.elapsed(),
|
||||||
|
fmt_hash
|
||||||
|
);
|
||||||
|
|
||||||
Ok(instance)
|
Ok(instance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ pub struct Runtime {
|
||||||
|
|
||||||
impl Runtime {
|
impl Runtime {
|
||||||
pub fn new(backend: Box<dyn Backend>) -> anyhow::Result<Self> {
|
pub fn new(backend: Box<dyn Backend>) -> anyhow::Result<Self> {
|
||||||
|
log::info!("Initializing runtime with {} backend", backend.name());
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
backend,
|
backend,
|
||||||
font_store: Arc::new(FontStore::new()),
|
font_store: Arc::new(FontStore::new()),
|
||||||
|
|
|
@ -220,6 +220,7 @@ impl Default for FontStore {
|
||||||
|
|
||||||
impl FontStore {
|
impl FontStore {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
log::info!("Initializing FontStore");
|
||||||
let source = font_kit::source::SystemSource::new();
|
let source = font_kit::source::SystemSource::new();
|
||||||
let source = Box::new(source);
|
let source = Box::new(source);
|
||||||
|
|
||||||
|
@ -241,14 +242,14 @@ impl FontStore {
|
||||||
use font_kit::handle::Handle;
|
use font_kit::handle::Handle;
|
||||||
use font_kit::properties::Properties;
|
use font_kit::properties::Properties;
|
||||||
|
|
||||||
println!("loading font family {}", title);
|
log::info!("Finding font by family: {}", title);
|
||||||
|
|
||||||
let font_handle = self
|
let font_handle = self
|
||||||
.source
|
.source
|
||||||
.select_best_match(&[FamilyName::Title(title.to_string())], &Properties::new())
|
.select_best_match(&[FamilyName::Title(title.to_string())], &Properties::new())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("loading font file: {:?}", font_handle);
|
log::info!("Loading font file: {:?}", font_handle);
|
||||||
|
|
||||||
let font_data = if let Handle::Path {
|
let font_data = if let Handle::Path {
|
||||||
path,
|
path,
|
||||||
|
|
Loading…
Reference in New Issue