From 9713cafd3c31dbc34ccb07d174102ffa60f1972c Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 19 Nov 2023 11:09:42 +0100 Subject: [PATCH] eframe: Remove warm-starting --- crates/eframe/src/epi.rs | 12 --------- crates/eframe/src/native/epi_integration.rs | 27 +------------------ crates/eframe/src/native/run.rs | 29 ++++----------------- crates/eframe/src/web/app_runner.rs | 11 -------- crates/eframe/src/web/web_runner.rs | 3 +-- 5 files changed, 7 insertions(+), 75 deletions(-) diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index 8ee14657cb8..12e1664b7ab 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -212,18 +212,6 @@ pub trait App { fn persist_egui_memory(&self) -> bool { true } - - /// If `true` a warm-up call to [`Self::update`] will be issued where - /// `ctx.memory(|mem| mem.everything_is_visible())` will be set to `true`. - /// - /// This can help pre-caching resources loaded by different parts of the UI, preventing stutter later on. - /// - /// In this warm-up call, all painted shapes will be ignored. - /// - /// The default is `false`, and it is unlikely you will want to change this. - fn warm_up_enabled(&self) -> bool { - false - } } /// Selects the level of hardware graphics acceleration. diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 8b66510efc9..bace3f309cc 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -4,10 +4,7 @@ use winit::event_loop::EventLoopWindowTarget; use raw_window_handle::{HasRawDisplayHandle as _, HasRawWindowHandle as _}; -use egui::{ - DeferredViewportUiCallback, NumExt as _, ViewportBuilder, ViewportId, ViewportIdPair, - ViewportInfo, -}; +use egui::{DeferredViewportUiCallback, NumExt as _, ViewportBuilder, ViewportId}; use egui_winit::{EventResponse, WindowSettings}; use crate::{epi, Theme}; @@ -206,28 +203,6 @@ impl EpiIntegration { }); } - pub fn warm_up( - &mut self, - app: &mut dyn epi::App, - window: &winit::window::Window, - egui_winit: &mut egui_winit::State, - ) { - crate::profile_function!(); - let saved_memory: egui::Memory = self.egui_ctx.memory(|mem| mem.clone()); - self.egui_ctx - .memory_mut(|mem| mem.set_everything_is_visible(true)); - - let mut raw_input = egui_winit.take_egui_input(window, ViewportIdPair::ROOT); - raw_input.viewports = - std::iter::once((ViewportId::ROOT, ViewportInfo::default())).collect(); - self.pre_update(); - let full_output = self.update(app, None, raw_input); - self.post_update(); - self.pending_full_output.append(full_output); // Handle it next frame - self.egui_ctx.memory_mut(|mem| *mem = saved_memory); // We don't want to remember that windows were huge. - self.egui_ctx.clear_animations(); - } - /// If `true`, it is time to close the native window. pub fn should_close(&self) -> bool { self.close diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index e17b869ab28..cad2d6dcf05 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -1151,12 +1151,6 @@ mod glow_integration { .expect("viewport doesn't exist") } - fn viewport_mut(&mut self, viewport_id: ViewportId) -> &mut Viewport { - self.viewports - .get_mut(&viewport_id) - .expect("viewport doesn't exist") - } - fn window(&self, viewport_id: ViewportId) -> Rc { self.viewport(viewport_id) .window @@ -1488,7 +1482,7 @@ mod glow_integration { let app = { let window = glutin.window(ViewportId::ROOT); - let mut app = app_creator(&epi::CreationContext { + let cc = epi::CreationContext { egui_ctx: integration.egui_ctx.clone(), integration_info: integration.frame.info().clone(), storage: integration.frame.storage(), @@ -1497,18 +1491,9 @@ mod glow_integration { wgpu_render_state: None, raw_display_handle: window.raw_display_handle(), raw_window_handle: window.raw_window_handle(), - }); - - if app.warm_up_enabled() { - let viewport = glutin.viewport_mut(ViewportId::ROOT); - integration.warm_up( - app.as_mut(), - &window, - viewport.egui_winit.as_mut().unwrap(), - ); - } - - app + }; + crate::profile_scope!("app_creator"); + app_creator(&cc) }; let glutin = Rc::new(RefCell::new(glutin)); @@ -2124,15 +2109,11 @@ mod wgpu_integration { raw_display_handle: window.raw_display_handle(), raw_window_handle: window.raw_window_handle(), }; - let mut app = { + let app = { crate::profile_scope!("user_app_creator"); app_creator(&cc) }; - if app.warm_up_enabled() { - integration.warm_up(app.as_mut(), &window, &mut egui_winit); - } - let mut viewport_from_window = HashMap::default(); viewport_from_window.insert(window.id(), ViewportId::ROOT); diff --git a/crates/eframe/src/web/app_runner.rs b/crates/eframe/src/web/app_runner.rs index cca5397dced..00c3240e377 100644 --- a/crates/eframe/src/web/app_runner.rs +++ b/crates/eframe/src/web/app_runner.rs @@ -153,17 +153,6 @@ impl AppRunner { self.painter.canvas_id() } - pub fn warm_up(&mut self) { - if self.app.warm_up_enabled() { - let saved_memory: egui::Memory = self.egui_ctx.memory(|m| m.clone()); - self.egui_ctx - .memory_mut(|m| m.set_everything_is_visible(true)); - self.logic(); - self.egui_ctx.memory_mut(|m| *m = saved_memory); // We don't want to remember that windows were huge. - self.egui_ctx.clear_animations(); - } - } - pub fn destroy(mut self) { log::debug!("Destroying AppRunner"); self.painter.destroy(); diff --git a/crates/eframe/src/web/web_runner.rs b/crates/eframe/src/web/web_runner.rs index ff7ae377a9a..31ed1464670 100644 --- a/crates/eframe/src/web/web_runner.rs +++ b/crates/eframe/src/web/web_runner.rs @@ -58,8 +58,7 @@ impl WebRunner { let follow_system_theme = web_options.follow_system_theme; - let mut runner = AppRunner::new(canvas_id, web_options, app_creator).await?; - runner.warm_up(); + let runner = AppRunner::new(canvas_id, web_options, app_creator).await?; self.runner.replace(Some(runner)); {