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

Fixed flickering mouse cursor in Icewind Dale 2

This commit is contained in:
narzoul 2021-05-15 16:06:26 +02:00
parent 9fa1a8a047
commit 359256660e
4 changed files with 15 additions and 7 deletions

View File

@ -1,3 +1,4 @@
#include <atomic>
#include <string>
#include <Common/Log.h>
@ -31,6 +32,7 @@ namespace
Compat::SrwLock g_lastOpenAdapterInfoSrwLock;
std::string g_lastDDrawCreateDcDevice;
std::atomic<long long> g_qpcLastVsync = 0;
UINT g_vsyncCounter = 0;
CONDITION_VARIABLE g_vsyncCounterCv = CONDITION_VARIABLE_INIT;
Compat::SrwLock g_vsyncCounterSrwLock;
@ -235,6 +237,7 @@ namespace
while (true)
{
waitForVerticalBlank();
g_qpcLastVsync = Time::queryPerformanceCounter();
{
Compat::ScopedSrwLockExclusive lock(g_vsyncCounterSrwLock);
@ -298,6 +301,11 @@ namespace D3dDdi
return g_lastOpenAdapterInfo.monitorRect;
}
long long getQpcLastVsync()
{
return g_qpcLastVsync;
}
UINT getVsyncCounter()
{
Compat::ScopedSrwLockShared lock(g_vsyncCounterSrwLock);

View File

@ -7,6 +7,7 @@ namespace D3dDdi
namespace KernelModeThunks
{
RECT getMonitorRect();
long long getQpcLastVsync();
UINT getVsyncCounter();
void installHooks();
void setDcFormatOverride(UINT format);

View File

@ -396,7 +396,7 @@ namespace D3dDdi
{
surfaceInfo[i].Width = m_fixedData.pSurfList[i].Width;
surfaceInfo[i].Height = m_fixedData.pSurfList[i].Height;
surfaceInfo[i].SysMemPitch = (surfaceInfo[i].Width * m_formatInfo.bytesPerPixel + 7) & ~7;
surfaceInfo[i].SysMemPitch = (surfaceInfo[i].Width * m_formatInfo.bytesPerPixel + 3) & ~3;
if (i != 0)
{
std::uintptr_t offset = reinterpret_cast<std::uintptr_t>(surfaceInfo[i - 1].pSysMem) +

View File

@ -36,7 +36,6 @@ namespace
bool g_isUpdatePending = false;
bool g_waitingForPrimaryUnlock = false;
std::atomic<long long> g_qpcLastUpdate = 0;
long long g_qpcFlipEnd = 0;
UINT g_flipEndVsyncCount = 0;
UINT g_presentEndVsyncCount = 0;
@ -228,7 +227,10 @@ namespace
DDraw::ScopedThreadLock lock;
if (g_isUpdatePending && !isPresentPending())
{
if (Time::qpcToMs(Time::queryPerformanceCounter() - g_qpcFlipEnd) < 1)
auto qpcNow = Time::queryPerformanceCounter();
auto qpcLastVsync = D3dDdi::KernelModeThunks::getQpcLastVsync();
if (Time::qpcToMs(qpcNow - qpcLastVsync) < 1 ||
Time::qpcToMs(qpcNow - g_qpcLastUpdate) < 1 && Time::qpcToMs(qpcNow - qpcLastVsync) <= 3)
{
skipWaitForVsync = true;
}
@ -429,10 +431,7 @@ namespace DDraw
return !isFlipPending();
}
if (D3dDdi::KernelModeThunks::waitForVsyncCounter(g_flipEndVsyncCount))
{
g_qpcFlipEnd = Time::queryPerformanceCounter();
}
D3dDdi::KernelModeThunks::waitForVsyncCounter(g_flipEndVsyncCount);
return true;
}
}