Skip to content

Commit fd7addf

Browse files
authored
Merge branch 'master' into gg_sliding
2 parents 09b3fca + 75614eb commit fd7addf

71 files changed

Lines changed: 1652 additions & 659 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 20 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"node-graph/gapplication-io",
88
"node-graph/gbrush",
99
"node-graph/gcore",
10+
"node-graph/gcore-shaders",
1011
"node-graph/gstd",
1112
"node-graph/gmath-nodes",
1213
"node-graph/gpath-bool",
@@ -28,6 +29,7 @@ default-members = [
2829
"frontend/wasm",
2930
"node-graph/gbrush",
3031
"node-graph/gcore",
32+
"node-graph/gcore-shaders",
3133
"node-graph/gstd",
3234
"node-graph/gmath-nodes",
3335
"node-graph/gpath-bool",
@@ -50,6 +52,7 @@ path-bool = { path = "libraries/path-bool" }
5052
graphene-application-io = { path = "node-graph/gapplication-io" }
5153
graphene-brush = { path = "node-graph/gbrush" }
5254
graphene-core = { path = "node-graph/gcore" }
55+
graphene-core-shaders = { path = "node-graph/gcore-shaders" }
5356
graphene-math-nodes = { path = "node-graph/gmath-nodes" }
5457
graphene-path-bool = { path = "node-graph/gpath-bool" }
5558
graph-craft = { path = "node-graph/graph-craft" }
@@ -156,12 +159,17 @@ iai-callgrind = { version = "0.12.3" }
156159
ndarray = "0.16.1"
157160
strum = { version = "0.26.3", features = ["derive"] }
158161
dirs = "6.0"
162+
cef = "138.5.0"
163+
include_dir = "0.7.4"
164+
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
165+
tracing = "0.1.41"
159166

160167
[profile.dev]
161168
opt-level = 1
162169

163170
[profile.dev.package]
164171
graphite-editor = { opt-level = 1 }
172+
graphene-core-shaders = { opt-level = 1 }
165173
graphene-core = { opt-level = 1 }
166174
graphene-std = { opt-level = 1 }
167175
interpreted-executor = { opt-level = 1 } # This is a mitigation for https://github.com/rustwasm/wasm-pack/issues/981 which is needed because the node_registry function is too large

desktop/Cargo.toml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,23 @@ edition = "2024"
99
rust-version = "1.87"
1010

1111
[features]
12-
default = ["gpu"]
13-
gpu = ["graphite-editor/gpu"]
12+
# default = ["gpu"]
13+
# gpu = ["graphite-editor/gpu"]
1414

1515
[dependencies]
1616
# Local dependencies
17-
graphite-editor = { path = "../editor", features = [
18-
"gpu",
19-
"ron",
20-
"vello",
21-
"decouple-execution",
22-
] }
17+
# graphite-editor = { path = "../editor", features = [
18+
# "gpu",
19+
# "ron",
20+
# "vello",
21+
# "decouple-execution",
22+
# ] }
2323
wgpu = { workspace = true }
2424
winit = { workspace = true, features = ["serde"] }
25-
base64.workspace = true
26-
thiserror.workspace = true
27-
pollster = "0.3"
28-
cef = "138.5.0"
29-
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
30-
tracing = "0.1.41"
31-
bytemuck = { version = "1.23.1", features = ["derive"] }
32-
include_dir = "0.7.4"
33-
dirs.workspace = true
25+
thiserror = { workspace = true }
26+
futures = { workspace = true }
27+
cef = { workspace = true }
28+
include_dir = { workspace = true }
29+
tracing-subscriber = { workspace = true }
30+
tracing = { workspace = true }
31+
dirs = {workspace = true}

desktop/src/app.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::CustomEvent;
2-
use crate::FrameBuffer;
32
use crate::WindowSize;
43
use crate::render::GraphicsState;
4+
use crate::render::WgpuContext;
55
use std::sync::Arc;
66
use std::sync::mpsc::Sender;
77
use std::time::Duration;
@@ -12,7 +12,6 @@ use winit::event::StartCause;
1212
use winit::event::WindowEvent;
1313
use winit::event_loop::ActiveEventLoop;
1414
use winit::event_loop::ControlFlow;
15-
use winit::event_loop::EventLoopProxy;
1615
use winit::window::Window;
1716
use winit::window::WindowId;
1817

@@ -22,33 +21,34 @@ pub(crate) struct WinitApp {
2221
pub(crate) cef_context: cef::Context<cef::Initialized>,
2322
pub(crate) window: Option<Arc<Window>>,
2423
cef_schedule: Option<Instant>,
25-
ui_frame_buffer: Option<FrameBuffer>,
24+
_ui_frame_buffer: Option<wgpu::Texture>,
2625
window_size_sender: Sender<WindowSize>,
27-
_viewport_frame_buffer: Option<FrameBuffer>,
26+
_viewport_frame_buffer: Option<wgpu::Texture>,
2827
graphics_state: Option<GraphicsState>,
29-
event_loop_proxy: EventLoopProxy<CustomEvent>,
28+
wgpu_context: WgpuContext,
3029
}
3130

3231
impl WinitApp {
33-
pub(crate) fn new(cef_context: cef::Context<cef::Initialized>, window_size_sender: Sender<WindowSize>, event_loop_proxy: EventLoopProxy<CustomEvent>) -> Self {
32+
pub(crate) fn new(cef_context: cef::Context<cef::Initialized>, window_size_sender: Sender<WindowSize>, wgpu_context: WgpuContext) -> Self {
3433
Self {
3534
cef_context,
3635
window: None,
3736
cef_schedule: Some(Instant::now()),
3837
_viewport_frame_buffer: None,
39-
ui_frame_buffer: None,
38+
_ui_frame_buffer: None,
4039
graphics_state: None,
4140
window_size_sender,
42-
event_loop_proxy,
41+
wgpu_context,
4342
}
4443
}
4544
}
4645

4746
impl ApplicationHandler<CustomEvent> for WinitApp {
4847
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
4948
// Set a timeout in case we miss any cef schedule requests
50-
let timeout = Instant::now() + Duration::from_millis(100);
49+
let timeout = Instant::now() + Duration::from_millis(10);
5150
let wait_until = timeout.min(self.cef_schedule.unwrap_or(timeout));
51+
self.cef_context.work();
5252
event_loop.set_control_flow(ControlFlow::WaitUntil(wait_until));
5353
}
5454

@@ -71,7 +71,7 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
7171
)
7272
.unwrap(),
7373
);
74-
let graphics_state = pollster::block_on(GraphicsState::new(window.clone()));
74+
let graphics_state = GraphicsState::new(window.clone(), self.wgpu_context.clone());
7575

7676
self.window = Some(window);
7777
self.graphics_state = Some(graphics_state);
@@ -81,24 +81,21 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
8181

8282
fn user_event(&mut self, _: &ActiveEventLoop, event: CustomEvent) {
8383
match event {
84-
CustomEvent::UiUpdate(frame_buffer) => {
84+
CustomEvent::UiUpdate(texture) => {
8585
if let Some(graphics_state) = self.graphics_state.as_mut() {
86-
graphics_state.update_texture(&frame_buffer);
86+
graphics_state.bind_texture(&texture);
87+
graphics_state.resize(texture.width(), texture.height());
8788
}
88-
self.ui_frame_buffer = Some(frame_buffer);
8989
if let Some(window) = &self.window {
9090
window.request_redraw();
9191
}
9292
}
9393
CustomEvent::ScheduleBrowserWork(instant) => {
94-
if let Some(graphics_state) = self.graphics_state.as_mut()
95-
&& let Some(frame_buffer) = &self.ui_frame_buffer
96-
&& graphics_state.ui_texture_outdated(frame_buffer)
97-
{
94+
if instant <= Instant::now() {
9895
self.cef_context.work();
99-
let _ = self.event_loop_proxy.send_event(CustomEvent::ScheduleBrowserWork(Instant::now() + Duration::from_millis(1)));
96+
} else {
97+
self.cef_schedule = Some(instant);
10098
}
101-
self.cef_schedule = Some(instant);
10299
}
103100
}
104101
}
@@ -113,9 +110,6 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
113110
}
114111
WindowEvent::Resized(PhysicalSize { width, height }) => {
115112
let _ = self.window_size_sender.send(WindowSize::new(width as usize, height as usize));
116-
if let Some(ref mut graphics_state) = self.graphics_state {
117-
graphics_state.resize(width, height);
118-
}
119113
self.cef_context.notify_of_resize();
120114
}
121115

desktop/src/cef.rs

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{CustomEvent, FrameBuffer};
1+
use crate::{CustomEvent, WgpuContext, render::FrameBufferRef};
22
use std::{
33
sync::{Arc, Mutex, mpsc::Receiver},
44
time::Instant,
@@ -15,7 +15,7 @@ use winit::event_loop::EventLoopProxy;
1515

1616
pub(crate) trait CefEventHandler: Clone {
1717
fn window_size(&self) -> WindowSize;
18-
fn draw(&self, frame_buffer: FrameBuffer);
18+
fn draw<'a>(&self, frame_buffer: FrameBufferRef<'a>);
1919
/// Scheudule the main event loop to run the cef event loop after the timeout
2020
/// [`_cef_browser_process_handler_t::on_schedule_message_pump_work`] for more documentation.
2121
fn schedule_cef_message_loop_work(&self, scheduled_time: Instant);
@@ -37,6 +37,7 @@ impl WindowSize {
3737
pub(crate) struct CefHandler {
3838
window_size_receiver: Arc<Mutex<WindowSizeReceiver>>,
3939
event_loop_proxy: EventLoopProxy<CustomEvent>,
40+
wgpu_context: WgpuContext,
4041
}
4142
struct WindowSizeReceiver {
4243
receiver: Receiver<WindowSize>,
@@ -51,10 +52,11 @@ impl WindowSizeReceiver {
5152
}
5253
}
5354
impl CefHandler {
54-
pub(crate) fn new(window_size_receiver: Receiver<WindowSize>, event_loop_proxy: EventLoopProxy<CustomEvent>) -> Self {
55+
pub(crate) fn new(window_size_receiver: Receiver<WindowSize>, event_loop_proxy: EventLoopProxy<CustomEvent>, wgpu_context: WgpuContext) -> Self {
5556
Self {
5657
window_size_receiver: Arc::new(Mutex::new(WindowSizeReceiver::new(window_size_receiver))),
5758
event_loop_proxy,
59+
wgpu_context,
5860
}
5961
}
6062
}
@@ -71,8 +73,44 @@ impl CefEventHandler for CefHandler {
7173
}
7274
*window_size
7375
}
74-
fn draw(&self, frame_buffer: FrameBuffer) {
75-
let _ = self.event_loop_proxy.send_event(CustomEvent::UiUpdate(frame_buffer));
76+
fn draw<'a>(&self, frame_buffer: FrameBufferRef<'a>) {
77+
let width = frame_buffer.width() as u32;
78+
let height = frame_buffer.height() as u32;
79+
let texture = self.wgpu_context.device.create_texture(&wgpu::TextureDescriptor {
80+
label: Some("CEF Texture"),
81+
size: wgpu::Extent3d {
82+
width,
83+
height,
84+
depth_or_array_layers: 1,
85+
},
86+
mip_level_count: 1,
87+
sample_count: 1,
88+
dimension: wgpu::TextureDimension::D2,
89+
format: wgpu::TextureFormat::Bgra8UnormSrgb,
90+
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
91+
view_formats: &[],
92+
});
93+
self.wgpu_context.queue.write_texture(
94+
wgpu::TexelCopyTextureInfo {
95+
texture: &texture,
96+
mip_level: 0,
97+
origin: wgpu::Origin3d::ZERO,
98+
aspect: wgpu::TextureAspect::All,
99+
},
100+
frame_buffer.buffer(),
101+
wgpu::TexelCopyBufferLayout {
102+
offset: 0,
103+
bytes_per_row: Some(4 * width),
104+
rows_per_image: Some(height),
105+
},
106+
wgpu::Extent3d {
107+
width,
108+
height,
109+
depth_or_array_layers: 1,
110+
},
111+
);
112+
113+
let _ = self.event_loop_proxy.send_event(CustomEvent::UiUpdate(texture));
76114
}
77115

78116
fn schedule_cef_message_loop_work(&self, scheduled_time: std::time::Instant) {

desktop/src/cef/context.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cef::sys::CEF_API_VERSION_LAST;
1+
use cef::sys::{CEF_API_VERSION_LAST, cef_resultcode_t};
22
use cef::{App, BrowserSettings, Client, DictionaryValue, ImplBrowser, ImplBrowserHost, ImplCommandLine, RenderHandler, RequestContext, WindowInfo, browser_host_create_browser_sync, initialize};
33
use cef::{Browser, CefString, Settings, api_hash, args::Args, execute_process};
44
use thiserror::Error;
@@ -74,7 +74,11 @@ impl Context<Setup> {
7474

7575
let result = initialize(Some(self.args.as_main_args()), Some(&settings), Some(&mut cef_app), std::ptr::null_mut());
7676
if result != 1 {
77-
return Err(InitError::InitializationFailed);
77+
let cef_exit_code = cef::get_exit_code() as u32;
78+
if cef_exit_code == cef_resultcode_t::CEF_RESULT_CODE_NORMAL_EXIT_PROCESS_NOTIFIED as u32 {
79+
return Err(InitError::AlreadyRunning);
80+
}
81+
return Err(InitError::InitializationFailed(cef_exit_code));
7882
}
7983

8084
let render_handler = RenderHandlerImpl::new(event_handler.clone());
@@ -146,5 +150,7 @@ pub(crate) enum SetupError {
146150
#[derive(Error, Debug)]
147151
pub(crate) enum InitError {
148152
#[error("initialization failed")]
149-
InitializationFailed,
153+
InitializationFailed(u32),
154+
#[error("Another instance is already running")]
155+
AlreadyRunning,
150156
}

0 commit comments

Comments
 (0)