DXGL r491 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r490‎ | r491 | r492 >
Date:21:23, 16 August 2014
Author:admin
Status:new
Tags:
Comment:
Add DDPCAPS_ALLOW256 support.
Validate several DDraw APIs.
Fix a palette object leak in dxgltest.
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDrawPalette.c (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /dxgltest/Tests2D.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -330,6 +330,7 @@
331331 HRESULT EnumDisplayModes(DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext, LPDDENUMMODESCALLBACK lpEnumModesCallback)
332332 {
333333 if(!lpEnumModesCallback) return DDERR_INVALIDPARAMS;
 334+ if (dwFlags & 0xFFFFFFFC) return DDERR_INVALIDPARAMS;
334335 bool match;
335336 DWORD modenum = 0;
336337 DWORD modemax = 128;
@@ -795,6 +796,7 @@
796797 {
797798 TRACE_ENTER(1,14,this);
798799 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
 800+ if (!fullscreen) TRACE_RET(HRESULT, 23, DDERR_NOEXCLUSIVEMODE);
799801 TRACE_EXIT(23,DD_OK);
800802 return DD_OK;
801803 }
@@ -924,6 +926,7 @@
925927 HRESULT error = DD_OK;
926928 if(primary)
927929 {
 930+ if (!primary->GetBackbuffer()) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
928931 if(primary->flipcount)
929932 {
930933 while(primary->flipcount != 0)
@@ -1234,6 +1237,7 @@
12351238 TRACE_ENTER(3,14,this,13,hWnd,9,dwFlags);
12361239 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
12371240 if(hWnd && !IsWindow(hWnd)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
 1241+ if ((dwFlags & DDSCL_EXCLUSIVE) && !hWnd) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
12381242 if(dwFlags & 0xFFFFE020) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
12391243 this->hWnd = hWnd;
12401244 winstyle = GetWindowLongPtrA(hWnd,GWL_STYLE);
@@ -1374,6 +1378,9 @@
13751379 {
13761380 TRACE_ENTER(6,14,this,8,dwWidth,8,dwHeight,8,dwBPP,8,dwRefreshRate,9,dwFlags);
13771381 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
 1382+ if (dwFlags & 0xFFFFFFFE) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 1383+ if ((dwBPP != 4) && (dwBPP != 8) && (dwBPP != 15) && (dwBPP != 16) && (dwBPP != 24) && (dwBPP != 32))
 1384+ TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
13781385 DEBUG("IDirectDraw::SetDisplayMode: implement multiple monitors\n");
13791386 DEVMODE newmode,newmode2;
13801387 DEVMODE currmode;
Index: ddraw/glDirectDrawPalette.c
@@ -173,7 +173,12 @@
174174 else entrysize = sizeof(PALETTEENTRY);
175175 if((dwStartingEntry + dwCount) > allentries) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
176176 memcpy(((char *)This->palette)+(dwStartingEntry*entrysize),lpEntries,dwCount*entrysize);
177 - TRACE_EXIT(23,DD_OK);
 177+ if (!(This->flags & DDPCAPS_ALLOW256))
 178+ {
 179+ memcpy(&This->palette[0], DefaultPalette, 4);
 180+ memcpy(&This->palette[255], DefaultPalette + 1020, 4);
 181+ }
 182+ TRACE_EXIT(23, DD_OK);
178183 return DD_OK;
179184 }
180185
@@ -205,6 +210,10 @@
206211 glDirectDrawPalette *newpal;
207212 TRACE_ENTER(3,9,dwFlags,14,lpDDColorArray,14,lplpDDPalette);
208213 if (!lplpDDPalette) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
 214+ if (dwFlags & 0xFFFFF000) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 215+ if ((dwFlags & DDPCAPS_8BIT) && (dwFlags & DDPCAPS_8BITENTRIES)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 216+ if (((dwFlags & DDPCAPS_1BIT) || (dwFlags & DDPCAPS_2BIT) || (dwFlags & DDPCAPS_4BIT)) && (dwFlags & DDPCAPS_ALLOW256))
 217+ TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
209218 newpal = (glDirectDrawPalette*)malloc(sizeof(glDirectDrawPalette));
210219 if (!newpal) TRACE_RET(HRESULT, 23, DDERR_OUTOFMEMORY);
211220 ZeroMemory(newpal, sizeof(glDirectDrawPalette));
@@ -211,7 +220,11 @@
212221 newpal->refcount = 1;
213222 newpal->flags = dwFlags;
214223 newpal->lpVtbl = &glDirectDrawPalette_iface;
215 - if(lpDDColorArray == NULL) memcpy(newpal->palette,DefaultPalette,1024);
 224+ if (lpDDColorArray == NULL)
 225+ {
 226+ if (dwFlags & 0x800) memcpy(newpal->palette, DefaultPalette, 1024);
 227+ else return DDERR_INVALIDPARAMS;
 228+ }
216229 else
217230 {
218231 if(newpal->flags & DDPCAPS_1BIT)
@@ -223,7 +236,15 @@
224237 else if(newpal->flags & DDPCAPS_4BIT)
225238 if(newpal->flags & DDPCAPS_8BITENTRIES) memcpy(newpal->palette,lpDDColorArray,16);
226239 else memcpy(newpal->palette,lpDDColorArray,16*sizeof(PALETTEENTRY));
227 - else memcpy(newpal->palette,lpDDColorArray,256*sizeof(PALETTEENTRY));
 240+ else
 241+ {
 242+ memcpy(newpal->palette, lpDDColorArray, 256 * sizeof(PALETTEENTRY));
 243+ if (!(dwFlags & DDPCAPS_ALLOW256))
 244+ {
 245+ memcpy(&newpal->palette[0], DefaultPalette, 4);
 246+ memcpy(&newpal->palette[255], DefaultPalette + 1020, 4);
 247+ }
 248+ }
228249 }
229250 if(lplpDDPalette) *lplpDDPalette = (LPDIRECTDRAWPALETTE)newpal;
230251 TRACE_EXIT(23,DD_OK);
Index: ddraw/glDirectDrawSurface.cpp
@@ -125,7 +125,7 @@
126126 }
127127 if(ddInterface->GetBPP() == 8)
128128 {
129 - if (!palettein) glDirectDrawPalette_Create(DDPCAPS_8BIT|DDPCAPS_ALLOW256|DDPCAPS_PRIMARYSURFACE,NULL,(LPDIRECTDRAWPALETTE*)&palette);
 129+ if (!palettein) glDirectDrawPalette_Create(DDPCAPS_8BIT|DDPCAPS_ALLOW256|DDPCAPS_PRIMARYSURFACE|0x800,NULL,(LPDIRECTDRAWPALETTE*)&palette);
130130 else
131131 {
132132 palette = palettein;
@@ -759,6 +759,7 @@
760760 TRACE_ENTER(3,14,this,14,lpDDSurfaceTargetOverride,9,dwFlags);
761761 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
762762 HRESULT ret = Flip2(lpDDSurfaceTargetOverride,dwFlags);
 763+ if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
763764 if(ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
764765 {
765766 if(ddInterface->lastsync)
@@ -1282,7 +1283,7 @@
12831284 if(palette)
12841285 {
12851286 glDirectDrawPalette_Release(palette);
1286 - if(!lpDDPalette) glDirectDrawPalette_Create(DDPCAPS_8BIT|DDPCAPS_ALLOW256|DDPCAPS_PRIMARYSURFACE,NULL,(LPDIRECTDRAWPALETTE*)&palette);
 1287+ if(!lpDDPalette) glDirectDrawPalette_Create(DDPCAPS_8BIT|DDPCAPS_ALLOW256|DDPCAPS_PRIMARYSURFACE|0x800,NULL,(LPDIRECTDRAWPALETTE*)&palette);
12871288 }
12881289 if(lpDDPalette)
12891290 {
Index: dxgltest/Tests2D.cpp
@@ -574,6 +574,7 @@
575575 ddinterface->CreateSurface(&ddsd, &sprites[0].surface, NULL);
576576 ddsrender->GetPalette(&palette);
577577 error = sprites[0].surface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
 578+ if(palette) palette->Release();
578579 DrawGradients(ddsd, (unsigned char *)ddsd.lpSurface, hWnd, palette, 1, 0);
579580 error = sprites[0].surface->Unlock(NULL);
580581 sprites[0].width = (float)ddsd.dwWidth;