Browse Source

Add more profiling scopes (#3332)

pull/3333/head
Emil Ernerfeldt 1 year ago
committed by GitHub
parent
commit
4b5146d35d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      crates/eframe/src/native/app_icon.rs
  2. 3
      crates/eframe/src/native/epi_integration.rs
  3. 26
      crates/eframe/src/native/run.rs
  4. 2
      crates/egui-winit/src/lib.rs

5
crates/eframe/src/native/app_icon.rs

@ -191,6 +191,8 @@ fn set_app_icon_windows(icon_data: &IconData) -> AppIconStatus {
#[cfg(target_os = "macos")]
#[allow(unsafe_code)]
fn set_title_and_icon_mac(title: &str, icon_data: Option<&IconData>) -> AppIconStatus {
crate::profile_function!();
use cocoa::{
appkit::{NSApp, NSApplication, NSImage, NSMenu, NSWindow},
base::{id, nil},
@ -221,12 +223,15 @@ fn set_title_and_icon_mac(title: &str, icon_data: Option<&IconData>) -> AppIconS
png_bytes.len() as u64,
);
let app_icon = NSImage::initWithData_(NSImage::alloc(nil), data);
crate::profile_scope!("setApplicationIconImage_");
app.setApplicationIconImage_(app_icon);
}
// Change the title in the top bar - for python processes this would be again "python" otherwise.
let main_menu = app.mainMenu();
let app_menu: id = msg_send![main_menu.itemAtIndex_(0), submenu];
crate::profile_scope!("setTitle_");
app_menu.setTitle_(NSString::alloc(nil).init_str(title));
// The title in the Dock apparently can't be changed.

3
crates/eframe/src/native/epi_integration.rs

@ -187,6 +187,7 @@ pub fn apply_native_options_to_window(
native_options: &crate::NativeOptions,
window_settings: Option<WindowSettings>,
) {
crate::profile_function!();
use winit::window::WindowLevel;
window.set_window_level(if native_options.always_on_top {
WindowLevel::AlwaysOnTop
@ -465,6 +466,8 @@ impl EpiIntegration {
app: &mut dyn epi::App,
event: &winit::event::WindowEvent<'_>,
) -> EventResponse {
crate::profile_function!();
use winit::event::{ElementState, MouseButton, WindowEvent};
match event {

26
crates/eframe/src/native/run.rs

@ -567,6 +567,8 @@ mod glow_integration {
/// we presently assume that we will
#[allow(unsafe_code)]
fn on_resume(&mut self, event_loop: &EventLoopWindowTarget<UserEvent>) -> Result<()> {
crate::profile_function!();
if self.gl_surface.is_some() {
log::warn!("on_resume called even thought we already have a surface. early return");
return Ok(());
@ -981,6 +983,8 @@ mod glow_integration {
event_loop: &EventLoopWindowTarget<UserEvent>,
event: &winit::event::Event<'_, UserEvent>,
) -> Result<EventResult> {
crate::profile_function!();
Ok(match event {
winit::event::Event::Resumed => {
// first resume event.
@ -1031,7 +1035,7 @@ mod glow_integration {
// Resize with 0 width and height is used by winit to signal a minimize event on Windows.
// See: https://github.com/rust-windowing/winit/issues/208
// This solves an issue where the app would panic when minimizing on Windows.
if physical_size.width > 0 && physical_size.height > 0 {
if 0 < physical_size.width && 0 < physical_size.height {
running.gl_window.resize(*physical_size);
}
}
@ -1069,11 +1073,13 @@ mod glow_integration {
EventResult::Wait
}
}
#[cfg(feature = "accesskit")]
winit::event::Event::UserEvent(UserEvent::AccessKitActionRequest(
accesskit_winit::ActionRequestEvent { request, .. },
)) => {
if let Some(running) = &mut self.running {
crate::profile_scope!("on_accesskit_action_request");
running
.integration
.on_accesskit_action_request(request.clone());
@ -1182,10 +1188,14 @@ mod wgpu_integration {
native_options: &NativeOptions,
) -> std::result::Result<winit::window::Window, winit::error::OsError> {
crate::profile_function!();
let window_settings = epi_integration::load_window_settings(storage);
let window_builder =
epi_integration::window_builder(event_loop, title, native_options, window_settings);
let window = window_builder.build(event_loop)?;
let window = {
crate::profile_scope!("WindowBuilder::build");
window_builder.build(event_loop)?
};
epi_integration::apply_native_options_to_window(
&window,
native_options,
@ -1278,7 +1288,7 @@ mod wgpu_integration {
let app_creator = std::mem::take(&mut self.app_creator)
.expect("Single-use AppCreator has unexpectedly already been taken");
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(),
@ -1287,7 +1297,11 @@ mod wgpu_integration {
wgpu_render_state,
raw_display_handle: window.raw_display_handle(),
raw_window_handle: window.raw_window_handle(),
});
};
let mut app = {
crate::profile_scope!("user_app_creator");
app_creator(&cc)
};
if app.warm_up_enabled() {
integration.warm_up(app.as_mut(), &window);
@ -1418,6 +1432,8 @@ mod wgpu_integration {
event_loop: &EventLoopWindowTarget<UserEvent>,
event: &winit::event::Event<'_, UserEvent>,
) -> Result<EventResult> {
crate::profile_function!();
Ok(match event {
winit::event::Event::Resumed => {
if let Some(running) = &self.running {
@ -1480,7 +1496,7 @@ mod wgpu_integration {
// Resize with 0 width and height is used by winit to signal a minimize event on Windows.
// See: https://github.com/rust-windowing/winit/issues/208
// This solves an issue where the app would panic when minimizing on Windows.
if physical_size.width > 0 && physical_size.height > 0 {
if 0 < physical_size.width && 0 < physical_size.height {
running.painter.on_window_resized(
physical_size.width,
physical_size.height,

2
crates/egui-winit/src/lib.rs

@ -190,6 +190,8 @@ impl State {
egui_ctx: &egui::Context,
event: &winit::event::WindowEvent<'_>,
) -> EventResponse {
crate::profile_function!();
use winit::event::WindowEvent;
match event {
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {

Loading…
Cancel
Save