Skip to content

Commit

Permalink
Change how EnumDisplayModes works with interface 1
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Dec 14, 2024
1 parent 22dcdda commit 02b45ef
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 30 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 7382
#define BUILD_NUMBER 7383
72 changes: 50 additions & 22 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ HRESULT m_IDirectDrawX::DuplicateSurface(LPDIRECTDRAWSURFACE7 lpDDSurface, LPDIR
return hr;
}

HRESULT m_IDirectDrawX::EnumDisplayModes(DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext, LPDDENUMMODESCALLBACK lpEnumModesCallback)
HRESULT m_IDirectDrawX::EnumDisplayModes(DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext, LPDDENUMMODESCALLBACK lpEnumModesCallback, DWORD DirectXVersion)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

Expand Down Expand Up @@ -909,13 +909,13 @@ HRESULT m_IDirectDrawX::EnumDisplayModes(DWORD dwFlags, LPDDSURFACEDESC lpDDSurf
ConvertSurfaceDesc(Desc2, *lpDDSurfaceDesc);
}

return EnumDisplayModes2(dwFlags, (lpDDSurfaceDesc) ? &Desc2 : nullptr, &CallbackContext, EnumDisplay::ConvertCallback);
return EnumDisplayModes2(dwFlags, (lpDDSurfaceDesc) ? &Desc2 : nullptr, &CallbackContext, EnumDisplay::ConvertCallback, DirectXVersion);
}

return GetProxyInterfaceV3()->EnumDisplayModes(dwFlags, lpDDSurfaceDesc, lpContext, lpEnumModesCallback);
}

HRESULT m_IDirectDrawX::EnumDisplayModes2(DWORD dwFlags, LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPVOID lpContext, LPDDENUMMODESCALLBACK2 lpEnumModesCallback2)
HRESULT m_IDirectDrawX::EnumDisplayModes2(DWORD dwFlags, LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPVOID lpContext, LPDDENUMMODESCALLBACK2 lpEnumModesCallback2, DWORD DirectXVersion)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

Expand Down Expand Up @@ -1014,6 +1014,27 @@ HRESULT m_IDirectDrawX::EnumDisplayModes2(DWORD dwFlags, LPDDSURFACEDESC2 lpDDSu
}
}

struct EnumDisplay
{
static void GetSurfaceDesc2(DDSURFACEDESC2& Desc2, DWORD Width, DWORD Height, DWORD RefreshRate, DWORD bpMode)
{
Desc2.dwSize = sizeof(DDSURFACEDESC2);
Desc2.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_REFRESHRATE;
Desc2.dwWidth = Width;
Desc2.dwHeight = Height;
Desc2.dwRefreshRate = RefreshRate;

// Set adapter pixel format
Desc2.dwFlags |= DDSD_PIXELFORMAT;
Desc2.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
D3DFORMAT Format = SetDisplayFormat(Desc2.ddpfPixelFormat, bpMode);

// Set pitch
Desc2.dwFlags |= DDSD_PITCH;
Desc2.lPitch = ComputePitch(Format, GetByteAlignedWidth(Desc2.dwWidth, bpMode), bpMode);
}
};

// Set display bit count modes
std::vector<DWORD> BitCountList;
if (DisplayAllModes)
Expand All @@ -1028,30 +1049,37 @@ HRESULT m_IDirectDrawX::EnumDisplayModes2(DWORD dwFlags, LPDDSURFACEDESC2 lpDDSu
}

// Loop through each bit count
for (DWORD bpMode : BitCountList)
if (DirectXVersion == 1)
{
for (auto& entry : ResolutionList)
{
// Set surface desc options
DDSURFACEDESC2 Desc2 = {};
Desc2.dwSize = sizeof(DDSURFACEDESC2);
Desc2.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_REFRESHRATE;
Desc2.dwWidth = entry.Width;
Desc2.dwHeight = entry.Height;
Desc2.dwRefreshRate = entry.RefreshRate;

// Set adapter pixel format
Desc2.dwFlags |= DDSD_PIXELFORMAT;
Desc2.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
D3DFORMAT Format = SetDisplayFormat(Desc2.ddpfPixelFormat, bpMode);

// Set pitch
Desc2.dwFlags |= DDSD_PITCH;
Desc2.lPitch = ComputePitch(Format, GetByteAlignedWidth(Desc2.dwWidth, bpMode), bpMode);
for (DWORD bpMode : BitCountList)
{
// Get surface desc options
DDSURFACEDESC2 Desc2 = {};
EnumDisplay::GetSurfaceDesc2(Desc2, entry.Width, entry.Height, entry.RefreshRate, bpMode);

if (lpEnumModesCallback2(&Desc2, lpContext) == DDENUMRET_CANCEL)
if (lpEnumModesCallback2(&Desc2, lpContext) == DDENUMRET_CANCEL)
{
return DD_OK;
}
}
}
}
else
{
for (DWORD bpMode : BitCountList)
{
for (auto& entry : ResolutionList)
{
return DD_OK;
// Get surface desc options
DDSURFACEDESC2 Desc2 = {};
EnumDisplay::GetSurfaceDesc2(Desc2, entry.Width, entry.Height, entry.RefreshRate, bpMode);

if (lpEnumModesCallback2(&Desc2, lpContext) == DDENUMRET_CANCEL)
{
return DD_OK;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ddraw/IDirectDrawX.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class m_IDirectDrawX : public IUnknown, public AddressLookupTableDdrawObject
HRESULT CreateSurface(LPDDSURFACEDESC, LPDIRECTDRAWSURFACE7 FAR *, IUnknown FAR *, DWORD);
HRESULT CreateSurface2(LPDDSURFACEDESC2, LPDIRECTDRAWSURFACE7 FAR *, IUnknown FAR *, DWORD);
STDMETHOD(DuplicateSurface)(THIS_ LPDIRECTDRAWSURFACE7, LPDIRECTDRAWSURFACE7 FAR *, DWORD);
HRESULT EnumDisplayModes(DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK);
HRESULT EnumDisplayModes2(DWORD, LPDDSURFACEDESC2, LPVOID, LPDDENUMMODESCALLBACK2);
HRESULT EnumDisplayModes(DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK, DWORD);
HRESULT EnumDisplayModes2(DWORD, LPDDSURFACEDESC2, LPVOID, LPDDENUMMODESCALLBACK2, DWORD);
HRESULT EnumSurfaces(DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMSURFACESCALLBACK, DWORD);
HRESULT EnumSurfaces2(DWORD, LPDDSURFACEDESC2, LPVOID, LPDDENUMSURFACESCALLBACK7, DWORD);
STDMETHOD(FlipToGDISurface)(THIS);
Expand Down
2 changes: 1 addition & 1 deletion ddraw/Versions/IDirectDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ HRESULT m_IDirectDraw::EnumDisplayModes(DWORD a, LPDDSURFACEDESC b, LPVOID c, LP
{
return DDERR_INVALIDOBJECT;
}
return ProxyInterface->EnumDisplayModes(a, b, c, d);
return ProxyInterface->EnumDisplayModes(a, b, c, d, DirectXVersion);
}

HRESULT m_IDirectDraw::EnumSurfaces(DWORD a, LPDDSURFACEDESC b, LPVOID c, LPDDENUMSURFACESCALLBACK d)
Expand Down
2 changes: 1 addition & 1 deletion ddraw/Versions/IDirectDraw2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ HRESULT m_IDirectDraw2::EnumDisplayModes(DWORD a, LPDDSURFACEDESC b, LPVOID c, L
{
return DDERR_INVALIDOBJECT;
}
return ProxyInterface->EnumDisplayModes(a, b, c, d);
return ProxyInterface->EnumDisplayModes(a, b, c, d, DirectXVersion);
}

HRESULT m_IDirectDraw2::EnumSurfaces(DWORD a, LPDDSURFACEDESC b, LPVOID c, LPDDENUMSURFACESCALLBACK d)
Expand Down
2 changes: 1 addition & 1 deletion ddraw/Versions/IDirectDraw3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ HRESULT m_IDirectDraw3::EnumDisplayModes(DWORD a, LPDDSURFACEDESC b, LPVOID c, L
{
return DDERR_INVALIDOBJECT;
}
return ProxyInterface->EnumDisplayModes(a, b, c, d);
return ProxyInterface->EnumDisplayModes(a, b, c, d, DirectXVersion);
}

HRESULT m_IDirectDraw3::EnumSurfaces(DWORD a, LPDDSURFACEDESC b, LPVOID c, LPDDENUMSURFACESCALLBACK d)
Expand Down
2 changes: 1 addition & 1 deletion ddraw/Versions/IDirectDraw4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ HRESULT m_IDirectDraw4::EnumDisplayModes(DWORD a, LPDDSURFACEDESC2 b, LPVOID c,
{
return DDERR_INVALIDOBJECT;
}
return ProxyInterface->EnumDisplayModes2(a, b, c, d);
return ProxyInterface->EnumDisplayModes2(a, b, c, d, DirectXVersion);
}

HRESULT m_IDirectDraw4::EnumSurfaces(DWORD a, LPDDSURFACEDESC2 b, LPVOID c, LPDDENUMSURFACESCALLBACK2 d)
Expand Down
2 changes: 1 addition & 1 deletion ddraw/Versions/IDirectDraw7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ HRESULT m_IDirectDraw7::EnumDisplayModes(DWORD a, LPDDSURFACEDESC2 b, LPVOID c,
{
return DDERR_INVALIDOBJECT;
}
return ProxyInterface->EnumDisplayModes2(a, b, c, d);
return ProxyInterface->EnumDisplayModes2(a, b, c, d, DirectXVersion);
}

HRESULT m_IDirectDraw7::EnumSurfaces(DWORD a, LPDDSURFACEDESC2 b, LPVOID c, LPDDENUMSURFACESCALLBACK7 d)
Expand Down

0 comments on commit 02b45ef

Please sign in to comment.