From 111719eaf799156540c3744836a5796fafa82cda Mon Sep 17 00:00:00 2001 From: narzoul Date: Sat, 16 Apr 2016 15:59:05 +0200 Subject: [PATCH] Removed unnecessary GDI redraws when GDI emulation is disabled --- DDrawCompat/CompatGdi.cpp | 17 +++++++++++++++-- DDrawCompat/CompatGdi.h | 1 + DDrawCompat/CompatGdiDcFunctions.cpp | 5 ++--- DDrawCompat/CompatGdiScrollFunctions.cpp | 5 ++++- DDrawCompat/CompatGdiWinProc.cpp | 17 +++++++++++++++-- 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/DDrawCompat/CompatGdi.cpp b/DDrawCompat/CompatGdi.cpp index a47c106..3e429c1 100644 --- a/DDrawCompat/CompatGdi.cpp +++ b/DDrawCompat/CompatGdi.cpp @@ -130,7 +130,7 @@ namespace CompatGdi bool beginGdiRendering() { - if (!RealPrimarySurface::isFullScreen()) + if (!isEmulationEnabled()) { return false; } @@ -233,11 +233,24 @@ namespace CompatGdi void invalidate(const RECT* rect) { - EnumWindows(&invalidateWindow, reinterpret_cast(rect)); + if (isEmulationEnabled()) + { + EnumWindows(&invalidateWindow, reinterpret_cast(rect)); + } + } + + bool isEmulationEnabled() + { + return RealPrimarySurface::isFullScreen(); } void updatePalette(DWORD startingEntry, DWORD count) { + if (!isEmulationEnabled()) + { + return; + } + Compat::ScopedCriticalSection gdiLock(g_gdiCriticalSection); CompatGdiDcCache::clear(); diff --git a/DDrawCompat/CompatGdi.h b/DDrawCompat/CompatGdi.h index 7cc68ba..ddddc8e 100644 --- a/DDrawCompat/CompatGdi.h +++ b/DDrawCompat/CompatGdi.h @@ -12,6 +12,7 @@ namespace CompatGdi void hookWndProc(LPCSTR className, WNDPROC &oldWndProc, WNDPROC newWndProc); void installHooks(); void invalidate(const RECT* rect); + bool isEmulationEnabled(); void updatePalette(DWORD startingEntry, DWORD count); extern CRITICAL_SECTION g_gdiCriticalSection; diff --git a/DDrawCompat/CompatGdiDcFunctions.cpp b/DDrawCompat/CompatGdiDcFunctions.cpp index e3319a5..9a21025 100644 --- a/DDrawCompat/CompatGdiDcFunctions.cpp +++ b/DDrawCompat/CompatGdiDcFunctions.cpp @@ -5,7 +5,6 @@ #include "CompatGdiDcFunctions.h" #include "DDrawLog.h" #include "Hook.h" -#include "RealPrimarySurface.h" namespace { @@ -77,9 +76,9 @@ namespace { Compat::Log() << "Skipping redirection since there is no display DC argument"; } - else if (!RealPrimarySurface::isFullScreen()) + else if (!CompatGdi::isEmulationEnabled()) { - Compat::Log() << "Skipping redirection due to windowed mode"; + Compat::Log() << "Skipping redirection since GDI emulation is disabled"; } else { diff --git a/DDrawCompat/CompatGdiScrollFunctions.cpp b/DDrawCompat/CompatGdiScrollFunctions.cpp index c74493a..edb7d3f 100644 --- a/DDrawCompat/CompatGdiScrollFunctions.cpp +++ b/DDrawCompat/CompatGdiScrollFunctions.cpp @@ -58,6 +58,9 @@ namespace CompatGdiScrollFunctions void updateScrolledWindow(HWND hwnd) { - RedrawWindow(hwnd, nullptr, nullptr, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_NOCHILDREN); + if (CompatGdi::isEmulationEnabled()) + { + RedrawWindow(hwnd, nullptr, nullptr, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_NOCHILDREN); + } } } diff --git a/DDrawCompat/CompatGdiWinProc.cpp b/DDrawCompat/CompatGdiWinProc.cpp index 692722d..89b1d6d 100644 --- a/DDrawCompat/CompatGdiWinProc.cpp +++ b/DDrawCompat/CompatGdiWinProc.cpp @@ -121,6 +121,11 @@ namespace void onActivate(HWND hwnd) { + if (!CompatGdi::isEmulationEnabled()) + { + return; + } + RECT windowRect = {}; GetWindowRect(hwnd, &windowRect); RECT clientRect = {}; @@ -139,6 +144,11 @@ namespace void onMenuSelect() { + if (!CompatGdi::isEmulationEnabled()) + { + return; + } + HWND menuWindow = FindWindow(reinterpret_cast(0x8000), nullptr); while (menuWindow) { @@ -159,8 +169,11 @@ namespace if (IsWindowVisible(hwnd)) { - GetWindowRect(hwnd, it != g_prevWindowRect.end() ? &it->second : &g_prevWindowRect[hwnd]); - RedrawWindow(hwnd, nullptr, nullptr, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN); + if (CompatGdi::isEmulationEnabled()) + { + GetWindowRect(hwnd, it != g_prevWindowRect.end() ? &it->second : &g_prevWindowRect[hwnd]); + RedrawWindow(hwnd, nullptr, nullptr, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN); + } } else if (it != g_prevWindowRect.end()) {