Desktop: Implement desktop wrapper module (#3039)

* Prototyping desktop wrapper api

* Separate into multiple modules

* Some fixup

* Reimplement most functionality with editor api

* Fix texture life time crashes

* Fix scale

* Implement editor wrapper message queue

* Improve performance

* Handle native messages directly without submitting to event loop

* Fix overlay latency

* Move editor message execution to executor allows no shared state in editor wrapper

* Small clean up

* Small cleanup

* Some renames

* Cleaning up desktop wrapper interface

* Fix formatting

* Fix naming

* Move node graph execution result handling to app

* Fix FrontendMessage RenderOverlays usage

* Reimplement file drop and clean up file import and open messages

* Remove dbg

* Post merge fix

* Review changes
This commit is contained in:
Timon
2025-08-20 13:27:36 +00:00
committed by GitHub
parent a70c48f69a
commit 30e5d66105
14 changed files with 558 additions and 265 deletions
+11 -15
View File
@@ -1,8 +1,5 @@
use std::process::exit;
use std::time::Instant;
use std::{fmt::Debug, time::Duration};
use graphite_editor::messages::prelude::Message;
use std::time::{Duration, Instant};
use tracing_subscriber::EnvFilter;
use winit::event_loop::EventLoop;
@@ -12,22 +9,21 @@ mod cef;
use cef::{Setup, WindowSize};
mod render;
use render::WgpuContext;
mod app;
use app::WinitApp;
mod dirs;
mod dialogs;
mod desktop_wrapper;
use desktop_wrapper::messages::DesktopWrapperMessage;
use desktop_wrapper::{DesktopWrapper, NodeGraphExecutionResult};
#[derive(Debug)]
pub(crate) enum CustomEvent {
UiUpdate(wgpu::Texture),
ScheduleBrowserWork(Instant),
DispatchMessage(Message),
MessageReceived(Message),
NodeGraphRan(Option<wgpu::Texture>),
DesktopWrapperMessage(DesktopWrapperMessage),
NodeGraphExecutionResult(NodeGraphExecutionResult),
}
fn main() {
@@ -46,7 +42,7 @@ fn main() {
let (window_size_sender, window_size_receiver) = std::sync::mpsc::channel();
let wgpu_context = futures::executor::block_on(WgpuContext::new()).unwrap();
let wgpu_context = futures::executor::block_on(desktop_wrapper::WgpuContext::new()).unwrap();
let cef_context = match cef_context.init(cef::CefHandler::new(window_size_receiver, event_loop.create_proxy(), wgpu_context.clone())) {
Ok(c) => c,
Err(cef::InitError::AlreadyRunning) => {
@@ -66,10 +62,10 @@ fn main() {
std::thread::spawn(move || {
loop {
let last_render = Instant::now();
let (has_run, texture) = futures::executor::block_on(graphite_editor::node_graph_executor::run_node_graph());
if has_run {
let _ = rendering_loop_proxy.send_event(CustomEvent::NodeGraphRan(texture.map(|t| (*t.texture).clone())));
}
let result = futures::executor::block_on(DesktopWrapper::execute_node_graph());
let _ = rendering_loop_proxy.send_event(CustomEvent::NodeGraphExecutionResult(result));
let frame_time = Duration::from_secs_f32((target_fps as f32).recip());
let sleep = last_render + frame_time - Instant::now();
std::thread::sleep(sleep);