@@ -493,6 +493,9 @@ impl GlowWinitRunning {
493
493
#[ cfg( feature = "puffin" ) ]
494
494
puffin:: GlobalProfiler :: lock ( ) . new_frame ( ) ;
495
495
496
+ let mut frame_timer = crate :: stopwatch:: Stopwatch :: new ( ) ;
497
+ frame_timer. start ( ) ;
498
+
496
499
{
497
500
let glutin = self . glutin . borrow ( ) ;
498
501
let viewport = & glutin. viewports [ & viewport_id] ;
@@ -556,7 +559,11 @@ impl GlowWinitRunning {
556
559
557
560
let screen_size_in_pixels: [ u32 ; 2 ] = window. inner_size ( ) . into ( ) ;
558
561
559
- change_gl_context ( current_gl_context, gl_surface) ;
562
+ {
563
+ frame_timer. pause ( ) ;
564
+ change_gl_context ( current_gl_context, gl_surface) ;
565
+ frame_timer. resume ( ) ;
566
+ }
560
567
561
568
self . painter
562
569
. borrow ( )
@@ -600,17 +607,20 @@ impl GlowWinitRunning {
600
607
601
608
let viewport = viewports. get_mut ( & viewport_id) . unwrap ( ) ;
602
609
viewport. info . events . clear ( ) ; // they should have been processed
603
- let window = viewport. window . as_ref ( ) . unwrap ( ) ;
610
+ let window = viewport. window . clone ( ) . unwrap ( ) ;
604
611
let gl_surface = viewport. gl_surface . as_ref ( ) . unwrap ( ) ;
605
612
let egui_winit = viewport. egui_winit . as_mut ( ) . unwrap ( ) ;
606
613
607
- integration. post_update ( ) ;
608
- egui_winit. handle_platform_output ( window, platform_output) ;
614
+ egui_winit. handle_platform_output ( & window, platform_output) ;
609
615
610
616
let clipped_primitives = integration. egui_ctx . tessellate ( shapes, pixels_per_point) ;
611
617
612
- // We may need to switch contexts again, because of immediate viewports:
613
- change_gl_context ( current_gl_context, gl_surface) ;
618
+ {
619
+ // We may need to switch contexts again, because of immediate viewports:
620
+ frame_timer. pause ( ) ;
621
+ change_gl_context ( current_gl_context, gl_surface) ;
622
+ frame_timer. resume ( ) ;
623
+ }
614
624
615
625
let screen_size_in_pixels: [ u32 ; 2 ] = window. inner_size ( ) . into ( ) ;
616
626
@@ -637,10 +647,12 @@ impl GlowWinitRunning {
637
647
image : screenshot. into ( ) ,
638
648
} ) ;
639
649
}
640
- integration. post_rendering ( window) ;
650
+ integration. post_rendering ( & window) ;
641
651
}
642
652
643
653
{
654
+ // vsync - don't count as frame-time:
655
+ frame_timer. pause ( ) ;
644
656
crate :: profile_scope!( "swap_buffers" ) ;
645
657
if let Err ( err) = gl_surface. swap_buffers (
646
658
current_gl_context
@@ -649,6 +661,7 @@ impl GlowWinitRunning {
649
661
) {
650
662
log:: error!( "swap_buffers failed: {err}" ) ;
651
663
}
664
+ frame_timer. resume ( ) ;
652
665
}
653
666
654
667
// give it time to settle:
@@ -659,7 +672,11 @@ impl GlowWinitRunning {
659
672
}
660
673
}
661
674
662
- integration. maybe_autosave ( app. as_mut ( ) , Some ( window) ) ;
675
+ glutin. handle_viewport_output ( event_loop, & integration. egui_ctx , viewport_output) ;
676
+
677
+ integration. report_frame_time ( frame_timer. total_time_sec ( ) ) ; // don't count auto-save time as part of regular frame time
678
+
679
+ integration. maybe_autosave ( app. as_mut ( ) , Some ( & window) ) ;
663
680
664
681
if window. is_minimized ( ) == Some ( true ) {
665
682
// On Mac, a minimized Window uses up all CPU:
@@ -668,8 +685,6 @@ impl GlowWinitRunning {
668
685
std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) ;
669
686
}
670
687
671
- glutin. handle_viewport_output ( event_loop, & integration. egui_ctx , viewport_output) ;
672
-
673
688
if integration. should_close ( ) {
674
689
EventResult :: Exit
675
690
} else {
0 commit comments