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.

324 lines
8.1 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: texiunk.c
  6. * Content: Direct3DTexture 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. /*
  28. * D3DTextIUnknown_QueryInterface
  29. */
  30. #undef DPF_MODNAME
  31. #define DPF_MODNAME "Direct3DTexture::QueryInterface"
  32. HRESULT D3DAPI CDirect3DTextureUnk::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_DWORD_PTR(this)) {
  42. D3D_ERR( "Invalid Direct3DTexture pointer" );
  43. return DDERR_INVALIDOBJECT;
  44. }
  45. if( !VALID_OUTPTR( ppvObj ) )
  46. {
  47. D3D_ERR( "Invalid obj ptr" );
  48. return DDERR_INVALIDPARAMS;
  49. }
  50. *ppvObj = NULL;
  51. }
  52. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  53. {
  54. D3D_ERR( "Exception encountered validating parameters" );
  55. return DDERR_INVALIDPARAMS;
  56. }
  57. *ppvObj = NULL;
  58. if(IsEqualIID(riid, IID_IUnknown))
  59. {
  60. /*
  61. * Asking for IUnknown and we are IUnknown.
  62. * NOTE: Must AddRef through the interface being returned.
  63. */
  64. pTexI->AddRef();
  65. *ppvObj = static_cast<LPVOID>(static_cast<LPUNKNOWN>(this));
  66. }
  67. else if (IsEqualIID(riid, IID_IDirect3DTexture))
  68. {
  69. /*
  70. * Asking for the actual IDirect3DTexture interface
  71. * NOTE: Must AddRef throught the interface being returned.
  72. */
  73. pTexI->AddRef();
  74. *ppvObj = static_cast<LPVOID>(static_cast<LPDIRECT3DTEXTURE>(pTexI));
  75. }
  76. else if (IsEqualIID(riid, IID_IDirect3DTexture2))
  77. {
  78. /*
  79. * Asking for the actual IDirect3DTexture2 interface
  80. * NOTE: Must AddRef throught the interface being returned.
  81. */
  82. pTexI->AddRef();
  83. *ppvObj = static_cast<LPVOID>(static_cast<LPDIRECT3DTEXTURE2>(pTexI));
  84. }
  85. else
  86. {
  87. return (E_NOINTERFACE);
  88. }
  89. return (D3D_OK);
  90. } /* D3DTextIUnknown_QueryInterface */
  91. /*
  92. * D3DTextIUnknown_AddRef
  93. */
  94. #undef DPF_MODNAME
  95. #define DPF_MODNAME "Direct3DTexture::AddRef"
  96. ULONG D3DAPI CDirect3DTextureUnk::AddRef()
  97. {
  98. DWORD rcnt;
  99. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  100. // Release in the destructor
  101. /*
  102. * validate parms
  103. */
  104. TRY
  105. {
  106. if (!VALID_DWORD_PTR(this)) {
  107. D3D_ERR( "Invalid Direct3DTexture pointer" );
  108. return 0;
  109. }
  110. }
  111. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  112. {
  113. D3D_ERR( "Exception encountered validating parameters" );
  114. return 0;
  115. }
  116. this->refCnt++;
  117. rcnt = this->refCnt;
  118. D3D_INFO(3, "Direct3DTexture IUnknown AddRef: Reference count = %d", rcnt);
  119. return (rcnt);
  120. } /* D3DTextIUnknown_AddRef */
  121. /*
  122. * D3DTextIUnknown_Release
  123. */
  124. #undef DPF_MODNAME
  125. #define DPF_MODNAME "Direct3DTexture::Release"
  126. ULONG D3DAPI CDirect3DTextureUnk::Release()
  127. {
  128. DWORD lastrefcnt;
  129. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  130. // Release in the destructor
  131. /*
  132. * validate parms
  133. */
  134. TRY
  135. {
  136. if (!VALID_DWORD_PTR(this)) {
  137. D3D_ERR( "Invalid Direct3DTexture pointer" );
  138. return 0;
  139. }
  140. }
  141. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  142. {
  143. D3D_ERR( "Exception encountered validating parameters" );
  144. return 0;
  145. }
  146. /*
  147. * decrement the ref count. if we hit 0, free the object
  148. */
  149. this->refCnt--;
  150. lastrefcnt = this->refCnt;
  151. D3D_INFO(3, "Direct3DTexture IUnknown Release: Reference count = %d", lastrefcnt);
  152. if (lastrefcnt == 0)
  153. {
  154. delete pTexI; // Delete Parent object
  155. return 0;
  156. }
  157. return lastrefcnt;
  158. } /* D3DTextIUnknown_Release */
  159. DIRECT3DTEXTUREI::~DIRECT3DTEXTUREI()
  160. {
  161. /*
  162. * just in case someone comes back in with this pointer, set
  163. * an invalid vtbl. Once we do that, it is safe to leave
  164. * the protected area...
  165. */
  166. while (LIST_FIRST(&this->blocks)) {
  167. LPD3DI_TEXTUREBLOCK tBlock = LIST_FIRST(&this->blocks);
  168. D3DI_RemoveTextureHandle(tBlock);
  169. // Remove from device
  170. LIST_DELETE(tBlock, devList);
  171. // Remove from texture
  172. LIST_DELETE(tBlock, list);
  173. D3DFree(tBlock);
  174. }
  175. if (lpTMBucket)
  176. { //need to release the private lpDDS if any
  177. lpDDS1Tex->Release();
  178. lpDDS->Release();
  179. lpTMBucket->lpD3DTexI=NULL;
  180. }
  181. }
  182. /*
  183. * D3DText_QueryInterface
  184. */
  185. #undef DPF_MODNAME
  186. #define DPF_MODNAME "Direct3DTexture::QueryInterface"
  187. HRESULT D3DAPI DIRECT3DTEXTUREI::QueryInterface(REFIID riid, LPVOID* ppvObj)
  188. {
  189. HRESULT ret;
  190. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  191. // Release in the destructor
  192. /*
  193. * validate parms
  194. */
  195. TRY
  196. {
  197. if (!VALID_DIRECT3DTEXTURE_PTR(this)) {
  198. D3D_ERR( "Invalid IDirect3DTexture pointer" );
  199. return DDERR_INVALIDOBJECT;
  200. }
  201. if( !VALID_OUTPTR( ppvObj ) )
  202. {
  203. D3D_ERR( "Invalid obj ptr" );
  204. return DDERR_INVALIDPARAMS;
  205. }
  206. }
  207. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  208. {
  209. D3D_ERR( "Exception encountered validating parameters" );
  210. return DDERR_INVALIDPARAMS;
  211. }
  212. /*
  213. * Punt to the owning interface.
  214. */
  215. ret = this->lpOwningIUnknown->QueryInterface(riid, ppvObj);
  216. return ret;
  217. }
  218. /*
  219. * D3DText_AddRef
  220. */
  221. #undef DPF_MODNAME
  222. #define DPF_MODNAME "Direct3DTexture::AddRef"
  223. ULONG D3DAPI DIRECT3DTEXTUREI::AddRef()
  224. {
  225. ULONG ret;
  226. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  227. // Release in the destructor
  228. /*
  229. * validate parms
  230. */
  231. TRY
  232. {
  233. if (!VALID_DIRECT3DTEXTURE_PTR(this)) {
  234. D3D_ERR( "Invalid Direct3DTexture pointer" );
  235. return 0;
  236. }
  237. }
  238. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  239. {
  240. D3D_ERR( "Exception encountered validating parameters" );
  241. return 0;
  242. }
  243. /*
  244. * Punt to owning interface.
  245. */
  246. ret = this->lpOwningIUnknown->AddRef();
  247. return ret;
  248. } /* D3DText_AddRef */
  249. /*
  250. * D3DText_Release
  251. */
  252. #undef DPF_MODNAME
  253. #define DPF_MODNAME "Direct3DTexture::Release"
  254. ULONG D3DAPI DIRECT3DTEXTUREI::Release()
  255. {
  256. ULONG ret;
  257. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  258. // Release in the destructor
  259. /*
  260. * validate parms
  261. */
  262. TRY
  263. {
  264. if (!VALID_DIRECT3DTEXTURE2_PTR(this)) {
  265. D3D_ERR( "Invalid Direct3DTexture pointer" );
  266. return 0;
  267. }
  268. }
  269. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  270. {
  271. D3D_ERR( "Exception encountered validating parameters" );
  272. return 0;
  273. }
  274. /*
  275. * Punt to owning interface.
  276. */
  277. ret = this->lpOwningIUnknown->Release();
  278. return ret;
  279. } /* D3DText_Release */