DXGL r533 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r532‎ | r533 | r534 >
Date:18:52, 14 September 2014
Author:admin
Status:new
Tags:
Comment:
Merge D3D Device refcounts and link to surface for version 1.
Modified paths:
  • /ddraw/glDirect3D.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)

Diff [purge]

Index: ddraw/glDirect3D.cpp
@@ -208,7 +208,7 @@
209209 TRACE_ENTER(4,14,this,24,&rclsid,14,lpDDS,14,lplpD3DDevice);
210210 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
211211 HRESULT ret;
212 - glDirect3DDevice7 *glD3DDev7 = new glDirect3DDevice7(rclsid,this,(glDirectDrawSurface7*)lpDDS);
 212+ glDirect3DDevice7 *glD3DDev7 = new glDirect3DDevice7(rclsid,this,(glDirectDrawSurface7*)lpDDS,NULL);
213213 if(!glD3DDev7) TRACE_RET(HRESULT,23,DDERR_OUTOFMEMORY);
214214 if(FAILED(glD3DDev7->err()))
215215 {
Index: ddraw/glDirect3DDevice.cpp
@@ -271,15 +271,12 @@
272272 }
273273 }
274274
275 -glDirect3DDevice7::glDirect3DDevice7(REFCLSID rclsid, glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7)
 275+glDirect3DDevice7::glDirect3DDevice7(REFCLSID rclsid, glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7, IUnknown *creator)
276276 {
277277 TRACE_ENTER(4,14,this,24,&rclsid,14,glD3D7,14,glDDS7);
278278 d3ddesc = d3ddesc_default;
279279 d3ddesc3 = d3ddesc3_default;
280280 int zbuffer = 0;
281 - glD3DDev3 = NULL;
282 - glD3DDev2 = NULL;
283 - glD3DDev1 = NULL;
284281 maxmaterials = 32;
285282 materials = (glDirect3DMaterial3**)malloc(32*sizeof(glDirect3DMaterial3*));
286283 if(!materials)
@@ -339,7 +336,7 @@
340337 this->glD3D7 = glD3D7;
341338 glD3D7->AddRef();
342339 this->glDDS7 = glDDS7;
343 - glDDS7->AddRef();
 340+ if(!creator) glDDS7->AddRef();
344341 renderer = this->glD3D7->glDD7->renderer;
345342 ZeroMemory(&viewport,sizeof(D3DVIEWPORT7));
346343 if(glDDS7->GetZBuffer()) zbuffer = 1;
@@ -367,6 +364,10 @@
368365 scalex = scaley = 0;
369366 mhWorld = mhView = mhProjection = 0;
370367 glRenderer_InitD3D(renderer,zbuffer);
 368+ glD3DDev3 = new glDirect3DDevice3(this);
 369+ glD3DDev2 = new glDirect3DDevice2(this);
 370+ glD3DDev1 = new glDirect3DDevice1(this);
 371+ this->creator = creator;
371372 error = D3D_OK;
372373 TRACE_EXIT(-1,0);
373374 }
@@ -406,8 +407,11 @@
407408 free(materials);
408409 free(textures);
409410 if(matrices) free(matrices);
 411+ if (glD3DDev3) delete glD3DDev3;
 412+ if (glD3DDev2) delete glD3DDev2;
 413+ if (glD3DDev1) delete glD3DDev1;
410414 glD3D7->Release();
411 - glDDS7->Release();
 415+ if(!creator) glDDS7->Release();
412416 TRACE_EXIT(-1,0);
413417 }
414418
@@ -446,65 +450,29 @@
447451 }
448452 if(riid == IID_IDirect3DDevice3)
449453 {
450 - if(glD3DDev3)
451 - {
452 - *ppvObj = glD3DDev3;
453 - glD3DDev3->AddRef();
454 - TRACE_VAR("*ppvObj",14,*ppvObj);
455 - TRACE_EXIT(23,D3D_OK);
456 - return D3D_OK;
457 - }
458 - else
459 - {
460 - this->AddRef();
461 - *ppvObj = new glDirect3DDevice3(this);
462 - glD3DDev3 = (glDirect3DDevice3*)*ppvObj;
463 - TRACE_VAR("*ppvObj",14,*ppvObj);
464 - TRACE_EXIT(23,D3D_OK);
465 - return D3D_OK;
466 - }
 454+ *ppvObj = glD3DDev3;
 455+ glD3DDev3->AddRef();
 456+ TRACE_VAR("*ppvObj",14,*ppvObj);
 457+ TRACE_EXIT(23,D3D_OK);
 458+ return D3D_OK;
467459 }
468460 if(riid == IID_IDirect3DDevice2)
469461 {
470 - if(glD3DDev2)
471 - {
472 - *ppvObj = glD3DDev2;
473 - glD3DDev2->AddRef();
474 - TRACE_VAR("*ppvObj",14,*ppvObj);
475 - TRACE_EXIT(23,D3D_OK);
476 - return D3D_OK;
477 - }
478 - else
479 - {
480 - this->AddRef();
481 - *ppvObj = new glDirect3DDevice2(this);
482 - glD3DDev2 = (glDirect3DDevice2*)*ppvObj;
483 - TRACE_VAR("*ppvObj",14,*ppvObj);
484 - TRACE_EXIT(23,D3D_OK);
485 - return D3D_OK;
486 - }
 462+ *ppvObj = glD3DDev2;
 463+ glD3DDev2->AddRef();
 464+ TRACE_VAR("*ppvObj",14,*ppvObj);
 465+ TRACE_EXIT(23,D3D_OK);
 466+ return D3D_OK;
487467 }
488468 if(riid == IID_IDirect3DDevice)
489469 {
490 - if(glD3DDev1)
491 - {
492 - *ppvObj = glD3DDev1;
493 - glD3DDev1->AddRef();
494 - TRACE_VAR("*ppvObj",14,*ppvObj);
495 - TRACE_EXIT(23,D3D_OK);
496 - return D3D_OK;
497 - }
498 - else
499 - {
500 - this->AddRef();
501 - *ppvObj = new glDirect3DDevice1(this);
502 - glD3DDev1 = (glDirect3DDevice1*)*ppvObj;
503 - TRACE_VAR("*ppvObj",14,*ppvObj);
504 - TRACE_EXIT(23,D3D_OK);
505 - return D3D_OK;
506 - }
 470+ *ppvObj = glD3DDev1;
 471+ glD3DDev1->AddRef();
 472+ TRACE_VAR("*ppvObj",14,*ppvObj);
 473+ TRACE_EXIT(23,D3D_OK);
 474+ return D3D_OK;
507475 }
508 - if (glDDS7) TRACE_RET(HRESULT, 23, glDDS7->QueryInterface(riid, ppvObj));
 476+ if (creator) TRACE_RET(HRESULT, 23, creator->QueryInterface(riid, ppvObj));
509477 TRACE_EXIT(23,E_NOINTERFACE);
510478 return E_NOINTERFACE;
511479 }
@@ -511,6 +479,22 @@
512480
513481 ULONG WINAPI glDirect3DDevice7::AddRef()
514482 {
 483+ TRACE_ENTER(1, 14, this);
 484+ if (!this) TRACE_RET(ULONG, 8, 0);
 485+ if (creator) TRACE_RET(ULONG, 8, creator->AddRef());
 486+ TRACE_RET(ULONG, 8, AddRefInternal());
 487+}
 488+
 489+ULONG WINAPI glDirect3DDevice7::Release()
 490+{
 491+ TRACE_ENTER(1, 14, this);
 492+ if (!this) TRACE_RET(ULONG, 8, 0);
 493+ if (creator) TRACE_RET(ULONG, 8, creator->Release());
 494+ TRACE_RET(ULONG, 8, ReleaseInternal());
 495+}
 496+
 497+ULONG glDirect3DDevice7::AddRefInternal()
 498+{
515499 TRACE_ENTER(1,14,this);
516500 if(!this) TRACE_RET(ULONG,8,0);
517501 refcount++;
@@ -517,7 +501,7 @@
518502 TRACE_EXIT(8,refcount);
519503 return refcount;
520504 }
521 -ULONG WINAPI glDirect3DDevice7::Release()
 505+ULONG glDirect3DDevice7::ReleaseInternal()
522506 {
523507 TRACE_ENTER(1,14,this);
524508 if(!this) TRACE_RET(ULONG,8,0);
@@ -1458,7 +1442,7 @@
14591443 ddsd.dwSize = sizeof(DDSURFACEDESC2);
14601444 lpNewRenderTarget->GetSurfaceDesc(&ddsd);
14611445 if(!(ddsd.ddsCaps.dwCaps & DDSCAPS_3DDEVICE)) TRACE_RET(HRESULT,23,DDERR_INVALIDSURFACETYPE);
1462 - glDDS7->Release();
 1446+ if(glDDS7) glDDS7->Release();
14631447 glDDS7 = (glDirectDrawSurface7*)lpNewRenderTarget;
14641448 glDDS7->AddRef();
14651449 TRACE_EXIT(23,D3D_OK);
@@ -2918,18 +2902,9 @@
29192903 {
29202904 TRACE_ENTER(2,14,this,14,glD3DDev7);
29212905 this->glD3DDev7 = glD3DDev7;
2922 - refcount = 1;
29232906 TRACE_EXIT(-1,0);
29242907 }
29252908
2926 -glDirect3DDevice3::~glDirect3DDevice3()
2927 -{
2928 - TRACE_ENTER(1,14,this);
2929 - glD3DDev7->glD3DDev3 = NULL;
2930 - glD3DDev7->Release();
2931 - TRACE_EXIT(-1,0);
2932 -}
2933 -
29342909 HRESULT WINAPI glDirect3DDevice3::QueryInterface(REFIID riid, void** ppvObj)
29352910 {
29362911 TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
@@ -2949,9 +2924,7 @@
29502925 {
29512926 TRACE_ENTER(1,14,this);
29522927 if(!this) TRACE_RET(ULONG,8,0);
2953 - refcount++;
2954 - TRACE_EXIT(8,refcount);
2955 - return refcount;
 2928+ TRACE_RET(ULONG, 8, glD3DDev7->AddRef());
29562929 }
29572930
29582931 ULONG WINAPI glDirect3DDevice3::Release()
@@ -2958,12 +2931,7 @@
29592932 {
29602933 TRACE_ENTER(1,14,this);
29612934 if(!this) TRACE_RET(ULONG,8,0);
2962 - ULONG ret;
2963 - refcount--;
2964 - ret = refcount;
2965 - if(refcount == 0) delete this;
2966 - TRACE_EXIT(8,ret);
2967 - return ret;
 2935+ TRACE_RET(ULONG, 8, glD3DDev7->Release());
29682936 }
29692937
29702938 HRESULT WINAPI glDirect3DDevice3::AddViewport(LPDIRECT3DVIEWPORT3 lpDirect3DViewport)
@@ -3277,18 +3245,9 @@
32783246 TRACE_ENTER(2,14,this,14,glD3DDev7);
32793247 this->glD3DDev7 = glD3DDev7;
32803248 glD3DDev7->InitDX5();
3281 - refcount = 1;
32823249 TRACE_EXIT(-1,0);
32833250 }
32843251
3285 -glDirect3DDevice2::~glDirect3DDevice2()
3286 -{
3287 - TRACE_ENTER(1,14,this);
3288 - glD3DDev7->glD3DDev2 = NULL;
3289 - glD3DDev7->Release();
3290 - TRACE_EXIT(-1,0);
3291 -}
3292 -
32933252 HRESULT WINAPI glDirect3DDevice2::QueryInterface(REFIID riid, void** ppvObj)
32943253 {
32953254 TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
@@ -3308,9 +3267,7 @@
33093268 {
33103269 TRACE_ENTER(1,14,this);
33113270 if(!this) TRACE_RET(ULONG,8,0);
3312 - refcount++;
3313 - TRACE_EXIT(8,refcount);
3314 - return refcount;
 3271+ TRACE_RET(ULONG, 8, glD3DDev7->AddRef());
33153272 }
33163273
33173274 ULONG WINAPI glDirect3DDevice2::Release()
@@ -3317,12 +3274,7 @@
33183275 {
33193276 TRACE_ENTER(1,14,this);
33203277 if(!this) TRACE_RET(ULONG,8,0);
3321 - ULONG ret;
3322 - refcount--;
3323 - ret = refcount;
3324 - if(refcount == 0) delete this;
3325 - TRACE_EXIT(8,ret);
3326 - return ret;
 3278+ TRACE_RET(ULONG, 8, glD3DDev7->Release());
33273279 }
33283280
33293281 HRESULT WINAPI glDirect3DDevice2::AddViewport(LPDIRECT3DVIEWPORT2 lpDirect3DViewport2)
@@ -3628,18 +3580,9 @@
36293581 TRACE_ENTER(2,14,this,14,glD3DDev7);
36303582 this->glD3DDev7 = glD3DDev7;
36313583 glD3DDev7->InitDX5();
3632 - refcount = 1;
36333584 TRACE_EXIT(-1,0);
36343585 }
36353586
3636 -glDirect3DDevice1::~glDirect3DDevice1()
3637 -{
3638 - TRACE_ENTER(1,14,this);
3639 - glD3DDev7->glD3DDev1 = NULL;
3640 - glD3DDev7->Release();
3641 - TRACE_EXIT(-1,0);
3642 -}
3643 -
36443587 HRESULT WINAPI glDirect3DDevice1::QueryInterface(REFIID riid, void** ppvObj)
36453588 {
36463589 TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
@@ -3659,9 +3602,7 @@
36603603 {
36613604 TRACE_ENTER(1,14,this);
36623605 if(!this) TRACE_RET(ULONG,8,0);
3663 - refcount++;
3664 - TRACE_EXIT(8,refcount);
3665 - return refcount;
 3606+ TRACE_RET(ULONG, 8, glD3DDev7->AddRef());
36663607 }
36673608
36683609 ULONG WINAPI glDirect3DDevice1::Release()
@@ -3668,12 +3609,7 @@
36693610 {
36703611 TRACE_ENTER(1,14,this);
36713612 if(!this) TRACE_RET(ULONG,8,0);
3672 - ULONG ret;
3673 - refcount--;
3674 - ret = refcount;
3675 - if(refcount == 0) delete this;
3676 - TRACE_EXIT(8,ret);
3677 - return ret;
 3613+ TRACE_RET(ULONG, 8, glD3DDev7->Release());
36783614 }
36793615
36803616 HRESULT WINAPI glDirect3DDevice1::AddViewport(LPDIRECT3DVIEWPORT lpDirect3DViewport)
Index: ddraw/glDirect3DDevice.h
@@ -70,7 +70,7 @@
7171 class glDirect3DDevice7 : public IDirect3DDevice7
7272 {
7373 public:
74 - glDirect3DDevice7(REFCLSID rclsid, glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7);
 74+ glDirect3DDevice7(REFCLSID rclsid, glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7, IUnknown *creator);
7575 virtual ~glDirect3DDevice7();
7676 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
7777 ULONG WINAPI AddRef();
@@ -170,6 +170,8 @@
171171 void InitDX5();
172172 __int64 SelectShader(GLVERTEX *VertexType);
173173 void SetScale(D3DVALUE x, D3DVALUE y){scalex = x; scaley = y;}
 174+ ULONG AddRefInternal();
 175+ ULONG ReleaseInternal();
174176 GLfloat matWorld[16];
175177 GLfloat matView[16];
176178 GLfloat matProjection[16];
@@ -232,6 +234,7 @@
233235 D3DDEVICEDESC7 d3ddesc;
234236 D3DDEVICEDESC d3ddesc3;
235237 glRenderer *renderer;
 238+ IUnknown *creator;
236239 };
237240
238241 #endif //__GLDIRECT3DDEVICE_H
@@ -240,7 +243,6 @@
241244 {
242245 public:
243246 glDirect3DDevice3(glDirect3DDevice7 *glD3DDev7);
244 - virtual ~glDirect3DDevice3();
245247 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
246248 ULONG WINAPI AddRef();
247249 ULONG WINAPI Release();
@@ -292,7 +294,6 @@
293295 glDirect3DDevice7 *GetGLD3DDev7(){return glD3DDev7;}
294296 private:
295297 glDirect3DDevice7 *glD3DDev7;
296 - ULONG refcount;
297298 };
298299
299300
@@ -300,7 +301,6 @@
301302 {
302303 public:
303304 glDirect3DDevice2(glDirect3DDevice7 *glD3DDev7);
304 - virtual ~glDirect3DDevice2();
305305 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
306306 ULONG WINAPI AddRef();
307307 ULONG WINAPI Release();
@@ -338,7 +338,6 @@
339339 HRESULT WINAPI Vertex(LPVOID lpVertexType);
340340 private:
341341 glDirect3DDevice7 *glD3DDev7;
342 - ULONG refcount;
343342 };
344343
345344 class glDirect3DDevice1 : public IDirect3DDevice
@@ -345,7 +344,6 @@
346345 {
347346 public:
348347 glDirect3DDevice1(glDirect3DDevice7 *glD3DDev7);
349 - virtual ~glDirect3DDevice1();
350348 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
351349 ULONG WINAPI AddRef();
352350 ULONG WINAPI Release();
@@ -372,5 +370,4 @@
373371 HRESULT WINAPI SwapTextureHandles(LPDIRECT3DTEXTURE lpD3DTex1, LPDIRECT3DTEXTURE lpD3DTex2);
374372 private:
375373 glDirect3DDevice7 *glD3DDev7;
376 - ULONG refcount;
377374 };
\ No newline at end of file
Index: ddraw/glDirectDrawSurface.cpp
@@ -47,6 +47,7 @@
4848 dirty = 2;
4949 handle = 0;
5050 device = NULL;
 51+ device1 = NULL;
5152 locked = 0;
5253 pagelocked = 0;
5354 flipcount = 0;
@@ -424,7 +425,8 @@
425426 if(bigbuffer) free(bigbuffer);
426427 if(zbuffer) zbuffer_iface->Release();
427428 if(miptexture) miptexture->Release();
428 - if(device) device->Release();
 429+ if (device) device->Release();
 430+ if (device1) delete device1;
429431 ddInterface->DeleteSurface(this);
430432 if (creator) creator->Release();
431433 TRACE_EXIT(-1,0);
@@ -431,6 +433,7 @@
432434 }
433435 HRESULT WINAPI glDirectDrawSurface7::QueryInterface(REFIID riid, void** ppvObj)
434436 {
 437+ HRESULT ret;
435438 TRACE_ENTER(3,14,this,24,&riid,14,ppvObj);
436439 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
437440 if(!ppvObj) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
@@ -500,34 +503,34 @@
501504 }
502505 if (riid == IID_IDirectDrawColorControl)
503506 {
504 - FIXME("Add color control\n");
 507+ DEBUG("FIXME: Add color control\n");
505508 TRACE_EXIT(23, E_NOINTERFACE);
506 - ERR(E_NOINTERFACE);
 509+ return E_NOINTERFACE;
507510 }
508511 if ((riid == IID_IDirect3DHALDevice) || (riid == IID_IDirect3DRGBDevice) ||
509512 (riid == IID_IDirect3DRampDevice) || (riid == IID_IDirect3DRefDevice))
510513 {
511514
512 - if(!device)
 515+ if(!device1)
513516 {
514517 glDirect3D7 *tmpd3d;
515 - glDirect3DDevice7 *tmpdev;
516518 ddInterface->QueryInterface(IID_IDirect3D7,(void**)&tmpd3d);
517519 if(!tmpd3d) TRACE_RET(HRESULT,23,E_NOINTERFACE);
518 - tmpd3d->CreateDevice(riid,this,(LPDIRECT3DDEVICE7*)&tmpdev);
519 - if(!tmpdev)
 520+ device1 = new glDirect3DDevice7(riid, tmpd3d, this, dds1);
 521+ if (FAILED(device1->err()))
520522 {
 523+ ret = device1->err();
 524+ delete device1;
521525 tmpd3d->Release();
522 - TRACE_EXIT(23,E_NOINTERFACE);
523 - return E_NOINTERFACE;
 526+ TRACE_EXIT(23, ret);
 527+ return ret;
524528 }
525 - HRESULT ret = tmpdev->QueryInterface(IID_IDirect3DDevice,ppvObj);
526 - tmpdev->SetRenderTarget(this,0);
527 - tmpdev->Release();
 529+ *ppvObj = device1->glD3DDev1;
 530+ device1->glD3DDev1->AddRef();
528531 tmpd3d->Release();
529532 TRACE_VAR("*ppvObj",14,*ppvObj);
530 - TRACE_EXIT(23,ret);
531 - return ret;
 533+ TRACE_EXIT(23,DD_OK);
 534+ return DD_OK;
532535 }
533536 else
534537 {
Index: ddraw/glDirectDrawSurface.h
@@ -173,6 +173,7 @@
174174 int surfacetype; // 0-generic memory, 1-GDI surface, 2-OpenGL Texture
175175 int pagelocked;
176176 GLint magfilter,minfilter;
 177+ glDirect3DDevice7 *device1;
177178 glDirect3DDevice7 *device;
178179 bool overlay;
179180 IUnknown *zbuffer_iface;