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.

216 lines
5.8 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: d3diunk.c
  6. * Content: Direct3D 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. * 27/08/96 stevela Ifdefed out the Close of gHEvent. We're using
  16. * DirectDraw's critical section.
  17. *@@END_MSINTERNAL
  18. *
  19. ***************************************************************************/
  20. #include "pch.cpp"
  21. #pragma hdrstop
  22. /*
  23. * If we are built with aggregation enabled then we actually need two
  24. * different Direct3D QueryInterface, AddRef and Releases. One which
  25. * does the right thing on the Direct3D object and one which simply
  26. * punts to the owning interface.
  27. */
  28. /*
  29. * CDirect3DUnk::QueryInterface
  30. */
  31. #undef DPF_MODNAME
  32. #define DPF_MODNAME "Direct3D::QueryInterface"
  33. HRESULT D3DAPI CDirect3DUnk::QueryInterface(REFIID riid, LPVOID* ppvObj)
  34. {
  35. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  36. // Release in the destructor
  37. if( !VALID_OUTPTR( ppvObj ) )
  38. {
  39. D3D_ERR( "Invalid obj ptr" );
  40. return DDERR_INVALIDPARAMS;
  41. }
  42. *ppvObj = NULL;
  43. D3D_INFO(3, "Direct3D IUnknown QueryInterface");
  44. if(IsEqualIID(riid, IID_IUnknown))
  45. {
  46. /*
  47. * Asking for IUnknown and we are IUnknown so just bump the
  48. * reference count and return this interface.
  49. * NOTE: Must AddRef through the interface being returned.
  50. */
  51. pD3DI->AddRef();
  52. // explicit ::CDirect3D disambiguation required since there are multiple IUnknown DIRECT3DI inherits from
  53. *ppvObj = static_cast<LPVOID>(static_cast<LPUNKNOWN>(static_cast<DIRECT3DI*>(pD3DI)));
  54. }
  55. else if (IsEqualIID(riid, IID_IDirect3D7))
  56. {
  57. pD3DI->AddRef();
  58. // No disambiguation required. Only one IDirect3D3 base for DIRECT3DI
  59. *ppvObj = static_cast<LPVOID>(static_cast<LPDIRECT3D7>(pD3DI));
  60. }
  61. else
  62. {
  63. /*
  64. * Don't understand this interface. Fail.
  65. * NOTE: Used to return DDERR_GENERIC. Now return
  66. * E_NOINTERFACE.
  67. */
  68. return (E_NOINTERFACE);
  69. }
  70. return (D3D_OK);
  71. } /* CDirect3DUnk::QueryInterface */
  72. /*
  73. * CDirect3DUnk::AddRef
  74. */
  75. #undef DPF_MODNAME
  76. #define DPF_MODNAME "CDirect3DUnk::AddRef"
  77. ULONG D3DAPI CDirect3DUnk::AddRef()
  78. {
  79. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  80. // Release in the destructor
  81. refCnt++;
  82. D3D_INFO(3, "Direct3D IUnknown AddRef: Reference count = %d", refCnt);
  83. return (refCnt);
  84. } /* CDirect3DUnk::AddRef */
  85. /*
  86. * CDirect3DUnk::Release
  87. */
  88. #undef DPF_MODNAME
  89. #define DPF_MODNAME "CDirect3DUnk::Release"
  90. ULONG D3DAPI CDirect3DUnk::Release()
  91. {
  92. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  93. // Release in the destructor
  94. /*
  95. * decrement the ref count. if we hit 0, free the object
  96. */
  97. refCnt--;
  98. D3D_INFO(3, "Direct3D IUnknown Release: Reference count = %d", refCnt);
  99. if( refCnt == 0 )
  100. {
  101. delete pD3DI; // Delete Parent object
  102. return 0;
  103. }
  104. return refCnt;
  105. } /* D3DIUnknown_Release */
  106. DIRECT3DI::~DIRECT3DI()
  107. {
  108. D3D_INFO(3, "Release Direct3D Object");
  109. #if COLLECTSTATS
  110. if(m_hFont)
  111. {
  112. DeleteObject(m_hFont);
  113. }
  114. #endif
  115. delete lpTextureManager;
  116. /*
  117. * free up all allocated Buckets
  118. */
  119. #if DBG
  120. /* this->lpFreeList must have all the buckets that are allocated */
  121. if (this->lpFreeList || this->lpBufferList)
  122. {
  123. int i,j;
  124. LPD3DBUCKET temp;
  125. for (i=0,temp=this->lpFreeList;temp;i++) temp=temp->next;
  126. for (j=0,temp=this->lpBufferList;temp;j++) temp=temp->next;
  127. D3D_INFO(4,"D3D Release: recovered %d buckets in lpFreeList in %d buffers",i,j);
  128. DDASSERT(j*(D3DBUCKETBUFFERSIZE-1)==i);
  129. }
  130. #endif //DBG
  131. while (this->lpBufferList)
  132. {
  133. LPD3DBUCKET temp=this->lpBufferList;
  134. this->lpBufferList=temp->next;
  135. D3DFree(temp->lpBuffer);
  136. D3D_INFO(4,"D3D Release:lpBufferList %d bytes freed",D3DBUCKETBUFFERSIZE*sizeof(D3DBUCKET));
  137. }
  138. this->lpFreeList=NULL;
  139. }
  140. /*
  141. * DIRECT3DI::QueryInterface
  142. */
  143. #undef DPF_MODNAME
  144. #define DPF_MODNAME "DIRECT3DI::QueryInterface"
  145. HRESULT D3DAPI DIRECT3DI::QueryInterface(REFIID riid, LPVOID* ppvObj)
  146. {
  147. HRESULT ret;
  148. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  149. if( !VALID_OUTPTR( ppvObj ) )
  150. {
  151. D3D_ERR( "Invalid obj ptr" );
  152. return DDERR_INVALIDPARAMS;
  153. }
  154. *ppvObj = NULL;
  155. ret = this->lpOwningIUnknown->QueryInterface(riid, ppvObj);
  156. return ret;
  157. }
  158. /*
  159. * DIRECT3DI::AddRef
  160. */
  161. #undef DPF_MODNAME
  162. #define DPF_MODNAME "DIRECT3DI::AddRef"
  163. ULONG D3DAPI DIRECT3DI::AddRef()
  164. {
  165. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  166. // Release in the destructor
  167. /*
  168. * Punt to the owning interface.
  169. */
  170. return this->lpOwningIUnknown->AddRef();
  171. }
  172. /*
  173. * DIRECT3DI::Release
  174. */
  175. #undef DPF_MODNAME
  176. #define DPF_MODNAME "DIRECT3DI::Release"
  177. ULONG D3DAPI DIRECT3DI::Release()
  178. {
  179. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  180. // Release in the destructor
  181. /*
  182. * Punt to the owning interface.
  183. */
  184. return this->lpOwningIUnknown->Release();
  185. }