Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ impl App {
if let Some(render_state) = &mut self.render_state {
render_state.set_overlays_scene(scene);
}
if let Some(window) = &self.window {
window.request_redraw();
}
}
DesktopFrontendMessage::PersistenceWriteDocument { id, document } => {
self.persistent_data.write_document(id, document);
Expand Down Expand Up @@ -544,6 +547,7 @@ impl ApplicationHandler for App {
Err(RenderError::SurfaceError(e)) => tracing::error!("Render error: {:?}", e),
}
let _ = self.start_render_sender.try_send(());
// self.cef_context.schedule_frame();
}
}
WindowEvent::DragDropped { paths, .. } => {
Expand Down Expand Up @@ -612,7 +616,6 @@ impl ApplicationHandler for App {
fn about_to_wait(&mut self, event_loop: &dyn ActiveEventLoop) {
// Set a timeout in case we miss any cef schedule requests
let timeout = Instant::now() + Duration::from_millis(10);
let wait_until = timeout.min(self.cef_schedule.unwrap_or(timeout));
if let Some(schedule) = self.cef_schedule
&& schedule < Instant::now()
{
Expand All @@ -621,11 +624,9 @@ impl ApplicationHandler for App {
for _ in 0..CEF_MESSAGE_LOOP_MAX_ITERATIONS {
self.cef_context.work();
}
} else {
let wait_until = timeout.min(self.cef_schedule.unwrap_or(timeout));
event_loop.set_control_flow(ControlFlow::WaitUntil(wait_until));
}
if let Some(window) = &self.window.as_ref() {
window.request_redraw();
}

event_loop.set_control_flow(ControlFlow::WaitUntil(wait_until));
}
}
11 changes: 11 additions & 0 deletions desktop/src/render/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(crate) struct RenderState {
bind_group: Option<wgpu::BindGroup>,
#[derivative(Debug = "ignore")]
overlays_scene: Option<vello::Scene>,
surface_outdated: bool,
}

impl RenderState {
Expand Down Expand Up @@ -186,6 +187,7 @@ impl RenderState {
ui_texture: None,
bind_group: None,
overlays_scene: None,
surface_outdated: true,
}
}

Expand All @@ -196,6 +198,7 @@ impl RenderState {

self.desired_width = width;
self.desired_height = height;
self.surface_outdated = true;

if width > 0 && height > 0 && (self.config.width != width || self.config.height != height) {
self.config.width = width;
Expand All @@ -215,14 +218,17 @@ impl RenderState {
}

pub(crate) fn set_viewport_scale(&mut self, scale: [f32; 2]) {
self.surface_outdated = true;
self.viewport_scale = scale;
}

pub(crate) fn set_viewport_offset(&mut self, offset: [f32; 2]) {
self.surface_outdated = true;
self.viewport_offset = offset;
}

pub(crate) fn set_overlays_scene(&mut self, scene: vello::Scene) {
self.surface_outdated = true;
self.overlays_scene = Some(scene);
}

Expand All @@ -244,6 +250,9 @@ impl RenderState {
}

pub(crate) fn render(&mut self, window: &Window) -> Result<(), RenderError> {
if !self.surface_outdated {
return Ok(());
}
let ui_scale = if let Some(ui_texture) = &self.ui_texture
&& (self.desired_width != ui_texture.width() || self.desired_height != ui_texture.height())
{
Expand Down Expand Up @@ -305,11 +314,13 @@ impl RenderState {
if ui_scale.is_some() {
return Err(RenderError::OutdatedUITextureError);
}
self.surface_outdated = false;

Ok(())
}

fn update_bindgroup(&mut self) {
self.surface_outdated = true;
let viewport_texture_view = self.viewport_texture.as_ref().unwrap_or(&self.transparent_texture).create_view(&wgpu::TextureViewDescriptor::default());
let overlays_texture_view = self
.overlays_texture
Expand Down