WIP fixes

This commit is contained in:
Christian Semmler 2024-01-20 13:30:26 -05:00
parent 0c01fd7981
commit c92e0c8cbf

View File

@ -591,7 +591,7 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN; ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY | DDSCAPS_OFFSCREENPLAIN;
if (draw->CreateSurface(&ddsd, &surface, NULL) != S_OK) { if (draw->CreateSurface(&ddsd, &surface, NULL) != S_OK) {
if (!*p_ret) { if (*p_ret) {
*p_ret = 0; *p_ret = 0;
// Try creating bitmap surface in vram if system ram ran out // Try creating bitmap surface in vram if system ram ran out
@ -602,28 +602,24 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
surface = NULL; surface = NULL;
} }
} }
else
surface = NULL;
} }
if (!surface) { if (surface) {
return NULL;
}
memset(&ddsd, 0, sizeof(ddsd)); memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd); ddsd.dwSize = sizeof(ddsd);
if (surface->Lock(NULL, &ddsd, 1, 0) != S_OK) { if (surface->Lock(NULL, &ddsd, DDLOCK_WAIT, 0) != S_OK) {
surface->Release(); surface->Release();
return NULL; surface = NULL;
goto done;
} }
if (p_doNotWriteToSurface) { if (p_doNotWriteToSurface) {
return surface; goto done;
} }
BITMAPINFOHEADER* hdr = p_bitmap->GetBmiHeader();
MxU32 rowsBeforeTop;
MxU8* bitmapSrcPtr;
// The goal here is to enable us to walk through the bitmap's rows // The goal here is to enable us to walk through the bitmap's rows
// in order, regardless of the orientation. We want to end up at the // in order, regardless of the orientation. We want to end up at the
// start of the first row, which is either at position 0, or at // start of the first row, which is either at position 0, or at
@ -632,8 +628,10 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
// Reminder: Negative biHeight means this is a top-down DIB. // Reminder: Negative biHeight means this is a top-down DIB.
// Otherwise it is bottom-up. // Otherwise it is bottom-up.
MxU8* bitmapSrcPtr;
switch (p_bitmap->GetBmiHeader()->biCompression) { switch (p_bitmap->GetBmiHeader()->biCompression) {
case BI_RGB: { case BI_RGB: {
MxS32 rowsBeforeTop;
if (p_bitmap->GetBmiHeight() < 0) if (p_bitmap->GetBmiHeight() < 0)
rowsBeforeTop = 0; rowsBeforeTop = 0;
else else
@ -645,6 +643,7 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
bitmapSrcPtr = p_bitmap->GetBitmapData(); bitmapSrcPtr = p_bitmap->GetBitmapData();
break; break;
default: { default: {
MxS32 rowsBeforeTop;
if (p_bitmap->GetBmiHeight() < 0) if (p_bitmap->GetBmiHeight() < 0)
rowsBeforeTop = 0; rowsBeforeTop = 0;
else else
@ -664,6 +663,7 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
MxS32 rowSeek = ((p_bitmap->GetBmiWidth() + 3) & -4); MxS32 rowSeek = ((p_bitmap->GetBmiWidth() + 3) & -4);
if (p_bitmap->GetBmiHeader()->biCompression != BI_RGB_TOPDOWN && p_bitmap->GetBmiHeight() >= 0) if (p_bitmap->GetBmiHeader()->biCompression != BI_RGB_TOPDOWN && p_bitmap->GetBmiHeight() >= 0)
rowSeek = -rowSeek; rowSeek = -rowSeek;
MxU32 newPitch = ddsd.lPitch; MxU32 newPitch = ddsd.lPitch;
switch (ddsd.ddpfPixelFormat.dwRGBBitCount) { switch (ddsd.ddpfPixelFormat.dwRGBBitCount) {
case 8: { case 8: {
@ -726,7 +726,9 @@ LPDIRECTDRAWSURFACE MxDisplaySurface::VTable0x44(
surface->Unlock(ddsd.lpSurface); surface->Unlock(ddsd.lpSurface);
} }
} }
}
done:
return surface; return surface;
} }