From f12b95ec9f28ce1dcccc2fccafef85c95e9b9411 Mon Sep 17 00:00:00 2001 From: narzoul Date: Wed, 6 Apr 2016 20:57:15 +0200 Subject: [PATCH] Removed unnecessary GDI redraws --- DDrawCompat/CompatGdiPaintHandlers.cpp | 8 ++++- DDrawCompat/CompatGdiScrollFunctions.cpp | 19 +++++++++-- DDrawCompat/CompatGdiWinProc.cpp | 42 +----------------------- 3 files changed, 24 insertions(+), 45 deletions(-) diff --git a/DDrawCompat/CompatGdiPaintHandlers.cpp b/DDrawCompat/CompatGdiPaintHandlers.cpp index 8626224..e4a7865 100644 --- a/DDrawCompat/CompatGdiPaintHandlers.cpp +++ b/DDrawCompat/CompatGdiPaintHandlers.cpp @@ -2,6 +2,7 @@ #include "CompatGdiDc.h" #include "CompatGdiPaintHandlers.h" #include "CompatGdiScrollBar.h" +#include "CompatGdiScrollFunctions.h" #include "CompatGdiTitleBar.h" #include "CompatPaletteConverter.h" #include "CompatPrimarySurface.h" @@ -81,7 +82,12 @@ namespace LRESULT WINAPI editWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - return defPaintProc(hwnd, msg, wParam, lParam, g_origEditWndProc, "editWndProc"); + LRESULT result = defPaintProc(hwnd, msg, wParam, lParam, g_origEditWndProc, "editWndProc"); + if (0 == result && (WM_HSCROLL == msg || WM_VSCROLL == msg)) + { + CompatGdiScrollFunctions::updateScrolledWindow(hwnd); + } + return result; } LRESULT WINAPI listBoxWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) diff --git a/DDrawCompat/CompatGdiScrollFunctions.cpp b/DDrawCompat/CompatGdiScrollFunctions.cpp index 4c2536d..c74493a 100644 --- a/DDrawCompat/CompatGdiScrollFunctions.cpp +++ b/DDrawCompat/CompatGdiScrollFunctions.cpp @@ -1,5 +1,6 @@ #include "CompatGdi.h" #include "CompatGdiScrollFunctions.h" +#include "DDrawLog.h" #include "Hook.h" namespace @@ -11,8 +12,13 @@ namespace _In_ const RECT *lpRect, _In_ const RECT *lpClipRect) { + Compat::LogEnter("scrollWindow", hWnd, XAmount, YAmount, lpRect, lpClipRect); BOOL result = CALL_ORIG_FUNC(ScrollWindow)(hWnd, XAmount, YAmount, lpRect, lpClipRect); - CompatGdiScrollFunctions::updateScrolledWindow(hWnd); + if (result) + { + CompatGdiScrollFunctions::updateScrolledWindow(hWnd); + } + Compat::LogLeave("scrollWindow", hWnd, XAmount, YAmount, lpRect, lpClipRect) << result; return result; } @@ -26,9 +32,16 @@ namespace _Out_ LPRECT prcUpdate, _In_ UINT flags) { + Compat::LogEnter("scrollWindowEx", + hWnd, dx, dy, prcScroll, prcClip, hrgnUpdate, prcUpdate, flags); int result = CALL_ORIG_FUNC(ScrollWindowEx)( hWnd, dx, dy, prcScroll, prcClip, hrgnUpdate, prcUpdate, flags); - CompatGdiScrollFunctions::updateScrolledWindow(hWnd); + if (ERROR != result) + { + CompatGdiScrollFunctions::updateScrolledWindow(hWnd); + } + Compat::LogLeave("scrollWindowEx", + hWnd, dx, dy, prcScroll, prcClip, hrgnUpdate, prcUpdate, flags) << result; return result; } } @@ -45,6 +58,6 @@ namespace CompatGdiScrollFunctions void updateScrolledWindow(HWND hwnd) { - RedrawWindow(hwnd, nullptr, nullptr, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN); + RedrawWindow(hwnd, nullptr, nullptr, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_NOCHILDREN); } } diff --git a/DDrawCompat/CompatGdiWinProc.cpp b/DDrawCompat/CompatGdiWinProc.cpp index 95ae4c7..ae6e9c4 100644 --- a/DDrawCompat/CompatGdiWinProc.cpp +++ b/DDrawCompat/CompatGdiWinProc.cpp @@ -19,7 +19,6 @@ namespace void disableDwmAttributes(HWND hwnd); void onMenuSelect(); - void onScroll(HWND hwnd, HWND scrollBar); void onWindowPosChanged(HWND hwnd); void removeDropShadow(HWND hwnd); @@ -44,15 +43,10 @@ namespace { onWindowPosChanged(ret->hwnd); } - else if (WM_VSCROLL == ret->message || WM_HSCROLL == ret->message) - { - onScroll(ret->hwnd, reinterpret_cast(ret->lParam)); - } else if (WM_COMMAND == ret->message) { - auto msgSource = LOWORD(ret->wParam); auto notifCode = HIWORD(ret->wParam); - if (0 != msgSource && 1 != msgSource && (EN_HSCROLL == notifCode || EN_VSCROLL == notifCode)) + if (ret->lParam && (EN_HSCROLL == notifCode || EN_VSCROLL == notifCode)) { CompatGdiScrollFunctions::updateScrolledWindow(reinterpret_cast(ret->lParam)); } @@ -61,10 +55,6 @@ namespace { onMenuSelect(); } - else if (BM_SETSTYLE == ret->message) - { - RedrawWindow(ret->hwnd, nullptr, nullptr, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE); - } } LRESULT result = CallNextHookEx(nullptr, nCode, wParam, lParam); @@ -83,20 +73,6 @@ namespace &disableTransitions, sizeof(disableTransitions)); } - LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam) - { - if (HC_ACTION == nCode) - { - auto mhs = reinterpret_cast(lParam); - if (WM_MOUSEWHEEL == wParam || WM_MOUSEHWHEEL == wParam) - { - CompatGdiScrollFunctions::updateScrolledWindow(mhs->hwnd); - } - } - - return CallNextHookEx(nullptr, nCode, wParam, lParam); - } - void CALLBACK objectStateChangeEvent( HWINEVENTHOOK /*hWinEventHook*/, DWORD /*event*/, @@ -147,21 +123,6 @@ namespace } } - void onScroll(HWND hwnd, HWND scrollBar) - { - if (scrollBar) - { - UpdateWindow(scrollBar); - } - - CompatGdiScrollFunctions::updateScrolledWindow(hwnd); - - if (scrollBar) - { - ValidateRect(scrollBar, nullptr); - } - } - void onWindowPosChanged(HWND hwnd) { CompatGdi::GdiScopedThreadLock lock; @@ -199,7 +160,6 @@ namespace CompatGdiWinProc { const DWORD threadId = GetCurrentThreadId(); SetWindowsHookEx(WH_CALLWNDPROCRET, callWndRetProc, nullptr, threadId); - SetWindowsHookEx(WH_MOUSE, &mouseProc, nullptr, threadId); SetWinEventHook(EVENT_OBJECT_STATECHANGE, EVENT_OBJECT_STATECHANGE, nullptr, &objectStateChangeEvent, 0, threadId, WINEVENT_OUTOFCONTEXT); }