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.

469 lines
17 KiB

  1. /*******************************************************************************
  2. * DTBase.h *
  3. *----------*
  4. * Description:
  5. * This is the header file for the CDXBaseNTo1 implementation. It is
  6. * used as a base class to implement discrete transform objects that support
  7. * DXSurfaces.
  8. *-------------------------------------------------------------------------------
  9. * Created By: Ed Connell Date: 07/27/97
  10. * Copyright (C) 1997 Microsoft Corporation
  11. * All Rights Reserved
  12. *
  13. *-------------------------------------------------------------------------------
  14. * Revisions:
  15. *
  16. *******************************************************************************/
  17. #ifndef DTBase_h
  18. #define DTBase_h
  19. //--- Additional includes
  20. #ifndef DXHelper_h
  21. #include <DXHelper.h>
  22. #endif
  23. #ifndef DXTmpl_h
  24. #include <DXTmpl.h>
  25. #endif
  26. #ifndef dxatlpb_h
  27. #include <dxatlpb.h>
  28. #endif
  29. #ifndef _ASSERT
  30. #include <crtdbg.h>
  31. #endif
  32. #ifndef DXTDbg_h
  33. #include <DXTDbg.h>
  34. #endif
  35. //=== Constants ====================================================
  36. #define DXBOF_INPUTS_MESHBUILDER 0x00000001
  37. #define DXBOF_OUTPUT_MESHBUILDER 0x00000002
  38. #define DXBOF_SAME_SIZE_INPUTS 0x00000004
  39. #define DXBOF_CENTER_INPUTS 0x00000008
  40. #define DXB_MAX_IMAGE_BANDS 4 // Maximum of 4 image bands
  41. //=== Class, Enum, Struct and Union Declarations ===================
  42. class CDXBaseNTo1;
  43. //=== Enumerated Set Definitions ===================================
  44. //=== Function Type Definitions ====================================
  45. //=== Class, Struct and Union Definitions ==========================
  46. /*** CDXDataPtr
  47. *
  48. */
  49. class CDXDataPtr
  50. {
  51. friend CDXBaseNTo1;
  52. public:
  53. IUnknown *m_pUnkOriginalObject;
  54. IUnknown *m_pNativeInterface;
  55. IDXBaseObject *m_pBaseObj;
  56. DWORD m_dwLastDirtyGenId;
  57. DXSAMPLEFORMATENUM m_SampleFormat;
  58. CDXDataPtr() :
  59. m_pUnkOriginalObject(NULL),
  60. m_pNativeInterface(NULL),
  61. m_pBaseObj(NULL),
  62. m_dwLastUpdGenId(0),
  63. m_dwLastDirtyGenId(0),
  64. m_SampleFormat(DXPF_NONSTANDARD)
  65. {};
  66. ~CDXDataPtr() { Release(); }
  67. void Release()
  68. {
  69. if (m_pNativeInterface)
  70. {
  71. m_pNativeInterface->Release();
  72. m_pNativeInterface = NULL;
  73. }
  74. if (m_pBaseObj)
  75. {
  76. m_pBaseObj->Release();
  77. m_pBaseObj = NULL;
  78. }
  79. if (m_pUnkOriginalObject)
  80. {
  81. m_pUnkOriginalObject->Release();
  82. m_pUnkOriginalObject = NULL;
  83. }
  84. }
  85. HRESULT Assign(BOOL bMeshBuilder, IUnknown * pObject, IDXSurfaceFactory *pSurfFact);
  86. bool IsDirty(void);
  87. DWORD GenerationId(void);
  88. ULONG ObjectSize(void);
  89. private: // This should only be called by base class
  90. DWORD m_dwLastUpdGenId;
  91. bool UpdateGenerationId(void);
  92. };
  93. /*--- CDXTWorkInfoNTo1
  94. * This structure is used to hold the arguments needed by the
  95. * image processing function defined by the derived class
  96. */
  97. class CDXTWorkInfoNTo1
  98. {
  99. public:
  100. CDXTWorkInfoNTo1()
  101. { pvThis = NULL; pUserInstData = NULL; hr = S_OK; }
  102. void * pvThis; // The owning class object (must be cast to the right type)
  103. CDXDBnds DoBnds; // The portion of the output space to render
  104. CDXDBnds OutputBnds; // The portion of the output SURFACE to render
  105. void* pUserInstData; // User field for instance data
  106. HRESULT hr; // Error return code from work procedure
  107. };
  108. /*** CDXBaseNTo1
  109. * This is a base class used for implementing 1 in 1 out discrete transforms.
  110. */
  111. class ATL_NO_VTABLE CDXBaseNTo1 :
  112. public CComObjectRootEx<CComMultiThreadModel>,
  113. #if(_ATL_VER < 0x0300)
  114. public IObjectSafetyImpl<CDXBaseNTo1>,
  115. #else
  116. public IObjectSafetyImpl<CDXBaseNTo1,INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
  117. #endif
  118. public IDXTransform,
  119. public IDXSurfacePick,
  120. public IObjectWithSite
  121. {
  122. /*=== ATL Setup ===*/
  123. public:
  124. BEGIN_COM_MAP(CDXBaseNTo1)
  125. COM_INTERFACE_ENTRY(IDXTransform)
  126. COM_INTERFACE_ENTRY(IDXBaseObject)
  127. COM_INTERFACE_ENTRY(IObjectWithSite)
  128. #if(_ATL_VER < 0x0300)
  129. COM_INTERFACE_ENTRY_IMPL(IObjectSafety)
  130. #else
  131. COM_INTERFACE_ENTRY(IObjectSafety)
  132. #endif
  133. COM_INTERFACE_ENTRY_FUNC(IID_IDXSurfacePick, 0, QI2DPick)
  134. END_COM_MAP()
  135. //
  136. // Only return the 2D pick inteface for surface to surface transforms
  137. //
  138. static HRESULT WINAPI QI2DPick(void* pv, REFIID riid, LPVOID* ppv, ULONG_PTR dw)
  139. {
  140. CDXBaseNTo1 * pThis = (CDXBaseNTo1 *)pv;
  141. if (pThis->m_dwOptionFlags & (DXBOF_INPUTS_MESHBUILDER | DXBOF_OUTPUT_MESHBUILDER))
  142. {
  143. return S_FALSE; // Continue processing COM map
  144. }
  145. *ppv = (IDXSurfacePick *)pThis;
  146. ((IDXSurfacePick *)pThis)->AddRef();
  147. return S_OK;
  148. }
  149. CComPtr<IOleClientSite> m_cpOleClientSite;
  150. /*=== Member Data ===*/
  151. protected:
  152. CComPtr<IUnknown> m_cpUnkSite;
  153. CComPtr<IDXTransformFactory> m_cpTransFact;
  154. CComPtr<IDXSurfaceFactory> m_cpSurfFact;
  155. CComPtr<IDXTaskManager> m_cpTaskMgr;
  156. CComPtr<IDirectDraw> m_cpDirectDraw;
  157. CComPtr<IDirect3DRM3> m_cpDirect3DRM;
  158. DWORD m_dwMiscFlags;
  159. HANDLE m_aEvent[DXB_MAX_IMAGE_BANDS];
  160. ULONG m_ulNumProcessors;
  161. DWORD m_dwGenerationId;
  162. DWORD m_dwCleanGenId;
  163. BOOL m_bPickDoneByBase;
  164. float m_Duration;
  165. float m_StepResolution;
  166. float m_fQuality; // Set DXTMF_QUALITY_SUPPORTED in m_dwMiscFlags if you use this property.
  167. ULONG m_ulNumInputs;
  168. DWORD m_dwBltFlags; // Ser prior to OnSetup and any Execute for classes with surface outputs
  169. BOOL m_bInMultiThreadWorkProc; // Base class sets to TRUE when scheduling tasks on multiple threads
  170. //
  171. // Derived classes should set these values in their constructor or in FinalConstruct()
  172. //
  173. DWORD m_dwOptionFlags;
  174. ULONG m_ulLockTimeOut; // The amount of time used for blocking
  175. ULONG m_ulMaxInputs;
  176. ULONG m_ulNumInRequired;
  177. ULONG m_ulMaxImageBands; // Only used for surface->Surface transforms
  178. float m_Progress;
  179. private:
  180. CDXDataPtr* m_aInputs;
  181. CDXDataPtr m_Output;
  182. // m_fIsSetup This is true when the DXTransform has been properly set up.
  183. unsigned m_fIsSetup : 1;
  184. /*=== Methods =======*/
  185. public:
  186. //--- Constructors
  187. CDXBaseNTo1();
  188. ~CDXBaseNTo1();
  189. //--- Support virtuals for derived classes
  190. virtual HRESULT OnInitInstData( CDXTWorkInfoNTo1& /*WorkInfo*/, ULONG& /*ulNumBandsToDo*/) { return S_OK; }
  191. virtual HRESULT OnFreeInstData( CDXTWorkInfoNTo1& /*WorkInfo*/ ) { return S_OK; }
  192. virtual HRESULT OnSetup( DWORD /* dwFlags */) { return S_OK; } // Override to be notified of a new non-null setup
  193. virtual void OnReleaseObjects() {} // Override to be notified of NULL setup
  194. virtual HRESULT OnExecute(const GUID* /* pRequestID */, const DXBNDS * /*pClipBnds */,
  195. const DXVEC * /*pPlacement */ ) { return E_FAIL; }
  196. virtual void OnUpdateGenerationId(void);
  197. virtual ULONG OnGetObjectSize(void);
  198. virtual HRESULT WorkProc(const CDXTWorkInfoNTo1 & WorkInfo, BOOL* pbContinueProcessing) { return E_FAIL; } // Override to do work
  199. virtual HRESULT DetermineBnds(CDXCBnds & Bnds) { return S_OK; } // Override for mesh output transforms
  200. virtual HRESULT DetermineBnds(CDXDBnds & Bnds) { return S_OK; } // Override for surface output transforms
  201. //
  202. // Only override this function if you need to do a customized point pick implementation. Otherwise simply
  203. // override GetPointPickOrder() and return appropriate information.
  204. //
  205. virtual HRESULT OnSurfacePick(const CDXDBnds & OutPoint, ULONG & ulInputIndex, CDXDVec & InVec) { return E_NOTIMPL; }
  206. virtual void OnGetSurfacePickOrder(const CDXDBnds & OutPoint, ULONG & ulInToTest, ULONG aInIndex[], BYTE aWeight[])
  207. {
  208. m_bPickDoneByBase = true;
  209. ulInToTest = 1;
  210. aInIndex[0] = 0;
  211. aWeight[0] = 255;
  212. }
  213. //--- Private helpers
  214. private:
  215. static DXTASKPROC _TaskProc;
  216. void _ReleaseReferences();
  217. void _ReleaseServices();
  218. void _UpdateBltFlags(void);
  219. HRESULT _MakeInputsSameSize(void);
  220. HRESULT _ImageMapIn2Out(CDXDBnds & bnds, ULONG ulNumBnds, const CDXDBnds * pInBounds);
  221. HRESULT _MeshMapIn2Out(CDXCBnds & bnds, ULONG ulNumInBnds, CDXCBnds * pInBounds);
  222. //
  223. //--- Public helpers
  224. //
  225. public:
  226. float GetEffectProgress(void) { return m_Progress; }
  227. ULONG GetNumInputs(void) { return m_ulNumInputs; }
  228. //
  229. // Use these inline functions to access input and output objects
  230. //
  231. BOOL HaveInput(ULONG i = 0) { return (m_ulNumInputs > i && m_aInputs[i].m_pNativeInterface); }
  232. IDirect3DRMMeshBuilder3 * OutputMeshBuilder()
  233. {
  234. _ASSERT(m_dwOptionFlags & DXBOF_OUTPUT_MESHBUILDER);
  235. return (IDirect3DRMMeshBuilder3 *)m_Output.m_pNativeInterface;
  236. }
  237. IDXSurface * OutputSurface()
  238. {
  239. _ASSERT((m_dwOptionFlags & DXBOF_OUTPUT_MESHBUILDER) == 0);
  240. return (IDXSurface *)m_Output.m_pNativeInterface;
  241. }
  242. IDirect3DRMMeshBuilder3 * InputMeshBuilder(ULONG i = 0)
  243. {
  244. _ASSERT(i < m_ulNumInputs);
  245. _ASSERT(m_dwOptionFlags & DXBOF_INPUTS_MESHBUILDER);
  246. return (IDirect3DRMMeshBuilder3 *)m_aInputs[i].m_pNativeInterface;
  247. }
  248. IDXSurface * InputSurface(ULONG i = 0)
  249. {
  250. _ASSERT(i < m_ulNumInputs);
  251. _ASSERT((m_dwOptionFlags & DXBOF_INPUTS_MESHBUILDER) == 0);
  252. return (IDXSurface *)m_aInputs[i].m_pNativeInterface;
  253. }
  254. DXSAMPLEFORMATENUM OutputSampleFormat(void)
  255. {
  256. _ASSERT((m_dwOptionFlags & DXBOF_OUTPUT_MESHBUILDER) == 0);
  257. return m_Output.m_SampleFormat;
  258. }
  259. DXSAMPLEFORMATENUM InputSampleFormat(ULONG i = 0)
  260. {
  261. _ASSERT(i < m_ulNumInputs);
  262. _ASSERT((m_dwOptionFlags & DXBOF_INPUTS_MESHBUILDER) == 0);
  263. return m_aInputs[i].m_SampleFormat;
  264. }
  265. BOOL HaveOutput(void) { return m_Output.m_pNativeInterface != NULL; }
  266. bool IsInputDirty(ULONG i = 0)
  267. {
  268. _ASSERT(i < m_ulNumInputs);
  269. return m_aInputs[i].IsDirty();
  270. }
  271. bool IsOutputDirty()
  272. {
  273. _ASSERT(HaveOutput());
  274. return m_Output.IsDirty();
  275. }
  276. //--- Public helpers. Should be called with critical seciton claimed.
  277. inline BOOL DoOver(void) const
  278. {
  279. return m_dwBltFlags & DXBOF_DO_OVER;
  280. }
  281. inline BOOL DoDither(void) const
  282. {
  283. return m_dwBltFlags & DXBOF_DITHER;
  284. }
  285. BOOL NeedSrcPMBuff(ULONG i = 0)
  286. {
  287. return ((m_dwBltFlags & DXBOF_DITHER) || InputSampleFormat(i) != DXPF_PMARGB32);
  288. }
  289. BOOL NeedDestPMBuff(void)
  290. {
  291. return OutputSampleFormat() != DXPF_PMARGB32;
  292. }
  293. void SetDirty() { m_dwGenerationId++; }
  294. void ClearDirty() { OnUpdateGenerationId(); m_dwCleanGenId = m_dwGenerationId; }
  295. BOOL IsTransformDirty() { OnUpdateGenerationId(); return m_dwCleanGenId != m_dwGenerationId; }
  296. public:
  297. //=== IObjectWithSite =======================================
  298. STDMETHOD( SetSite )( IUnknown *pUnkSite );
  299. STDMETHOD( GetSite )( REFIID riid, void ** ppvSite );
  300. //=== IDXBaseObject =========================================
  301. STDMETHOD( GetGenerationId ) (ULONG * pGenId);
  302. STDMETHOD( IncrementGenerationId) (BOOL bRefresh);
  303. STDMETHOD( GetObjectSize ) (ULONG * pcbSize);
  304. //=== IDXTransform ===============================================
  305. STDMETHOD( Setup )( IUnknown * const * punkInputs, ULONG ulNumIn,
  306. IUnknown * const * punkOutputs, ULONG ulNumOut, DWORD dwFlags );
  307. STDMETHOD( Execute )( const GUID* pRequestID,
  308. const DXBNDS *pOutBounds, const DXVEC *pPlacement );
  309. STDMETHOD( MapBoundsIn2Out )( const DXBNDS *pInBounds, ULONG ulNumInBnds,
  310. ULONG ulOutIndex, DXBNDS *pOutBounds );
  311. STDMETHOD( MapBoundsOut2In )( ULONG ulOutIndex, const DXBNDS *pOutBounds, ULONG ulInIndex, DXBNDS *pInBounds );
  312. STDMETHOD( SetMiscFlags ) ( DWORD dwOptionFlags );
  313. STDMETHOD( GetMiscFlags ) ( DWORD * pdwMiscFlags );
  314. STDMETHOD( GetInOutInfo )( BOOL bOutput, ULONG ulIndex, DWORD *pdwFlags, GUID * pIDs, ULONG * pcIDs, IUnknown **ppUnkCurObj);
  315. STDMETHOD( SetQuality )( float fQuality );
  316. STDMETHOD( GetQuality )( float *pfQuality );
  317. STDMETHOD (PointPick) (const DXVEC *pPoint,
  318. ULONG * pulInputSurfaceIndex,
  319. DXVEC *pInputPoint);
  320. //
  321. // Effect interface
  322. //
  323. // NOTE: Derived classes MUST implement get_Capabilities. Use macros below.
  324. //
  325. STDMETHODIMP get_Capabilities(long *pVal) { _ASSERT(true); return E_NOTIMPL; }
  326. //
  327. // All other methods are implemented in the base.
  328. //
  329. STDMETHODIMP get_Progress(float *pVal);
  330. STDMETHODIMP put_Progress(float newVal);
  331. STDMETHODIMP get_StepResolution(float *pVal);
  332. STDMETHODIMP get_Duration(float *pVal);
  333. STDMETHODIMP put_Duration(float newVal);
  334. //
  335. // Helper functions derived classes can use
  336. //
  337. //
  338. // Static function for registering in one or more component categories
  339. //
  340. static HRESULT RegisterTransform(REFCLSID rcid, int ResourceId, ULONG cCatImpl, const CATID * pCatImpl,
  341. ULONG cCatReq, const CATID * pCatReq, BOOL bRegister);
  342. };
  343. //=== Inline Function Definitions ==================================
  344. //=== Macro Definitions ============================================
  345. #define DECLARE_REGISTER_DX_TRANSFORM(id, catid)\
  346. static HRESULT WINAPI UpdateRegistry(BOOL bRegister) \
  347. { \
  348. return CDXBaseNTo1::RegisterTransform(GetObjectCLSID(), (id), 1, &(catid), 0, NULL, bRegister); \
  349. }
  350. #define DECLARE_REGISTER_DX_TRANS_CATS(id, countimpl, pcatidsimpl, countreq, pcatidsreq)\
  351. static HRESULT WINAPI UpdateRegistry(BOOL bRegister) \
  352. { \
  353. return CDXBaseNTo1::RegisterTransform(GetObjectCLSID(), (id), (count), (pcatids), (countreq), (pcatidsreq), bRegister); \
  354. }
  355. #define DECLARE_REGISTER_DX_IMAGE_TRANS(id) \
  356. DECLARE_REGISTER_DX_TRANSFORM(id, CATID_DXImageTransform)
  357. #define DECLARE_REGISTER_DX_3D_TRANS(id) \
  358. DECLARE_REGISTER_DX_TRANSFORM(id, CATID_DX3DTransform)
  359. #define DECLARE_REGISTER_DX_IMAGE_AUTHOR_TRANS(id) \
  360. static HRESULT WINAPI UpdateRegistry(BOOL bRegister) \
  361. { \
  362. GUID a_Cats[2]; \
  363. a_Cats[0] = CATID_DXImageTransform; \
  364. a_Cats[1] = CATID_DXAuthoringTransform; \
  365. return CDXBaseNTo1::RegisterTransform(GetObjectCLSID(), (id), 2, a_Cats, 0, NULL, bRegister); \
  366. }
  367. #define DECLARE_REGISTER_DX_3D_AUTHOR_TRANS(id) \
  368. static HRESULT WINAPI UpdateRegistry(BOOL bRegister) \
  369. { \
  370. GUID a_Cats[2]; \
  371. a_Cats[0] = CATID_DX3DTransform; \
  372. a_Cats[1] = CATID_DXAuthoringTransform; \
  373. return CDXBaseNTo1::RegisterTransform(GetObjectCLSID(), (id), 2, a_Cats, 0, NULL, bRegister); \
  374. }
  375. //
  376. // Effect interface
  377. //
  378. #define DECLARE_GET_CAPABILITIES(Caps)\
  379. STDMETHODIMP get_Capabilities(long *pVal) { if (DXIsBadWritePtr(pVal, sizeof(*pVal))) return E_POINTER; *pVal = Caps; return S_OK; }
  380. #define DECLARE_GET_PROGRESS()\
  381. STDMETHODIMP get_Progress(float *pVal) { return CDXBaseNTo1::get_Progress(pVal); }
  382. #define DECLARE_PUT_PROGRESS()\
  383. STDMETHODIMP put_Progress(float newVal) { return CDXBaseNTo1::put_Progress(newVal); }
  384. #define DECLARE_GET_STEPRESOLUTION()\
  385. STDMETHODIMP get_StepResolution(float *pVal) { return CDXBaseNTo1::get_StepResolution(pVal); }
  386. #define DECLARE_GET_DURATION()\
  387. STDMETHODIMP get_Duration(float *pVal) { return CDXBaseNTo1::get_Duration(pVal); }
  388. #define DECLARE_PUT_DURATION()\
  389. STDMETHODIMP put_Duration(float newVal) { return CDXBaseNTo1::put_Duration(newVal); }
  390. #define DECLARE_IDXEFFECT_METHODS(Caps)\
  391. DECLARE_GET_CAPABILITIES(Caps)\
  392. DECLARE_GET_PROGRESS()\
  393. DECLARE_PUT_PROGRESS()\
  394. DECLARE_GET_STEPRESOLUTION()\
  395. DECLARE_GET_DURATION()\
  396. DECLARE_PUT_DURATION()
  397. //=== Global Data Declarations =====================================
  398. //=== Function Prototypes ==========================================
  399. #endif /* This must be the last line in the file */