From fa69ef4a174782488f51341f454679597bb58ebc Mon Sep 17 00:00:00 2001 From: narzoul Date: Sun, 28 Feb 2016 17:40:50 +0100 Subject: [PATCH] Improved debug logging of GDI function calls and window messages --- DDrawCompat/CompatGdiFunctions.cpp | 29 ++++++++++++++++++++++++----- DDrawCompat/CompatGdiWinProc.cpp | 8 ++++++-- DDrawCompat/DDrawLog.cpp | 8 ++++++++ DDrawCompat/DDrawLog.h | 1 + DDrawCompat/RealPrimarySurface.cpp | 2 +- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/DDrawCompat/CompatGdiFunctions.cpp b/DDrawCompat/CompatGdiFunctions.cpp index e7126a8..66fdfe1 100644 --- a/DDrawCompat/CompatGdiFunctions.cpp +++ b/DDrawCompat/CompatGdiFunctions.cpp @@ -2,6 +2,7 @@ #include "CompatGdiDc.h" #include "CompatGdiFunctions.h" #include "DDrawLog.h" +#include "RealPrimarySurface.h" #include @@ -57,15 +58,33 @@ namespace template Result WINAPI compatGdiFunc(Params... params) { - if (!hasDisplayDcArg(params...) || !CompatGdi::beginGdiRendering()) - { - return CompatGdi::getOrigFuncPtr()(params...); - } - #ifdef _DEBUG Compat::LogEnter(CompatGdi::g_funcNames[origFunc], params...); #endif + if (!hasDisplayDcArg(params...) || !CompatGdi::beginGdiRendering()) + { + Result result = CompatGdi::getOrigFuncPtr()(params...); + +#ifdef _DEBUG + if (!hasDisplayDcArg(params...)) + { + Compat::Log() << "Skipping redirection since there is no display DC argument"; + } + else if (!RealPrimarySurface::isFullScreen()) + { + Compat::Log() << "Skipping redirection due to windowed mode"; + } + else + { + Compat::Log() << "Skipping redirection since the primary surface could not be locked"; + } + Compat::LogLeave(CompatGdi::g_funcNames[origFunc], params...) << result; +#endif + + return result; + } + Result result = CompatGdi::getOrigFuncPtr()(replaceDc(params)...); releaseDc(params...); CompatGdi::endGdiRendering(); diff --git a/DDrawCompat/CompatGdiWinProc.cpp b/DDrawCompat/CompatGdiWinProc.cpp index 634b55b..6392a43 100644 --- a/DDrawCompat/CompatGdiWinProc.cpp +++ b/DDrawCompat/CompatGdiWinProc.cpp @@ -25,9 +25,11 @@ namespace LRESULT CALLBACK callWndRetProc(int nCode, WPARAM wParam, LPARAM lParam) { + auto ret = reinterpret_cast(lParam); + Compat::LogEnter("callWndRetProc", nCode, wParam, ret); + if (HC_ACTION == nCode) { - auto ret = reinterpret_cast(lParam); if (WM_CREATE == ret->message) { disableDwmAttributes(ret->hwnd); @@ -75,7 +77,9 @@ namespace } } - return CallNextHookEx(nullptr, nCode, wParam, lParam); + LRESULT result = CallNextHookEx(nullptr, nCode, wParam, lParam); + Compat::LogLeave("callWndRetProc", nCode, wParam, ret) << result; + return result; } void disableDwmAttributes(HWND hwnd) diff --git a/DDrawCompat/DDrawLog.cpp b/DDrawCompat/DDrawLog.cpp index 06e29df..c25a4ba 100644 --- a/DDrawCompat/DDrawLog.cpp +++ b/DDrawCompat/DDrawLog.cpp @@ -72,6 +72,14 @@ std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2& sd) sd.lpSurface << "," << sd.ddpfPixelFormat << "," << sd.ddsCaps << "," << sd.dwTextureStage << ')'; } +std::ostream& operator<<(std::ostream& os, const CWPRETSTRUCT& cwrp) +{ + RECT wr = {}; + GetWindowRect(cwrp.hwnd, &wr); + return os << "CWRP(" << std::hex << cwrp.message << "," << cwrp.hwnd << ":" << std::dec << wr << "," << + std::hex << cwrp.wParam << "," << cwrp.lParam << "," << cwrp.lResult << std::dec << ")"; +} + namespace Compat { Log::Log() diff --git a/DDrawCompat/DDrawLog.h b/DDrawCompat/DDrawLog.h index 7e68ad3..5936e6b 100644 --- a/DDrawCompat/DDrawLog.h +++ b/DDrawCompat/DDrawLog.h @@ -21,6 +21,7 @@ std::ostream& operator<<(std::ostream& os, const DDSCAPS2& caps); std::ostream& operator<<(std::ostream& os, const DDPIXELFORMAT& pf); std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC& sd); std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2& sd); +std::ostream& operator<<(std::ostream& os, const CWPRETSTRUCT& cwrp); template typename std::enable_if::value && !std::is_same::value, std::ostream&>::type diff --git a/DDrawCompat/RealPrimarySurface.cpp b/DDrawCompat/RealPrimarySurface.cpp index 2c7baf3..1461728 100644 --- a/DDrawCompat/RealPrimarySurface.cpp +++ b/DDrawCompat/RealPrimarySurface.cpp @@ -55,7 +55,7 @@ namespace HDC converterDc = nullptr; origVtable.GetDC(g_paletteConverterSurface, &converterDc); - result = TRUE == BitBlt(destDc, 0, 0, + result = TRUE == CALL_ORIG_GDI(BitBlt)(destDc, 0, 0, RealPrimarySurface::s_surfaceDesc.dwWidth, RealPrimarySurface::s_surfaceDesc.dwHeight, converterDc, 0, 0, SRCCOPY);