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.

293 lines
10 KiB

  1. /*******************************************************************************
  2. * DXSurfB.h *
  3. *----------*
  4. * Description:
  5. * This is the header file for the CDXBaseSurface implementation. It is
  6. * used as a base class to implement read-only procedural DXSurfaces.
  7. *-------------------------------------------------------------------------------
  8. * Created By: RAL Date: 02/12/1998
  9. * Copyright (C) 1998 Microsoft Corporation
  10. * All Rights Reserved
  11. *
  12. *-------------------------------------------------------------------------------
  13. * Revisions:
  14. *
  15. *******************************************************************************/
  16. #ifndef __DXSurfB_H__
  17. #define __DXSurfB_H__
  18. #include "dtbase.h"
  19. class CDXBaseSurface;
  20. class CDXBaseARGBPtr;
  21. class ATL_NO_VTABLE CDXBaseSurface :
  22. public CDXBaseNTo1,
  23. public IDXSurface,
  24. public IDXSurfaceInit
  25. {
  26. /*=== ATL Setup ===*/
  27. public:
  28. BEGIN_COM_MAP(CDXBaseSurface)
  29. COM_INTERFACE_ENTRY(IDXSurface)
  30. COM_INTERFACE_ENTRY(IDXSurfaceInit)
  31. COM_INTERFACE_ENTRY_CHAIN(CDXBaseNTo1)
  32. END_COM_MAP()
  33. DECLARE_GET_CONTROLLING_UNKNOWN()
  34. /*=== Member Data ===*/
  35. public:
  36. ULONG m_Height;
  37. ULONG m_Width;
  38. DWORD m_dwStatusFlags;
  39. HANDLE m_hSemaphore;
  40. ULONG m_ulLocks;
  41. ULONG m_ulThreadsWaiting;
  42. CDXBaseARGBPtr *m_pFreePtr;
  43. DWORD_PTR m_dwAppData;
  44. CComAutoCriticalSection m_MPWorkProcCrit; // See comments in LockSurface for details
  45. CDXBaseSurface();
  46. HRESULT FinalConstruct();
  47. void FinalRelease();
  48. //
  49. // IDXBaseObject
  50. //
  51. STDMETHODIMP GetGenerationId(ULONG *pGenId);
  52. STDMETHODIMP IncrementGenerationId(BOOL bRefresh);
  53. STDMETHODIMP GetObjectSize(ULONG *pulze);
  54. //
  55. // Overridden methods of DXTransform
  56. //
  57. STDMETHODIMP MapBoundsIn2Out(const DXBNDS *pInBounds, ULONG ulNumInBnds,
  58. ULONG /*ulOutIndex*/, DXBNDS *pOutBounds );
  59. //
  60. // IDXSurfaceInit
  61. //
  62. STDMETHODIMP InitSurface(IUnknown *pDirectDraw,
  63. const DDSURFACEDESC * pDDSurfaceDesc,
  64. const GUID * pFormatId,
  65. const DXBNDS *pBounds,
  66. DWORD dwFlags);
  67. //
  68. // IDXSurface methods
  69. //
  70. STDMETHODIMP GetPixelFormat(GUID *pFormat, DXSAMPLEFORMATENUM *pSampleEnum);
  71. STDMETHODIMP GetBounds(DXBNDS *pBounds);
  72. STDMETHODIMP GetStatusFlags(DWORD * pdwStatusFlags);
  73. STDMETHODIMP SetStatusFlags(DWORD dwStatusFlags);
  74. STDMETHODIMP GetDirectDrawSurface(REFIID riid, void **ppSurface);
  75. STDMETHODIMP LockSurface(const DXBNDS *pBounds, ULONG ulTimeOut, DWORD dwFlags,
  76. REFIID riid, void **ppPointer, DWORD * pGenerationId);
  77. STDMETHODIMP SetAppData(DWORD_PTR dwAppData)
  78. {
  79. m_dwAppData = dwAppData;
  80. return S_OK;
  81. }
  82. STDMETHODIMP GetAppData(DWORD_PTR *pdwAppData)
  83. {
  84. if (DXIsBadWritePtr(pdwAppData, sizeof(*pdwAppData)))
  85. {
  86. return E_POINTER;
  87. }
  88. *pdwAppData = m_dwAppData;
  89. return S_OK;
  90. }
  91. //
  92. // These methods aren't supported by procedural surfaces...
  93. //
  94. STDMETHODIMP GetColorKey(DXSAMPLE *pColorKey)
  95. {
  96. return E_NOTIMPL;
  97. }
  98. STDMETHODIMP SetColorKey(DXSAMPLE pColorKey)
  99. {
  100. return E_NOTIMPL;
  101. }
  102. STDMETHODIMP LockSurfaceDC(const DXBNDS *pBounds, ULONG ulTimeOut, DWORD dwFlags, IDXDCLock **ppDXLock)
  103. {
  104. return E_NOTIMPL;
  105. }
  106. //
  107. // Surfaces should override this.
  108. //
  109. virtual ULONG OnGetObjectSize(void) { return sizeof(*this); }
  110. //
  111. // This work procedure can be overridden by the derived class to improve performance
  112. // or execution of the transform by directly producing data in large blocks if desired.
  113. //
  114. virtual HRESULT WorkProc(const CDXTWorkInfoNTo1 & WI, BOOL* pbContinueProcessing)
  115. {
  116. return DXBitBlt(OutputSurface(), WI.OutputBnds, this, WI.DoBnds, m_dwBltFlags, m_ulLockTimeOut);
  117. }
  118. //
  119. // Pick interface needs to test procedural surface.
  120. //
  121. virtual HRESULT OnSurfacePick(const CDXDBnds & OutPoint, ULONG & ulInputIndex, CDXDVec & InVec);
  122. //
  123. // Helper functions
  124. //
  125. // _EnterCritWith0PtrLocks()
  126. //
  127. // This function is similar to calling Lock() except that it will wait until there
  128. // are no pointers to the surface before returning. This should be used whenever you
  129. // are going to change the state of a surface, for example the size or some other
  130. // property that the read pointers rely on.
  131. //
  132. // WARNING: You must be sure that one of the following is true:
  133. // 1) The objects critical section has NOT been taken prior to calling this function
  134. // or 2) There are no pointers to the surface taken prior to calling this function.
  135. //
  136. // Case 2 is useful in nested function calls. If the outer function has already used this
  137. // function to enter the critical section, then it is OK to use it on the inner nested
  138. // function. If the object's lock is taken, but there are outstanding pointers, YOU WILL DEADLOCK!
  139. //
  140. inline void _EnterCritWith0PtrLocks(void)
  141. {
  142. while (TRUE)
  143. {
  144. Lock();
  145. if (m_ulLocks == 0) break;
  146. m_ulThreadsWaiting++;
  147. Unlock();
  148. WaitForSingleObject(m_hSemaphore, INFINITE);
  149. }
  150. }
  151. //
  152. // Virtual functions derived class MUST override
  153. //
  154. virtual const GUID & SurfaceCLSID() = 0;
  155. virtual HRESULT CreateARGBPointer(CDXBaseSurface * pSurface, CDXBaseARGBPtr ** ppPtr) = 0;
  156. virtual void DeleteARGBPointer(CDXBaseARGBPtr *pPtr) = 0;
  157. //
  158. // Class may override this virtual function to return a more accurate enum
  159. // for example, no transparency or translucency.
  160. //
  161. virtual DXSAMPLEFORMATENUM SampleFormatEnum()
  162. {
  163. return (DXSAMPLEFORMATENUM)(DXPF_NONSTANDARD | DXPF_TRANSPARENCY | DXPF_TRANSLUCENCY);
  164. }
  165. //
  166. // Class may override this virtual function to perform necessary computations
  167. // when the size of the surface changes. The base class will only call this
  168. // function from InitSurface. You may choose to call it from other interfaces
  169. // you implement, for example IDXTScaleOutput.
  170. //
  171. // This function will be called with the critical section taken and 0 outstanding
  172. // surface pointers (_EnterCritWith0PtrLocks).
  173. //
  174. virtual HRESULT OnSetSize(ULONG Width, ULONG Height)
  175. {
  176. if (m_Width != Width || m_Height != Height)
  177. {
  178. m_Width = Width;
  179. m_Height = Height;
  180. m_dwGenerationId++;
  181. }
  182. return S_OK;
  183. }
  184. //
  185. // Internal functions for base class
  186. //
  187. void _InternalUnlock(CDXBaseARGBPtr *pPtrToUnlock);
  188. //
  189. // Static member function for registering surface
  190. //
  191. static HRESULT RegisterSurface(REFCLSID rcid, int ResourceId, ULONG cCatImpl, const CATID * pCatImpl,
  192. ULONG cCatReq, const CATID * pCatReq, BOOL bRegister);
  193. };
  194. struct DXPtrFillInfo
  195. {
  196. DXBASESAMPLE * pSamples;
  197. ULONG cSamples;
  198. ULONG x;
  199. ULONG y;
  200. BOOL bPremult;
  201. };
  202. class CDXBaseARGBPtr : public IDXARGBReadPtr
  203. {
  204. public:
  205. CDXBaseARGBPtr * m_pNext;
  206. CDXBaseSurface * m_pSurface;
  207. ULONG m_ulRefCount;
  208. DXPtrFillInfo m_FillInfo;
  209. RECT m_LockedRect;
  210. DXRUNINFO m_RunInfo;
  211. CDXBaseARGBPtr(CDXBaseSurface *pSurface) :
  212. m_pSurface(pSurface),
  213. m_pNext(NULL),
  214. m_ulRefCount(0) {}
  215. //
  216. // IUnknown
  217. //
  218. STDMETHODIMP QueryInterface(REFIID riid, void ** ppv);
  219. ULONG STDMETHODCALLTYPE AddRef();
  220. ULONG STDMETHODCALLTYPE Release();
  221. //
  222. // IDXARGBReadPtr
  223. //
  224. HRESULT STDMETHODCALLTYPE GetSurface(REFIID riid, void **ppSurface);
  225. DXSAMPLEFORMATENUM STDMETHODCALLTYPE GetNativeType(DXNATIVETYPEINFO *pInfo);
  226. void STDMETHODCALLTYPE Move(long cSamples);
  227. void STDMETHODCALLTYPE MoveToRow(ULONG y);
  228. void STDMETHODCALLTYPE MoveToXY(ULONG x, ULONG y);
  229. ULONG STDMETHODCALLTYPE MoveAndGetRunInfo(ULONG Row, const DXRUNINFO ** ppInfo);
  230. DXSAMPLE *STDMETHODCALLTYPE Unpack(DXSAMPLE *pSamples, ULONG cSamples, BOOL bMove);
  231. DXPMSAMPLE *STDMETHODCALLTYPE UnpackPremult(DXPMSAMPLE *pSamples, ULONG cSamples, BOOL bMove);
  232. void STDMETHODCALLTYPE UnpackRect(const DXPACKEDRECTDESC *pDesc);
  233. //
  234. // Virtual function derived class MUST override
  235. //
  236. virtual void FillSamples(const DXPtrFillInfo & FillInfo) = 0;
  237. //
  238. // Virtual functions derived class MAY want to override (but you will need to call the base class too)
  239. //
  240. virtual HRESULT InitFromLock(const RECT & rect, ULONG ulTimeOut, DWORD dwLockFlags, REFIID riid, void ** ppv);
  241. };
  242. //=== Macro Definitions ============================================
  243. #define DECLARE_REGISTER_DX_SURFACE(id)\
  244. static HRESULT WINAPI UpdateRegistry(BOOL bRegister) \
  245. { \
  246. CATID cat[2]; \
  247. cat[0] = CATID_DXSurface; \
  248. cat[1] = CATID_DXImageTransform; \
  249. return RegisterSurface(GetObjectCLSID(), (id), 2, cat, 0, NULL, bRegister); \
  250. }
  251. #define DECLARE_REGISTER_DX_AUTHORING_SURFACE(id)\
  252. static HRESULT WINAPI UpdateRegistry(BOOL bRegister) \
  253. { \
  254. CATID cat[3]; \
  255. cat[0] = CATID_DXSurface; \
  256. cat[1] = CATID_DXImageTransform; \
  257. cat[2] = CATID_DXAuthoringTransform; \
  258. return RegisterSurface(GetObjectCLSID(), (id), 3, cat, 0, NULL, bRegister); \
  259. }
  260. #endif