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

Fix reported memory caps of primary surface

Changed primary surface caps to report video memory in case the surface
was only forced into system memory by DDrawCompat.

Fixes startup issues in C&C 95 and Red Alert, reported in issue #3.
This commit is contained in:
narzoul 2017-08-06 21:42:24 +02:00
parent e3396a18b8
commit 8ab8058ceb
3 changed files with 18 additions and 8 deletions

View File

@ -10,7 +10,7 @@ namespace
DDSURFACEDESC2 g_primarySurfaceDesc = {};
CompatWeakPtr<IDirectDrawSurface> g_gdiSurface = nullptr;
CompatWeakPtr<IDirectDrawSurface> g_primarySurface = nullptr;
bool g_isFlipEmulated = false;
DWORD g_origCaps = 0;
}
namespace DDraw
@ -26,7 +26,7 @@ namespace DDraw
g_gdiSurface = nullptr;
g_primarySurface = nullptr;
g_isFlipEmulated = false;
g_origCaps = 0;
s_palette = nullptr;
s_surfaceBuffers.clear();
ZeroMemory(&s_paletteEntries, sizeof(s_paletteEntries));
@ -46,6 +46,8 @@ namespace DDraw
return result;
}
const DWORD origCaps = desc.ddsCaps.dwCaps;
const auto& dm = DDraw::getDisplayMode(*CompatPtr<IDirectDraw7>::from(&dd));
desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
desc.dwWidth = dm.dwWidth;
@ -69,7 +71,7 @@ namespace DDraw
CompatPtr<IDirectDrawSurface> surface1(Compat::queryInterface<IDirectDrawSurface>(surface));
g_gdiSurface = surface1;
g_primarySurface = surface1;
g_isFlipEmulated = 0 != (desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY);
g_origCaps = origCaps;
ZeroMemory(&g_primarySurfaceDesc, sizeof(g_primarySurfaceDesc));
g_primarySurfaceDesc.dwSize = sizeof(g_primarySurfaceDesc);
@ -130,9 +132,9 @@ namespace DDraw
Compat::queryInterface<IDirectDrawSurface7>(g_primarySurface.get()));
}
bool PrimarySurface::isFlipEmulated()
DWORD PrimarySurface::getOrigCaps()
{
return g_isFlipEmulated;
return g_origCaps;
}
void PrimarySurface::resizeBuffers(CompatRef<IDirectDrawSurface7> surface)

View File

@ -20,7 +20,7 @@ namespace DDraw
static const DDSURFACEDESC2& getDesc();
static CompatPtr<IDirectDrawSurface7> getGdiSurface();
static CompatPtr<IDirectDrawSurface7> getPrimary();
static bool isFlipEmulated();
static DWORD getOrigCaps();
void updateGdiSurfacePtr(IDirectDrawSurface* flipTargetOverride);

View File

@ -10,6 +10,13 @@ namespace
{
caps &= ~DDSCAPS_OFFSCREENPLAIN;
caps |= DDSCAPS_PRIMARYSURFACE | DDSCAPS_VISIBLE;
if ((caps & DDSCAPS_SYSTEMMEMORY) &&
!(DDraw::PrimarySurface::getOrigCaps() & DDSCAPS_SYSTEMMEMORY))
{
caps &= ~DDSCAPS_SYSTEMMEMORY;
caps |= DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM;
}
}
}
@ -85,8 +92,9 @@ namespace DDraw
return result;
}
const bool isFlipEmulated = 0 != (PrimarySurface::getOrigCaps() & DDSCAPS_SYSTEMMEMORY);
result = RealPrimarySurface::flip(dwFlags);
if (SUCCEEDED(result) && !PrimarySurface::isFlipEmulated())
if (SUCCEEDED(result) && !isFlipEmulated)
{
static_cast<PrimarySurface*>(m_data)->updateGdiSurfacePtr(
CompatPtr<IDirectDrawSurface>::from(lpDDSurfaceTargetOverride));
@ -95,7 +103,7 @@ namespace DDraw
undoFlip(This, lpDDSurfaceTargetOverride);
if (SUCCEEDED(result) && PrimarySurface::isFlipEmulated())
if (SUCCEEDED(result) && isFlipEmulated)
{
if (lpDDSurfaceTargetOverride)
{