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.

277 lines
5.8 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. return DDENUMRET_CANCEL;
  26. }
  27. if (pObj->m_nCount >= pObj->m_nMax)
  28. {
  29. pObj->m_nMax += 10;
  30. if (pObj->m_pList)
  31. {
  32. void* tmp = realloc(pObj->m_pList,sizeof(void*) * pObj->m_nMax);
  33. if (tmp)
  34. pObj->m_pList=(IDirectDrawSurface7**)tmp;
  35. else
  36. return DDENUMRET_CANCEL;
  37. }
  38. else
  39. pObj->m_pList=(IDirectDrawSurface7**)malloc(sizeof(void*) * pObj->m_nMax);
  40. if (pObj->m_pList==NULL)
  41. {
  42. pObj->m_bProblem=TRUE;
  43. return DDENUMRET_OK;
  44. }
  45. }
  46. pObj->m_pList[pObj->m_nCount]=lpddSurf;
  47. pObj->m_nCount++;
  48. //no need to release the surface we do that on tear down
  49. return DDENUMRET_OK;
  50. }
  51. DWORD C_dxj_DirectDrawEnumSurfacesObject::InternalAddRef(){
  52. DWORD i;
  53. i=CComObjectRoot::InternalAddRef();
  54. DPF2(1,"EnumSurf7 [%d] AddRef %d \n",creationid,i);
  55. return i;
  56. }
  57. DWORD C_dxj_DirectDrawEnumSurfacesObject::InternalRelease(){
  58. DWORD i;
  59. i=CComObjectRoot::InternalRelease();
  60. DPF2(1,"EnumSurf7 [%d] Release %d \n",creationid,i);
  61. return i;
  62. }
  63. C_dxj_DirectDrawEnumSurfacesObject::C_dxj_DirectDrawEnumSurfacesObject()
  64. {
  65. m_nMax=0;
  66. m_pList=NULL;
  67. m_nCount=0;
  68. m_bProblem=FALSE;
  69. parent=NULL;
  70. }
  71. C_dxj_DirectDrawEnumSurfacesObject::~C_dxj_DirectDrawEnumSurfacesObject()
  72. {
  73. //empty list
  74. if (m_pList){
  75. for (int i=0;i<m_nCount;i++)
  76. {
  77. if (m_pList[i]) m_pList[i]->Release();
  78. }
  79. free(m_pList);
  80. }
  81. //if (m_pDDS) m_pDDS->Release();
  82. //if (m_pDD) m_pDD->Release();
  83. if (parent) IUNK(parent)->Release();
  84. }
  85. HRESULT C_dxj_DirectDrawEnumSurfacesObject::create(I_dxj_DirectDraw7 *dd7, long flags, DDSurfaceDesc2 *desc,I_dxj_DirectDrawEnumSurfaces **ppRet)
  86. {
  87. if (!dd7) return E_INVALIDARG;
  88. LPDIRECTDRAW7 dd=NULL;
  89. dd7->InternalGetObject((IUnknown**)&dd);
  90. //For the sake of making sure that all Surface7 are destroyed before
  91. //ddraw is
  92. HRESULT hr;
  93. C_dxj_DirectDrawEnumSurfacesObject *pNew=NULL;
  94. *ppRet=NULL;
  95. pNew= new CComObject<C_dxj_DirectDrawEnumSurfacesObject>;
  96. if (!pNew) return E_OUTOFMEMORY;
  97. pNew->m_bProblem=FALSE;
  98. pNew->parent=dd7;
  99. IUNK(pNew->parent)->AddRef();
  100. //if FAILED(hr) return hr;
  101. if ((desc==NULL)||(IsAllZeros(desc,sizeof(DDSurfaceDesc2))))
  102. {
  103. hr=dd->EnumSurfaces((DWORD)flags,NULL,(void*)pNew,objEnumSurfaces7Callback);
  104. }
  105. else
  106. {
  107. DDSURFACEDESC2 realdesc;
  108. hr=CopyInDDSurfaceDesc2(&realdesc,desc);
  109. if (hr==S_OK){
  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_DirectDrawEnumSurfaces,(void**)ppRet);
  120. return hr;
  121. }
  122. HRESULT C_dxj_DirectDrawEnumSurfacesObject::createZEnum( I_dxj_DirectDrawSurface7 *ddS, long flags, I_dxj_DirectDrawEnumSurfaces **ppRet)
  123. {
  124. HRESULT hr;
  125. LPDIRECTDRAWSURFACE7 dd=NULL;
  126. if (!ddS) return E_INVALIDARG;
  127. ddS->InternalGetObject((IUnknown**)&dd);
  128. C_dxj_DirectDrawEnumSurfacesObject *pNew=NULL;
  129. if (!dd) return E_INVALIDARG;
  130. *ppRet=NULL;
  131. pNew= new CComObject<C_dxj_DirectDrawEnumSurfacesObject>;
  132. if (!pNew) return E_OUTOFMEMORY;
  133. pNew->m_bProblem=FALSE;
  134. pNew->parent=ddS;
  135. IUNK(pNew->parent)->AddRef();
  136. hr=dd->EnumOverlayZOrders((DWORD)flags,(void*)pNew,objEnumSurfaces7Callback);
  137. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  138. if FAILED(hr)
  139. {
  140. delete pNew;
  141. return hr;
  142. }
  143. hr=pNew->QueryInterface(IID_I_dxj_DirectDrawEnumSurfaces,(void**)ppRet);
  144. return hr;
  145. }
  146. HRESULT C_dxj_DirectDrawEnumSurfacesObject::createAttachedEnum(I_dxj_DirectDrawSurface7 *ddS, I_dxj_DirectDrawEnumSurfaces **ppRet)
  147. {
  148. //For the sake of making sure that all Surfaces2 are destroyed before
  149. //ddraw is
  150. HRESULT hr;
  151. LPDIRECTDRAWSURFACE7 dd=NULL;
  152. C_dxj_DirectDrawEnumSurfacesObject *pNew=NULL;
  153. if (!ddS) return E_INVALIDARG;
  154. ddS->InternalGetObject((IUnknown**)&dd);
  155. *ppRet=NULL;
  156. pNew= new CComObject<C_dxj_DirectDrawEnumSurfacesObject>;
  157. if (!pNew) return E_OUTOFMEMORY;
  158. pNew->m_bProblem=FALSE;
  159. pNew->parent=ddS;
  160. IUNK(pNew->parent)->AddRef();
  161. hr=dd->EnumAttachedSurfaces((void*)pNew,objEnumSurfaces7Callback);
  162. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  163. if FAILED(hr)
  164. {
  165. delete pNew;
  166. return hr;
  167. }
  168. hr=pNew->QueryInterface(IID_I_dxj_DirectDrawEnumSurfaces,(void**)ppRet);
  169. return hr;
  170. }
  171. HRESULT C_dxj_DirectDrawEnumSurfacesObject::getItem( long index, I_dxj_DirectDrawSurface7 **info)
  172. {
  173. if (m_pList==NULL) return E_FAIL;
  174. if (index < 1) return E_INVALIDARG;
  175. if (index > m_nCount) return E_INVALIDARG;
  176. IDirectDrawSurface7 *pRealSurf=m_pList[index-1];
  177. if (!pRealSurf) return E_FAIL;
  178. pRealSurf->AddRef();
  179. INTERNAL_CREATE(_dxj_DirectDrawSurface7, pRealSurf, info);
  180. return S_OK;
  181. }
  182. HRESULT C_dxj_DirectDrawEnumSurfacesObject::getCount(long *retVal)
  183. {
  184. *retVal=m_nCount;
  185. return S_OK;
  186. }