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.

272 lines
5.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: ddenumsurfacesobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "DDSurface7Obj.h"
  14. #include "DDEnumSurfacesObj.h"
  15. #include "DDraw7obj.h"
  16. extern BOOL IsAllZeros(void*,DWORD size);
  17. extern "C" HRESULT PASCAL objEnumSurfaces7Callback(LPDIRECTDRAWSURFACE7 lpddSurf,
  18. LPDDSURFACEDESC2 lpDDSurfaceDesc, void *lpArg)
  19. {
  20. DPF(1,"Entered objEnumSurfaces7Callback \r\n");
  21. if (!lpddSurf) return DDENUMRET_CANCEL;
  22. C_dxj_DirectDrawEnumSurfacesObject *pObj=(C_dxj_DirectDrawEnumSurfacesObject *)lpArg;
  23. I_dxj_DirectDrawSurface7 *lpddSNew=NULL;
  24. if (pObj==NULL) {
  25. pObj->m_bProblem=TRUE;
  26. return DDENUMRET_CANCEL;
  27. }
  28. if (pObj->m_nCount >= pObj->m_nMax)
  29. {
  30. pObj->m_nMax += 10;
  31. if (pObj->m_pList)
  32. pObj->m_pList=(IDirectDrawSurface7**)realloc(pObj->m_pList,sizeof(void*) * pObj->m_nMax);
  33. else
  34. pObj->m_pList=(IDirectDrawSurface7**)malloc(sizeof(void*) * pObj->m_nMax);
  35. if (pObj->m_pList==NULL)
  36. {
  37. pObj->m_bProblem=TRUE;
  38. return DDENUMRET_OK;
  39. }
  40. }
  41. pObj->m_pList[pObj->m_nCount]=lpddSurf;
  42. pObj->m_nCount++;
  43. //no need to release the surface we do that on tear down
  44. return DDENUMRET_OK;
  45. }
  46. DWORD C_dxj_DirectDrawEnumSurfacesObject::InternalAddRef(){
  47. DWORD i;
  48. i=CComObjectRoot::InternalAddRef();
  49. DPF2(1,"EnumSurf7 [%d] AddRef %d \n",creationid,i);
  50. return i;
  51. }
  52. DWORD C_dxj_DirectDrawEnumSurfacesObject::InternalRelease(){
  53. DWORD i;
  54. i=CComObjectRoot::InternalRelease();
  55. DPF2(1,"EnumSurf7 [%d] Release %d \n",creationid,i);
  56. return i;
  57. }
  58. C_dxj_DirectDrawEnumSurfacesObject::C_dxj_DirectDrawEnumSurfacesObject()
  59. {
  60. m_nMax=0;
  61. m_pList=NULL;
  62. m_nCount=0;
  63. m_bProblem=FALSE;
  64. parent=NULL;
  65. }
  66. C_dxj_DirectDrawEnumSurfacesObject::~C_dxj_DirectDrawEnumSurfacesObject()
  67. {
  68. //empty list
  69. if (m_pList){
  70. for (int i=0;i<m_nCount;i++)
  71. {
  72. if (m_pList[i]) m_pList[i]->Release();
  73. }
  74. free(m_pList);
  75. }
  76. //if (m_pDDS) m_pDDS->Release();
  77. //if (m_pDD) m_pDD->Release();
  78. if (parent) IUNK(parent)->Release();
  79. }
  80. HRESULT C_dxj_DirectDrawEnumSurfacesObject::create(I_dxj_DirectDraw7 *dd7, long flags, DDSurfaceDesc2 *desc,I_dxj_DirectDrawEnumSurfaces **ppRet)
  81. {
  82. if (!dd7) return E_INVALIDARG;
  83. LPDIRECTDRAW7 dd=NULL;
  84. dd7->InternalGetObject((IUnknown**)&dd);
  85. //For the sake of making sure that all Surface7 are destroyed before
  86. //ddraw is
  87. HRESULT hr;
  88. C_dxj_DirectDrawEnumSurfacesObject *pNew=NULL;
  89. *ppRet=NULL;
  90. pNew= new CComObject<C_dxj_DirectDrawEnumSurfacesObject>;
  91. if (!pNew) return E_OUTOFMEMORY;
  92. pNew->m_bProblem=FALSE;
  93. pNew->parent=dd7;
  94. IUNK(pNew->parent)->AddRef();
  95. //if FAILED(hr) return hr;
  96. if ((desc==NULL)||(IsAllZeros(desc,sizeof(DDSurfaceDesc2))))
  97. {
  98. hr=dd->EnumSurfaces((DWORD)flags,NULL,(void*)pNew,objEnumSurfaces7Callback);
  99. }
  100. else
  101. {
  102. DDSURFACEDESC2 realdesc;
  103. hr=CopyInDDSurfaceDesc2(&realdesc,desc);
  104. if (hr==S_OK){
  105. hr=dd->EnumSurfaces((DWORD)flags,(DDSURFACEDESC2*)&realdesc,(void*)pNew,objEnumSurfaces7Callback);
  106. }
  107. }
  108. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  109. if FAILED(hr)
  110. {
  111. delete pNew;
  112. return hr;
  113. }
  114. hr=pNew->QueryInterface(IID_I_dxj_DirectDrawEnumSurfaces,(void**)ppRet);
  115. return hr;
  116. }
  117. HRESULT C_dxj_DirectDrawEnumSurfacesObject::createZEnum( I_dxj_DirectDrawSurface7 *ddS, long flags, I_dxj_DirectDrawEnumSurfaces **ppRet)
  118. {
  119. HRESULT hr;
  120. LPDIRECTDRAWSURFACE7 dd=NULL;
  121. if (!ddS) return E_INVALIDARG;
  122. ddS->InternalGetObject((IUnknown**)&dd);
  123. C_dxj_DirectDrawEnumSurfacesObject *pNew=NULL;
  124. if (!dd) return E_INVALIDARG;
  125. *ppRet=NULL;
  126. pNew= new CComObject<C_dxj_DirectDrawEnumSurfacesObject>;
  127. if (!pNew) return E_OUTOFMEMORY;
  128. pNew->m_bProblem=FALSE;
  129. pNew->parent=ddS;
  130. IUNK(pNew->parent)->AddRef();
  131. hr=dd->EnumOverlayZOrders((DWORD)flags,(void*)pNew,objEnumSurfaces7Callback);
  132. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  133. if FAILED(hr)
  134. {
  135. delete pNew;
  136. return hr;
  137. }
  138. hr=pNew->QueryInterface(IID_I_dxj_DirectDrawEnumSurfaces,(void**)ppRet);
  139. return hr;
  140. }
  141. HRESULT C_dxj_DirectDrawEnumSurfacesObject::createAttachedEnum(I_dxj_DirectDrawSurface7 *ddS, I_dxj_DirectDrawEnumSurfaces **ppRet)
  142. {
  143. //For the sake of making sure that all Surfaces2 are destroyed before
  144. //ddraw is
  145. HRESULT hr;
  146. LPDIRECTDRAWSURFACE7 dd=NULL;
  147. C_dxj_DirectDrawEnumSurfacesObject *pNew=NULL;
  148. if (!ddS) return E_INVALIDARG;
  149. ddS->InternalGetObject((IUnknown**)&dd);
  150. *ppRet=NULL;
  151. pNew= new CComObject<C_dxj_DirectDrawEnumSurfacesObject>;
  152. if (!pNew) return E_OUTOFMEMORY;
  153. pNew->m_bProblem=FALSE;
  154. pNew->parent=ddS;
  155. IUNK(pNew->parent)->AddRef();
  156. hr=dd->EnumAttachedSurfaces((void*)pNew,objEnumSurfaces7Callback);
  157. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  158. if FAILED(hr)
  159. {
  160. delete pNew;
  161. return hr;
  162. }
  163. hr=pNew->QueryInterface(IID_I_dxj_DirectDrawEnumSurfaces,(void**)ppRet);
  164. return hr;
  165. }
  166. HRESULT C_dxj_DirectDrawEnumSurfacesObject::getItem( long index, I_dxj_DirectDrawSurface7 **info)
  167. {
  168. if (m_pList==NULL) return E_FAIL;
  169. if (index < 1) return E_INVALIDARG;
  170. if (index > m_nCount) return E_INVALIDARG;
  171. IDirectDrawSurface7 *pRealSurf=m_pList[index-1];
  172. if (!pRealSurf) return E_FAIL;
  173. pRealSurf->AddRef();
  174. INTERNAL_CREATE(_dxj_DirectDrawSurface7, pRealSurf, info);
  175. return S_OK;
  176. }
  177. HRESULT C_dxj_DirectDrawEnumSurfacesObject::getCount(long *retVal)
  178. {
  179. *retVal=m_nCount;
  180. return S_OK;
  181. }