Skip to content

Commit 7919dc5

Browse files
committed
Delay reset of surface desc flags
1 parent 2d51409 commit 7919dc5

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

Dllmain/BuildNo.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define BUILD_NUMBER 8112
1+
#define BUILD_NUMBER 8113

ddraw/IDirectDrawSurfaceX.cpp

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5075,37 +5075,45 @@ void m_IDirectDrawSurfaceX::UpdateAttachedDepthStencil(m_IDirectDrawSurfaceX* lp
50755075

50765076
void m_IDirectDrawSurfaceX::UpdateSurfaceDesc()
50775077
{
5078+
// Get surface flags
50785079
bool IsChanged = false;
5080+
DWORD Flags = surfaceDesc2.dwFlags;
5081+
if (ShouldResetDisplayFlags)
5082+
{
5083+
Flags &= ~ResetDisplayFlags;
5084+
}
5085+
5086+
// Add missing flags
50795087
if (SUCCEEDED(CheckInterface(__FUNCTION__, false, false, false)) &&
5080-
((surfaceDesc2.dwFlags & (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT)) != (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT) ||
5081-
((surfaceDesc2.dwFlags & DDSD_REFRESHRATE) && !surfaceDesc2.dwRefreshRate)))
5088+
((Flags & (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT)) != (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT) ||
5089+
((Flags & DDSD_REFRESHRATE) && !surfaceDesc2.dwRefreshRate)))
50825090
{
50835091
// Get resolution
50845092
DWORD Width, Height, RefreshRate, BPP;
50855093
ddrawParent->GetSurfaceDisplay(Width, Height, BPP, RefreshRate);
50865094

50875095
// Set Height and Width
50885096
if (Width && Height &&
5089-
(surfaceDesc2.dwFlags & (DDSD_WIDTH | DDSD_HEIGHT)) != (DDSD_WIDTH | DDSD_HEIGHT))
5097+
(Flags & (DDSD_WIDTH | DDSD_HEIGHT)) != (DDSD_WIDTH | DDSD_HEIGHT))
50905098
{
50915099
ResetDisplayFlags |= DDSD_WIDTH | DDSD_HEIGHT;
5092-
surfaceDesc2.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
5100+
Flags |= DDSD_WIDTH | DDSD_HEIGHT;
50935101
surfaceDesc2.dwWidth = Width;
50945102
surfaceDesc2.dwHeight = Height;
50955103
surfaceDesc2.lPitch = 0;
50965104
IsChanged = true;
50975105
}
50985106
// Set Refresh Rate
5099-
if (RefreshRate && ((surfaceDesc2.dwFlags & DDSD_REFRESHRATE) || IsPrimaryOrBackBuffer()))
5107+
if (RefreshRate && ((Flags & DDSD_REFRESHRATE) || IsPrimaryOrBackBuffer()))
51005108
{
5101-
surfaceDesc2.dwFlags |= DDSD_REFRESHRATE;
5109+
Flags |= DDSD_REFRESHRATE;
51025110
surfaceDesc2.dwRefreshRate = RefreshRate;
51035111
}
51045112
// Set PixelFormat
5105-
if (BPP && !(surfaceDesc2.dwFlags & DDSD_PIXELFORMAT))
5113+
if (BPP && !(Flags & DDSD_PIXELFORMAT))
51065114
{
51075115
ResetDisplayFlags |= DDSD_PIXELFORMAT;
5108-
surfaceDesc2.dwFlags |= DDSD_PIXELFORMAT;
5116+
Flags |= DDSD_PIXELFORMAT;
51095117
ddrawParent->GetDisplayPixelFormat(surfaceDesc2.ddpfPixelFormat, BPP);
51105118
surfaceDesc2.lPitch = 0;
51115119
IsChanged = true;
@@ -5124,34 +5132,34 @@ void m_IDirectDrawSurfaceX::UpdateSurfaceDesc()
51245132
// Remove surface memory pointer
51255133
if (!surface.UsingSurfaceMemory)
51265134
{
5127-
surfaceDesc2.dwFlags &= ~DDSD_LPSURFACE;
5135+
Flags &= ~DDSD_LPSURFACE;
51285136
surfaceDesc2.lpSurface = nullptr;
51295137
}
51305138
// Unset lPitch
5131-
if ((((surfaceDesc2.dwFlags & (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT)) != (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT) ||
5132-
!(surfaceDesc2.dwFlags & DDSD_PITCH)) && !(surfaceDesc2.dwFlags & DDSD_LINEARSIZE)) || !surfaceDesc2.lPitch)
5139+
if ((((Flags & (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT)) != (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT) ||
5140+
!(Flags & DDSD_PITCH)) && !(Flags & DDSD_LINEARSIZE)) || !surfaceDesc2.lPitch)
51335141
{
5134-
surfaceDesc2.dwFlags &= ~(DDSD_PITCH | DDSD_LINEARSIZE);
5142+
Flags &= ~(DDSD_PITCH | DDSD_LINEARSIZE);
51355143
surfaceDesc2.lPitch = 0;
51365144
}
51375145
// Set lPitch
5138-
if ((surfaceDesc2.dwFlags & (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT)) == (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT) &&
5139-
!(surfaceDesc2.dwFlags & DDSD_LINEARSIZE) && !(surfaceDesc2.dwFlags & DDSD_PITCH))
5146+
if ((Flags & (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT)) == (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT) &&
5147+
!(Flags & DDSD_LINEARSIZE) && !(Flags & DDSD_PITCH))
51405148
{
51415149
DWORD Pitch = ComputePitch(GetDisplayFormat(surfaceDesc2.ddpfPixelFormat), surfaceDesc2.dwWidth, surfaceDesc2.dwHeight);
51425150
if (Pitch)
51435151
{
5144-
surfaceDesc2.dwFlags |= DDSD_PITCH;
5152+
Flags |= DDSD_PITCH;
51455153
surfaceDesc2.lPitch = Pitch;
51465154
}
51475155
}
51485156
// Set surface format
5149-
if (surface.Format == D3DFMT_UNKNOWN && (surfaceDesc2.dwFlags & DDSD_PIXELFORMAT))
5157+
if (surface.Format == D3DFMT_UNKNOWN && (Flags & DDSD_PIXELFORMAT))
51505158
{
51515159
surface.Format = GetDisplayFormat(surfaceDesc2.ddpfPixelFormat);
51525160
}
51535161
// Set attached stencil surface size
5154-
if (IsChanged && (surfaceDesc2.dwFlags & (DDSD_WIDTH | DDSD_HEIGHT)) == (DDSD_WIDTH | DDSD_HEIGHT))
5162+
if (IsChanged && (Flags & (DDSD_WIDTH | DDSD_HEIGHT)) == (DDSD_WIDTH | DDSD_HEIGHT))
51555163
{
51565164
m_IDirectDrawSurfaceX* lpAttachedSurfaceX = GetAttachedDepthStencil();
51575165
if (lpAttachedSurfaceX && (surfaceDesc2.dwWidth != lpAttachedSurfaceX->surfaceDesc2.dwWidth ||
@@ -5168,6 +5176,15 @@ void m_IDirectDrawSurfaceX::UpdateSurfaceDesc()
51685176
}
51695177
}
51705178
}
5179+
5180+
// Add flags to surface desc
5181+
surfaceDesc2.dwFlags |= Flags;
5182+
5183+
// Clear reset flag
5184+
if ((Flags & ResetDisplayFlags) == ResetDisplayFlags)
5185+
{
5186+
ShouldResetDisplayFlags = false;
5187+
}
51715188
}
51725189

51735190
void m_IDirectDrawSurfaceX::SetAsRenderTarget()
@@ -5482,7 +5499,7 @@ void m_IDirectDrawSurfaceX::ReleaseD9Surface(bool BackupData, bool ResetSurface)
54825499
// Reset display flags
54835500
if (ResetDisplayFlags && !ResetSurface)
54845501
{
5485-
surfaceDesc2.dwFlags &= ~ResetDisplayFlags;
5502+
ShouldResetDisplayFlags = true;
54865503
}
54875504

54885505
if (surfaceDesc2.dwFlags & DDSD_REFRESHRATE)

ddraw/IDirectDrawSurfaceX.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj
209209
m_IDirect3DTextureX *attached3DTexture = nullptr; // Associated texture
210210
m_IDirect3DDeviceX *attached3DDevice = nullptr; // Associated device
211211
DDSURFACEDESC2 surfaceDesc2 = {}; // Surface description for this surface
212+
bool ShouldResetDisplayFlags = false; // Determines when flags should be reset
212213
DWORD ResetDisplayFlags = 0; // Flags that need to be reset when display mode changes
213214
DWORD UniquenessValue = 0;
214215
LONG overlayX = 0;

0 commit comments

Comments
 (0)