1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Improved scheduling for overlay updates

This commit is contained in:
narzoul 2022-12-03 12:32:19 +01:00
parent 08d3b95afd
commit 2b8805d9ef
8 changed files with 36 additions and 29 deletions

View File

@ -55,6 +55,7 @@ namespace
Compat::CriticalSection g_presentCs; Compat::CriticalSection g_presentCs;
bool g_isDelayedFlipPending = false; bool g_isDelayedFlipPending = false;
bool g_isOverlayUpdatePending = false;
bool g_isUpdatePending = false; bool g_isUpdatePending = false;
bool g_isUpdateReady = false; bool g_isUpdateReady = false;
DWORD g_lastUpdateThreadId = 0; DWORD g_lastUpdateThreadId = 0;
@ -304,6 +305,7 @@ namespace
} }
Compat::ScopedCriticalSection lock(g_presentCs); Compat::ScopedCriticalSection lock(g_presentCs);
g_isOverlayUpdatePending = false;
g_isUpdatePending = false; g_isUpdatePending = false;
g_isUpdateReady = false; g_isUpdateReady = false;
g_qpcLastUpdate = Time::queryPerformanceCounter() - Time::msToQpc(DELAYED_FLIP_MODE_TIMEOUT_MS); g_qpcLastUpdate = Time::queryPerformanceCounter() - Time::msToQpc(DELAYED_FLIP_MODE_TIMEOUT_MS);
@ -357,6 +359,7 @@ namespace
{ {
{ {
Compat::ScopedCriticalSection lock(g_presentCs); Compat::ScopedCriticalSection lock(g_presentCs);
g_isOverlayUpdatePending = false;
g_isUpdatePending = false; g_isUpdatePending = false;
g_isUpdateReady = false; g_isUpdateReady = false;
} }
@ -533,18 +536,16 @@ namespace DDraw
PrimarySurface::waitForIdle(); PrimarySurface::waitForIdle();
Compat::ScopedCriticalSection lock(g_presentCs); Compat::ScopedCriticalSection lock(g_presentCs);
g_isDelayedFlipPending = true; g_isDelayedFlipPending = true;
g_isOverlayUpdatePending = false;
g_isUpdatePending = false; g_isUpdatePending = false;
g_isUpdateReady = false; g_isUpdateReady = false;
g_lastUpdateThreadId = GetCurrentThreadId(); g_lastUpdateThreadId = GetCurrentThreadId();
} }
else else
{ {
auto statsWindow = Gdi::GuiThread::getStatsWindow(); D3dDdi::KernelModeThunks::waitForVsyncCounter(g_presentEndVsyncCount);
if (statsWindow && statsWindow->isVisible()) g_isUpdateReady = true;
{ flush();
statsWindow->updateStats();
}
updateNow(PrimarySurface::getPrimary());
} }
g_flipEndVsyncCount = D3dDdi::KernelModeThunks::getVsyncCounter() + flipInterval; g_flipEndVsyncCount = D3dDdi::KernelModeThunks::getVsyncCounter() + flipInterval;
@ -570,10 +571,18 @@ namespace DDraw
return -1; return -1;
} }
auto statsWindow = Gdi::GuiThread::getStatsWindow(); static UINT lastOverlayCheckVsyncCount = 0;
if (statsWindow && statsWindow->isVisible()) if (vsyncCount != lastOverlayCheckVsyncCount)
{ {
statsWindow->updateStats(); Gdi::Cursor::update();
Gdi::Caret::blink();
auto statsWindow = Gdi::GuiThread::getStatsWindow();
if (statsWindow && statsWindow->isVisible())
{
statsWindow->updateStats();
g_qpcLastUpdate = Time::queryPerformanceCounter();
}
lastOverlayCheckVsyncCount = vsyncCount;
} }
{ {
@ -599,6 +608,11 @@ namespace DDraw
g_isDelayedFlipPending = false; g_isDelayedFlipPending = false;
g_isUpdateReady = true; g_isUpdateReady = true;
} }
else if (g_isOverlayUpdatePending)
{
g_qpcLastUpdate = Time::queryPerformanceCounter();
g_isUpdateReady = true;
}
} }
if (!g_isUpdateReady) if (!g_isUpdateReady)
@ -727,6 +741,12 @@ namespace DDraw
return create(*CompatPtr<IDirectDraw>::from(dd.get())); return create(*CompatPtr<IDirectDraw>::from(dd.get()));
} }
void RealPrimarySurface::scheduleOverlayUpdate()
{
Compat::ScopedCriticalSection lock(g_presentCs);
g_isOverlayUpdatePending = true;
}
void RealPrimarySurface::scheduleUpdate() void RealPrimarySurface::scheduleUpdate()
{ {
Compat::ScopedCriticalSection lock(g_presentCs); Compat::ScopedCriticalSection lock(g_presentCs);

View File

@ -27,6 +27,7 @@ namespace DDraw
static bool isLost(); static bool isLost();
static void release(); static void release();
static HRESULT restore(); static HRESULT restore();
static void scheduleOverlayUpdate();
static void scheduleUpdate(); static void scheduleUpdate();
static HRESULT setGammaRamp(DDGAMMARAMP* rampData); static HRESULT setGammaRamp(DDGAMMARAMP* rampData);
static void setUpdateReady(); static void setUpdateReady();

View File

@ -235,7 +235,7 @@ namespace Gdi
(cursorInfo.hCursor != g_prevCursorInfo.hCursor || cursorInfo.ptScreenPos != g_prevCursorInfo.ptScreenPos)) (cursorInfo.hCursor != g_prevCursorInfo.hCursor || cursorInfo.ptScreenPos != g_prevCursorInfo.ptScreenPos))
{ {
g_prevCursorInfo = cursorInfo; g_prevCursorInfo = cursorInfo;
DDraw::RealPrimarySurface::scheduleUpdate(); DDraw::RealPrimarySurface::scheduleOverlayUpdate();
} }
} }
} }

View File

@ -6,8 +6,6 @@
#include <D3dDdi/ScopedCriticalSection.h> #include <D3dDdi/ScopedCriticalSection.h>
#include <Dll/Dll.h> #include <Dll/Dll.h>
#include <DDraw/RealPrimarySurface.h> #include <DDraw/RealPrimarySurface.h>
#include <Gdi/Caret.h>
#include <Gdi/Cursor.h>
#include <Gdi/GuiThread.h> #include <Gdi/GuiThread.h>
#include <Gdi/Region.h> #include <Gdi/Region.h>
#include <Gdi/WinProc.h> #include <Gdi/WinProc.h>
@ -101,16 +99,6 @@ namespace
return 0; return 0;
} }
unsigned WINAPI updateThreadProc(LPVOID /*lpParameter*/)
{
while (true)
{
Sleep(5);
Gdi::Caret::blink();
Gdi::Cursor::update();
}
}
} }
namespace Gdi namespace Gdi
@ -194,7 +182,6 @@ namespace Gdi
void start() void start()
{ {
Dll::createThread(messageWindowThreadProc, &g_threadId, THREAD_PRIORITY_TIME_CRITICAL, 0); Dll::createThread(messageWindowThreadProc, &g_threadId, THREAD_PRIORITY_TIME_CRITICAL, 0);
Dll::createThread(updateThreadProc, nullptr, THREAD_PRIORITY_TIME_CRITICAL, 0);
} }
} }
} }

View File

@ -521,7 +521,7 @@ namespace
BOOL result = CALL_ORIG_FUNC(SetLayeredWindowAttributes)(hwnd, crKey, bAlpha, dwFlags); BOOL result = CALL_ORIG_FUNC(SetLayeredWindowAttributes)(hwnd, crKey, bAlpha, dwFlags);
if (result && DDraw::RealPrimarySurface::isFullscreen()) if (result && DDraw::RealPrimarySurface::isFullscreen())
{ {
DDraw::RealPrimarySurface::scheduleUpdate(); DDraw::RealPrimarySurface::scheduleOverlayUpdate();
} }
return LOG_RESULT(result); return LOG_RESULT(result);
} }

View File

@ -58,7 +58,7 @@ namespace
} }
case WM_WINDOWPOSCHANGED: case WM_WINDOWPOSCHANGED:
DDraw::RealPrimarySurface::scheduleUpdate(); DDraw::RealPrimarySurface::scheduleOverlayUpdate();
break; break;
} }
@ -121,6 +121,7 @@ namespace
cp.x = min(max(g_monitorRect.left, cp.x), g_monitorRect.right); cp.x = min(max(g_monitorRect.left, cp.x), g_monitorRect.right);
cp.y = min(max(g_monitorRect.top, cp.y), g_monitorRect.bottom); cp.y = min(max(g_monitorRect.top, cp.y), g_monitorRect.bottom);
g_cursorPos = cp; g_cursorPos = cp;
DDraw::RealPrimarySurface::scheduleOverlayUpdate();
} }
auto cp = getRelativeCursorPos(); auto cp = getRelativeCursorPos();
@ -140,7 +141,6 @@ namespace
break; break;
} }
DDraw::RealPrimarySurface::scheduleUpdate();
return 1; return 1;
} }
return CallNextHookEx(nullptr, nCode, wParam, lParam); return CallNextHookEx(nullptr, nCode, wParam, lParam);

View File

@ -155,7 +155,6 @@ namespace Overlay
if (m_parent && (m_style & WS_TABSTOP)) if (m_parent && (m_style & WS_TABSTOP))
{ {
m_parent->m_highlightedChild = this; m_parent->m_highlightedChild = this;
invalidate();
} }
} }

View File

@ -106,7 +106,7 @@ namespace Overlay
void Window::invalidate() void Window::invalidate()
{ {
m_invalid = true; m_invalid = true;
DDraw::RealPrimarySurface::scheduleUpdate(); DDraw::RealPrimarySurface::scheduleOverlayUpdate();
} }
void Window::setTransparency(int transparency) void Window::setTransparency(int transparency)
@ -136,7 +136,7 @@ namespace Overlay
} }
ShowWindow(m_hwnd, SW_HIDE); ShowWindow(m_hwnd, SW_HIDE);
} }
DDraw::RealPrimarySurface::scheduleUpdate(); DDraw::RealPrimarySurface::scheduleOverlayUpdate();
} }
LRESULT CALLBACK Window::staticWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK Window::staticWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)