DXGL r517 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r516‎ | r517 | r518 >
Date:23:41, 4 September 2014
Author:admin
Status:new
Tags:
Comment:
Merge glDirectDrawSurface and glDirectDrawTexture reference counts.
Fix D3D device descriptions.
Move (not yet implemented) IDirectDrawGammaControl QueryInterface to surface interface.
Modified paths:
  • /ddraw/glDirect3DTexture.cpp (modified) (history)
  • /ddraw/glDirect3DTexture.h (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DTexture.cpp
@@ -29,18 +29,9 @@
3030 {
3131 TRACE_ENTER(2,14,this,14,glDDS7);
3232 this->glDDS7 = glDDS7;
33 - refcount = 1;
3433 TRACE_EXIT(-1,0);
3534 }
3635
37 -glDirect3DTexture2::~glDirect3DTexture2()
38 -{
39 - TRACE_ENTER(1,14,this);
40 - glDDS7->d3dt2 = NULL;
41 - glDDS7->Release();
42 - TRACE_EXIT(-1,0);
43 -}
44 -
4536 HRESULT WINAPI glDirect3DTexture2::QueryInterface(REFIID riid, void** ppvObj)
4637 {
4738 TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
@@ -60,9 +51,7 @@
6152 {
6253 TRACE_ENTER(1,14,this);
6354 if(!this) TRACE_RET(ULONG,8,0);
64 - refcount++;
65 - TRACE_EXIT(8,refcount);
66 - return refcount;
 55+ TRACE_RET(ULONG, 8, glDDS7->textureparent->AddRef());
6756 }
6857
6958 ULONG WINAPI glDirect3DTexture2::Release()
@@ -69,12 +58,7 @@
7059 {
7160 TRACE_ENTER(1,14,this);
7261 if(!this) TRACE_RET(ULONG,8,0);
73 - ULONG ret;
74 - refcount--;
75 - ret = refcount;
76 - if(refcount == 0) delete this;
77 - TRACE_EXIT(8,ret);
78 - return ret;
 62+ TRACE_RET(ULONG, 8, glDDS7->textureparent->Release());
7963 }
8064
8165 HRESULT WINAPI glDirect3DTexture2::GetHandle(LPDIRECT3DDEVICE2 lpDirect3DDevice2, LPD3DTEXTUREHANDLE lpHandle)
@@ -109,16 +93,8 @@
11094 {
11195 TRACE_ENTER(2,14,this,14,glDDS7);
11296 this->glDDS7 = glDDS7;
113 - refcount = 1;
11497 TRACE_EXIT(-1,0);
11598 }
116 -glDirect3DTexture1::~glDirect3DTexture1()
117 -{
118 - TRACE_ENTER(1,14,this);
119 - glDDS7->d3dt1 = NULL;
120 - glDDS7->Release();
121 - TRACE_EXIT(-1,0);
122 -}
12399 HRESULT WINAPI glDirect3DTexture1::QueryInterface(REFIID riid, void** ppvObj)
124100 {
125101 TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
@@ -137,20 +113,13 @@
138114 {
139115 TRACE_ENTER(1,14,this);
140116 if(!this) TRACE_RET(ULONG,8,0);
141 - refcount++;
142 - TRACE_EXIT(8,refcount);
143 - return refcount;
 117+ TRACE_RET(ULONG, 8, glDDS7->textureparent->AddRef());
144118 }
145119 ULONG WINAPI glDirect3DTexture1::Release()
146120 {
147121 TRACE_ENTER(1,14,this);
148122 if(!this) TRACE_RET(ULONG,8,0);
149 - ULONG ret;
150 - refcount--;
151 - ret = refcount;
152 - if(refcount == 0) delete this;
153 - TRACE_EXIT(8,ret);
154 - return ret;
 123+ TRACE_RET(ULONG, 8, glDDS7->textureparent->Release());
155124 }
156125
157126 HRESULT WINAPI glDirect3DTexture1::GetHandle(LPDIRECT3DDEVICE lpDirect3DDevice, LPD3DTEXTUREHANDLE lpHandle)
Index: ddraw/glDirect3DTexture.h
@@ -23,7 +23,6 @@
2424 {
2525 public:
2626 glDirect3DTexture2(glDirectDrawSurface7 *glDDS7);
27 - virtual ~glDirect3DTexture2();
2827 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
2928 ULONG WINAPI AddRef();
3029 ULONG WINAPI Release();
@@ -33,7 +32,6 @@
3433 glDirectDrawSurface7 *GetDDS7(){return glDDS7;}
3534 private:
3635 glDirectDrawSurface7 *glDDS7;
37 - ULONG refcount;
3836 };
3937
4038 class glDirect3DTexture1 : public IDirect3DTexture
@@ -40,7 +38,6 @@
4139 {
4240 public:
4341 glDirect3DTexture1(glDirectDrawSurface7 *glDDS7);
44 - virtual ~glDirect3DTexture1();
4542 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
4643 ULONG WINAPI AddRef();
4744 ULONG WINAPI Release();
@@ -52,7 +49,6 @@
5350 glDirectDrawSurface7 *GetDDS7(){return glDDS7;}
5451 private:
5552 glDirectDrawSurface7 *glDDS7;
56 - ULONG refcount;
5753 };
5854
5955 #endif //__GLDIRECT3DTEXTURE_H
\ No newline at end of file
Index: ddraw/glDirectDraw.cpp
@@ -589,9 +589,6 @@
590590 refcount2 = 0;
591591 refcount1 = 0;
592592 renderer = NULL;
593 - d3ddesc = d3ddesc_default;
594 - d3ddesc3 = d3ddesc3_default;
595 - memcpy(stored_devices, d3ddevices, 3 * sizeof(D3DDevice));
596593 TRACE_EXIT(-1, 0);
597594 }
598595
@@ -750,12 +747,6 @@
751748 TRACE_EXIT(23,DD_OK);
752749 return DD_OK;
753750 }
754 - if(riid == IID_IDirectDrawGammaControl)
755 - {
756 - FIXME("Add gamma control\n");
757 - TRACE_EXIT(23,DDERR_GENERIC);
758 - ERR(DDERR_GENERIC);
759 - }
760751 /*if(riid == IID_IDDVideoPortContainer)
761752 {
762753 ERR(DDERR_GENERIC);
@@ -923,11 +914,11 @@
924915 if(!lpDDSurfaceDesc2) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
925916 if(pUnkOuter) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
926917 if(lpDDSurfaceDesc2->dwSize < sizeof(DDSURFACEDESC2)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
927 - HRESULT ret = CreateSurface2(lpDDSurfaceDesc2,lplpDDSurface,pUnkOuter,TRUE);
 918+ HRESULT ret = CreateSurface2(lpDDSurfaceDesc2,lplpDDSurface,pUnkOuter,TRUE,7);
928919 if (ret == DD_OK)
929920 {
930921 this->AddRef();
931 - ((glDirectDrawSurface7*)lplpDDSurface)->creator = this;
 922+ ((glDirectDrawSurface7*)*lplpDDSurface)->creator = this;
932923 }
933924 TRACE_EXIT(23, ret);
934925 return ret;
@@ -934,7 +925,7 @@
935926 }
936927
937928
938 -HRESULT glDirectDraw7::CreateSurface2(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 FAR *lplpDDSurface, IUnknown FAR *pUnkOuter, BOOL RecordSurface)
 929+HRESULT glDirectDraw7::CreateSurface2(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 FAR *lplpDDSurface, IUnknown FAR *pUnkOuter, BOOL RecordSurface, int version)
939930 {
940931 HRESULT error;
941932 int mipcount;
@@ -977,7 +968,7 @@
978969 ZeroMemory(&surfaces[surfacecountmax], 1024 * sizeof(glDirectDrawSurface7 *));
979970 surfacecountmax += 1024;
980971 }
981 - surfaces[surfacecount - 1] = new glDirectDrawSurface7(this, lpDDSurfaceDesc2, &error, NULL, NULL, 0);
 972+ surfaces[surfacecount - 1] = new glDirectDrawSurface7(this, lpDDSurfaceDesc2, &error, NULL, NULL, 0, version);
982973 if (lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
983974 {
984975 primary = surfaces[surfacecount - 1];
@@ -988,7 +979,7 @@
989980 else
990981 {
991982 if (lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
992 - *lplpDDSurface = new glDirectDrawSurface7(this, lpDDSurfaceDesc2, &error, NULL, NULL, 0);
 983+ *lplpDDSurface = new glDirectDrawSurface7(this, lpDDSurfaceDesc2, &error, NULL, NULL, 0, version);
993984 }
994985 TRACE_VAR("*lplpDDSurface",14,*lplpDDSurface);
995986 TRACE_EXIT(23,error);
@@ -1406,6 +1397,9 @@
14071398 useguid = true;
14081399 DEBUG("Display GUIDs not yet supported, using primary.\n");
14091400 }
 1401+ d3ddesc = d3ddesc_default;
 1402+ d3ddesc3 = d3ddesc3_default;
 1403+ memcpy(stored_devices, d3ddevices, 3 * sizeof(D3DDevice));
14101404 initialized = true;
14111405 TRACE_EXIT(23,DD_OK);
14121406 return DD_OK;
@@ -1951,11 +1945,11 @@
19521946 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
19531947 ddsd.dwWidth = width;
19541948 ddsd.dwHeight = height;
1955 - error = CreateSurface2(&ddsd, (LPDIRECTDRAWSURFACE7*)&tmpsurface, NULL, FALSE);
 1949+ error = CreateSurface2(&ddsd, (LPDIRECTDRAWSURFACE7*)&tmpsurface, NULL, FALSE, 7);
19561950 if (error == DDERR_OUTOFVIDEOMEMORY)
19571951 {
19581952 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
1959 - error = CreateSurface2(&ddsd, (LPDIRECTDRAWSURFACE7*)&tmpsurface, NULL, FALSE);
 1953+ error = CreateSurface2(&ddsd, (LPDIRECTDRAWSURFACE7*)&tmpsurface, NULL, FALSE, 7);
19601954 }
19611955 if (error != DD_OK) return error;
19621956 }
@@ -2065,7 +2059,7 @@
20662060 ZeroMemory(&ddsd2, sizeof(DDSURFACEDESC2));
20672061 memcpy(&ddsd2, lpDDSurfaceDesc, sizeof(DDSURFACEDESC));
20682062 ddsd2.dwSize = sizeof(DDSURFACEDESC2);
2069 - HRESULT err = glDD7->CreateSurface2(&ddsd2,&lpDDS7,pUnkOuter,TRUE);
 2063+ HRESULT err = glDD7->CreateSurface2(&ddsd2,&lpDDS7,pUnkOuter,TRUE,1);
20702064 if(err == DD_OK)
20712065 {
20722066 lpDDS7->QueryInterface(IID_IDirectDrawSurface,(LPVOID*) lplpDDSurface);
@@ -2269,7 +2263,7 @@
22702264 ZeroMemory(&ddsd2, sizeof(DDSURFACEDESC2));
22712265 memcpy(&ddsd2, lpDDSurfaceDesc, sizeof(DDSURFACEDESC));
22722266 ddsd2.dwSize = sizeof(DDSURFACEDESC2);
2273 - HRESULT err = glDD7->CreateSurface2(&ddsd2, &lpDDS7, pUnkOuter, TRUE);
 2267+ HRESULT err = glDD7->CreateSurface2(&ddsd2, &lpDDS7, pUnkOuter, TRUE, 2);
22742268 if(err == DD_OK)
22752269 {
22762270 lpDDS7->QueryInterface(IID_IDirectDrawSurface,(LPVOID*) lplpDDSurface);
@@ -2497,7 +2491,7 @@
24982492 if(!lpDDSurfaceDesc) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
24992493 if(lpDDSurfaceDesc->dwSize < sizeof(DDSURFACEDESC2)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
25002494 LPDIRECTDRAWSURFACE7 lpDDS7;
2501 - HRESULT err = glDD7->CreateSurface2((LPDDSURFACEDESC2)lpDDSurfaceDesc,&lpDDS7,pUnkOuter,TRUE);
 2495+ HRESULT err = glDD7->CreateSurface2((LPDDSURFACEDESC2)lpDDSurfaceDesc,&lpDDS7,pUnkOuter,TRUE,4);
25022496 if(err == DD_OK)
25032497 {
25042498 lpDDS7->QueryInterface(IID_IDirectDrawSurface4,(LPVOID*) lplpDDSurface);
Index: ddraw/glDirectDraw.h
@@ -87,7 +87,7 @@
8888 ULONG WINAPI Release2();
8989 ULONG WINAPI AddRef1();
9090 ULONG WINAPI Release1();
91 - HRESULT CreateSurface2(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 FAR *lplpDDSurface, IUnknown FAR *pUnkOuter, BOOL RecordSurface);
 91+ HRESULT CreateSurface2(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 FAR *lplpDDSurface, IUnknown FAR *pUnkOuter, BOOL RecordSurface, int version);
9292 HRESULT CreateClipper2(DWORD dwFlags, LPDIRECTDRAWCLIPPER FAR *lplpDDClipper, IUnknown FAR *pUnkOuter);
9393 HRESULT CreatePalette2(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, LPDIRECTDRAWPALETTE FAR *lplpDDPalette, IUnknown FAR *pUnkOuter);
9494 HRESULT err() { return error; }
Index: ddraw/glDirectDrawSurface.cpp
@@ -37,7 +37,7 @@
3838
3939 // DDRAW7 routines
4040 glDirectDrawSurface7::glDirectDrawSurface7(LPDIRECTDRAW7 lpDD7, LPDDSURFACEDESC2 lpDDSurfaceDesc2, HRESULT *error,
41 - glDirectDrawPalette *palettein, TEXTURE *parenttex, DWORD miplevel)
 41+ glDirectDrawPalette *palettein, TEXTURE *parenttex, DWORD miplevel, int version)
4242 {
4343 TRACE_ENTER(5,14,this,14,lpDD7,14,lpDDSurfaceDesc2,14,error,14,palettein);
4444 creator = NULL;
@@ -60,12 +60,12 @@
6161 texture = NULL;
6262 clipper = NULL;
6363 hdc = NULL;
64 - dds1 = NULL;
65 - dds2 = NULL;
66 - dds3 = NULL;
67 - dds4 = NULL;
68 - d3dt2 = NULL;
69 - d3dt1 = NULL;
 64+ dds1 = new glDirectDrawSurface1(this);
 65+ dds2 = new glDirectDrawSurface2(this);
 66+ dds3 = new glDirectDrawSurface3(this);
 67+ dds4 = new glDirectDrawSurface4(this);
 68+ d3dt2 = new glDirect3DTexture2(this);
 69+ d3dt1 = new glDirect3DTexture1(this);
7070 buffer = gdibuffer = NULL;
7171 bigbuffer = NULL;
7272 zbuffer = NULL;
@@ -327,7 +327,7 @@
328328 newdesc.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
329329 newdesc.dwMipMapCount = ddsd.dwMipMapCount - 1;
330330 HRESULT miperror;
331 - if(newdesc.dwMipMapCount) miptexture = new glDirectDrawSurface7(lpDD7, &newdesc, &miperror, palette, texture, miplevel + 1);
 331+ if(newdesc.dwMipMapCount) miptexture = new glDirectDrawSurface7(lpDD7, &newdesc, &miperror, palette, texture, miplevel + 1, version);
332332 }
333333
334334 if(ddsd.ddpfPixelFormat.dwRGBBitCount > 8)
@@ -339,7 +339,13 @@
340340 }
341341 if(!bitmapinfo->bmiHeader.biBitCount)
342342 bitmapinfo->bmiHeader.biBitCount = (WORD)ddsd.ddpfPixelFormat.dwRGBBitCount;
343 - refcount = 1;
 343+ refcount7 = 1;
 344+ refcount4 = 0;
 345+ refcount3 = 0;
 346+ refcount2 = 0;
 347+ refcount1 = 0;
 348+ refcountgamma = 0;
 349+ refcountcolor = 0;
344350 *error = DD_OK;
345351 backbuffer = NULL;
346352 if(ddsd.ddsCaps.dwCaps & DDSCAPS_COMPLEX)
@@ -354,12 +360,27 @@
355361 ddsdBack.dwBackBufferCount--;
356362 ddsdBack.ddsCaps.dwCaps |= DDSCAPS_BACKBUFFER;
357363 ddsdBack.ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER;
358 - backbuffer = new glDirectDrawSurface7(ddInterface,&ddsdBack,error,palette,parenttex,miplevel);
 364+ backbuffer = new glDirectDrawSurface7(ddInterface,&ddsdBack,error,palette,parenttex,miplevel,version);
359365 }
360366 else if (ddsd.dwFlags & DDSD_BACKBUFFERCOUNT){}
361367 else *error = DDERR_INVALIDPARAMS;
362368 }
363369 }
 370+ switch (version)
 371+ {
 372+ case 1:
 373+ case 2:
 374+ case 3:
 375+ default:
 376+ textureparent = this->dds1;
 377+ break;
 378+ case 4:
 379+ textureparent = this->dds4;
 380+ break;
 381+ case 7:
 382+ textureparent = this;
 383+ break;
 384+ }
364385 TRACE_VAR("*error",23,*error);
365386 TRACE_EXIT(-1,0);
366387 }
@@ -367,16 +388,18 @@
368389 {
369390 TRACE_ENTER(1,14,this);
370391 AddRef();
371 - if(dds1) dds1->Release();
372 - if(dds2) dds2->Release();
373 - if(dds3) dds3->Release();
374 - if(dds4) dds4->Release();
 392+ if (dds1) delete dds1;
 393+ if (dds2) delete dds2;
 394+ if (dds3) delete dds3;
 395+ if (dds4) delete dds4;
 396+ if (d3dt1) delete d3dt1;
 397+ if (d3dt2) delete d3dt2;
375398 if(paltex)
376399 {
377400 glRenderer_DeleteTexture(ddInterface->renderer, paltex);
378401 delete paltex;
379402 }
380 - if(texture)
 403+ if(texture && !(ddsd.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL))
381404 {
382405 glRenderer_DeleteTexture(ddInterface->renderer, texture);
383406 delete texture;
@@ -394,7 +417,7 @@
395418 if(clipper) glDirectDrawClipper_Release(clipper);
396419 if(buffer) free(buffer);
397420 if(bigbuffer) free(bigbuffer);
398 - if(zbuffer) zbuffer->Release();
 421+ if(zbuffer) zbuffer_iface->Release();
399422 if(miptexture) miptexture->Release();
400423 if(device) device->Release();
401424 ddInterface->DeleteSurface(this);
@@ -406,7 +429,7 @@
407430 TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
408431 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
409432 if(!ppvObj) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
410 - if(riid == IID_IUnknown)
 433+ if((riid == IID_IUnknown) || (riid == IID_IDirectDrawSurface7))
411434 {
412435 this->AddRef();
413436 *ppvObj = this;
@@ -414,135 +437,67 @@
415438 TRACE_EXIT(23,DD_OK);
416439 return DD_OK;
417440 }
418 - if(riid == IID_IDirectDrawSurface7)
 441+ if(riid == IID_IDirectDrawSurface4)
419442 {
420 - this->AddRef();
421 - *ppvObj = this;
 443+ this->AddRef4();
 444+ *ppvObj = dds4;
422445 TRACE_VAR("*ppvObj",14,*ppvObj);
423446 TRACE_EXIT(23,DD_OK);
424447 return DD_OK;
425448 }
426 - if(riid == IID_IDirectDrawSurface4)
427 - {
428 - if(dds4)
429 - {
430 - *ppvObj = dds4;
431 - dds4->AddRef();
432 - TRACE_VAR("*ppvObj",14,*ppvObj);
433 - TRACE_EXIT(23,DD_OK);
434 - return DD_OK;
435 - }
436 - else
437 - {
438 - this->AddRef();
439 - *ppvObj = new glDirectDrawSurface4(this);
440 - dds4 = (glDirectDrawSurface4*)*ppvObj;
441 - TRACE_VAR("*ppvObj",14,*ppvObj);
442 - TRACE_EXIT(23,DD_OK);
443 - return DD_OK;
444 - }
445 - }
446449 if(riid == IID_IDirectDrawSurface3)
447450 {
448 - if(dds3)
449 - {
450 - *ppvObj = dds3;
451 - dds3->AddRef();
452 - TRACE_VAR("*ppvObj",14,*ppvObj);
453 - TRACE_EXIT(23,DD_OK);
454 - return DD_OK;
455 - }
456 - else
457 - {
458 - this->AddRef();
459 - *ppvObj = new glDirectDrawSurface3(this);
460 - dds3 = (glDirectDrawSurface3*)*ppvObj;
461 - TRACE_VAR("*ppvObj",14,*ppvObj);
462 - TRACE_EXIT(23,DD_OK);
463 - return DD_OK;
464 - }
 451+ this->AddRef3();
 452+ *ppvObj = dds3;
 453+ TRACE_VAR("*ppvObj",14,*ppvObj);
 454+ TRACE_EXIT(23,DD_OK);
 455+ return DD_OK;
465456 }
466457 if(riid == IID_IDirectDrawSurface2)
467458 {
468 - if(dds2)
469 - {
470 - *ppvObj = dds2;
471 - dds2->AddRef();
472 - TRACE_VAR("*ppvObj",14,*ppvObj);
473 - TRACE_EXIT(23,DD_OK);
474 - return DD_OK;
475 - }
476 - else
477 - {
478 - this->AddRef();
479 - *ppvObj = new glDirectDrawSurface2(this);
480 - dds2 = (glDirectDrawSurface2*)*ppvObj;
481 - TRACE_VAR("*ppvObj",14,*ppvObj);
482 - TRACE_EXIT(23,DD_OK);
483 - return DD_OK;
484 - }
 459+ this->AddRef2();
 460+ *ppvObj = dds2;
 461+ TRACE_VAR("*ppvObj",14,*ppvObj);
 462+ TRACE_EXIT(23,DD_OK);
 463+ return DD_OK;
485464 }
486465 if(riid == IID_IDirectDrawSurface)
487466 {
488 - if(dds1)
489 - {
490 - *ppvObj = dds1;
491 - dds1->AddRef();
492 - TRACE_VAR("*ppvObj",14,*ppvObj);
493 - TRACE_EXIT(23,DD_OK);
494 - return DD_OK;
495 - }
496 - else
497 - {
498 - this->AddRef();
499 - *ppvObj = new glDirectDrawSurface1(this);
500 - dds1 = (glDirectDrawSurface1*)*ppvObj;
501 - TRACE_VAR("*ppvObj",14,*ppvObj);
502 - TRACE_EXIT(23,DD_OK);
503 - return DD_OK;
504 - }
 467+ this->AddRef1();
 468+ *ppvObj = dds1;
 469+ TRACE_VAR("*ppvObj",14,*ppvObj);
 470+ TRACE_EXIT(23,DD_OK);
 471+ return DD_OK;
505472 }
506473 if(riid == IID_IDirect3DTexture2)
507474 {
508 - if(d3dt2)
509 - {
510 - *ppvObj = d3dt2;
511 - d3dt2->AddRef();
512 - TRACE_VAR("*ppvObj",14,*ppvObj);
513 - TRACE_EXIT(23,DD_OK);
514 - return DD_OK;
515 - }
516 - else
517 - {
518 - this->AddRef();
519 - *ppvObj = new glDirect3DTexture2(this);
520 - d3dt2 = (glDirect3DTexture2*)*ppvObj;
521 - TRACE_VAR("*ppvObj",14,*ppvObj);
522 - TRACE_EXIT(23,DD_OK);
523 - return DD_OK;
524 - }
 475+ d3dt2->AddRef();
 476+ *ppvObj = d3dt2;
 477+ TRACE_VAR("*ppvObj",14,*ppvObj);
 478+ TRACE_EXIT(23,DD_OK);
 479+ return DD_OK;
525480 }
526481 if(riid == IID_IDirect3DTexture)
527482 {
528 - if(d3dt1)
529 - {
530 - *ppvObj = d3dt1;
531 - d3dt1->AddRef();
532 - TRACE_VAR("*ppvObj",14,*ppvObj);
533 - TRACE_EXIT(23,DD_OK);
534 - return DD_OK;
535 - }
536 - else
537 - {
538 - this->AddRef();
539 - *ppvObj = new glDirect3DTexture1(this);
540 - d3dt1 = (glDirect3DTexture1*)*ppvObj;
541 - TRACE_VAR("*ppvObj",14,*ppvObj);
542 - TRACE_EXIT(23,DD_OK);
543 - return DD_OK;
544 - }
 483+ d3dt1->AddRef();
 484+ *ppvObj = d3dt1;
 485+ TRACE_VAR("*ppvObj",14,*ppvObj);
 486+ TRACE_EXIT(23,DD_OK);
 487+ return DD_OK;
545488 }
546 - if((riid == IID_IDirect3DDevice) || (riid == IID_IDirect3DHALDevice) || (riid == IID_IDirect3DRGBDevice) ||
 489+ if (riid == IID_IDirectDrawGammaControl)
 490+ {
 491+ FIXME("Add gamma control\n");
 492+ TRACE_EXIT(23, E_NOINTERFACE);
 493+ ERR(E_NOINTERFACE);
 494+ }
 495+ if (riid == IID_IDirectDrawColorControl)
 496+ {
 497+ FIXME("Add color control\n");
 498+ TRACE_EXIT(23, E_NOINTERFACE);
 499+ ERR(E_NOINTERFACE);
 500+ }
 501+ if ((riid == IID_IDirect3DDevice) || (riid == IID_IDirect3DHALDevice) || (riid == IID_IDirect3DRGBDevice) ||
547502 (riid == IID_IDirect3DRampDevice) || (riid == IID_IDirect3DRefDevice))
548503 {
549504
@@ -582,9 +537,9 @@
583538 {
584539 TRACE_ENTER(1,14,this);
585540 if(!this) TRACE_RET(ULONG,8,0);
586 - refcount++;
587 - TRACE_EXIT(8,refcount);
588 - return refcount;
 541+ refcount7++;
 542+ TRACE_EXIT(8,refcount7);
 543+ return refcount7;
589544 }
590545 ULONG WINAPI glDirectDrawSurface7::Release()
591546 {
@@ -591,15 +546,160 @@
592547 TRACE_ENTER(1,14,this);
593548 if(!this) TRACE_RET(ULONG,8,0);
594549 ULONG ret;
595 - refcount--;
596 - ret = refcount;
597 - if(refcount == 0) delete this;
 550+ if (refcount7 == 0) TRACE_RET(ULONG, 8, 0);
 551+ refcount7--;
 552+ ret = refcount7;
 553+ if ((refcount7 == 0) && (refcount4 == 0) && (refcount3 == 0) && (refcount2 == 0) &&
 554+ (refcount1 == 0) && (refcountgamma == 0) && (refcountcolor == 0))delete this;
598555 TRACE_EXIT(8,ret);
599556 return ret;
600557 }
 558+ULONG WINAPI glDirectDrawSurface7::AddRef4()
 559+{
 560+ TRACE_ENTER(1, 14, this);
 561+ if (!this) TRACE_RET(ULONG, 8, 0);
 562+ refcount4++;
 563+ TRACE_EXIT(8, refcount4);
 564+ return refcount4;
 565+}
 566+ULONG WINAPI glDirectDrawSurface7::Release4()
 567+{
 568+ TRACE_ENTER(1, 14, this);
 569+ if (!this) TRACE_RET(ULONG, 8, 0);
 570+ ULONG ret;
 571+ if (refcount4 == 0) TRACE_RET(ULONG, 8, 0);
 572+ refcount4--;
 573+ ret = refcount4;
 574+ if ((refcount7 == 0) && (refcount4 == 0) && (refcount3 == 0) && (refcount2 == 0) &&
 575+ (refcount1 == 0) && (refcountgamma == 0) && (refcountcolor == 0))delete this;
 576+ TRACE_EXIT(8, ret);
 577+ return ret;
 578+}
 579+ULONG WINAPI glDirectDrawSurface7::AddRef3()
 580+{
 581+ TRACE_ENTER(1, 14, this);
 582+ if (!this) TRACE_RET(ULONG, 8, 0);
 583+ refcount3++;
 584+ TRACE_EXIT(8, refcount3);
 585+ return refcount3;
 586+}
 587+ULONG WINAPI glDirectDrawSurface7::Release3()
 588+{
 589+ TRACE_ENTER(1, 14, this);
 590+ if (!this) TRACE_RET(ULONG, 8, 0);
 591+ ULONG ret;
 592+ if (refcount3 == 0) TRACE_RET(ULONG, 8, 0);
 593+ refcount3--;
 594+ ret = refcount3;
 595+ if ((refcount7 == 0) && (refcount4 == 0) && (refcount3 == 0) && (refcount2 == 0) &&
 596+ (refcount1 == 0) && (refcountgamma == 0) && (refcountcolor == 0))delete this;
 597+ TRACE_EXIT(8, ret);
 598+ return ret;
 599+}
 600+ULONG WINAPI glDirectDrawSurface7::AddRef2()
 601+{
 602+ TRACE_ENTER(1, 14, this);
 603+ if (!this) TRACE_RET(ULONG, 8, 0);
 604+ refcount2++;
 605+ TRACE_EXIT(8, refcount2);
 606+ return refcount2;
 607+}
 608+ULONG WINAPI glDirectDrawSurface7::Release2()
 609+{
 610+ TRACE_ENTER(1, 14, this);
 611+ if (!this) TRACE_RET(ULONG, 8, 0);
 612+ ULONG ret;
 613+ if (refcount2 == 0) TRACE_RET(ULONG, 8, 0);
 614+ refcount2--;
 615+ ret = refcount2;
 616+ if ((refcount7 == 0) && (refcount4 == 0) && (refcount3 == 0) && (refcount2 == 0) &&
 617+ (refcount1 == 0) && (refcountgamma == 0) && (refcountcolor == 0))delete this;
 618+ TRACE_EXIT(8, ret);
 619+ return ret;
 620+}
 621+ULONG WINAPI glDirectDrawSurface7::AddRef1()
 622+{
 623+ TRACE_ENTER(1, 14, this);
 624+ if (!this) TRACE_RET(ULONG, 8, 0);
 625+ refcount1++;
 626+ TRACE_EXIT(8, refcount1);
 627+ return refcount1;
 628+}
 629+ULONG WINAPI glDirectDrawSurface7::Release1()
 630+{
 631+ TRACE_ENTER(1, 14, this);
 632+ if (!this) TRACE_RET(ULONG, 8, 0);
 633+ ULONG ret;
 634+ if (refcount1 == 0) TRACE_RET(ULONG, 8, 0);
 635+ refcount1--;
 636+ ret = refcount1;
 637+ if ((refcount7 == 0) && (refcount4 == 0) && (refcount3 == 0) && (refcount2 == 0) &&
 638+ (refcount1 == 0) && (refcountgamma == 0) && (refcountcolor == 0))delete this;
 639+ TRACE_EXIT(8, ret);
 640+ return ret;
 641+}
 642+ULONG WINAPI glDirectDrawSurface7::AddRefGamma()
 643+{
 644+ TRACE_ENTER(1, 14, this);
 645+ if (!this) TRACE_RET(ULONG, 8, 0);
 646+ refcountgamma++;
 647+ TRACE_EXIT(8, refcountgamma);
 648+ return refcountgamma;
 649+}
 650+ULONG WINAPI glDirectDrawSurface7::ReleaseGamma()
 651+{
 652+ TRACE_ENTER(1, 14, this);
 653+ if (!this) TRACE_RET(ULONG, 8, 0);
 654+ ULONG ret;
 655+ if (refcountgamma == 0) TRACE_RET(ULONG, 8, 0);
 656+ refcountgamma--;
 657+ ret = refcountgamma;
 658+ if ((refcount7 == 0) && (refcount4 == 0) && (refcount3 == 0) && (refcount2 == 0) &&
 659+ (refcount1 == 0) && (refcountgamma == 0) && (refcountcolor == 0))delete this;
 660+ TRACE_EXIT(8, ret);
 661+ return ret;
 662+}
 663+ULONG WINAPI glDirectDrawSurface7::AddRefColor()
 664+{
 665+ TRACE_ENTER(1, 14, this);
 666+ if (!this) TRACE_RET(ULONG, 8, 0);
 667+ refcountcolor++;
 668+ TRACE_EXIT(8, refcountcolor);
 669+ return refcountcolor;
 670+}
 671+ULONG WINAPI glDirectDrawSurface7::ReleaseColor()
 672+{
 673+ TRACE_ENTER(1, 14, this);
 674+ if (!this) TRACE_RET(ULONG, 8, 0);
 675+ ULONG ret;
 676+ if (refcountcolor == 0) TRACE_RET(ULONG, 8, 0);
 677+ refcountcolor--;
 678+ ret = refcountcolor;
 679+ if ((refcount7 == 0) && (refcount4 == 0) && (refcount3 == 0) && (refcount2 == 0) &&
 680+ (refcount1 == 0) && (refcountgamma == 0) && (refcountcolor == 0))delete this;
 681+ TRACE_EXIT(8, ret);
 682+ return ret;
 683+}
 684+
601685 HRESULT WINAPI glDirectDrawSurface7::AddAttachedSurface(LPDIRECTDRAWSURFACE7 lpDDSAttachedSurface)
602686 {
603 - TRACE_ENTER(2,14,this,14,lpDDSAttachedSurface);
 687+ TRACE_ENTER(2, 14, this, 15, lpDDSAttachedSurface);
 688+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 689+ if (!lpDDSAttachedSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 690+ LPDIRECTDRAWSURFACE7 dds7;
 691+ HRESULT ret;
 692+ ret = ((IUnknown*)lpDDSAttachedSurface)->QueryInterface(IID_IDirectDrawSurface7, (void**)&dds7);
 693+ if (ret != S_OK) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 694+ ret = AddAttachedSurface2(dds7, lpDDSAttachedSurface);
 695+ if (ret == DD_OK) ((IUnknown*)lpDDSAttachedSurface)->AddRef();
 696+ dds7->Release();
 697+ TRACE_RET(HRESULT, 23, ret);
 698+ return ret;
 699+}
 700+
 701+HRESULT glDirectDrawSurface7::AddAttachedSurface2(LPDIRECTDRAWSURFACE7 lpDDSAttachedSurface, IUnknown *iface)
 702+{
 703+ TRACE_ENTER(3,14,this,14,lpDDSAttachedSurface,iface);
604704 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
605705 if(!lpDDSAttachedSurface) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
606706 if(zbuffer) TRACE_RET(HRESULT,23,DDERR_SURFACEALREADYATTACHED);
@@ -609,8 +709,8 @@
610710 attached->GetSurfaceDesc(&ddsd);
611711 if((ddsd.ddpfPixelFormat.dwFlags & DDPF_ZBUFFER) || (ddsd.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
612712 {
613 - attached->AddRef();
614713 zbuffer = attached;
 714+ zbuffer_iface = iface;
615715 TRACE_EXIT(23,DD_OK);
616716 return DD_OK;
617717 }
@@ -750,7 +850,7 @@
751851 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
752852 if(lpDDSAttachedSurface == (LPDIRECTDRAWSURFACE7)zbuffer)
753853 {
754 - zbuffer->Release();
 854+ zbuffer_iface->Release();
755855 zbuffer = NULL;
756856 TRACE_EXIT(23,DD_OK);
757857 return DD_OK;
@@ -1627,30 +1727,8 @@
16281728 {
16291729 TRACE_ENTER(2,14,this,14,gl_DDS7);
16301730 glDDS7 = gl_DDS7;
1631 - refcount = 1;
1632 - attachments = (glDirectDrawSurface1**)malloc(16 * sizeof(glDirectDrawSurface1*));
1633 - attachcount = 0;
1634 - maxattach = 16;
1635 - if (attachments)
1636 - {
1637 - if (attachcount)
1638 - {
1639 - for (int i = 0; i < attachcount; i++)
1640 - {
1641 - if (attachments[i]) attachments[i]->Release();
1642 - }
1643 - }
1644 - free(attachments);
1645 - }
16461731 TRACE_EXIT(-1, 0);
16471732 }
1648 -glDirectDrawSurface1::~glDirectDrawSurface1()
1649 -{
1650 - TRACE_ENTER(1,14,this);
1651 - glDDS7->dds1 = NULL;
1652 - glDDS7->Release();
1653 - TRACE_EXIT(-1,0);
1654 -}
16551733 HRESULT WINAPI glDirectDrawSurface1::QueryInterface(REFIID riid, void** ppvObj)
16561734 {
16571735 TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
@@ -1669,74 +1747,27 @@
16701748 {
16711749 TRACE_ENTER(1,14,this);
16721750 if(!this) TRACE_RET(ULONG,8,0);
1673 - refcount++;
1674 - TRACE_EXIT(8,refcount);
1675 - return refcount;
 1751+ TRACE_RET(ULONG, 8, glDDS7->AddRef1());
16761752 }
16771753 ULONG WINAPI glDirectDrawSurface1::Release()
16781754 {
16791755 TRACE_ENTER(1,14,this);
16801756 if(!this) TRACE_RET(ULONG,8,0);
1681 - ULONG ret;
1682 - refcount--;
1683 - ret = refcount;
1684 - if(refcount == 0) delete this;
1685 - TRACE_EXIT(8,ret);
1686 - return ret;
 1757+ TRACE_RET(ULONG, 8, glDDS7->Release1());
16871758 }
1688 -void glDirectDrawSurface1::AddAttach(glDirectDrawSurface1 *attach)
1689 -{
1690 - bool emptyspace = false;
1691 - int index;
1692 - for (int i = 0; i < attachcount; i++)
1693 - {
1694 - if (!attachments[i])
1695 - {
1696 - emptyspace = true;
1697 - index = i;
1698 - break;
1699 - }
1700 - }
1701 - if (emptyspace) attachments[index] = attach;
1702 - else
1703 - {
1704 - attachcount++;
1705 - if (attachcount >= maxattach)
1706 - {
1707 - glDirectDrawSurface1 **newattach = (glDirectDrawSurface1**)realloc(attachments,
1708 - (maxattach + 16)*sizeof(glDirectDrawSurface1*));
1709 - if (newattach)
1710 - {
1711 - maxattach += 16;
1712 - attachments = newattach;
1713 - }
1714 - }
1715 - attachments[attachcount-1] = attach;
1716 - }
1717 - attach->AddRef();
1718 -}
1719 -void glDirectDrawSurface1::DeleteAttach(glDirectDrawSurface1 *attach)
1720 -{
1721 - if (!attachcount) return;
1722 - for (int i = 0; i < attachcount; i++)
1723 - {
1724 - if (attachments[i] == attach)
1725 - {
1726 - attach->Release();
1727 - attachments[i] = NULL;
1728 - return;
1729 - }
1730 - }
1731 -}
17321759 HRESULT WINAPI glDirectDrawSurface1::AddAttachedSurface(LPDIRECTDRAWSURFACE lpDDSAttachedSurface)
17331760 {
1734 - TRACE_ENTER(2,14,this,14,lpDDSAttachedSurface);
1735 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
1736 - if(!lpDDSAttachedSurface) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
1737 - HRESULT ret = glDDS7->AddAttachedSurface(((glDirectDrawSurface1*)lpDDSAttachedSurface)->GetDDS7());
1738 - if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
1739 - AddAttach((glDirectDrawSurface1*)lpDDSAttachedSurface);
1740 - TRACE_EXIT(23, ret);
 1761+ TRACE_ENTER(2, 14, this, 15, lpDDSAttachedSurface);
 1762+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 1763+ if (!lpDDSAttachedSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 1764+ LPDIRECTDRAWSURFACE7 dds7;
 1765+ HRESULT ret;
 1766+ ret = ((IUnknown*)lpDDSAttachedSurface)->QueryInterface(IID_IDirectDrawSurface7, (void**)&dds7);
 1767+ if (ret != S_OK) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 1768+ ret = glDDS7->AddAttachedSurface2(dds7, lpDDSAttachedSurface);
 1769+ if (ret == DD_OK) ((IUnknown*)lpDDSAttachedSurface)->AddRef();
 1770+ dds7->Release();
 1771+ TRACE_RET(HRESULT, 23, ret);
17411772 return ret;
17421773 }
17431774 HRESULT WINAPI glDirectDrawSurface1::AddOverlayDirtyRect(LPRECT lpRect)
@@ -1784,7 +1815,6 @@
17851816 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
17861817 HRESULT ret = glDDS7->DeleteAttachedSurface(dwFlags, ((glDirectDrawSurface1*)lpDDSAttachedSurface)->GetDDS7());
17871818 if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
1788 - DeleteAttach((glDirectDrawSurface1*)lpDDSAttachedSurface);
17891819 TRACE_EXIT(23, ret);
17901820 return ret;
17911821 }
@@ -2003,30 +2033,8 @@
20042034 {
20052035 TRACE_ENTER(2,14,this,14,gl_DDS7);
20062036 glDDS7 = gl_DDS7;
2007 - refcount = 1;
2008 - attachments = (glDirectDrawSurface2**)malloc(16 * sizeof(glDirectDrawSurface2*));
2009 - attachcount = 0;
2010 - maxattach = 16;
20112037 TRACE_EXIT(-1, 0);
20122038 }
2013 -glDirectDrawSurface2::~glDirectDrawSurface2()
2014 -{
2015 - TRACE_ENTER(1,14,this);
2016 - glDDS7->dds2 = NULL;
2017 - glDDS7->Release();
2018 - if (attachments)
2019 - {
2020 - if (attachcount)
2021 - {
2022 - for (int i = 0; i < attachcount; i++)
2023 - {
2024 - if (attachments[i]) attachments[i]->Release();
2025 - }
2026 - }
2027 - free(attachments);
2028 - }
2029 - TRACE_EXIT(-1, 0);
2030 -}
20312039 HRESULT WINAPI glDirectDrawSurface2::QueryInterface(REFIID riid, void** ppvObj)
20322040 {
20332041 TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
@@ -2044,74 +2052,27 @@
20452053 {
20462054 TRACE_ENTER(1,14,this);
20472055 if(!this) TRACE_RET(ULONG,8,0);
2048 - refcount++;
2049 - TRACE_EXIT(8,refcount);
2050 - return refcount;
 2056+ TRACE_RET(ULONG, 8, glDDS7->AddRef2());
20512057 }
20522058 ULONG WINAPI glDirectDrawSurface2::Release()
20532059 {
20542060 TRACE_ENTER(1,14,this);
20552061 if(!this) TRACE_RET(ULONG,8,0);
2056 - ULONG ret;
2057 - refcount--;
2058 - ret = refcount;
2059 - if(refcount == 0) delete this;
2060 - TRACE_EXIT(8,ret);
2061 - return ret;
 2062+ TRACE_RET(ULONG, 8, glDDS7->Release2());
20622063 }
2063 -void glDirectDrawSurface2::AddAttach(glDirectDrawSurface2 *attach)
2064 -{
2065 - bool emptyspace = false;
2066 - int index;
2067 - for (int i = 0; i < attachcount; i++)
2068 - {
2069 - if (!attachments[i])
2070 - {
2071 - emptyspace = true;
2072 - index = i;
2073 - break;
2074 - }
2075 - }
2076 - if (emptyspace) attachments[index] = attach;
2077 - else
2078 - {
2079 - attachcount++;
2080 - if (attachcount >= maxattach)
2081 - {
2082 - glDirectDrawSurface2 **newattach = (glDirectDrawSurface2**)realloc(attachments,
2083 - (maxattach + 16)*sizeof(glDirectDrawSurface2*));
2084 - if (newattach)
2085 - {
2086 - maxattach += 16;
2087 - attachments = newattach;
2088 - }
2089 - }
2090 - attachments[attachcount-1] = attach;
2091 - }
2092 - attach->AddRef();
2093 -}
2094 -void glDirectDrawSurface2::DeleteAttach(glDirectDrawSurface2 *attach)
2095 -{
2096 - if (!attachcount) return;
2097 - for (int i = 0; i < attachcount; i++)
2098 - {
2099 - if (attachments[i] == attach)
2100 - {
2101 - attach->Release();
2102 - attachments[i] = NULL;
2103 - return;
2104 - }
2105 - }
2106 -}
21072064 HRESULT WINAPI glDirectDrawSurface2::AddAttachedSurface(LPDIRECTDRAWSURFACE2 lpDDSAttachedSurface)
21082065 {
2109 - TRACE_ENTER(2,14,this,14,lpDDSAttachedSurface);
2110 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2111 - if(!lpDDSAttachedSurface) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
2112 - HRESULT ret = glDDS7->AddAttachedSurface(((glDirectDrawSurface2*)lpDDSAttachedSurface)->GetDDS7());
2113 - if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
2114 - AddAttach((glDirectDrawSurface2*)lpDDSAttachedSurface);
2115 - TRACE_EXIT(23, ret);
 2066+ TRACE_ENTER(2, 14, this, 15, lpDDSAttachedSurface);
 2067+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 2068+ if (!lpDDSAttachedSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2069+ LPDIRECTDRAWSURFACE7 dds7;
 2070+ HRESULT ret;
 2071+ ret = ((IUnknown*)lpDDSAttachedSurface)->QueryInterface(IID_IDirectDrawSurface7, (void**)&dds7);
 2072+ if (ret != S_OK) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2073+ ret = glDDS7->AddAttachedSurface2(dds7, lpDDSAttachedSurface);
 2074+ if (ret == DD_OK) ((IUnknown*)lpDDSAttachedSurface)->AddRef();
 2075+ dds7->Release();
 2076+ TRACE_RET(HRESULT, 23, ret);
21162077 return ret;
21172078 }
21182079 HRESULT WINAPI glDirectDrawSurface2::AddOverlayDirtyRect(LPRECT lpRect)
@@ -2159,7 +2120,6 @@
21602121 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
21612122 HRESULT ret = glDDS7->DeleteAttachedSurface(dwFlags, ((glDirectDrawSurface2*)lpDDSAttachedSurface)->GetDDS7());
21622123 if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
2163 - DeleteAttach((glDirectDrawSurface2*)lpDDSAttachedSurface);
21642124 TRACE_EXIT(23, ret);
21652125 return ret;
21662126 }
@@ -2401,30 +2361,8 @@
24022362 {
24032363 TRACE_ENTER(2,14,this,14,gl_DDS7);
24042364 glDDS7 = gl_DDS7;
2405 - refcount = 1;
2406 - attachments = (glDirectDrawSurface3**)malloc(16 * sizeof(glDirectDrawSurface3*));
2407 - attachcount = 0;
2408 - maxattach = 16;
24092365 TRACE_EXIT(-1, 0);
24102366 }
2411 -glDirectDrawSurface3::~glDirectDrawSurface3()
2412 -{
2413 - TRACE_ENTER(1,14,this);
2414 - glDDS7->dds3 = NULL;
2415 - glDDS7->Release();
2416 - if (attachments)
2417 - {
2418 - if (attachcount)
2419 - {
2420 - for (int i = 0; i < attachcount; i++)
2421 - {
2422 - if (attachments[i]) attachments[i]->Release();
2423 - }
2424 - }
2425 - free(attachments);
2426 - }
2427 - TRACE_EXIT(-1, 0);
2428 -}
24292367 HRESULT WINAPI glDirectDrawSurface3::QueryInterface(REFIID riid, void** ppvObj)
24302368 {
24312369 TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
@@ -2442,75 +2380,28 @@
24432381 ULONG WINAPI glDirectDrawSurface3::AddRef()
24442382 {
24452383 TRACE_ENTER(1,14,this);
2446 - if(!this) return 0;
2447 - refcount++;
2448 - TRACE_EXIT(23,refcount);
2449 - return refcount;
 2384+ if (!this) TRACE_RET(ULONG,8,0);
 2385+ TRACE_RET(ULONG, 8, glDDS7->AddRef3());
24502386 }
24512387 ULONG WINAPI glDirectDrawSurface3::Release()
24522388 {
24532389 TRACE_ENTER(1,14,this);
24542390 if(!this) TRACE_RET(ULONG,8,0);
2455 - ULONG ret;
2456 - refcount--;
2457 - ret = refcount;
2458 - if(refcount == 0) delete this;
2459 - TRACE_EXIT(8,ret);
2460 - return ret;
 2391+ TRACE_RET(ULONG, 8, glDDS7->Release3());
24612392 }
2462 -void glDirectDrawSurface3::AddAttach(glDirectDrawSurface3 *attach)
2463 -{
2464 - bool emptyspace = false;
2465 - int index;
2466 - for (int i = 0; i < attachcount; i++)
2467 - {
2468 - if (!attachments[i])
2469 - {
2470 - emptyspace = true;
2471 - index = i;
2472 - break;
2473 - }
2474 - }
2475 - if (emptyspace) attachments[index] = attach;
2476 - else
2477 - {
2478 - attachcount++;
2479 - if (attachcount >= maxattach)
2480 - {
2481 - glDirectDrawSurface3 **newattach = (glDirectDrawSurface3**)realloc(attachments,
2482 - (maxattach + 16)*sizeof(glDirectDrawSurface3*));
2483 - if (newattach)
2484 - {
2485 - maxattach += 16;
2486 - attachments = newattach;
2487 - }
2488 - }
2489 - attachments[attachcount-1] = attach;
2490 - }
2491 - attach->AddRef();
2492 -}
2493 -void glDirectDrawSurface3::DeleteAttach(glDirectDrawSurface3 *attach)
2494 -{
2495 - if (!attachcount) return;
2496 - for (int i = 0; i < attachcount; i++)
2497 - {
2498 - if (attachments[i] == attach)
2499 - {
2500 - attach->Release();
2501 - attachments[i] = NULL;
2502 - return;
2503 - }
2504 - }
2505 -}
25062393 HRESULT WINAPI glDirectDrawSurface3::AddAttachedSurface(LPDIRECTDRAWSURFACE3 lpDDSAttachedSurface)
25072394 {
2508 - TRACE_ENTER(2,14,this,14,lpDDSAttachedSurface);
2509 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2510 - if(!lpDDSAttachedSurface) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
2511 - HRESULT ret = glDDS7->AddAttachedSurface(((glDirectDrawSurface3*)lpDDSAttachedSurface)->GetDDS7());
2512 - if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
2513 - AddAttach((glDirectDrawSurface3*)lpDDSAttachedSurface);
2514 - TRACE_EXIT(23, ret);
 2395+ TRACE_ENTER(2, 14, this, 15, lpDDSAttachedSurface);
 2396+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 2397+ if (!lpDDSAttachedSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2398+ LPDIRECTDRAWSURFACE7 dds7;
 2399+ HRESULT ret;
 2400+ ret = ((IUnknown*)lpDDSAttachedSurface)->QueryInterface(IID_IDirectDrawSurface7, (void**)&dds7);
 2401+ if (ret != S_OK) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2402+ ret = glDDS7->AddAttachedSurface2(dds7, lpDDSAttachedSurface);
 2403+ if (ret == DD_OK) ((IUnknown*)lpDDSAttachedSurface)->AddRef();
 2404+ dds7->Release();
 2405+ TRACE_RET(HRESULT, 23, ret);
25152406 return ret;
25162407 }
25172408 HRESULT WINAPI glDirectDrawSurface3::AddOverlayDirtyRect(LPRECT lpRect)
@@ -2558,7 +2449,6 @@
25592450 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
25602451 HRESULT ret = glDDS7->DeleteAttachedSurface(dwFlags, ((glDirectDrawSurface3*)lpDDSAttachedSurface)->GetDDS7());
25612452 if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
2562 - DeleteAttach((glDirectDrawSurface3*)lpDDSAttachedSurface);
25632453 TRACE_EXIT(23, ret);
25642454 return ret;
25652455 }
@@ -2807,30 +2697,8 @@
28082698 {
28092699 TRACE_ENTER(2,14,this,14,gl_DDS7);
28102700 glDDS7 = gl_DDS7;
2811 - refcount = 1;
2812 - attachments = (glDirectDrawSurface4**)malloc(16 * sizeof(glDirectDrawSurface4*));
2813 - attachcount = 0;
2814 - maxattach = 16;
28152701 TRACE_EXIT(-1, 0);
28162702 }
2817 -glDirectDrawSurface4::~glDirectDrawSurface4()
2818 -{
2819 - TRACE_ENTER(1,14,this);
2820 - glDDS7->dds4 = NULL;
2821 - glDDS7->Release();
2822 - if (attachments)
2823 - {
2824 - if (attachcount)
2825 - {
2826 - for (int i = 0; i < attachcount; i++)
2827 - {
2828 - if (attachments[i]) attachments[i]->Release();
2829 - }
2830 - }
2831 - free(attachments);
2832 - }
2833 - TRACE_EXIT(-1,0);
2834 -}
28352703 HRESULT WINAPI glDirectDrawSurface4::QueryInterface(REFIID riid, void** ppvObj)
28362704 {
28372705 TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
@@ -2849,73 +2717,27 @@
28502718 {
28512719 TRACE_ENTER(1,14,this);
28522720 if(!this) TRACE_RET(ULONG,8,0);
2853 - refcount++;
2854 - TRACE_EXIT(8,refcount);
2855 - return refcount;
 2721+ TRACE_RET(ULONG, 8, glDDS7->AddRef4());
28562722 }
28572723 ULONG WINAPI glDirectDrawSurface4::Release()
28582724 {
28592725 TRACE_ENTER(1,14,this);
28602726 if(!this) TRACE_RET(ULONG,8,0);
2861 - ULONG ret;
2862 - refcount--;
2863 - ret = refcount;
2864 - if(refcount == 0) delete this;
2865 - TRACE_EXIT(8,ret);
2866 - return ret;
 2727+ TRACE_RET(ULONG, 8, glDDS7->Release4());
28672728 }
2868 -void glDirectDrawSurface4::AddAttach(glDirectDrawSurface4 *attach)
2869 -{
2870 - bool emptyspace = false;
2871 - int index;
2872 - for (int i = 0; i < attachcount; i++)
2873 - {
2874 - if (!attachments[i])
2875 - {
2876 - emptyspace = true;
2877 - index = i;
2878 - break;
2879 - }
2880 - }
2881 - if (emptyspace) attachments[index] = attach;
2882 - else
2883 - {
2884 - attachcount++;
2885 - if (attachcount >= maxattach)
2886 - {
2887 - glDirectDrawSurface4 **newattach = (glDirectDrawSurface4**)realloc(attachments,
2888 - (maxattach + 16)*sizeof(glDirectDrawSurface4*));
2889 - if (newattach)
2890 - {
2891 - maxattach += 16;
2892 - attachments = newattach;
2893 - }
2894 - }
2895 - attachments[attachcount-1] = attach;
2896 - }
2897 - attach->AddRef();
2898 -}
2899 -void glDirectDrawSurface4::DeleteAttach(glDirectDrawSurface4 *attach)
2900 -{
2901 - if (!attachcount) return;
2902 - for (int i = 0; i < attachcount; i++)
2903 - {
2904 - if (attachments[i] == attach)
2905 - {
2906 - attach->Release();
2907 - attachments[i] = NULL;
2908 - return;
2909 - }
2910 - }
2911 -}
29122729 HRESULT WINAPI glDirectDrawSurface4::AddAttachedSurface(LPDIRECTDRAWSURFACE4 lpDDSAttachedSurface)
29132730 {
2914 - TRACE_ENTER(2,14,this,14,lpDDSAttachedSurface);
2915 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2916 - HRESULT ret = glDDS7->AddAttachedSurface(((glDirectDrawSurface4*)lpDDSAttachedSurface)->GetDDS7());
2917 - if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
2918 - AddAttach((glDirectDrawSurface4*)lpDDSAttachedSurface);
2919 - TRACE_EXIT(23, ret);
 2731+ TRACE_ENTER(2, 14, this, 15, lpDDSAttachedSurface);
 2732+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 2733+ if (!lpDDSAttachedSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2734+ LPDIRECTDRAWSURFACE7 dds7;
 2735+ HRESULT ret;
 2736+ ret = ((IUnknown*)lpDDSAttachedSurface)->QueryInterface(IID_IDirectDrawSurface7, (void**)&dds7);
 2737+ if (ret != S_OK) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2738+ ret = glDDS7->AddAttachedSurface2(dds7, lpDDSAttachedSurface);
 2739+ if (ret == DD_OK) ((IUnknown*)lpDDSAttachedSurface)->AddRef();
 2740+ dds7->Release();
 2741+ TRACE_RET(HRESULT, 23, ret);
29202742 return ret;
29212743 }
29222744 HRESULT WINAPI glDirectDrawSurface4::AddOverlayDirtyRect(LPRECT lpRect)
@@ -2963,7 +2785,6 @@
29642786 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
29652787 HRESULT ret = glDDS7->DeleteAttachedSurface(dwFlags, ((glDirectDrawSurface4*)lpDDSAttachedSurface)->GetDDS7());
29662788 if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
2967 - DeleteAttach((glDirectDrawSurface4*)lpDDSAttachedSurface);
29682789 TRACE_EXIT(23, ret);
29692790 return ret;
29702791 }
Index: ddraw/glDirectDrawSurface.h
@@ -39,7 +39,7 @@
4040 class glDirectDrawSurface7 : public IDirectDrawSurface7
4141 {
4242 public:
43 - glDirectDrawSurface7(LPDIRECTDRAW7 lpDD7, LPDDSURFACEDESC2 lpDDSurfaceDesc2, HRESULT *error, glDirectDrawPalette *palettein, TEXTURE *parenttex, DWORD miplevel);
 43+ glDirectDrawSurface7(LPDIRECTDRAW7 lpDD7, LPDDSURFACEDESC2 lpDDSurfaceDesc2, HRESULT *error, glDirectDrawPalette *palettein, TEXTURE *parenttex, DWORD miplevel, int version);
4444 virtual ~glDirectDrawSurface7();
4545 // ddraw 1+ api
4646 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
@@ -96,6 +96,18 @@
9797 HRESULT WINAPI SetLOD(DWORD dwMaxLOD);
9898 HRESULT WINAPI GetLOD(LPDWORD lpdwMaxLOD);
9999 // internal functions
 100+ ULONG WINAPI AddRef4();
 101+ ULONG WINAPI Release4();
 102+ ULONG WINAPI AddRef3();
 103+ ULONG WINAPI Release3();
 104+ ULONG WINAPI AddRef2();
 105+ ULONG WINAPI Release2();
 106+ ULONG WINAPI AddRef1();
 107+ ULONG WINAPI Release1();
 108+ ULONG WINAPI AddRefGamma();
 109+ ULONG WINAPI ReleaseGamma();
 110+ ULONG WINAPI AddRefColor();
 111+ ULONG WINAPI ReleaseColor();
100112 void SetFilter(int level, GLint mag, GLint min, glExtensions *ext, TextureManager *texman);
101113 TEXTURE *GetTexture(){
102114 return texture;
@@ -102,7 +114,8 @@
103115 }
104116 void Restore2();
105117 HRESULT Flip2(LPDIRECTDRAWSURFACE7 lpDDSurfaceTargetOverride, DWORD dwFlags);
106 - void SetTexture(TEXTURE *newtexture){texture = newtexture;};
 118+ HRESULT AddAttachedSurface2(LPDIRECTDRAWSURFACE7 lpDDSAttachedSurface, IUnknown *iface);
 119+ void SetTexture(TEXTURE *newtexture){ texture = newtexture; };
107120 glDirectDrawSurface7 *GetBackbuffer(){return backbuffer;};
108121 glDirectDrawSurface7 *GetZBuffer(){return zbuffer;};
109122 void RenderScreen(TEXTURE *texture, glDirectDrawSurface7 *surface, int vsync);
@@ -128,7 +141,6 @@
129142 TEXTURE *stencil;
130143 bool hasstencil;
131144 DWORD miplevel;
132 - glDirectDrawSurface7 *miptexture;
133145 char *buffer;
134146 char *bigbuffer;
135147 char *gdibuffer;
@@ -135,15 +147,19 @@
136148 DDSURFACEDESC2 ddsd;
137149 glDirectDrawPalette *palette;
138150 HGLRC hRC;
139 - glDirectDrawSurface7 *zbuffer;
140151 D3DMATERIALHANDLE handle;
141152 FBO fbo;
142153 FBO stencilfbo;
143154 glDirectDrawClipper *clipper;
144155 IUnknown *creator;
 156+ IUnknown *textureparent;
 157+ glDirectDrawSurface7 *zbuffer;
 158+ glDirectDrawSurface7 *miptexture;
 159+ glDirectDrawSurface7 *backbuffer;
145160 private:
146161 int swapinterval;
147 - ULONG refcount;
 162+ ULONG refcount7, refcount4, refcount3, refcount2, refcount1;
 163+ ULONG refcountgamma, refcountcolor;
148164 int locked;
149165 HDC hdc;
150166 HBITMAP hbitmap;
@@ -150,11 +166,11 @@
151167 BITMAPINFO *bitmapinfo;
152168 glDirectDraw7 *ddInterface;
153169 int surfacetype; // 0-generic memory, 1-GDI surface, 2-OpenGL Texture
154 - glDirectDrawSurface7 *backbuffer;
155170 int pagelocked;
156171 GLint magfilter,minfilter;
157172 glDirect3DDevice7 *device;
158173 bool overlay;
 174+ IUnknown *zbuffer_iface;
159175 };
160176
161177 // Legacy DDRAW Interfaces
@@ -162,7 +178,6 @@
163179 {
164180 public:
165181 glDirectDrawSurface1(glDirectDrawSurface7 *gl_DDS7);
166 - virtual ~glDirectDrawSurface1();
167182 // ddraw 1+ api
168183 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
169184 ULONG WINAPI AddRef();
@@ -201,20 +216,13 @@
202217 HRESULT WINAPI UpdateOverlayDisplay(DWORD dwFlags);
203218 HRESULT WINAPI UpdateOverlayZOrder(DWORD dwFlags, LPDIRECTDRAWSURFACE lpDDSReference);
204219 glDirectDrawSurface7 *GetDDS7() {return glDDS7;};
205 - void AddAttach(glDirectDrawSurface1 *attach);
206 - void DeleteAttach(glDirectDrawSurface1 *attach);
207220 private:
208 - UINT refcount;
209221 glDirectDrawSurface7 *glDDS7;
210 - glDirectDrawSurface1 **attachments;
211 - int attachcount;
212 - int maxattach;
213222 };
214223 class glDirectDrawSurface2 : public IDirectDrawSurface2
215224 {
216225 public:
217226 glDirectDrawSurface2(glDirectDrawSurface7 *gl_DDS7);
218 - virtual ~glDirectDrawSurface2();
219227 // ddraw 1+ api
220228 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
221229 ULONG WINAPI AddRef();
@@ -257,20 +265,13 @@
258266 HRESULT WINAPI PageLock(DWORD dwFlags);
259267 HRESULT WINAPI PageUnlock(DWORD dwFlags);
260268 glDirectDrawSurface7 *GetDDS7() {return glDDS7;};
261 - void AddAttach(glDirectDrawSurface2 *attach);
262 - void DeleteAttach(glDirectDrawSurface2 *attach);
263269 private:
264 - UINT refcount;
265270 glDirectDrawSurface7 *glDDS7;
266 - glDirectDrawSurface2 **attachments;
267 - int attachcount;
268 - int maxattach;
269271 };
270272 class glDirectDrawSurface3 : public IDirectDrawSurface3
271273 {
272274 public:
273275 glDirectDrawSurface3(glDirectDrawSurface7 *gl_DDS7);
274 - virtual ~glDirectDrawSurface3();
275276 // ddraw 1+ api
276277 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
277278 ULONG WINAPI AddRef();
@@ -315,20 +316,13 @@
316317 // ddraw 3+ api
317318 HRESULT WINAPI SetSurfaceDesc(LPDDSURFACEDESC lpddsd2, DWORD dwFlags);
318319 glDirectDrawSurface7 *GetDDS7() {return glDDS7;};
319 - void AddAttach(glDirectDrawSurface3 *attach);
320 - void DeleteAttach(glDirectDrawSurface3 *attach);
321320 private:
322 - UINT refcount;
323321 glDirectDrawSurface7 *glDDS7;
324 - glDirectDrawSurface3 **attachments;
325 - int attachcount;
326 - int maxattach;
327322 };
328323 class glDirectDrawSurface4 : public IDirectDrawSurface4
329324 {
330325 public:
331326 glDirectDrawSurface4(glDirectDrawSurface7 *gl_DDS7);
332 - virtual ~glDirectDrawSurface4();
333327 // ddraw 1+ api
334328 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
335329 ULONG WINAPI AddRef();
@@ -379,13 +373,7 @@
380374 HRESULT WINAPI GetUniquenessValue(LPDWORD lpValue);
381375 HRESULT WINAPI ChangeUniquenessValue();
382376 glDirectDrawSurface7 *GetDDS7() {return glDDS7;};
383 - void AddAttach(glDirectDrawSurface4 *attach);
384 - void DeleteAttach(glDirectDrawSurface4 *attach);
385377 private:
386 - UINT refcount;
387378 glDirectDrawSurface7 *glDDS7;
388 - glDirectDrawSurface4 **attachments;
389 - int attachcount;
390 - int maxattach;
391379 };
392380 #endif //_GLDIRECTDRAWSURFACE_H