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:
parent
9fa1a8a047
commit
359256660e
@ -1,3 +1,4 @@
|
|||||||
|
#include <atomic>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <Common/Log.h>
|
#include <Common/Log.h>
|
||||||
@ -31,6 +32,7 @@ namespace
|
|||||||
Compat::SrwLock g_lastOpenAdapterInfoSrwLock;
|
Compat::SrwLock g_lastOpenAdapterInfoSrwLock;
|
||||||
std::string g_lastDDrawCreateDcDevice;
|
std::string g_lastDDrawCreateDcDevice;
|
||||||
|
|
||||||
|
std::atomic<long long> g_qpcLastVsync = 0;
|
||||||
UINT g_vsyncCounter = 0;
|
UINT g_vsyncCounter = 0;
|
||||||
CONDITION_VARIABLE g_vsyncCounterCv = CONDITION_VARIABLE_INIT;
|
CONDITION_VARIABLE g_vsyncCounterCv = CONDITION_VARIABLE_INIT;
|
||||||
Compat::SrwLock g_vsyncCounterSrwLock;
|
Compat::SrwLock g_vsyncCounterSrwLock;
|
||||||
@ -235,6 +237,7 @@ namespace
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
waitForVerticalBlank();
|
waitForVerticalBlank();
|
||||||
|
g_qpcLastVsync = Time::queryPerformanceCounter();
|
||||||
|
|
||||||
{
|
{
|
||||||
Compat::ScopedSrwLockExclusive lock(g_vsyncCounterSrwLock);
|
Compat::ScopedSrwLockExclusive lock(g_vsyncCounterSrwLock);
|
||||||
@ -298,6 +301,11 @@ namespace D3dDdi
|
|||||||
return g_lastOpenAdapterInfo.monitorRect;
|
return g_lastOpenAdapterInfo.monitorRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long long getQpcLastVsync()
|
||||||
|
{
|
||||||
|
return g_qpcLastVsync;
|
||||||
|
}
|
||||||
|
|
||||||
UINT getVsyncCounter()
|
UINT getVsyncCounter()
|
||||||
{
|
{
|
||||||
Compat::ScopedSrwLockShared lock(g_vsyncCounterSrwLock);
|
Compat::ScopedSrwLockShared lock(g_vsyncCounterSrwLock);
|
||||||
|
@ -7,6 +7,7 @@ namespace D3dDdi
|
|||||||
namespace KernelModeThunks
|
namespace KernelModeThunks
|
||||||
{
|
{
|
||||||
RECT getMonitorRect();
|
RECT getMonitorRect();
|
||||||
|
long long getQpcLastVsync();
|
||||||
UINT getVsyncCounter();
|
UINT getVsyncCounter();
|
||||||
void installHooks();
|
void installHooks();
|
||||||
void setDcFormatOverride(UINT format);
|
void setDcFormatOverride(UINT format);
|
||||||
|
@ -396,7 +396,7 @@ namespace D3dDdi
|
|||||||
{
|
{
|
||||||
surfaceInfo[i].Width = m_fixedData.pSurfList[i].Width;
|
surfaceInfo[i].Width = m_fixedData.pSurfList[i].Width;
|
||||||
surfaceInfo[i].Height = m_fixedData.pSurfList[i].Height;
|
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)
|
if (i != 0)
|
||||||
{
|
{
|
||||||
std::uintptr_t offset = reinterpret_cast<std::uintptr_t>(surfaceInfo[i - 1].pSysMem) +
|
std::uintptr_t offset = reinterpret_cast<std::uintptr_t>(surfaceInfo[i - 1].pSysMem) +
|
||||||
|
@ -36,7 +36,6 @@ namespace
|
|||||||
bool g_isUpdatePending = false;
|
bool g_isUpdatePending = false;
|
||||||
bool g_waitingForPrimaryUnlock = false;
|
bool g_waitingForPrimaryUnlock = false;
|
||||||
std::atomic<long long> g_qpcLastUpdate = 0;
|
std::atomic<long long> g_qpcLastUpdate = 0;
|
||||||
long long g_qpcFlipEnd = 0;
|
|
||||||
UINT g_flipEndVsyncCount = 0;
|
UINT g_flipEndVsyncCount = 0;
|
||||||
UINT g_presentEndVsyncCount = 0;
|
UINT g_presentEndVsyncCount = 0;
|
||||||
|
|
||||||
@ -228,7 +227,10 @@ namespace
|
|||||||
DDraw::ScopedThreadLock lock;
|
DDraw::ScopedThreadLock lock;
|
||||||
if (g_isUpdatePending && !isPresentPending())
|
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;
|
skipWaitForVsync = true;
|
||||||
}
|
}
|
||||||
@ -429,10 +431,7 @@ namespace DDraw
|
|||||||
return !isFlipPending();
|
return !isFlipPending();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (D3dDdi::KernelModeThunks::waitForVsyncCounter(g_flipEndVsyncCount))
|
D3dDdi::KernelModeThunks::waitForVsyncCounter(g_flipEndVsyncCount);
|
||||||
{
|
|
||||||
g_qpcFlipEnd = Time::queryPerformanceCounter();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user