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

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