CI / core (push) Successful in 1m37s
GPUI's vsync thread invalidates the window at every vsync, minimised too, and each WM_PAINT went through GPUI, which has no frame to draw then, and DefWindowProc: the UI thread spent more minimised than visible (budget 3). A subclass validates the paint while the window is iconic. On the manual checks machine (240 Hz), minimised: 3.03 % of one core before, 0.22 % after; the window draws again on restore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0192He3DgZBggc9wJG9c1nqA
45 lines
1.7 KiB
Rust
45 lines
1.7 KiB
Rust
//! A minimised window draws nothing, yet GPUI's vsync thread invalidates it at each vsync, and
|
|
//! each WM_PAINT went through GPUI, which has no frame to draw while minimised, then
|
|
//! DefWindowProc: the UI thread spent more minimised than visible (budget 3,
|
|
//! `docs/performance.md`). The paint is validated here instead, before GPUI sees it.
|
|
|
|
use gpui_kit::Window;
|
|
use windows::Win32::Foundation::{HWND, LPARAM, LRESULT, WPARAM};
|
|
use windows::Win32::Graphics::Gdi::ValidateRect;
|
|
use windows::Win32::UI::Shell::{DefSubclassProc, RemoveWindowSubclass, SetWindowSubclass};
|
|
use windows::Win32::UI::WindowsAndMessaging::{IsIconic, WM_NCDESTROY, WM_PAINT};
|
|
|
|
use crate::tray::window_hwnd;
|
|
|
|
/// Subclass ids are per procedure.
|
|
const MINIMIZED_SUBCLASS: usize = 0;
|
|
|
|
pub(crate) fn skip_paint_while_minimized(window: &Window) {
|
|
if let Some(hwnd) = window_hwnd(window) {
|
|
// Without the subclass, GPUI handles these paints as before.
|
|
let _ = unsafe { SetWindowSubclass(hwnd, Some(paint_proc), MINIMIZED_SUBCLASS, 0) };
|
|
}
|
|
}
|
|
|
|
unsafe extern "system" fn paint_proc(
|
|
hwnd: HWND,
|
|
message: u32,
|
|
wparam: WPARAM,
|
|
lparam: LPARAM,
|
|
_id: usize,
|
|
_data: usize,
|
|
) -> LRESULT {
|
|
match message {
|
|
// GPUI gives its frame callback back at the restore's WM_SIZE, and draws then.
|
|
WM_PAINT if unsafe { IsIconic(hwnd) }.as_bool() => {
|
|
let _ = unsafe { ValidateRect(Some(hwnd), None) };
|
|
return LRESULT(0);
|
|
}
|
|
WM_NCDESTROY => {
|
|
let _ = unsafe { RemoveWindowSubclass(hwnd, Some(paint_proc), MINIMIZED_SUBCLASS) };
|
|
}
|
|
_ => {}
|
|
}
|
|
unsafe { DefSubclassProc(hwnd, message, wparam, lparam) }
|
|
}
|