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

Add more profiling scopes #3332

Merged
merged 1 commit into from
Sep 13, 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
5 changes: 5 additions & 0 deletions crates/eframe/src/native/app_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 21 additions & 5 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, .. } => {
Expand Down