DXGL r535 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r534‎ | r535 | r536 >
Date:23:30, 16 September 2014
Author:admin
Status:new
Tags:
Comment:
Make D3D device QueryInterface version dependent.
Modified paths:
  • /ddraw/glDirect3D.cpp (modified) (history)
  • /ddraw/glDirect3D.h (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glDirect3DMaterial.cpp (modified) (history)
  • /ddraw/glDirect3DTexture.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3D.cpp
@@ -202,13 +202,20 @@
203203 TRACE_RET(HRESULT, 23, glDD7->QueryInterface(riid, ppvObj));
204204 }
205205
206 -
207206 HRESULT WINAPI glDirect3D7::CreateDevice(REFCLSID rclsid, LPDIRECTDRAWSURFACE7 lpDDS, LPDIRECT3DDEVICE7 *lplpD3DDevice)
208207 {
209 - TRACE_ENTER(4,14,this,24,&rclsid,14,lpDDS,14,lplpD3DDevice);
 208+ TRACE_ENTER(4, 14, this, 24, &rclsid, 14, lpDDS, 14, lplpD3DDevice);
 209+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 210+ TRACE_RET(HRESULLT, 23, CreateDevice2(rclsid, lpDDS, lplpD3DDevice, 7));
 211+}
 212+
 213+HRESULT glDirect3D7::CreateDevice2(REFCLSID rclsid, LPDIRECTDRAWSURFACE7 lpDDS, LPDIRECT3DDEVICE7 *lplpD3DDevice, int version)
 214+{
 215+ TRACE_ENTER(5,14,this,24,&rclsid,14,lpDDS,14,lplpD3DDevice,11,version);
210216 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
 217+ if(!lplpD3DDevice) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
211218 HRESULT ret;
212 - glDirect3DDevice7 *glD3DDev7 = new glDirect3DDevice7(rclsid,this,(glDirectDrawSurface7*)lpDDS,NULL);
 219+ glDirect3DDevice7 *glD3DDev7 = new glDirect3DDevice7(rclsid,this,(glDirectDrawSurface7*)lpDDS,NULL,version);
213220 if(!glD3DDev7) TRACE_RET(HRESULT,23,DDERR_OUTOFMEMORY);
214221 if(FAILED(glD3DDev7->err()))
215222 {
@@ -487,7 +494,7 @@
488495 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
489496 if(pUnkOuter) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
490497 LPDIRECT3DDEVICE7 lpD3DDev7;
491 - HRESULT err = glD3D7->CreateDevice(rclsid,((glDirectDrawSurface4*)lpDDS)->GetDDS7(),&lpD3DDev7);
 498+ HRESULT err = glD3D7->CreateDevice2(rclsid,((glDirectDrawSurface4*)lpDDS)->GetDDS7(),&lpD3DDev7,3);
492499 if(err == D3D_OK)
493500 {
494501 lpD3DDev7->QueryInterface(IID_IDirect3DDevice3,(LPVOID*)lplpD3DDevice);
@@ -606,7 +613,7 @@
607614 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
608615 if(!lplpD3DDevice) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
609616 LPDIRECT3DDEVICE7 lpD3DDev7;
610 - HRESULT err = glD3D7->CreateDevice(rclsid,((glDirectDrawSurface1*)lpDDS)->GetDDS7(),&lpD3DDev7);
 617+ HRESULT err = glD3D7->CreateDevice2(rclsid,((glDirectDrawSurface1*)lpDDS)->GetDDS7(),&lpD3DDev7,2);
611618 if(err == D3D_OK)
612619 {
613620 lpD3DDev7->QueryInterface(IID_IDirect3DDevice2,(LPVOID*)lplpD3DDevice);
Index: ddraw/glDirect3D.h
@@ -45,6 +45,7 @@
4646 HRESULT WINAPI EvictManagedTextures();
4747 HRESULT WINAPI FindDevice(LPD3DFINDDEVICESEARCH lpD3DFDS, LPD3DFINDDEVICERESULT lpD3DFDR);
4848 glDirectDraw7 *glDD7;
 49+ HRESULT CreateDevice2(REFCLSID rclsid, LPDIRECTDRAWSURFACE7 lpDDS, LPDIRECT3DDEVICE7 *lplpD3DDevice, int version);
4950 };
5051
5152 class glDirect3D3 : public IDirect3D3
Index: ddraw/glDirect3DDevice.cpp
@@ -271,9 +271,10 @@
272272 }
273273 }
274274
275 -glDirect3DDevice7::glDirect3DDevice7(REFCLSID rclsid, glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7, IUnknown *creator)
 275+glDirect3DDevice7::glDirect3DDevice7(REFCLSID rclsid, glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7, IUnknown *creator, int version)
276276 {
277277 TRACE_ENTER(4,14,this,24,&rclsid,14,glD3D7,14,glDDS7);
 278+ this->version = version;
278279 d3ddesc = d3ddesc_default;
279280 d3ddesc3 = d3ddesc3_default;
280281 int zbuffer = 0;
@@ -440,39 +441,45 @@
441442 TRACE_EXIT(23,D3D_OK);
442443 return D3D_OK;
443444 }
444 - if(riid == IID_IDirect3DDevice7)
 445+ if (creator) TRACE_RET(HRESULT, 23, creator->QueryInterface(riid, ppvObj));
 446+ if (version == 7)
445447 {
446 - this->AddRef();
447 - *ppvObj = this;
448 - TRACE_VAR("*ppvObj",14,*ppvObj);
449 - TRACE_EXIT(23,D3D_OK);
450 - return D3D_OK;
 448+ if (riid == IID_IDirect3DDevice7)
 449+ {
 450+ this->AddRef();
 451+ *ppvObj = this;
 452+ TRACE_VAR("*ppvObj", 14, *ppvObj);
 453+ TRACE_EXIT(23, D3D_OK);
 454+ return D3D_OK;
 455+ }
451456 }
452 - if(riid == IID_IDirect3DDevice3)
 457+ else
453458 {
454 - *ppvObj = glD3DDev3;
455 - glD3DDev3->AddRef();
456 - TRACE_VAR("*ppvObj",14,*ppvObj);
457 - TRACE_EXIT(23,D3D_OK);
458 - return D3D_OK;
 459+ if ((riid == IID_IDirect3DDevice3) && (version >= 3))
 460+ {
 461+ *ppvObj = glD3DDev3;
 462+ glD3DDev3->AddRef();
 463+ TRACE_VAR("*ppvObj", 14, *ppvObj);
 464+ TRACE_EXIT(23, D3D_OK);
 465+ return D3D_OK;
 466+ }
 467+ if ((riid == IID_IDirect3DDevice2) && (version >= 2))
 468+ {
 469+ *ppvObj = glD3DDev2;
 470+ glD3DDev2->AddRef();
 471+ TRACE_VAR("*ppvObj", 14, *ppvObj);
 472+ TRACE_EXIT(23, D3D_OK);
 473+ return D3D_OK;
 474+ }
 475+ if (riid == IID_IDirect3DDevice)
 476+ {
 477+ *ppvObj = glD3DDev1;
 478+ glD3DDev1->AddRef();
 479+ TRACE_VAR("*ppvObj", 14, *ppvObj);
 480+ TRACE_EXIT(23, D3D_OK);
 481+ return D3D_OK;
 482+ }
459483 }
460 - if(riid == IID_IDirect3DDevice2)
461 - {
462 - *ppvObj = glD3DDev2;
463 - glD3DDev2->AddRef();
464 - TRACE_VAR("*ppvObj",14,*ppvObj);
465 - TRACE_EXIT(23,D3D_OK);
466 - return D3D_OK;
467 - }
468 - if(riid == IID_IDirect3DDevice)
469 - {
470 - *ppvObj = glD3DDev1;
471 - glD3DDev1->AddRef();
472 - TRACE_VAR("*ppvObj",14,*ppvObj);
473 - TRACE_EXIT(23,D3D_OK);
474 - return D3D_OK;
475 - }
476 - if (creator) TRACE_RET(HRESULT, 23, creator->QueryInterface(riid, ppvObj));
477484 TRACE_EXIT(23,E_NOINTERFACE);
478485 return E_NOINTERFACE;
479486 }
Index: ddraw/glDirect3DDevice.h
@@ -70,7 +70,7 @@
7171 class glDirect3DDevice7 : public IDirect3DDevice7
7272 {
7373 public:
74 - glDirect3DDevice7(REFCLSID rclsid, glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7, IUnknown *creator);
 74+ glDirect3DDevice7(REFCLSID rclsid, glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7, IUnknown *creator, int version);
7575 virtual ~glDirect3DDevice7();
7676 HRESULT WINAPI QueryInterface(REFIID riid, void** ppvObj);
7777 ULONG WINAPI AddRef();
@@ -235,6 +235,7 @@
236236 D3DDEVICEDESC d3ddesc3;
237237 glRenderer *renderer;
238238 IUnknown *creator;
 239+ int version;
239240 };
240241
241242 #endif //__GLDIRECT3DDEVICE_H
@@ -336,6 +337,7 @@
337338 HRESULT WINAPI SetTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix);
338339 HRESULT WINAPI SwapTextureHandles(LPDIRECT3DTEXTURE2 lpD3DTex1, LPDIRECT3DTEXTURE2 lpD3DTex2);
339340 HRESULT WINAPI Vertex(LPVOID lpVertexType);
 341+ glDirect3DDevice7 *GetGLD3DDev7(){ return glD3DDev7; }
340342 private:
341343 glDirect3DDevice7 *glD3DDev7;
342344 };
@@ -368,6 +370,7 @@
369371 LPD3DRECT lpRect);
370372 HRESULT WINAPI SetMatrix(D3DMATRIXHANDLE d3dMatHandle, LPD3DMATRIX lpD3DMatrix);
371373 HRESULT WINAPI SwapTextureHandles(LPDIRECT3DTEXTURE lpD3DTex1, LPDIRECT3DTEXTURE lpD3DTex2);
 374+ glDirect3DDevice7 *GetGLD3DDev7(){ return glD3DDev7; }
372375 private:
373376 glDirect3DDevice7 *glD3DDev7;
374377 };
\ No newline at end of file
Index: ddraw/glDirect3DMaterial.cpp
@@ -233,10 +233,8 @@
234234 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
235235 if(!lpDirect3DDevice) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
236236 glDirect3DDevice2 *glD3DDev2 = (glDirect3DDevice2*)lpDirect3DDevice;
237 - glDirect3DDevice3 *glD3DDev3;
238 - glD3DDev2->QueryInterface(IID_IDirect3DDevice3,(void**)&glD3DDev3);
 237+ glDirect3DDevice3 *glD3DDev3 = glD3DDev2->GetGLD3DDev7()->glD3DDev3;
239238 HRESULT ret = glD3DM3->GetHandle(glD3DDev3,lpHandle);
240 - glD3DDev3->Release();
241239 TRACE_EXIT(23,ret);
242240 return ret;
243241 }
@@ -296,10 +294,8 @@
297295 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
298296 if(!lpDirect3DDevice) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
299297 glDirect3DDevice1 *glD3DDev1 = (glDirect3DDevice1*)lpDirect3DDevice;
300 - glDirect3DDevice3 *glD3DDev3;
301 - glD3DDev1->QueryInterface(IID_IDirect3DDevice3,(void**)&glD3DDev3);
 298+ glDirect3DDevice3 *glD3DDev3 = glD3DDev1->GetGLD3DDev7()->glD3DDev3;
302299 HRESULT ret = glD3DM3->GetHandle(glD3DDev3,lpHandle);
303 - glD3DDev3->Release();
304300 TRACE_EXIT(23,ret);
305301 return ret;
306302 }
Index: ddraw/glDirect3DTexture.cpp
@@ -66,10 +66,8 @@
6767 TRACE_ENTER(3,14,this,14,lpDirect3DDevice2,14,lpHandle);
6868 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
6969 if(!lpDirect3DDevice2) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
70 - glDirect3DDevice7 *glD3DDev7;
71 - lpDirect3DDevice2->QueryInterface(IID_IDirect3DDevice7,(void**)&glD3DDev7);
 70+ glDirect3DDevice7 *glD3DDev7 = ((glDirect3DDevice2*)lpDirect3DDevice2)->GetGLD3DDev7();
7271 HRESULT ret = glDDS7->GetHandle(glD3DDev7,lpHandle);
73 - glD3DDev7->Release();
7472 TRACE_EXIT(23,ret);
7573 return ret;
7674 }
@@ -127,10 +125,8 @@
128126 TRACE_ENTER(3,14,this,14,lpDirect3DDevice,14,lpHandle);
129127 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
130128 if(!lpDirect3DDevice) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
131 - glDirect3DDevice7 *glD3DDev7;
132 - lpDirect3DDevice->QueryInterface(IID_IDirect3DDevice7,(void**)&glD3DDev7);
 129+ glDirect3DDevice7 *glD3DDev7 = ((glDirect3DDevice1*)lpDirect3DDevice)->GetGLD3DDev7();
133130 HRESULT ret = glDDS7->GetHandle(glD3DDev7,lpHandle);
134 - glD3DDev7->Release();
135131 TRACE_EXIT(23,ret);
136132 return ret;
137133 }
Index: ddraw/glDirectDrawSurface.cpp
@@ -517,7 +517,7 @@
518518 glDirect3D7 *tmpd3d;
519519 ddInterface->QueryInterface(IID_IDirect3D7,(void**)&tmpd3d);
520520 if(!tmpd3d) TRACE_RET(HRESULT,23,E_NOINTERFACE);
521 - device1 = new glDirect3DDevice7(riid, tmpd3d, this, dds1);
 521+ device1 = new glDirect3DDevice7(riid, tmpd3d, this, dds1, 1);
522522 if (FAILED(device1->err()))
523523 {
524524 ret = device1->err();
@@ -535,10 +535,11 @@
536536 }
537537 else
538538 {
539 - HRESULT ret = device1->QueryInterface(IID_IDirect3DDevice,ppvObj);
 539+ *ppvObj = device1->glD3DDev1;
 540+ device1->glD3DDev1->AddRef();
540541 TRACE_VAR("*ppvObj",14,*ppvObj);
541 - TRACE_EXIT(23,ret);
542 - return ret;
 542+ TRACE_EXIT(23,DD_OK);
 543+ return DD_OK;
543544 }
544545 }
545546 if (version == 7)