mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Create window using the graphen-cli
This commit is contained in:
committed by
Keavon Chambers
parent
dccb5235c0
commit
5d1581dd70
@@ -6,7 +6,13 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
gpu = ["interpreted-executor/gpu", "graphene-std/gpu", "graphene-core/gpu", "wgpu-executor", "gpu-executor"]
|
||||
gpu = [
|
||||
"interpreted-executor/gpu",
|
||||
"graphene-std/gpu",
|
||||
"graphene-core/gpu",
|
||||
"wgpu-executor",
|
||||
"gpu-executor",
|
||||
]
|
||||
default = ["wgpu"]
|
||||
wgpu = ["wgpu-executor", "gpu"]
|
||||
|
||||
@@ -30,7 +36,7 @@ gpu-executor = { path = "../gpu-executor", optional = true }
|
||||
interpreted-executor = { path = "../interpreted-executor" }
|
||||
dyn-any = { path = "../../libraries/dyn-any" }
|
||||
graphene-core = { path = "../gcore" }
|
||||
graphene-std = { path = "../gstd" }
|
||||
graphene-std = { path = "../gstd", features = [] }
|
||||
future-executor = { path = "../future-executor", optional = true }
|
||||
|
||||
wasm-bindgen = { version = "0.2.86", optional = true }
|
||||
|
||||
@@ -26,12 +26,37 @@ impl NodeGraphUpdateSender for UpdateLogger {
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
init_logging();
|
||||
|
||||
let document_path = std::env::args().nth(1).expect("No document path provided");
|
||||
|
||||
let document_string = std::fs::read_to_string(&document_path).expect("Failed to read document");
|
||||
|
||||
let executor = create_executor(document_string)?;
|
||||
println!("creating gpu context",);
|
||||
let editor_api = WasmEditorApi {
|
||||
image_frame: None,
|
||||
font_cache: &FontCache::default(),
|
||||
application_io: &block_on(WasmApplicationIo::new()),
|
||||
node_graph_message_sender: &UpdateLogger {},
|
||||
imaginate_preferences: &ImaginatePreferences::default(),
|
||||
};
|
||||
for i in 0..10 {
|
||||
//println!("executing");
|
||||
let result = block_on((&executor).execute(editor_api.clone()))?;
|
||||
//println!("result: {:?}", result);
|
||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn init_logging() {
|
||||
let colors = ColoredLevelConfig::new().debug(Color::Magenta).info(Color::Green).error(Color::Red);
|
||||
fern::Dispatch::new()
|
||||
.chain(std::io::stdout())
|
||||
.level_for("foodcalc", log::LevelFilter::Trace)
|
||||
.level_for("sqlx", log::LevelFilter::Trace)
|
||||
.level_for("iced", log::LevelFilter::Trace)
|
||||
.level_for("wgpu", log::LevelFilter::Debug)
|
||||
.level(log::LevelFilter::Trace)
|
||||
.format(move |out, message, record| {
|
||||
out.finish(format_args!(
|
||||
@@ -44,37 +69,38 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
})
|
||||
.apply()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let document_path = std::env::args().nth(1).expect("No document path provided");
|
||||
|
||||
let document_string = std::fs::read_to_string(&document_path).expect("Failed to read document");
|
||||
|
||||
fn create_executor(document_string: String) -> Result<DynamicExecutor, Box<dyn Error>> {
|
||||
let document: serde_json::Value = serde_json::from_str(&document_string).expect("Failed to parse document");
|
||||
let document = serde_json::from_value::<Document>(document["document_legacy"].clone()).expect("Failed to parse document");
|
||||
|
||||
let Some(LayerDataType::Layer(ref node_graph)) = document.root.iter().find(|layer| matches!(layer.data, LayerDataType::Layer(_))).map(|x|&x.data) else { panic!("failed to extract node graph from docmuent") };
|
||||
let network = &node_graph.network;
|
||||
|
||||
let wrapped_network = wrap_network_in_scope(network.clone());
|
||||
|
||||
let compiler = Compiler {};
|
||||
let protograph = compiler.compile_single(wrapped_network, true)?;
|
||||
|
||||
let mut executor = block_on(DynamicExecutor::new(protograph))?;
|
||||
Ok(executor)
|
||||
}
|
||||
|
||||
let editor_api = WasmEditorApi {
|
||||
image_frame: None,
|
||||
font_cache: &FontCache::default(),
|
||||
application_io: &block_on(WasmApplicationIo::new()),
|
||||
node_graph_message_sender: &UpdateLogger {},
|
||||
imaginate_preferences: &ImaginatePreferences::default(),
|
||||
};
|
||||
loop {
|
||||
let result = block_on((&executor).execute(editor_api.clone()))?;
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn gpu_surface() {
|
||||
let document_string = include_str!("../test_files/gpu_surface.graphite");
|
||||
let executor = create_executor(document_string.to_string()).unwrap();
|
||||
let editor_api = WasmEditorApi {
|
||||
image_frame: None,
|
||||
font_cache: &FontCache::default(),
|
||||
application_io: &block_on(WasmApplicationIo::new()),
|
||||
node_graph_message_sender: &UpdateLogger {},
|
||||
imaginate_preferences: &ImaginatePreferences::default(),
|
||||
};
|
||||
let result = block_on((&executor).execute(editor_api.clone())).unwrap();
|
||||
println!("result: {:?}", result);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn wrap_network_in_scope(mut network: NodeNetwork) -> NodeNetwork {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user