Skip to content

Commit

Permalink
Only use surface size when set by CreateSurface()
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Sep 7, 2023
1 parent 36c576c commit 8c12609
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 38 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 6800
#define BUILD_NUMBER 6801
2 changes: 1 addition & 1 deletion ddraw/IDirect3DTextureX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,6 @@ void m_IDirect3DTextureX::ReleaseTexture()

if (DDrawSurface)
{
DDrawSurface->ClearTexture();
DDrawSurface->ClearAttachedTexture();
}
}
17 changes: 0 additions & 17 deletions ddraw/IDirectDrawSurfaceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2505,23 +2505,6 @@ HRESULT m_IDirectDrawSurfaceX::SetClipper(LPDIRECTDRAWCLIPPER lpDDClipper)
return ProxyInterface->SetClipper(lpDDClipper);
}

bool m_IDirectDrawSurfaceX::GetColorKey(DWORD& ColorSpaceLowValue, DWORD& ColorSpaceHighValue)
{
if (surfaceDesc2.ddsCaps.dwCaps & DDSD_CKSRCBLT)
{
ColorSpaceLowValue = surfaceDesc2.ddckCKSrcBlt.dwColorSpaceLowValue;
ColorSpaceHighValue = surfaceDesc2.ddckCKSrcBlt.dwColorSpaceHighValue;
return true;
}
else if (surfaceDesc2.ddsCaps.dwCaps & DDCKEY_SRCOVERLAY)
{
ColorSpaceLowValue = surfaceDesc2.ddckCKSrcOverlay.dwColorSpaceLowValue;
ColorSpaceHighValue = surfaceDesc2.ddckCKSrcOverlay.dwColorSpaceHighValue;
return true;
}
return false;
}

HRESULT m_IDirectDrawSurfaceX::SetColorKey(DWORD dwFlags, LPDDCOLORKEY lpDDColorKey)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
Expand Down
33 changes: 29 additions & 4 deletions ddraw/IDirectDrawSurfaceX.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj
inline bool IsSurfaceInDC() { return IsInDC; }
inline bool IsSurfaceBusy() { return (IsSurfaceBlitting() || IsSurfaceLocked() || IsSurfaceInDC()); }
inline bool IsLockedFromOtherThread() { return (IsSurfaceBlitting() || IsSurfaceLocked()) && LockedWithID && LockedWithID != GetCurrentThreadId(); }
inline DWORD GetWidth() { return surfaceDesc2.dwWidth; }
inline DWORD GetHeight() { return surfaceDesc2.dwHeight; }
inline RECT GetSurfaceRect() { return { 0, 0, (LONG)surfaceDesc2.dwWidth, (LONG)surfaceDesc2.dwHeight }; }
inline bool CanSurfaceBeDeleted() { return (ComplexRoot || (surfaceDesc2.ddsCaps.dwCaps & DDSCAPS_COMPLEX) == 0); }
inline DDSCAPS2 GetSurfaceCaps() { return surfaceDesc2.ddsCaps; }
Expand Down Expand Up @@ -398,21 +400,44 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj
inline bool IsPalette() { return (surfaceFormat == D3DFMT_P8); }
inline bool IsDepthBuffer() { return (surfaceDesc2.ddpfPixelFormat.dwFlags & (DDPF_ZBUFFER | DDPF_STENCILBUFFER)) != 0; }
inline bool IsSurfaceManaged() { return (surfaceDesc2.ddsCaps.dwCaps2 & (DDSCAPS2_TEXTUREMANAGE | DDSCAPS2_D3DTEXTUREMANAGE)) != 0; }
inline DWORD GetWidth() { return surfaceDesc2.dwWidth; }
inline DWORD GetHeight() { return surfaceDesc2.dwHeight; }
bool GetColorKey(DWORD& ColorSpaceLowValue, DWORD& ColorSpaceHighValue);
inline bool IsUsingEmulation() { return (surface.emu && surface.emu->DC && surface.emu->GameDC && surface.emu->pBits); }
inline bool IsEmulationDCReady() { return (IsUsingEmulation() && !surface.emu->UsingGameDC); }
inline bool IsSurface3DDevice() { return Is3DRenderingTarget; }
inline bool IsSurfaceDirty() { return surface.IsDirtyFlag; }
inline bool GetColorKey(DWORD& ColorSpaceLowValue, DWORD& ColorSpaceHighValue)
{
if (surfaceDesc2.ddsCaps.dwCaps & DDSD_CKSRCBLT)
{
ColorSpaceLowValue = surfaceDesc2.ddckCKSrcBlt.dwColorSpaceLowValue;
ColorSpaceHighValue = surfaceDesc2.ddckCKSrcBlt.dwColorSpaceHighValue;
return true;
}
else if (surfaceDesc2.ddsCaps.dwCaps & DDCKEY_SRCOVERLAY)
{
ColorSpaceLowValue = surfaceDesc2.ddckCKSrcOverlay.dwColorSpaceLowValue;
ColorSpaceHighValue = surfaceDesc2.ddckCKSrcOverlay.dwColorSpaceHighValue;
return true;
}
return false;
}
inline bool GetSurfaceSetSize(DWORD& Width, DWORD& Height)
{
if ((ResetDisplayFlags & (DDSD_WIDTH | DDSD_HEIGHT)) == 0 && surfaceDesc2.dwWidth && surfaceDesc2.dwHeight)
{
Width = surfaceDesc2.dwWidth;
Height = surfaceDesc2.dwHeight;
return true;
}
return false;
}
inline void AttachD9BackBuffer() { Is3DRenderingTarget = true; }
inline void DetachD9BackBuffer() { Is3DRenderingTarget = false; }
LPDIRECT3DSURFACE9 Get3DSurface();
LPDIRECT3DTEXTURE9 Get3DTexture();
LPDIRECT3DSURFACE9 GetD3D9Surface();
LPDIRECT3DTEXTURE9 GetD3D9Texture();
inline m_IDirect3DTextureX* GetAttachedTexture() { return attachedTexture; }
inline void ClearTexture() { attachedTexture = nullptr; }
inline void ClearAttachedTexture() { attachedTexture = nullptr; }

// Draw 2D DirectDraw surface
HRESULT Draw2DSurface();
Expand Down
27 changes: 12 additions & 15 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2591,16 +2591,14 @@ void m_IDirectDrawX::GetSurfaceDisplay(DWORD& Width, DWORD& Height, DWORD& BPP,
Height = presParams.BackBufferHeight;
BPP = Utils::GetBitCount(hWnd);
}
else if (Direct3DSurface)
else if (Direct3DSurface && Direct3DSurface->GetSurfaceSetSize(Width, Height))
{
Width = Direct3DSurface->GetWidth();
Height = Direct3DSurface->GetHeight();
// Width and Height set by 3D surface
BPP = Utils::GetBitCount(hWnd);
}
else if (PrimarySurface)
else if (PrimarySurface && PrimarySurface->GetSurfaceSetSize(Width, Height))
{
Width = PrimarySurface->GetWidth();
Height = PrimarySurface->GetHeight();
// Width and Height set by primary surface
BPP = Utils::GetBitCount(hWnd);
}
else
Expand Down Expand Up @@ -2691,8 +2689,9 @@ void m_IDirectDrawX::SetD3DDevice(m_IDirect3DDeviceX* D3DDevice, m_IDirectDrawSu
Direct3DSurface = D3DSurface;

// Recreate Direct3D9 device
if (d3d9Device && !Device.Width && !Device.Height &&
Direct3DSurface->GetWidth() != presParams.BackBufferWidth || Direct3DSurface->GetHeight() != presParams.BackBufferHeight)
DWORD Width = 0, Height = 0;
if (d3d9Device && (!Device.Width || !Device.Height) && Direct3DSurface->GetSurfaceSetSize(Width, Height) &&
(Width != presParams.BackBufferWidth || Height != presParams.BackBufferHeight))
{
CreateD3D9Device();
}
Expand Down Expand Up @@ -2787,17 +2786,15 @@ HRESULT m_IDirectDrawX::CreateD3D9Device()
DWORD BackBufferHeight = Device.Height;
if (!BackBufferWidth || !BackBufferHeight)
{
if (Direct3DSurface)
if (Direct3DSurface && Direct3DSurface->GetSurfaceSetSize(BackBufferWidth, BackBufferHeight))
{
BackBufferWidth = Direct3DSurface->GetWidth();
BackBufferHeight = Direct3DSurface->GetHeight();
// Width and Height set by 3D surface
}
else if (PrimarySurface)
else if (PrimarySurface && PrimarySurface->GetSurfaceSetSize(BackBufferWidth, BackBufferHeight))
{
BackBufferWidth = PrimarySurface->GetWidth();
BackBufferHeight = PrimarySurface->GetHeight();
// Width and Height set by primary surface
}
if (!BackBufferWidth || !BackBufferHeight)
else
{
if (ExclusiveMode)
{
Expand Down

0 comments on commit 8c12609

Please sign in to comment.