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.

174 lines
4.3 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: matiunk.c
  6. * Content: Direct3DMaterial IUnknown implementation
  7. *@@BEGIN_MSINTERNAL
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 10/12/95 stevela Initial rev with this header.
  13. *@@END_MSINTERNAL
  14. *
  15. ***************************************************************************/
  16. #include "pch.cpp"
  17. #pragma hdrstop
  18. /*
  19. * D3DMat_QueryInterface
  20. */
  21. #undef DPF_MODNAME
  22. #define DPF_MODNAME "Direct3DMaterial::QueryInterface"
  23. HRESULT D3DAPI DIRECT3DMATERIALI::QueryInterface(REFIID riid, LPVOID* ppvObj)
  24. {
  25. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  26. // Release in the destructor
  27. /*
  28. * validate parms
  29. */
  30. TRY
  31. {
  32. if (!VALID_DIRECT3DMATERIAL2_PTR(this)) {
  33. D3D_ERR( "Invalid Direct3DMaterial pointer" );
  34. return DDERR_INVALIDOBJECT;
  35. }
  36. if (!VALID_OUTPTR(ppvObj)) {
  37. D3D_ERR( "Invalid pointer to pointer" );
  38. return DDERR_INVALIDPARAMS;
  39. }
  40. *ppvObj = NULL;
  41. }
  42. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  43. {
  44. D3D_ERR( "Exception encountered validating parameters" );
  45. return DDERR_INVALIDPARAMS;
  46. }
  47. if(IsEqualIID(riid, IID_IUnknown) ||
  48. IsEqualIID(riid, IID_IDirect3DMaterial3) )
  49. {
  50. AddRef();
  51. *ppvObj = static_cast<LPVOID>(static_cast<LPDIRECT3DMATERIAL3>(this));
  52. return (D3D_OK);
  53. }
  54. else if (IsEqualIID(riid, IID_IDirect3DMaterial2))
  55. {
  56. AddRef();
  57. *ppvObj = static_cast<LPVOID>(static_cast<LPDIRECT3DMATERIAL2>(this));
  58. return D3D_OK;
  59. }
  60. else if (IsEqualIID(riid, IID_IDirect3DMaterial))
  61. {
  62. AddRef();
  63. *ppvObj = static_cast<LPVOID>(static_cast<LPDIRECT3DMATERIAL>(this));
  64. return D3D_OK;
  65. }
  66. else
  67. {
  68. D3D_ERR( "Don't know this riid" );
  69. return (E_NOINTERFACE);
  70. }
  71. } /* D3DMat2_QueryInterface */
  72. /*
  73. * D3DMat_AddRef
  74. */
  75. #undef DPF_MODNAME
  76. #define DPF_MODNAME "Direct3DMaterial::AddRef"
  77. ULONG D3DAPI DIRECT3DMATERIALI::AddRef()
  78. {
  79. DWORD rcnt;
  80. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  81. // Release in the destructor
  82. /*
  83. * validate parms
  84. */
  85. TRY
  86. {
  87. if (!VALID_DIRECT3DMATERIAL2_PTR(this)) {
  88. D3D_ERR( "Invalid Direct3DMaterial pointer" );
  89. return 0;
  90. }
  91. }
  92. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  93. {
  94. D3D_ERR( "Exception encountered validating parameters" );
  95. return 0;
  96. }
  97. this->refCnt++;
  98. rcnt = this->refCnt;
  99. return (rcnt);
  100. } /* D3DMat_AddRef */
  101. /*
  102. * D3DMat_Release
  103. *
  104. */
  105. #undef DPF_MODNAME
  106. #define DPF_MODNAME "Direct3DMaterial::Release"
  107. ULONG D3DAPI DIRECT3DMATERIALI::Release()
  108. {
  109. DWORD lastrefcnt;
  110. CLockD3D lockObject(DPF_MODNAME, REMIND("")); // Takes D3D lock.
  111. // Release in the destructor
  112. /*
  113. * validate parms
  114. */
  115. TRY
  116. {
  117. if (!VALID_DIRECT3DMATERIAL2_PTR(this)) {
  118. D3D_ERR( "Invalid Direct3DMaterial pointer" );
  119. return 0;
  120. }
  121. }
  122. EXCEPT( EXCEPTION_EXECUTE_HANDLER )
  123. {
  124. D3D_ERR( "Exception encountered validating parameters" );
  125. return 0;
  126. }
  127. /*
  128. * decrement the ref count. if we hit 0, free the object
  129. */
  130. this->refCnt--;
  131. lastrefcnt = this->refCnt;
  132. if( lastrefcnt == 0 )
  133. {
  134. delete this;
  135. return 0;
  136. }
  137. return lastrefcnt;
  138. } /* D3DMat_Release */
  139. DIRECT3DMATERIALI::~DIRECT3DMATERIALI()
  140. {
  141. /*
  142. * Remove ourselves from the devices
  143. */
  144. while (LIST_FIRST(&this->blocks)) {
  145. LPD3DI_MATERIALBLOCK mBlock = LIST_FIRST(&this->blocks);
  146. D3DI_RemoveMaterialBlock(mBlock);
  147. }
  148. /*
  149. * Remove ourselves from the Direct3D object
  150. */
  151. LIST_DELETE(this, list);
  152. this->lpDirect3DI->numMaterials--;
  153. }