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

Return the emulated display mode from GetDisplayMode

This commit is contained in:
narzoul 2016-06-05 19:23:03 +02:00
parent d68cafa522
commit d9e095f75d
7 changed files with 54 additions and 50 deletions

View File

@ -36,7 +36,7 @@ namespace
dd->SetCooperativeLevel(&dd, g_fullScreenCooperativeWindow, g_fullScreenCooperativeFlags);
auto dm = CompatDisplayMode::getDisplayMode(dd);
dd->SetDisplayMode(&dd, dm.width, dm.height, 32, dm.refreshRate, dm.flags);
dd->SetDisplayMode(&dd, dm.dwWidth, dm.dwHeight, 32, dm.dwRefreshRate, 0);
auto primary(CompatPrimarySurface::getPrimary());
if (primary && SUCCEEDED(primary->Restore(primary)))

View File

@ -91,6 +91,7 @@ template <typename TDirectDraw>
void CompatDirectDraw<TDirectDraw>::setCompatVtable(Vtable<TDirectDraw>& vtable)
{
vtable.CreateSurface = &CreateSurface;
vtable.GetDisplayMode = &GetDisplayMode;
vtable.RestoreDisplayMode = &RestoreDisplayMode;
vtable.SetCooperativeLevel = &SetCooperativeLevel;
vtable.SetDisplayMode = &SetDisplayMode;
@ -129,7 +130,7 @@ HRESULT STDMETHODCALLTYPE CompatDirectDraw<TDirectDraw>::CreateSurface(
if (!(desc.dwFlags & DDSD_PIXELFORMAT))
{
desc.dwFlags |= DDSD_PIXELFORMAT;
desc.ddpfPixelFormat = dm.pixelFormat;
desc.ddpfPixelFormat = dm.ddpfPixelFormat;
}
if (!((desc.dwFlags & DDSD_CAPS) &&
(desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_OVERLAY | DDSCAPS_TEXTURE |
@ -154,6 +155,24 @@ HRESULT STDMETHODCALLTYPE CompatDirectDraw<TDirectDraw>::CreateSurface(
return result;
}
template <typename TDirectDraw>
HRESULT STDMETHODCALLTYPE CompatDirectDraw<TDirectDraw>::GetDisplayMode(
TDirectDraw* This, TSurfaceDesc* lpDDSurfaceDesc)
{
const DWORD size = lpDDSurfaceDesc ? lpDDSurfaceDesc->dwSize : 0;
if (sizeof(DDSURFACEDESC) != size && sizeof(DDSURFACEDESC2) != size)
{
return DDERR_INVALIDPARAMS;
}
CompatPtr<IDirectDraw7> dd(Compat::queryInterface<IDirectDraw7>(This));
const DDSURFACEDESC2 dm = CompatDisplayMode::getDisplayMode(*dd);
CopyMemory(lpDDSurfaceDesc, &dm, size);
lpDDSurfaceDesc->dwSize = size;
return DD_OK;
}
template <typename TDirectDraw>
HRESULT STDMETHODCALLTYPE CompatDirectDraw<TDirectDraw>::RestoreDisplayMode(TDirectDraw* This)
{

View File

@ -21,6 +21,7 @@ public:
TSurface** lplpDDSurface,
IUnknown* pUnkOuter);
static HRESULT STDMETHODCALLTYPE GetDisplayMode(TDirectDraw* This, TSurfaceDesc* lpDDSurfaceDesc);
static HRESULT STDMETHODCALLTYPE RestoreDisplayMode(TDirectDraw* This);
static HRESULT STDMETHODCALLTYPE SetCooperativeLevel(TDirectDraw* This, HWND hWnd, DWORD dwFlags);

View File

@ -188,11 +188,11 @@ HRESULT CompatDirectDrawSurface<TSurface>::createCompatPrimarySurface(
CompatPtr<IDirectDraw7> dd7(Compat::queryInterface<IDirectDraw7>(&dd));
const auto& dm = CompatDisplayMode::getDisplayMode(*dd7);
compatDesc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
compatDesc.dwWidth = dm.width;
compatDesc.dwHeight = dm.height;
compatDesc.dwWidth = dm.dwWidth;
compatDesc.dwHeight = dm.dwHeight;
compatDesc.ddsCaps.dwCaps &= ~DDSCAPS_PRIMARYSURFACE;
compatDesc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN;
compatDesc.ddpfPixelFormat = dm.pixelFormat;
compatDesc.ddpfPixelFormat = dm.ddpfPixelFormat;
result = dd->CreateSurface(&dd, &compatDesc, &compatSurface, nullptr);
if (FAILED(result))

View File

@ -8,7 +8,7 @@ namespace
{
CompatWeakPtr<IDirectDrawSurface7> g_compatibleSurface = {};
HDC g_compatibleDc = nullptr;
CompatDisplayMode::DisplayMode g_emulatedDisplayMode = {};
DDSURFACEDESC2 g_emulatedDisplayMode = {};
template <typename CStr, typename DevMode,
typename ChangeDisplaySettingsExPtr, typename EnumDisplaySettingsPtr>
@ -72,7 +72,7 @@ namespace
desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
desc.dwWidth = 1;
desc.dwHeight = 1;
desc.ddpfPixelFormat = g_emulatedDisplayMode.pixelFormat;
desc.ddpfPixelFormat = g_emulatedDisplayMode.ddpfPixelFormat;
desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
auto dd = DDrawRepository::getDirectDraw();
@ -130,6 +130,14 @@ namespace
return pf;
}
DDSURFACEDESC2 getRealDisplayMode(CompatRef<IDirectDraw7> dd)
{
DDSURFACEDESC2 desc = {};
desc.dwSize = sizeof(desc);
dd->GetDisplayMode(&dd, &desc);
return desc;
}
void releaseCompatibleDc()
{
if (g_compatibleDc)
@ -183,29 +191,15 @@ namespace CompatDisplayMode
return CALL_ORIG_FUNC(createDiscardableBitmap)(hdc, nWidth, nHeight);
}
DisplayMode getDisplayMode(CompatRef<IDirectDraw7> dd)
DDSURFACEDESC2 getDisplayMode(CompatRef<IDirectDraw7> dd)
{
if (0 == g_emulatedDisplayMode.width)
if (0 == g_emulatedDisplayMode.dwSize)
{
g_emulatedDisplayMode = getRealDisplayMode(dd);
}
return g_emulatedDisplayMode;
}
DisplayMode getRealDisplayMode(CompatRef<IDirectDraw7> dd)
{
DDSURFACEDESC2 desc = {};
desc.dwSize = sizeof(desc);
dd->GetDisplayMode(&dd, &desc);
DisplayMode dm = {};
dm.width = desc.dwWidth;
dm.height = desc.dwHeight;
dm.pixelFormat = desc.ddpfPixelFormat;
dm.refreshRate = desc.dwRefreshRate;
return dm;
}
void installHooks()
{
HOOK_FUNCTION(user32, ChangeDisplaySettingsExA, changeDisplaySettingsExA);
@ -240,11 +234,8 @@ namespace CompatDisplayMode
return result;
}
g_emulatedDisplayMode.width = width;
g_emulatedDisplayMode.height = height;
g_emulatedDisplayMode.pixelFormat = pf;
g_emulatedDisplayMode.refreshRate = refreshRate;
g_emulatedDisplayMode.flags = flags;
g_emulatedDisplayMode = getRealDisplayMode(dd);
g_emulatedDisplayMode.ddpfPixelFormat = pf;
updateCompatibleDc();
return DD_OK;

View File

@ -8,15 +8,6 @@
namespace CompatDisplayMode
{
struct DisplayMode
{
DWORD width;
DWORD height;
DDPIXELFORMAT pixelFormat;
DWORD refreshRate;
DWORD flags;
};
void installHooks();
HBITMAP WINAPI createCompatibleBitmap(HDC hdc, int cx, int cy);
@ -24,8 +15,7 @@ namespace CompatDisplayMode
const void* lpbInit, const BITMAPINFO* lpbmi, UINT fuUsage);
HBITMAP WINAPI createDiscardableBitmap(HDC hdc, int nWidth, int nHeight);
DisplayMode getDisplayMode(CompatRef<IDirectDraw7> dd);
DisplayMode getRealDisplayMode(CompatRef<IDirectDraw7> dd);
DDSURFACEDESC2 getDisplayMode(CompatRef<IDirectDraw7> dd);
HRESULT restoreDisplayMode(CompatRef<IDirectDraw7> dd);
HRESULT setDisplayMode(CompatRef<IDirectDraw7> dd,
DWORD width, DWORD height, DWORD bpp, DWORD refreshRate = 0, DWORD flags = 0);

View File

@ -26,7 +26,7 @@ namespace
}
}
HBITMAP createDibSection(const CompatDisplayMode::DisplayMode& dm, void*& bits)
HBITMAP createDibSection(const DDSURFACEDESC2& dm, void*& bits)
{
struct PalettizedBitmapInfo
{
@ -36,27 +36,27 @@ namespace
PalettizedBitmapInfo bmi = {};
bmi.header.biSize = sizeof(bmi.header);
bmi.header.biWidth = dm.width;
bmi.header.biHeight = -static_cast<LONG>(dm.height);
bmi.header.biWidth = dm.dwWidth;
bmi.header.biHeight = -static_cast<LONG>(dm.dwHeight);
bmi.header.biPlanes = 1;
bmi.header.biBitCount = static_cast<WORD>(dm.pixelFormat.dwRGBBitCount);
bmi.header.biBitCount = static_cast<WORD>(dm.ddpfPixelFormat.dwRGBBitCount);
bmi.header.biCompression = BI_RGB;
return CreateDIBSection(nullptr, reinterpret_cast<BITMAPINFO*>(&bmi),
DIB_RGB_COLORS, &bits, nullptr, 0);
}
CompatPtr<IDirectDrawSurface7> createSurface(const CompatDisplayMode::DisplayMode& dm, void* bits)
CompatPtr<IDirectDrawSurface7> createSurface(const DDSURFACEDESC2& dm, void* bits)
{
DDSURFACEDESC2 desc = {};
desc.dwSize = sizeof(desc);
desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS |
DDSD_PITCH | DDSD_LPSURFACE;
desc.dwWidth = dm.width;
desc.dwHeight = dm.height;
desc.ddpfPixelFormat = dm.pixelFormat;
desc.dwWidth = dm.dwWidth;
desc.dwHeight = dm.dwHeight;
desc.ddpfPixelFormat = dm.ddpfPixelFormat;
desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
desc.lPitch = (dm.width * dm.pixelFormat.dwRGBBitCount / 8 + 3) & ~3;
desc.lPitch = (dm.dwWidth * dm.ddpfPixelFormat.dwRGBBitCount / 8 + 3) & ~3;
desc.lpSurface = bits;
auto dd(DDrawRepository::getDirectDraw());
@ -72,8 +72,11 @@ namespace CompatPaletteConverter
{
auto dd(DDrawRepository::getDirectDraw());
auto dm(CompatDisplayMode::getDisplayMode(*dd));
if (dm.pixelFormat.dwRGBBitCount > 8 &&
CompatDisplayMode::getRealDisplayMode(*dd).pixelFormat.dwRGBBitCount > 8)
DDSURFACEDESC2 realDm = {};
realDm.dwSize = sizeof(realDm);
dd->GetDisplayMode(dd, &realDm);
if (dm.ddpfPixelFormat.dwRGBBitCount > 8 &&
realDm.ddpfPixelFormat.dwRGBBitCount > 8)
{
return true;
}