home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 May / PCFMay2001.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / dtbase.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  16.6 KB  |  468 lines

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