Add backend module
This commit is contained in:
parent
70a4d5b49b
commit
4061af264d
|
@ -0,0 +1,28 @@
|
||||||
|
//! This module defines backends for WebAssembly execution.
|
||||||
|
//!
|
||||||
|
//! Canary is designed to support multiple WebAssembly runtimes for different
|
||||||
|
//! purposes. Currently, [wasmtime](https://wasmtime.dev) is the only one
|
||||||
|
//! implemented, but in the future, [wasm3](https://github.com/wasm3/wasm3)
|
||||||
|
//! will also be provided.
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// A WebAssembly runtime backend.
|
||||||
|
pub trait Backend {
|
||||||
|
fn load_module(&self, module: &[u8]) -> Arc<dyn Instance>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An instance of a WebAssembly module.
|
||||||
|
///
|
||||||
|
/// All self parameters to this trait's functions are immutable, so the
|
||||||
|
/// implementation must provide interior mutability. This allows instances
|
||||||
|
/// to intelligently optimize the execution of their scripts, for example, by
|
||||||
|
/// allowing the execution of multiple ABI calls from multiple threads when
|
||||||
|
/// a script supports the WebAssembly multithreading extension.
|
||||||
|
pub trait Instance {
|
||||||
|
fn bind_panel(&self, panel: PanelId, msg: Vec<u8>) -> u32;
|
||||||
|
fn update(&self, panel: PanelId, dt: f32);
|
||||||
|
fn draw(&self, panel: PanelId) -> Vec<DrawCommand>;
|
||||||
|
fn on_cursor_event(&self, panel: PanelId, kind: CursorEventKind, at: Vec2);
|
||||||
|
fn on_message(&self, panel: PanelId, msg: Vec<u8>);
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ use slab::Slab;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub mod backend;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
|
|
||||||
/// Proportion constant between pixels (at 96dpi) to millimeters (Canary's unit measurement).
|
/// Proportion constant between pixels (at 96dpi) to millimeters (Canary's unit measurement).
|
||||||
|
|
Loading…
Reference in New Issue