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.

170 lines
3.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: d3denumpixelformats7obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "D3DEnumPixelFormats7obj.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_Direct3DEnumPixelFormats7Object *pObj=(C_dxj_Direct3DEnumPixelFormats7Object*)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. {
  30. void* tmp = realloc(pObj->m_pList,sizeof(DDPixelFormat)* pObj->m_nMax);
  31. if (tmp)
  32. pObj->m_pList=(DDPIXELFORMAT*)tmp;
  33. else
  34. return DDENUMRET_CANCEL;
  35. }
  36. else
  37. pObj->m_pList=(DDPIXELFORMAT*)malloc(sizeof(DDPixelFormat)* pObj->m_nMax);
  38. if (pObj->m_pList==NULL)
  39. {
  40. pObj->m_bProblem=TRUE;
  41. return FALSE;
  42. }
  43. }
  44. memcpy(&(pObj->m_pList[pObj->m_nCount]),pf,sizeof(DDPIXELFORMAT));
  45. pObj->m_nCount++;
  46. return TRUE;
  47. }
  48. C_dxj_Direct3DEnumPixelFormats7Object::C_dxj_Direct3DEnumPixelFormats7Object()
  49. {
  50. m_nMax=0;
  51. m_pList=NULL;
  52. m_nCount=0;
  53. m_bProblem=FALSE;
  54. }
  55. C_dxj_Direct3DEnumPixelFormats7Object::~C_dxj_Direct3DEnumPixelFormats7Object()
  56. {
  57. //empty list
  58. if (m_pList){
  59. free(m_pList);
  60. }
  61. }
  62. HRESULT C_dxj_Direct3DEnumPixelFormats7Object::create1(LPDIRECT3DDEVICE7 pd3d, I_dxj_Direct3DEnumPixelFormats **ppRet)
  63. {
  64. HRESULT hr;
  65. C_dxj_Direct3DEnumPixelFormats7Object *pNew=NULL;
  66. *ppRet=NULL;
  67. if (!pd3d) return E_INVALIDARG;
  68. pNew= new CComObject<C_dxj_Direct3DEnumPixelFormats7Object>;
  69. if (!pNew) return E_OUTOFMEMORY;
  70. pNew->m_bProblem=FALSE;
  71. hr=pd3d->EnumTextureFormats(objEnumPixelFormatsCallback,(void*)pNew);
  72. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  73. if FAILED(hr)
  74. {
  75. free(pNew->m_pList);
  76. pNew->m_pList=NULL;
  77. delete pNew;
  78. return hr;
  79. }
  80. hr=pNew->QueryInterface(IID_I_dxj_Direct3DEnumPixelFormats,(void**)ppRet);
  81. return hr;
  82. }
  83. HRESULT C_dxj_Direct3DEnumPixelFormats7Object::create2(LPDIRECT3D7 pd3d, BSTR strGuid, I_dxj_Direct3DEnumPixelFormats **ppRet)
  84. {
  85. HRESULT hr;
  86. C_dxj_Direct3DEnumPixelFormats7Object *pNew=NULL;
  87. GUID guid;
  88. hr=D3DBSTRtoGUID(&guid,strGuid);
  89. if FAILED(hr) return hr;
  90. *ppRet=NULL;
  91. if (!pd3d) return E_INVALIDARG;
  92. pNew= new CComObject<C_dxj_Direct3DEnumPixelFormats7Object>;
  93. if (!pNew) return E_OUTOFMEMORY;
  94. pNew->m_bProblem=FALSE;
  95. hr=pd3d->EnumZBufferFormats(guid,objEnumPixelFormatsCallback,(void*)pNew);
  96. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  97. if FAILED(hr)
  98. {
  99. free(pNew->m_pList);
  100. pNew->m_pList=NULL;
  101. delete pNew;
  102. return hr;
  103. }
  104. hr=pNew->QueryInterface(IID_I_dxj_Direct3DEnumPixelFormats,(void**)ppRet);
  105. return hr;
  106. }
  107. HRESULT C_dxj_Direct3DEnumPixelFormats7Object::getItem( long index, DDPixelFormat *desc)
  108. {
  109. if (m_pList==NULL) return E_FAIL;
  110. if (index < 1) return E_INVALIDARG;
  111. if (index > m_nCount) return E_INVALIDARG;
  112. CopyOutDDPixelFormat(desc ,&(m_pList[index-1]));
  113. return S_OK;
  114. }
  115. HRESULT C_dxj_Direct3DEnumPixelFormats7Object::getCount(long *retVal)
  116. {
  117. *retVal=m_nCount;
  118. return S_OK;
  119. }