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.

231 lines
4.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: d3denumpixelformatsobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "D3DEnumPixelFormatsobj.h"
  14. extern HRESULT CopyOutDDPixelFormat( DDPixelFormat *ddpfOut,DDPIXELFORMAT *pf);
  15. extern HRESULT CopyInDDPixelFormat(DDPIXELFORMAT *ddpfOut,DDPixelFormat *pf);
  16. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  17. extern BSTR D3DGUIDtoBSTR(LPGUID pg);
  18. extern HRESULT D3DBSTRtoGUID(LPGUID pGuid,BSTR str);
  19. extern BOOL IsAllZeros(void *pStruct,DWORD size);
  20. extern "C" HRESULT PASCAL objEnumPixelFormatsCallback(DDPIXELFORMAT *pf, void *lpArg)
  21. {
  22. DPF(1,"Entered objEnumPixelFormatsCallback\r\n");
  23. C_dxj_D3DEnumPixelFormatsObject *pObj=(C_dxj_D3DEnumPixelFormatsObject*)lpArg;
  24. if (pObj==NULL) return DDENUMRET_OK;
  25. if (pObj->m_nCount >= pObj->m_nMax)
  26. {
  27. pObj->m_nMax += 10;
  28. if (pObj->m_pList)
  29. pObj->m_pList=(DDPIXELFORMAT*)realloc(pObj->m_pList,sizeof(DDPixelFormat)* pObj->m_nMax);
  30. else
  31. pObj->m_pList=(DDPIXELFORMAT*)malloc(sizeof(DDPixelFormat)* pObj->m_nMax);
  32. if (pObj->m_pList==NULL)
  33. {
  34. pObj->m_bProblem=TRUE;
  35. return FALSE;
  36. }
  37. }
  38. memcpy(&(pObj->m_pList[pObj->m_nCount]),pf,sizeof(DDPIXELFORMAT));
  39. pObj->m_nCount++;
  40. return TRUE;
  41. }
  42. C_dxj_D3DEnumPixelFormatsObject::C_dxj_D3DEnumPixelFormatsObject()
  43. {
  44. m_nMax=0;
  45. m_pList=NULL;
  46. m_nCount=0;
  47. m_bProblem=FALSE;
  48. }
  49. C_dxj_D3DEnumPixelFormatsObject::~C_dxj_D3DEnumPixelFormatsObject()
  50. {
  51. //empty list
  52. if (m_pList){
  53. free(m_pList);
  54. }
  55. }
  56. HRESULT C_dxj_D3DEnumPixelFormatsObject::create(LPDIRECT3DDEVICE3 pd3d, I_dxj_D3DEnumPixelFormats **ppRet)
  57. {
  58. HRESULT hr;
  59. C_dxj_D3DEnumPixelFormatsObject *pNew=NULL;
  60. *ppRet=NULL;
  61. if (!pd3d) return E_INVALIDARG;
  62. pNew= new CComObject<C_dxj_D3DEnumPixelFormatsObject>;
  63. if (!pNew) return E_OUTOFMEMORY;
  64. pNew->m_bProblem=FALSE;
  65. hr=pd3d->EnumTextureFormats(objEnumPixelFormatsCallback,(void*)pNew);
  66. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  67. if FAILED(hr)
  68. {
  69. free(pNew->m_pList);
  70. pNew->m_pList=NULL;
  71. delete pNew;
  72. return hr;
  73. }
  74. hr=pNew->QueryInterface(IID_I_dxj_D3DEnumPixelFormats,(void**)ppRet);
  75. return hr;
  76. }
  77. HRESULT C_dxj_D3DEnumPixelFormatsObject::create2(LPDIRECT3D3 pd3d, BSTR strGuid, I_dxj_D3DEnumPixelFormats **ppRet)
  78. {
  79. HRESULT hr;
  80. C_dxj_D3DEnumPixelFormatsObject *pNew=NULL;
  81. GUID guid;
  82. hr=D3DBSTRtoGUID(&guid,strGuid);
  83. if FAILED(hr) return hr;
  84. *ppRet=NULL;
  85. if (!pd3d) return E_INVALIDARG;
  86. pNew= new CComObject<C_dxj_D3DEnumPixelFormatsObject>;
  87. if (!pNew) return E_OUTOFMEMORY;
  88. pNew->m_bProblem=FALSE;
  89. hr=pd3d->EnumZBufferFormats(guid,objEnumPixelFormatsCallback,(void*)pNew);
  90. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  91. if FAILED(hr)
  92. {
  93. free(pNew->m_pList);
  94. pNew->m_pList=NULL;
  95. delete pNew;
  96. return hr;
  97. }
  98. hr=pNew->QueryInterface(IID_I_dxj_D3DEnumPixelFormats,(void**)ppRet);
  99. return hr;
  100. }
  101. #if 0
  102. HRESULT C_dxj_D3DEnumPixelFormatsObject::create3(LPDIRECT3DDEVICE7 pd3d, I_dxj_D3DEnumPixelFormats **ppRet)
  103. {
  104. HRESULT hr;
  105. C_dxj_D3DEnumPixelFormatsObject *pNew=NULL;
  106. *ppRet=NULL;
  107. if (!pd3d) return E_INVALIDARG;
  108. pNew= new CComObject<C_dxj_D3DEnumPixelFormatsObject>;
  109. if (!pNew) return E_OUTOFMEMORY;
  110. pNew->m_bProblem=FALSE;
  111. hr=pd3d->EnumTextureFormats(objEnumPixelFormatsCallback,(void*)pNew);
  112. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  113. if FAILED(hr)
  114. {
  115. free(pNew->m_pList);
  116. pNew->m_pList=NULL;
  117. delete pNew;
  118. return hr;
  119. }
  120. hr=pNew->QueryInterface(IID_I_dxj_D3DEnumPixelFormats,(void**)ppRet);
  121. return hr;
  122. }
  123. HRESULT C_dxj_D3DEnumPixelFormatsObject::create4(LPDIRECT3D7 pd3d, BSTR strGuid, I_dxj_D3DEnumPixelFormats **ppRet)
  124. {
  125. HRESULT hr;
  126. C_dxj_D3DEnumPixelFormatsObject *pNew=NULL;
  127. GUID guid;
  128. hr=D3DBSTRtoGUID(&guid,strGuid);
  129. if FAILED(hr) return hr;
  130. *ppRet=NULL;
  131. if (!pd3d) return E_INVALIDARG;
  132. pNew= new CComObject<C_dxj_D3DEnumPixelFormatsObject>;
  133. if (!pNew) return E_OUTOFMEMORY;
  134. pNew->m_bProblem=FALSE;
  135. hr=pd3d->EnumZBufferFormats(guid,objEnumPixelFormatsCallback,(void*)pNew);
  136. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  137. if FAILED(hr)
  138. {
  139. free(pNew->m_pList);
  140. pNew->m_pList=NULL;
  141. delete pNew;
  142. return hr;
  143. }
  144. hr=pNew->QueryInterface(IID_I_dxj_D3DEnumPixelFormats,(void**)ppRet);
  145. return hr;
  146. }
  147. #endif
  148. HRESULT C_dxj_D3DEnumPixelFormatsObject::getItem( long index, DDPixelFormat *desc)
  149. {
  150. if (m_pList==NULL) return E_FAIL;
  151. if (index < 1) return E_INVALIDARG;
  152. if (index > m_nCount) return E_INVALIDARG;
  153. CopyOutDDPixelFormat(desc ,&(m_pList[index-1]));
  154. return S_OK;
  155. }
  156. HRESULT C_dxj_D3DEnumPixelFormatsObject::getCount(long *retVal)
  157. {
  158. *retVal=m_nCount;
  159. return S_OK;
  160. }