Skip to content

Commit

Permalink
Fix surface reuse address and palette color table
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Sep 1, 2023
1 parent 301728b commit 1253720
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 6787
#define BUILD_NUMBER 6788
1 change: 1 addition & 0 deletions ddraw/IDirectDrawSurfaceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6293,6 +6293,7 @@ void m_IDirectDrawSurfaceX::UpdatePaletteData()
if (IsUsingEmulation() && NewRGBPalette && surface.emu->LastPaletteUSN != NewPaletteUSN)
{
SetDIBColorTable(surface.emu->DC, 0, MaxPaletteSize, NewRGBPalette);
SetDIBColorTable(surface.emu->GameDC, 0, MaxPaletteSize, NewRGBPalette);
surface.emu->LastPaletteUSN = NewPaletteUSN;
}

Expand Down
8 changes: 2 additions & 6 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ struct HIGHRESCOUNTER

struct PRESENTTHREAD
{
bool UsingMultpleCores = false;
CRITICAL_SECTION ddpt = {};
HANDLE workerEvent = {};
HANDLE workerThread = {};
Expand Down Expand Up @@ -3020,9 +3019,6 @@ HRESULT m_IDirectDrawX::CreateD3D9Device()
DWORD tmpWidth = 0;
Utils::GetScreenSize(hWnd, tmpWidth, Counter.Height);

// Check if more than one process core is being used
PresentThread.UsingMultpleCores = (Utils::GetCoresUsedByProcess() > 1);

} while (false);

// Reset D3D device settings
Expand All @@ -3031,8 +3027,8 @@ HRESULT m_IDirectDrawX::CreateD3D9Device()
D3DDeviceInterface->ResetDevice();
}

ReleaseCriticalSection();
LeaveCriticalSection(&PresentThread.ddpt);
ReleaseCriticalSection();

// Return result
return hr;
Expand Down Expand Up @@ -3651,7 +3647,7 @@ HRESULT m_IDirectDrawX::Present(RECT* pSourceRect, RECT* pDestRect)
// Present everthing, skip Preset when using DdrawWriteToGDI
HRESULT hr;
EnterCriticalSection(&PresentThread.ddpt);
if (pSourceRect || pDestRect || (EnableWaitVsync && Config.EnableVSync) || !PresentThread.UsingMultpleCores)
if (pSourceRect || pDestRect || (EnableWaitVsync && Config.EnableVSync))
{
hr = d3d9Device->Present(pSourceRect, pDestRect, nullptr, nullptr);
EnableWaitVsync = (EnableWaitVsync && !Config.EnableVSync);
Expand Down
15 changes: 13 additions & 2 deletions ddraw/Versions/IDirectDrawSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ class m_IDirectDrawSurface : public IDirectDrawSurface, public AddressLookupTabl
ProxyAddressLookupTable.DeleteAddress(this);
}

void SetProxy(m_IDirectDrawSurfaceX* NewProxyInterface)
{
ProxyInterface = NewProxyInterface;
if (NewProxyInterface)
{
ProxyAddressLookupTable.SaveAddress(this, (RealInterface) ? RealInterface : (void*)ProxyInterface);
}
else
{
ProxyAddressLookupTable.DeleteAddress(this);
}
}

/*** IUnknown methods ***/
STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj);
STDMETHOD_(ULONG, AddRef) (THIS);
Expand Down Expand Up @@ -57,6 +70,4 @@ class m_IDirectDrawSurface : public IDirectDrawSurface, public AddressLookupTabl
STDMETHOD(UpdateOverlay)(THIS_ LPRECT, LPDIRECTDRAWSURFACE, LPRECT, DWORD, LPDDOVERLAYFX);
STDMETHOD(UpdateOverlayDisplay)(THIS_ DWORD);
STDMETHOD(UpdateOverlayZOrder)(THIS_ DWORD, LPDIRECTDRAWSURFACE);

void SetProxy(m_IDirectDrawSurfaceX* NewProxyInterface) { ProxyInterface = NewProxyInterface; }
};

0 comments on commit 1253720

Please sign in to comment.