Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eframe: Remove warm-starting #3574

Merged
merged 1 commit into from
Nov 19, 2023
Merged
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
12 changes: 0 additions & 12 deletions crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 1 addition & 26 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down
29 changes: 5 additions & 24 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Window> {
self.viewport(viewport_id)
.window
Expand Down Expand Up @@ -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(),
Expand All @@ -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));
Expand Down Expand Up @@ -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);

Expand Down
11 changes: 0 additions & 11 deletions crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions crates/eframe/src/web/web_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

{
Expand Down
Loading