Desktop: Use multithreaded CEF event loop on Windows and Linux (#3076)

* Prototype multi threaded event loop

* Fix input event dispatch

* Remove dead code

* Reenable do_message_loop_work for macos targets

* Cleanup

* Review cleanup

* Remove outdated comment

* Attempt to fix texture import errors

---------

Co-authored-by: Timon Schelling <me@timon.zip>
This commit is contained in:
Dennis Kobert
2025-08-21 19:46:13 +00:00
committed by GitHub
co-authored by Timon Schelling
parent 0e467907e2
commit e4dd3ce806
16 changed files with 525 additions and 341 deletions
+19 -13
View File
@@ -7,7 +7,6 @@ use winit::event_loop::EventLoop;
pub(crate) mod consts;
mod cef;
use cef::Setup;
mod render;
@@ -29,21 +28,24 @@ pub(crate) enum CustomEvent {
fn main() {
tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init();
let cef_context = match cef::Context::<Setup>::new() {
Ok(c) => c,
Err(cef::SetupError::Subprocess) => exit(0),
Err(cef::SetupError::SubprocessFailed(t)) => {
tracing::error!("Subprocess of type {t} failed");
exit(1);
}
};
let cef_context_builder = cef::CefContextBuilder::new();
if cef_context_builder.is_sub_process() {
// We are in a CEF subprocess
// This will block until the CEF subprocess quits
let error = cef_context_builder.execute_sub_process();
tracing::error!("Cef subprocess failed with error: {error}");
return;
}
let wgpu_context = futures::executor::block_on(WgpuContext::new()).unwrap();
let event_loop = EventLoop::<CustomEvent>::with_user_event().build().unwrap();
let (window_size_sender, window_size_receiver) = std::sync::mpsc::channel();
let wgpu_context = futures::executor::block_on(WgpuContext::new()).unwrap();
let cef_context = match cef_context.init(cef::CefHandler::new(window_size_receiver, event_loop.create_proxy(), wgpu_context.clone())) {
let cef_handler = cef::CefHandler::new(window_size_receiver, event_loop.create_proxy(), wgpu_context.clone());
let cef_context = match cef_context_builder.initialize(cef_handler) {
Ok(c) => c,
Err(cef::InitError::AlreadyRunning) => {
tracing::error!("Another instance is already running, Exiting.");
@@ -53,11 +55,15 @@ fn main() {
tracing::error!("Cef initialization failed with code: {code}");
exit(1);
}
Err(cef::InitError::BrowserCreationFailed) => {
tracing::error!("Failed to create CEF browser");
exit(1);
}
};
tracing::info!("Cef initialized successfully");
tracing::info!("CEF initialized successfully");
let mut winit_app = WinitApp::new(cef_context, window_size_sender, wgpu_context, event_loop.create_proxy());
let mut winit_app = WinitApp::new(Box::new(cef_context), window_size_sender, wgpu_context, event_loop.create_proxy());
event_loop.run_app(&mut winit_app).unwrap();
}