DXGL r516 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r515‎ | r516 | r517 >
Date:00:04, 2 September 2014
Author:admin
Status:new
Tags:
Comment:
Refcount fixes for clippers.
Track refcounts for palettes in DD4 and 7.
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.h (modified) (history)
  • /ddraw/glDirectDrawPalette.c (modified) (history)
  • /ddraw/glDirectDrawPalette.h (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -867,7 +867,7 @@
868868 if (ret == DD_OK)
869869 {
870870 this->AddRef();
871 - ((glDirectDrawClipper*)lplpDDClipper)->creator = this;
 871+ ((glDirectDrawClipper*)*lplpDDClipper)->creator = this;
872872 }
873873 TRACE_EXIT(23, ret);
874874 return ret;
@@ -892,6 +892,20 @@
893893 }
894894 HRESULT WINAPI glDirectDraw7::CreatePalette(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR *lplpDDPalette, IUnknown FAR *pUnkOuter)
895895 {
 896+ TRACE_ENTER(5, 14, this, 9, dwFlags, 14, lpDDColorArray, 14, lplpDDPalette, 14, pUnkOuter);
 897+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 898+ HRESULT ret = CreatePalette2(dwFlags, lpDDColorArray, lplpDDPalette, pUnkOuter);
 899+ if (ret == DD_OK)
 900+ {
 901+ this->AddRef();
 902+ ((glDirectDrawPalette*)*lplpDDPalette)->creator = this;
 903+ }
 904+ TRACE_EXIT(23, ret);
 905+ return ret;
 906+}
 907+
 908+HRESULT glDirectDraw7::CreatePalette2(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR *lplpDDPalette, IUnknown FAR *pUnkOuter)
 909+{
896910 TRACE_ENTER(5,14,this,9,dwFlags,14,lpDDColorArray,14,lplpDDPalette,14,pUnkOuter);
897911 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
898912 if(!lplpDDPalette) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
@@ -2027,7 +2041,7 @@
20282042 if (ret == DD_OK)
20292043 {
20302044 this->AddRef();
2031 - ((glDirectDrawClipper*)lplpDDClipper)->creator = this;
 2045+ ((glDirectDrawClipper*)*lplpDDClipper)->creator = this;
20322046 }
20332047 TRACE_EXIT(23, ret);
20342048 return ret;
@@ -2034,9 +2048,11 @@
20352049 }
20362050 HRESULT WINAPI glDirectDraw1::CreatePalette(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR *lplpDDPalette, IUnknown FAR *pUnkOuter)
20372051 {
2038 - TRACE_ENTER(5,14,this,9,dwFlags,14,lpDDColorArray,14,lplpDDPalette,14,pUnkOuter);
2039 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2040 - TRACE_RET(HRESULT,23,glDD7->CreatePalette(dwFlags,lpDDColorArray,lplpDDPalette,pUnkOuter));
 2052+ TRACE_ENTER(5, 14, this, 9, dwFlags, 14, lpDDColorArray, 14, lplpDDPalette, 14, pUnkOuter);
 2053+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 2054+ HRESULT ret = glDD7->CreatePalette2(dwFlags, lpDDColorArray, lplpDDPalette, pUnkOuter);
 2055+ TRACE_EXIT(23, ret);
 2056+ return ret;
20412057 }
20422058 HRESULT WINAPI glDirectDraw1::CreateSurface(LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRECTDRAWSURFACE FAR *lplpDDSurface, IUnknown FAR *pUnkOuter)
20432059 {
@@ -2228,7 +2244,7 @@
22292245 if (ret == DD_OK)
22302246 {
22312247 this->AddRef();
2232 - ((glDirectDrawClipper*)lplpDDClipper)->creator = this;
 2248+ ((glDirectDrawClipper*)*lplpDDClipper)->creator = this;
22332249 }
22342250 TRACE_EXIT(23, ret);
22352251 return ret;
@@ -2235,9 +2251,11 @@
22362252 }
22372253 HRESULT WINAPI glDirectDraw2::CreatePalette(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR *lplpDDPalette, IUnknown FAR *pUnkOuter)
22382254 {
2239 - TRACE_ENTER(5,14,this,9,dwFlags,14,lpDDColorArray,14,lplpDDPalette,14,pUnkOuter);
2240 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2241 - TRACE_RET(HRESULT,23,glDD7->CreatePalette(dwFlags,lpDDColorArray,lplpDDPalette,pUnkOuter));
 2255+ TRACE_ENTER(5, 14, this, 9, dwFlags, 14, lpDDColorArray, 14, lplpDDPalette, 14, pUnkOuter);
 2256+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 2257+ HRESULT ret = glDD7->CreatePalette2(dwFlags, lpDDColorArray, lplpDDPalette, pUnkOuter);
 2258+ TRACE_EXIT(23, ret);
 2259+ return ret;
22422260 }
22432261 HRESULT WINAPI glDirectDraw2::CreateSurface(LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRECTDRAWSURFACE FAR *lplpDDSurface, IUnknown FAR *pUnkOuter)
22442262 {
@@ -2453,7 +2471,7 @@
24542472 if (ret == DD_OK)
24552473 {
24562474 this->AddRef();
2457 - ((glDirectDrawClipper*)lplpDDClipper)->creator = this;
 2475+ ((glDirectDrawClipper*)*lplpDDClipper)->creator = this;
24582476 }
24592477 TRACE_EXIT(23, ret);
24602478 return ret;
@@ -2460,9 +2478,16 @@
24612479 }
24622480 HRESULT WINAPI glDirectDraw4::CreatePalette(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR *lplpDDPalette, IUnknown FAR *pUnkOuter)
24632481 {
2464 - TRACE_ENTER(5,14,this,9,dwFlags,14,lpDDColorArray,14,lplpDDPalette,14,pUnkOuter);
2465 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2466 - TRACE_RET(HRESULT,23,glDD7->CreatePalette(dwFlags,lpDDColorArray,lplpDDPalette,pUnkOuter));
 2482+ TRACE_ENTER(5, 14, this, 9, dwFlags, 14, lpDDColorArray, 14, lplpDDPalette, 14, pUnkOuter);
 2483+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 2484+ HRESULT ret = glDD7->CreatePalette2(dwFlags, lpDDColorArray, lplpDDPalette, pUnkOuter);
 2485+ if (ret == DD_OK)
 2486+ {
 2487+ this->AddRef();
 2488+ ((glDirectDrawPalette*)*lplpDDPalette)->creator = this;
 2489+ }
 2490+ TRACE_EXIT(23, ret);
 2491+ return ret;
24672492 }
24682493 HRESULT WINAPI glDirectDraw4::CreateSurface(LPDDSURFACEDESC2 lpDDSurfaceDesc, LPDIRECTDRAWSURFACE4 FAR *lplpDDSurface, IUnknown FAR *pUnkOuter)
24692494 {
Index: ddraw/glDirectDraw.h
@@ -89,6 +89,7 @@
9090 ULONG WINAPI Release1();
9191 HRESULT CreateSurface2(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 FAR *lplpDDSurface, IUnknown FAR *pUnkOuter, BOOL RecordSurface);
9292 HRESULT CreateClipper2(DWORD dwFlags, LPDIRECTDRAWCLIPPER FAR *lplpDDClipper, IUnknown FAR *pUnkOuter);
 93+ HRESULT CreatePalette2(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR *lplpDDPalette, IUnknown FAR *pUnkOuter);
9394 HRESULT err() { return error; }
9495 void RemoveSurface(glDirectDrawSurface7 *surface);
9596 void GetSizes(LONG *sizes);
Index: ddraw/glDirectDrawPalette.c
@@ -120,7 +120,11 @@
121121 if(!This) return 0;
122122 This->refcount--;
123123 ret = This->refcount;
124 - if (This->refcount == 0) free(This);
 124+ if (This->refcount == 0)
 125+ {
 126+ if (This->creator) This->creator->lpVtbl->Release(This->creator);
 127+ free(This);
 128+ }
125129 TRACE_EXIT(8,ret);
126130 return ret;
127131 }
@@ -209,7 +213,7 @@
210214 {
211215 glDirectDrawPalette *newpal;
212216 TRACE_ENTER(3,9,dwFlags,14,lpDDColorArray,14,lplpDDPalette);
213 - if (!lplpDDPalette) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
 217+ if (!lplpDDPalette) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
214218 if (dwFlags & 0xFFFFF000) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
215219 if ((dwFlags & DDPCAPS_8BIT) && (dwFlags & DDPCAPS_8BITENTRIES)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
216220 if (((dwFlags & DDPCAPS_1BIT) || (dwFlags & DDPCAPS_2BIT) || (dwFlags & DDPCAPS_4BIT)) && (dwFlags & DDPCAPS_ALLOW256))
@@ -220,6 +224,7 @@
221225 newpal->refcount = 1;
222226 newpal->flags = dwFlags;
223227 newpal->lpVtbl = &glDirectDrawPalette_iface;
 228+ newpal->creator = NULL;
224229 if (lpDDColorArray == NULL)
225230 {
226231 if (dwFlags & 0x800) memcpy(newpal->palette, DefaultPalette, 1024);
Index: ddraw/glDirectDrawPalette.h
@@ -31,6 +31,7 @@
3232 ULONG refcount;
3333 PALETTEENTRY palette[256];
3434 DWORD flags;
 35+ IUnknown *creator;
3536 } glDirectDrawPalette;
3637
3738 typedef struct glDirectDrawPaletteVtbl