From bc130b5e1b8c82395d1a4e746d1de3d2f09b179d Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 12 May 2024 16:15:18 +0900 Subject: [PATCH 1/9] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 34 +++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 0fbb48a09c7..c689b8163c9 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -504,7 +504,7 @@ impl GlowWinitRunning { ) -> EventResult { crate::profile_function!(); - let Some(viewport_id) = self + let Some(mut viewport_id) = self .glutin .borrow() .viewport_from_window @@ -520,24 +520,26 @@ impl GlowWinitRunning { let mut frame_timer = crate::stopwatch::Stopwatch::new(); frame_timer.start(); - { - let glutin = self.glutin.borrow(); - let viewport = &glutin.viewports[&viewport_id]; - let is_immediate = viewport.viewport_ui_cb.is_none(); - if is_immediate && viewport_id != ViewportId::ROOT { - // This will only happen if this is an immediate viewport. - // That means that the viewport cannot be rendered by itself and needs his parent to be rendered. - if let Some(parent_viewport) = glutin.viewports.get(&viewport.ids.parent) { - if let Some(window) = parent_viewport.window.as_ref() { - return EventResult::RepaintNext(window.id()); - } + let (raw_input, viewport_ui_cb) = { + crate::profile_scope!("Prepare"); + + let mut glutin = self.glutin.borrow_mut(); + let original_viewport = &glutin.viewports[&viewport_id]; + + // This will only happens when a Immediate Viewport. + if original_viewport.class == ViewportClass::Immediate { + let Some(parent_viewport) = glutin.viewports.get(&original_viewport.ids.parent) + else { + return EventResult::Wait; + }; + + if parent_viewport.class == ViewportClass::Deferred { + viewport_id = parent_viewport.ids.this; + } else { + viewport_id = ViewportId::ROOT; } - return EventResult::Wait; } - } - let (raw_input, viewport_ui_cb) = { - let mut glutin = self.glutin.borrow_mut(); let egui_ctx = glutin.egui_ctx.clone(); let Some(viewport) = glutin.viewports.get_mut(&viewport_id) else { return EventResult::Wait; From 7442edcff23559cba79fd605a3930df4adf7552b Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 12 May 2024 16:16:19 +0900 Subject: [PATCH 2/9] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index f365d74ad93..37e16479e07 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -525,7 +525,7 @@ impl WgpuWinitRunning { fn run_ui_and_paint(&mut self, window_id: WindowId) -> EventResult { crate::profile_function!(); - let Some(viewport_id) = self + let Some(mut viewport_id) = self .shared .borrow() .viewport_from_window @@ -555,20 +555,20 @@ impl WgpuWinitRunning { viewports, painter, .. } = &mut *shared_lock; - if viewport_id != ViewportId::ROOT { - let Some(viewport) = viewports.get(&viewport_id) else { + let Some(original_viewport) = viewports.get(&viewport_id) else { + return EventResult::Wait; + }; + + // This will only happens when a Immediate Viewport. + if original_viewport.class == ViewportClass::Immediate { + let Some(parent_viewport) = viewports.get(&original_viewport.ids.parent) else { return EventResult::Wait; }; - if viewport.viewport_ui_cb.is_none() { - // This will only happen if this is an immediate viewport. - // That means that the viewport cannot be rendered by itself and needs his parent to be rendered. - if let Some(viewport) = viewports.get(&viewport.ids.parent) { - if let Some(window) = viewport.window.as_ref() { - return EventResult::RepaintNext(window.id()); - } - } - return EventResult::Wait; + if parent_viewport.class == ViewportClass::Deferred { + viewport_id = parent_viewport.ids.this; + } else { + viewport_id = ViewportId::ROOT; } } From dc82f7e45d32e26a20ce20c6f06fd16311babc4a Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 12 May 2024 20:01:22 +0900 Subject: [PATCH 3/9] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 26 ++++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index c689b8163c9..fd8bd769a84 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -863,31 +863,31 @@ fn change_gl_context( ) { crate::profile_function!(); + let Some(p_current_gl_context) = current_gl_context.take() else { + return; + }; + if !cfg!(target_os = "windows") { // According to https://github.com/emilk/egui/issues/4289 // we cannot do this early-out on Windows. // TODO(emilk): optimize context switching on Windows too. // See https://github.com/emilk/egui/issues/4173 - if let Some(current_gl_context) = current_gl_context { - crate::profile_scope!("is_current"); - if gl_surface.is_current(current_gl_context) { - return; // Early-out to save a lot of time. - } + crate::profile_scope!("is_current"); + if gl_surface.is_current(&p_current_gl_context) { + return; // Early-out to save a lot of time. } } - let not_current = { - crate::profile_scope!("make_not_current"); - current_gl_context - .take() - .unwrap() - .make_not_current() - .unwrap() + crate::profile_scope!("make_not_current"); + let Ok(not_current) = p_current_gl_context.make_not_current() else { + return; }; crate::profile_scope!("make_current"); - *current_gl_context = Some(not_current.make_current(gl_surface).unwrap()); + if let Ok(current) = not_current.make_current(gl_surface) { + *current_gl_context = Some(current); + } } impl GlutinWindowContext { From 4810948ce511e00b0aed549dce7081c9ece378af Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 18 May 2024 14:21:43 +0900 Subject: [PATCH 4/9] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index fd8bd769a84..048426c7e5e 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -644,11 +644,15 @@ impl GlowWinitRunning { let Some(viewport) = viewports.get_mut(&viewport_id) else { return EventResult::Wait; }; - viewport.info.events.clear(); // they should have been processed - let window = viewport.window.clone().unwrap(); - let gl_surface = viewport.gl_surface.as_ref().unwrap(); - let egui_winit = viewport.egui_winit.as_mut().unwrap(); + + let (Some(egui_winit), Some(window), Some(gl_surface)) = ( + &mut viewport.egui_winit, + &viewport.window.clone(), + &viewport.gl_surface, + ) else { + return EventResult::Wait; + }; egui_winit.handle_platform_output(&window, platform_output); From 082bd294964cda4cf4121a704e62ecaad6b2ac97 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 18 May 2024 14:57:43 +0900 Subject: [PATCH 5/9] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 048426c7e5e..f58da8921f4 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -654,7 +654,7 @@ impl GlowWinitRunning { return EventResult::Wait; }; - egui_winit.handle_platform_output(&window, platform_output); + egui_winit.handle_platform_output(window, platform_output); let clipped_primitives = integration.egui_ctx.tessellate(shapes, pixels_per_point); @@ -711,7 +711,7 @@ impl GlowWinitRunning { } } - integration.post_rendering(&window); + integration.post_rendering(window); } { @@ -740,7 +740,7 @@ impl GlowWinitRunning { integration.report_frame_time(frame_timer.total_time_sec()); // don't count auto-save time as part of regular frame time - integration.maybe_autosave(app.as_mut(), Some(&window)); + integration.maybe_autosave(app.as_mut(), Some(window)); if window.is_minimized() == Some(true) { // On Mac, a minimized Window uses up all CPU: From 374434de8a1a90e7bcdfeb46323b9c34e7662b84 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 19 May 2024 02:27:51 +0900 Subject: [PATCH 6/9] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index f58da8921f4..f939f0eaa55 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -584,21 +584,21 @@ impl GlowWinitRunning { .. } = &mut *glutin; let viewport = &viewports[&viewport_id]; - let Some(window) = viewport.window.as_ref() else { - return EventResult::Wait; - }; let Some(gl_surface) = viewport.gl_surface.as_ref() else { return EventResult::Wait; }; - let screen_size_in_pixels: [u32; 2] = window.inner_size().into(); - { frame_timer.pause(); change_gl_context(current_gl_context, gl_surface); frame_timer.resume(); } + let Some(window) = viewport.window.as_ref() else { + return EventResult::Wait; + }; + let screen_size_in_pixels: [u32; 2] = window.inner_size().into(); + self.painter .borrow() .clear(screen_size_in_pixels, clear_color); From bf2bf28aebc1f12ebece2a7efcd46eadf97eaea8 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Tue, 21 May 2024 20:38:29 +0900 Subject: [PATCH 7/9] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index f939f0eaa55..69782147a1c 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -526,7 +526,6 @@ impl GlowWinitRunning { let mut glutin = self.glutin.borrow_mut(); let original_viewport = &glutin.viewports[&viewport_id]; - // This will only happens when a Immediate Viewport. if original_viewport.class == ViewportClass::Immediate { let Some(parent_viewport) = glutin.viewports.get(&original_viewport.ids.parent) else { From 69f9be28e253adc385275e305b4b023509e7b31e Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Tue, 21 May 2024 20:39:20 +0900 Subject: [PATCH 8/9] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 37e16479e07..87efe0e2fe4 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -559,7 +559,6 @@ impl WgpuWinitRunning { return EventResult::Wait; }; - // This will only happens when a Immediate Viewport. if original_viewport.class == ViewportClass::Immediate { let Some(parent_viewport) = viewports.get(&original_viewport.ids.parent) else { return EventResult::Wait; From 79d179a27ab6d13e4a5ca76ccc3131a0cc9c1429 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Wed, 12 Jun 2024 17:56:05 +0900 Subject: [PATCH 9/9] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 69782147a1c..dd67148aa3f 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -866,22 +866,24 @@ fn change_gl_context( ) { crate::profile_function!(); - let Some(p_current_gl_context) = current_gl_context.take() else { - return; - }; - if !cfg!(target_os = "windows") { // According to https://github.com/emilk/egui/issues/4289 // we cannot do this early-out on Windows. // TODO(emilk): optimize context switching on Windows too. // See https://github.com/emilk/egui/issues/4173 - crate::profile_scope!("is_current"); - if gl_surface.is_current(&p_current_gl_context) { - return; // Early-out to save a lot of time. + if let Some(current_gl_context) = current_gl_context { + crate::profile_scope!("is_current"); + if gl_surface.is_current(current_gl_context) { + return; // Early-out to save a lot of time. + } } } + let Some(p_current_gl_context) = current_gl_context.take() else { + return; + }; + crate::profile_scope!("make_not_current"); let Ok(not_current) = p_current_gl_context.make_not_current() else { return;