Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
6.4 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: deviunk.c
  6. * Content: Direct3DDevice IUnknown
  7. *@@BEGIN_MSINTERNAL
  8. *
  9. * $Id$
  10. *
  11. * History:
  12. * Date By Reason
  13. * ==== == ======
  14. * 07/12/95 stevela Merged Colin's changes.
  15. * 10/12/95 stevela Removed AGGREGATE_D3D.
  16. *@@END_MSINTERNAL
  17. *
  18. ***************************************************************************/
  19. #include "pch.cpp"
  20. #pragma hdrstop
  21. /*
  22. * If we are built with aggregation enabled then we actually need two
  23. * different Direct3D QueryInterface, AddRef and Releases. One which
  24. * does the right thing on the Direct3DTexture object and one which
  25. * simply punts to the owning interface.
  26. */
  27. #undef DPF_MODNAME
  28. #define DPF_MODNAME "Direct3DDevice"
  29. /*
  30. * D3DDevIUnknown_QueryInterface
  31. */
  32. HRESULT D3DAPI CDirect3DDeviceUnk::QueryInterface(REFIID riid, LPVOID* ppvObj)
  33. {
  34. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  35. // Release in the destructor
  36. /*
  37. * validate parms
  38. */
  39. TRY
  40. {
  41. if (!VALID_OUTPTR(ppvObj)) {
  42. D3D_ERR( "Invalid pointer to object pointer" );
  43. return DDERR_INVALIDPARAMS;
  44. }
  45. }
  46. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  47. {
  48. D3D_ERR( "Exception encountered validating parameters" );
  49. return DDERR_INVALIDPARAMS;
  50. }
  51. D3D_INFO(3, "Direct3DDevice IUnknown QueryInterface");
  52. *ppvObj = NULL;
  53. if (IsEqualIID(riid, IID_IUnknown))
  54. {
  55. /*
  56. * Asking for IUnknown and we are IUnknown.
  57. * NOTE: Must AddRef through the interface being returned.
  58. */
  59. pDevI->AddRef();
  60. *ppvObj = static_cast<LPVOID>(this);
  61. }
  62. else if (IS_DX5_COMPATIBLE_DEVICE(pDevI))
  63. { /* Non aggregated device, possible IIDs: Device, Device2, Device3 */
  64. if (IsEqualIID(riid, IID_IDirect3DDevice))
  65. {
  66. pDevI->AddRef();
  67. *ppvObj = static_cast<LPVOID>(static_cast<IDirect3DDevice*>(pDevI));
  68. pDevI->guid = IID_IDirect3DDevice;
  69. }
  70. else if (IsEqualIID(riid, IID_IDirect3DDevice2))
  71. {
  72. pDevI->AddRef();
  73. *ppvObj = static_cast<LPVOID>(static_cast<IDirect3DDevice2*>(pDevI));
  74. pDevI->guid = IID_IDirect3DDevice2;
  75. }
  76. else if (IsEqualIID(riid, IID_IDirect3DDevice3))
  77. {
  78. if(pDevI->dwVersion<3) {
  79. D3D_ERR("Cannot QueryInterface for Device3 from device created as Device2");
  80. return E_NOINTERFACE;
  81. }
  82. pDevI->AddRef();
  83. *ppvObj = static_cast<LPVOID>(static_cast<IDirect3DDevice3*>(pDevI));
  84. pDevI->guid = IID_IDirect3DDevice3;
  85. }
  86. else
  87. {
  88. D3D_ERR("unknown interface");
  89. return (E_NOINTERFACE);
  90. }
  91. }
  92. else if (IsEqualIID(riid, pDevI->guid))
  93. { /* DDraw Aggregated device, possible IIDs: RampDevice, RGBDevice, HALDevice */
  94. pDevI->AddRef();
  95. *ppvObj = static_cast<LPVOID>(static_cast<CDirect3DDevice*>(pDevI));
  96. }
  97. else
  98. {
  99. D3D_ERR("unknown interface");
  100. return (E_NOINTERFACE);
  101. }
  102. return (D3D_OK);
  103. } /* D3DDevIUnknown_QueryInterface */
  104. /*
  105. * D3DDevIUnknown_AddRef
  106. */
  107. #undef DPF_MODNAME
  108. #define DPF_MODNAME "Direct3DDevice::AddRef"
  109. ULONG D3DAPI CDirect3DDeviceUnk::AddRef()
  110. {
  111. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  112. // Release in the destructor
  113. this->refCnt++;
  114. D3D_INFO(3, "Direct3DDevice IUnknown AddRef: Reference count = %d", this->refCnt);
  115. return (this->refCnt);
  116. } /* D3DDevIUnknown_AddRef */
  117. /*
  118. * D3DDevIUnknown_Release
  119. *
  120. */
  121. #undef DPF_MODNAME
  122. #define DPF_MODNAME "Direct3DDevice::Release"
  123. ULONG D3DAPI CDirect3DDeviceUnk::Release()
  124. {
  125. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  126. // Release in the destructor
  127. /*
  128. * decrement the ref count. if we hit 0, free the object
  129. */
  130. this->refCnt--;
  131. D3D_INFO(3, "Direct3DDevice IUnknown Release: Reference count = %d", this->refCnt);
  132. if( this->refCnt == 0 )
  133. {
  134. delete pDevI; // Delete Parent object
  135. return 0;
  136. }
  137. return this->refCnt;
  138. } /* D3DDevIUnknown_Release */
  139. /*
  140. * D3DDev_QueryInterface
  141. */
  142. #undef DPF_MODNAME
  143. #define DPF_MODNAME "Direct3DDevice::QueryInterface"
  144. HRESULT D3DAPI DIRECT3DDEVICEI::QueryInterface(REFIID riid, LPVOID* ppvObj)
  145. {
  146. HRESULT ret;
  147. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  148. // Release in the destructor
  149. /*
  150. * validate parms
  151. , */
  152. TRY
  153. {
  154. if( !VALID_OUTPTR( ppvObj ) )
  155. {
  156. D3D_ERR("Invalid obj ptr" );
  157. return DDERR_INVALIDPARAMS;
  158. }
  159. }
  160. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  161. {
  162. D3D_ERR( "Exception encountered validating parameters" );
  163. return DDERR_INVALIDPARAMS;
  164. }
  165. *ppvObj = NULL;
  166. /*
  167. * Punt to the owning interface.
  168. */
  169. ret = this->lpOwningIUnknown->QueryInterface(riid, ppvObj);
  170. return ret;
  171. } /* D3DDev_QueryInterface */
  172. /*
  173. * D3DDev_AddRef
  174. */
  175. #undef DPF_MODNAME
  176. #define DPF_MODNAME "Direct3DDevice::AddRef"
  177. ULONG D3DAPI DIRECT3DDEVICEI::AddRef()
  178. {
  179. ULONG ret;
  180. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  181. // Release in the destructor
  182. /*
  183. * Punt to owning interface.
  184. */
  185. ret = this->lpOwningIUnknown->AddRef();
  186. return ret;
  187. } /* D3DDev_AddRef */
  188. /*
  189. * D3DDev_Release
  190. */
  191. #undef DPF_MODNAME
  192. #define DPF_MODNAME "Direct3DDevice::Release"
  193. ULONG D3DAPI DIRECT3DDEVICEI::Release()
  194. {
  195. ULONG ret;
  196. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  197. // Release in the destructor
  198. /*
  199. * Punt to owning interface.
  200. */
  201. ret = this->lpOwningIUnknown->Release();
  202. return ret;
  203. } /* D3DDev_Release */