Reduce redundant resize repaint passes

This commit is contained in:
2026-04-13 23:38:45 +08:00
parent 0d6b8bf7d8
commit d705cc839b
3 changed files with 17 additions and 9 deletions

View File

@@ -957,6 +957,7 @@ LRESULT CALLBACK Application::WndProc(HWND hwnd, UINT message, WPARAM wParam, LP
Application* application = Host::WindowMessageDispatcher::GetApplicationFromWindow(hwnd); Application* application = Host::WindowMessageDispatcher::GetApplicationFromWindow(hwnd);
if (application != nullptr && if (application != nullptr &&
Host::WindowMessageDispatcher::TryDispatch( Host::WindowMessageDispatcher::TryDispatch(
hwnd,
*application, *application,
message, message,
wParam, wParam,

View File

@@ -45,11 +45,23 @@ bool WindowMessageDispatcher::TryHandleNonClientCreate(
} }
bool WindowMessageDispatcher::TryDispatch( bool WindowMessageDispatcher::TryDispatch(
HWND hwnd,
Application& application, Application& application,
UINT message, UINT message,
WPARAM wParam, WPARAM wParam,
LPARAM lParam, LPARAM lParam,
LRESULT& outResult) { LRESULT& outResult) {
const auto renderAndValidateWindow = [&application, hwnd]() {
if (!application.m_renderReady) {
return;
}
application.RenderFrame();
if (hwnd != nullptr && IsWindow(hwnd)) {
ValidateRect(hwnd, nullptr);
}
};
switch (message) { switch (message) {
case WM_SETCURSOR: case WM_SETCURSOR:
if (LOWORD(lParam) == HTCLIENT && application.ApplyCurrentCursor()) { if (LOWORD(lParam) == HTCLIENT && application.ApplyCurrentCursor()) {
@@ -64,9 +76,7 @@ bool WindowMessageDispatcher::TryDispatch(
application.OnDpiChanged( application.OnDpiChanged(
static_cast<UINT>(LOWORD(wParam)), static_cast<UINT>(LOWORD(wParam)),
*reinterpret_cast<const RECT*>(lParam)); *reinterpret_cast<const RECT*>(lParam));
if (application.m_renderReady) { renderAndValidateWindow();
application.RenderFrame();
}
outResult = 0; outResult = 0;
return true; return true;
case WM_ENTERSIZEMOVE: case WM_ENTERSIZEMOVE:
@@ -75,9 +85,7 @@ bool WindowMessageDispatcher::TryDispatch(
return true; return true;
case WM_EXITSIZEMOVE: case WM_EXITSIZEMOVE:
application.OnExitSizeMove(); application.OnExitSizeMove();
if (application.m_renderReady) { renderAndValidateWindow();
application.RenderFrame();
}
outResult = 0; outResult = 0;
return true; return true;
case WM_SIZE: case WM_SIZE:
@@ -85,9 +93,7 @@ bool WindowMessageDispatcher::TryDispatch(
application.OnResize( application.OnResize(
static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(LOWORD(lParam)),
static_cast<UINT>(HIWORD(lParam))); static_cast<UINT>(HIWORD(lParam)));
if (application.m_renderReady) { renderAndValidateWindow();
application.RenderFrame();
}
} }
outResult = 0; outResult = 0;
return true; return true;

View File

@@ -21,6 +21,7 @@ public:
LPARAM lParam, LPARAM lParam,
LRESULT& outResult); LRESULT& outResult);
static bool TryDispatch( static bool TryDispatch(
HWND hwnd,
Application& application, Application& application,
UINT message, UINT message,
WPARAM wParam, WPARAM wParam,