Source code of Windows XP (NT5)
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.

265 lines
6.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: ddenumsurfaces7obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "DDSurface7Obj.h"
  14. #include "DDEnumSurfaces7Obj.h"
  15. extern BOOL IsAllZeros(void*,DWORD size);
  16. //extern HRESULT CopyInDDSurfaceDesc2(DDSURFACEDESC2*,DDSurfaceDesc2*);
  17. //extern HRESULT CopyOutDDSurfaceDesc2(DDSurfaceDesc2*,DDSURFACEDESC2*);
  18. //////////////////////////////////////////////////////////////////////
  19. // objEnumSurfaces7Callback
  20. //////////////////////////////////////////////////////////////////////
  21. extern "C" HRESULT PASCAL objEnumSurfaces7Callback(LPDIRECTDRAWSURFACE7 lpddSurf,
  22. LPDDSURFACEDESC2 lpDDSurfaceDesc, void *lpArg)
  23. {
  24. DPF1(1,"Entered objEnumSurfaces7Callback \r\n");
  25. C_dxj_DDEnumSurfaces7Object *pObj=(C_dxj_DDEnumSurfaces7Object *)lpArg;
  26. I_dxj_DirectDrawSurface7 *lpddSNew=NULL;
  27. if (pObj==NULL) {
  28. pObj->m_bProblem=TRUE;
  29. return DDENUMRET_CANCEL;
  30. }
  31. //create a surface7 object but dont have a back reference to this object!!!
  32. INTERNAL_CREATE_NOADDREF(_dxj_DirectDrawSurface7, lpddSurf, &lpddSNew);
  33. if (lpddSNew==NULL) {
  34. pObj->m_bProblem=TRUE;
  35. return DDENUMRET_CANCEL;
  36. }
  37. if (pObj->m_nCount >= pObj->m_nMax)
  38. {
  39. pObj->m_nMax += 10;
  40. if (pObj->m_pList)
  41. pObj->m_pList=(I_dxj_DirectDrawSurface7**)realloc(pObj->m_pList,sizeof(void*) * pObj->m_nMax);
  42. else
  43. pObj->m_pList=(I_dxj_DirectDrawSurface7**)malloc(sizeof(void*) * pObj->m_nMax);
  44. if (pObj->m_pList==NULL)
  45. {
  46. pObj->m_bProblem=TRUE;
  47. return DDENUMRET_OK;
  48. }
  49. }
  50. pObj->m_pList[pObj->m_nCount]=lpddSNew;
  51. return DDENUMRET_OK;
  52. }
  53. //////////////////////////////////////////////////////////////////////
  54. // C_dxj_DDEnumSurfaces7Object
  55. //////////////////////////////////////////////////////////////////////
  56. C_dxj_DDEnumSurfaces7Object::C_dxj_DDEnumSurfaces7Object()
  57. {
  58. m_nMax=0;
  59. m_pList=NULL;
  60. m_nCount=0;
  61. m_bProblem=FALSE;
  62. m_pDD=NULL;
  63. m_pDDS=NULL;
  64. }
  65. //////////////////////////////////////////////////////////////////////
  66. // ~C_dxj_DDEnumSurfaces7Object
  67. //////////////////////////////////////////////////////////////////////
  68. C_dxj_DDEnumSurfaces7Object::~C_dxj_DDEnumSurfaces7Object()
  69. {
  70. //empty list
  71. if (m_pList){
  72. for (int i=0;i<m_nCount;i++)
  73. {
  74. if (m_pList[i]) m_pList[i]->Release();
  75. }
  76. free(m_pList);
  77. }
  78. if (m_pDDS) m_pDDS->Release();
  79. if (m_pDD) m_pDD->Release();
  80. }
  81. //////////////////////////////////////////////////////////////////////
  82. // create ddraw->enum
  83. //////////////////////////////////////////////////////////////////////
  84. HRESULT C_dxj_DDEnumSurfaces7Object::create(LPDIRECTDRAW7 dd, long flags, DDSurfaceDesc2 *desc,I_dxj_DDEnumSurfaces7 **ppRet)
  85. {
  86. return E_NOTIMPL;
  87. //For the sake of making sure that all Surfaces2 are destroyed before
  88. //ddraw is
  89. HRESULT hr;
  90. C_dxj_DDEnumSurfaces7Object *pNew=NULL;
  91. if (!dd) return E_INVALIDARG;
  92. //ASSERT(ppRet,"C_dxj_DDEnumSurfaces7Object::create passed invalid arg");
  93. *ppRet=NULL;
  94. pNew= new CComObject<C_dxj_DDEnumSurfaces7Object>;
  95. if (!pNew) return E_OUTOFMEMORY;
  96. pNew->m_bProblem=FALSE;
  97. pNew->m_pDD=dd;
  98. pNew->m_pDD->AddRef();
  99. //if the description is all zeros allow use to pass in NULL
  100. if ((desc==NULL)||(IsAllZeros(desc,sizeof(DDSurfaceDesc2)))){
  101. //d3dcore bug
  102. //hr=dd->EnumSurfaces((DWORD)flags,NULL,(void*)pNew,objEnumSurfaces7Callback);
  103. }
  104. //otherwise use the surface description to enumerate
  105. else {
  106. DDSURFACEDESC2 realdesc;
  107. hr=CopyInDDSurfaceDesc2(&realdesc,desc);
  108. if (hr==S_OK){
  109. //d3dcore bug
  110. // hr=dd->EnumSurfaces((DWORD)flags,(DDSURFACEDESC2*)&realdesc,(void*)pNew,objEnumSurfaces7Callback);
  111. }
  112. }
  113. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  114. if FAILED(hr)
  115. {
  116. delete pNew;
  117. return hr;
  118. }
  119. hr=pNew->QueryInterface(IID_I_dxj_DDEnumSurfaces7,(void**)ppRet);
  120. return hr;
  121. }
  122. //////////////////////////////////////////////////////////////////////
  123. // createZEnum ddrawsurface->enumZ
  124. //////////////////////////////////////////////////////////////////////
  125. HRESULT C_dxj_DDEnumSurfaces7Object::createZEnum(LPDIRECTDRAWSURFACE7 dd, long flags, I_dxj_DDEnumSurfaces7 **ppRet)
  126. {
  127. //For the sake of making sure that all Surfaces2 are destroyed before
  128. //ddraw is
  129. //return E_NOTIMPL;
  130. HRESULT hr;
  131. C_dxj_DDEnumSurfaces7Object *pNew=NULL;
  132. if (!dd) return E_INVALIDARG;
  133. //ASSERT(ppRet,"C_dxj_DDEnumSurfaces7Object::create passed invalid arg");
  134. *ppRet=NULL;
  135. pNew= new CComObject<C_dxj_DDEnumSurfaces7Object>;
  136. if (!pNew) return E_OUTOFMEMORY;
  137. pNew->m_bProblem=FALSE;
  138. pNew->m_pDDS=dd;
  139. pNew->m_pDDS->AddRef();
  140. //d3d core bug
  141. hr=dd->EnumOverlayZOrders((DWORD)flags,(void*)pNew,objEnumSurfaces7Callback);
  142. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  143. if FAILED(hr)
  144. {
  145. delete pNew;
  146. return hr;
  147. }
  148. hr=pNew->QueryInterface(IID_I_dxj_DDEnumSurfaces7,(void**)ppRet);
  149. return hr;
  150. }
  151. //////////////////////////////////////////////////////////////////////
  152. // createAttachedEnum ddrawsurface->enum
  153. //////////////////////////////////////////////////////////////////////
  154. HRESULT C_dxj_DDEnumSurfaces7Object::createAttachedEnum(LPDIRECTDRAWSURFACE7 dd, I_dxj_DDEnumSurfaces7 **ppRet)
  155. {
  156. //For the sake of making sure that all Surfaces2 are destroyed before
  157. //ddraw is
  158. //return E_NOTIMPL;
  159. HRESULT hr;
  160. C_dxj_DDEnumSurfaces7Object *pNew=NULL;
  161. if (!dd) return E_INVALIDARG;
  162. //ASSERT(ppRet,"C_dxj_DDEnumSurfaces7Object::create passed invalid arg");
  163. *ppRet=NULL;
  164. pNew= new CComObject<C_dxj_DDEnumSurfaces7Object>;
  165. if (!pNew) return E_OUTOFMEMORY;
  166. pNew->m_bProblem=FALSE;
  167. pNew->m_pDDS=dd;
  168. pNew->m_pDDS->AddRef();
  169. hr=dd->EnumAttachedSurfaces((void*)pNew,objEnumSurfaces7Callback);
  170. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  171. if FAILED(hr)
  172. {
  173. delete pNew;
  174. return hr;
  175. }
  176. hr=pNew->QueryInterface(IID_I_dxj_DDEnumSurfaces7,(void**)ppRet);
  177. return hr;
  178. }
  179. //////////////////////////////////////////////////////////////////////
  180. // getItem
  181. //////////////////////////////////////////////////////////////////////
  182. HRESULT C_dxj_DDEnumSurfaces7Object::getItem( long index, I_dxj_DirectDrawSurface7 **info)
  183. {
  184. if (m_pList==NULL) return E_FAIL;
  185. if (index < 1) return E_INVALIDARG;
  186. if (index > m_nCount) return E_INVALIDARG;
  187. *info=m_pList[index];
  188. if (m_pList[index-1]) (m_pList[index-1])->AddRef();
  189. return S_OK;
  190. }
  191. //////////////////////////////////////////////////////////////////////
  192. // getCount
  193. //////////////////////////////////////////////////////////////////////
  194. HRESULT C_dxj_DDEnumSurfaces7Object::getCount(long *retVal)
  195. {
  196. *retVal=m_nCount;
  197. return S_OK;
  198. }