winroot.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:37k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #include "hxcom.h"
  36. #include "hxtypes.h"
  37. #include "hxmtypes.h"
  38. #include "hxwintyp.h"
  39. #include "hxvsurf.h"
  40. #include "hxslist.h"
  41. #include "hxerror.h"
  42. #include "hxstrutl.h"
  43. #include "hxver.h"
  44. //#include "surfroot.h"
  45. //#include "surfwles.h"
  46. //#include "sitewles.h"
  47. #include "winroot.h" // this muyst be included before colormap.h
  48. #include "colormap.h"
  49. #include "hxprefs.h"
  50. #include "hxtick.h"
  51. #include "ddpdb.h"
  52. #include "winsite.h"
  53. #ifndef _WIN32
  54. #error This is the Macintosh platform specific implementation.
  55. #endif
  56. typedef HRESULT (HXEXPORT_PTR FPDIRECTDRAWCREATE)(GUID FAR * lpGUID, 
  57.                                                   LPDIRECTDRAW FAR * lplpDD, IUnknown FAR * pUnkOuter);
  58. #define _DEBUGGING_WINDOWED_RENDERERS
  59. CWinBaseRootSurface::CWinBaseRootSurface(IUnknown* pContext, CHXBaseSite* pSite) :
  60. CBaseRootSurface(pContext, pSite),
  61.     m_bWindrawOpened(FALSE),
  62.     m_bWindrawCapsOpened(FALSE),
  63.     m_bBltLock(FALSE),
  64.     m_pScratchSurface(0),
  65.     m_nScratchSurfaceCID(0),
  66.     m_bScratchSurfaceCreated(FALSE),
  67.     m_bShowingText(FALSE),
  68.     m_hBrush(0),
  69.     m_hPen(0),
  70.     m_textColor(0),
  71.     m_nTextBackgroundColor(0),
  72.     m_hFont(0),
  73.     m_hOldFont(0),
  74.     m_hLastClipper(0),
  75.     m_pErrMsg(NULL),
  76.     m_pYUVScratchBits(NULL)
  77. {
  78.     memset( &m_windraw, 0, sizeof( m_windraw) );
  79.     memset( &m_windrawCaps, 0, sizeof( m_windrawCaps) );
  80.     memset( &m_compositionSurface, 0, sizeof( m_compositionSurface) );
  81. }
  82. CWinBaseRootSurface::~CWinBaseRootSurface()
  83. {
  84. _DestroyCompositionSurface();
  85. #ifdef _WORKAROUND_YUV_RGB_16BIT_HXCOLOR_BUG
  86.     DestroyScratchSurface();
  87. #endif /*_WORKAROUND_YUV_RGB_16BIT_HXCOLOR_BUG*/
  88.     if (m_bWindrawOpened)
  89.     {
  90.         m_overlayMgr.RemoveAll();
  91.         WinDraw2_Close(&m_windraw);
  92.         m_bWindrawOpened = FALSE;
  93.     }
  94.     if (m_bWindrawCapsOpened)
  95.     {
  96.         WinDraw2_Close(&m_windrawCaps);
  97.         m_bWindrawCapsOpened = FALSE;
  98.     }
  99.     HX_RELEASE(m_pErrMsg);
  100. }
  101. static void OpenDDPBD()
  102. {
  103.     HKEY    hKey;
  104.     long    lSize = _MAX_PATH-1;
  105.     char    szDBFileName[_MAX_PATH]; /* Flawfinder: ignore */
  106.     const char* szKeyName = "Software\"HXVER_COMMUNITY"\Preferences\DT_Plugins";
  107.     if (RegOpenKeyEx(HKEY_CLASSES_ROOT, szKeyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) 
  108.     {
  109.         /* retrieve path name: */
  110.         memset(szDBFileName, 0, _MAX_PATH);
  111.         if (RegQueryValue(hKey, "", szDBFileName, &lSize) == ERROR_SUCCESS) {
  112.             /* convert it at a string: */
  113.             SafeStrCat(szDBFileName, "\pvdu3260.bin", _MAX_PATH);
  114.             /*
  115. * Open Database file to check for buggy video drivers
  116. * If the file has not changed since the last time we read this
  117. * information, this call is basically a NO-OP
  118. */
  119.             DDPDB_Open(szDBFileName);
  120.         }
  121.         /* close hKey: */
  122.         RegCloseKey(hKey);
  123.     }
  124. }
  125. HX_RESULT CWinBaseRootSurface::_DebugBlt(UCHAR*                 /*IN*/  pImageData,
  126.                                          HXBitmapInfoHeader*   /*IN*/  pBitmapInfo,
  127.                                          REF(HXxRect)           /*IN*/  rDestRect,
  128.                                          REF(HXxRect)           /*IN*/  rSrcRect)
  129. {
  130.     if (m_pSite)
  131.     {
  132.         HXxWindow* pWindow = m_pSite->GetWindow();
  133.         if (pWindow && pWindow->window)
  134.         {
  135.             HWND hwnd = (HWND) pWindow->window;
  136.             HDC hDC = GetDC(hwnd);
  137.             HBRUSH      hBrush          = CreateSolidBrush(0x00008000);
  138.             HPEN        hPen            = CreatePen(PS_SOLID, 1, 0x00FF0000);
  139.             HBRUSH      hOldBrush       = (HBRUSH)SelectObject(hDC, hBrush);
  140.             HPEN        hOldPen         = (HPEN)SelectObject(hDC, hPen);
  141.             Rectangle(hDC,rDestRect.left,rDestRect.top,rDestRect.right,rDestRect.bottom);
  142.             SelectObject(hDC,hOldBrush);
  143.             SelectObject(hDC,hOldPen);
  144.             DeleteObject(hBrush);
  145.             DeleteObject(hPen);
  146.             ReleaseDC(hwnd, hDC);
  147.         }
  148.     }
  149.     return HXR_OK;
  150. }
  151. void CWinBaseRootSurface::_GetYUVScratchWidthHeight(UINT32* pWidth, UINT32* pHeight)
  152. {
  153.     *pWidth     = m_YUVScratchbmi.bmiHeader.biWidth;
  154.     *pHeight    = m_YUVScratchbmi.bmiHeader.biHeight;
  155. }
  156. void CWinBaseRootSurface::_CreateYUVScratchSurface(UINT32 width, UINT32 height)
  157. {
  158.     HX_VECTOR_DELETE(m_pYUVScratchBits);
  159.     m_pYUVScratchBits = NULL;
  160.     memset(&m_YUVScratchbmi, 0, sizeof(BITMAPINFO));
  161.     if (MakeBitmap(&m_YUVScratchbmi, sizeof(BITMAPINFO), 0, width, height, NULL, NULL))
  162.     {
  163. m_pYUVScratchBits = new UCHAR[m_YUVScratchbmi.bmiHeader.biSizeImage];
  164. m_nYUVPitch = GetBitmapPitch(&m_YUVScratchbmi);
  165.     }
  166. }
  167. void CWinBaseRootSurface::_GetYUVScratchSurfacePointer(UCHAR** pYUVBits, INT32* YUVPitch)
  168. {
  169.     *pYUVBits = m_pYUVScratchBits;
  170.     *YUVPitch = m_nYUVPitch;
  171. }
  172. void CWinBaseRootSurface::_BltFromScratchToComposition(REF(HXxRect) rDestRect, REF(HXxRect) rSrcRect)
  173. {
  174.     WinDrawSurface_Unlock(&m_windraw, &m_compositionSurface, 0);
  175.     WinDrawSurface_BltIndirect(&m_windraw, &m_compositionSurface, &m_scratchSurface, (RECT*)&rDestRect, (RECT*)&rSrcRect);
  176.     WinDrawSurface_Lock(&m_windraw, &m_compositionSurface, 0, 
  177. (void**) &m_pCompositionSurface, (LONG*)&m_nCompositionPitch);
  178. }
  179. HX_RESULT CWinBaseRootSurface::_LockComposition(UCHAR** pBits, INT32* pPitch)
  180. {
  181.     if (NOERROR == WinDrawSurface_Lock(&m_windraw, &m_compositionSurface, 0, 
  182.         (void**) pBits, (LONG*)pPitch))
  183.     {
  184.         return HXR_OK;
  185.     }
  186.     return HXR_FAIL;
  187. }
  188. HX_RESULT CWinBaseRootSurface::OpenWindraw()
  189. {
  190.     HX_RESULT retVal = HXR_FAIL;
  191.     if (m_bWindrawOpened)
  192.     {
  193.         return HXR_OK;
  194.     }
  195.     OpenDDPBD();
  196.     if (m_pSite)
  197.     {
  198.         if (!m_pErrMsg)
  199.             m_pContext->QueryInterface(IID_IHXErrorMessages, (void**)&m_pErrMsg);
  200.         HXxWindow* pWindow = m_pSite->GetWindow();
  201.         if (pWindow && pWindow->window)
  202.         {
  203.             memset(&m_windraw, 0, sizeof(WINDRAW));
  204.             HRESULT failed = TRUE;
  205.             if (m_fSurfaceType & HX_ACCELERATION_ON)
  206.             {
  207.                 failed = WinDraw2_Open(&m_windraw, (HWND) pWindow->window, WINDRAW_DIRECTDRAW, NULL, NULL);
  208.                 // do any required cleanup
  209.                 if (failed)
  210.                 {
  211.                     WinDraw2_Close(&m_windraw);
  212.                 }
  213.                 else
  214.                 {
  215.                     // Store the accelerated windraw
  216.                     m_windrawCaps = m_windraw;
  217.                     m_windraw.pErrMsg = m_pErrMsg;
  218.                     WinDraw2_GetMonitorProperties(&m_windraw);
  219.                 }
  220.             }
  221.             /* go to GDI mode */
  222.             if (failed)
  223.             {
  224.                 m_fSurfaceType  &= ~HX_ACCELERATION_ON;
  225.                 m_fSurfaceType  &= ~HX_USE_VIDEO_MEMORY;
  226.                 m_fSurfaceType  &= ~HX_USE_SYSTEM_MEMORY;
  227.                 failed = WinDraw2_Open(&m_windraw, (HWND) pWindow->window, NULL, NULL, NULL);
  228.             }
  229.             if (!failed)
  230.             {
  231.                 retVal = HXR_OK;
  232.                 m_bWindrawOpened = TRUE;
  233.             }
  234.         }
  235.     }
  236.     return retVal;
  237. }
  238. void CWinBaseRootSurface::_MinimalBlt(HXxRect& src, HXxRect& dst)
  239. {
  240. }
  241.     
  242. HX_RESULT CWinBaseRootSurface::_CreateCompositionSurface()
  243. {
  244.     HX_RESULT retVal = HXR_FAIL;
  245.     OpenWindraw();
  246.     if (m_bCompositionSurfaceCreated)
  247.     {
  248.         return HXR_OK;
  249.     }
  250.     if (!m_bWindrawOpened)
  251.     {
  252.         return retVal;
  253.     }
  254.     // Can we restore hw acceleratoin (don't do it during a video surface switch)
  255.     if((m_fSurfaceType & HX_ACCELERATION_ON) == HX_ACCELERATION_ON)
  256.     {
  257.         if(!_IsHardwareAccelerationAvail())
  258.         {
  259.             _LoseHardwareAcceleration();
  260.             return HXR_OK;
  261.         }
  262.     }
  263.     else if( m_bWindrawCapsOpened )
  264.     {
  265.         if( _IsHardwareAccelerationAvail() )
  266.             _AcquireHardwareAcceleration();
  267.         return HXR_OK;
  268.     }
  269.     // get primary surface CID.
  270.     BMI primaryBMI;
  271.     memset(&primaryBMI, 0, sizeof(BMI));
  272.     WinDraw2_GetDisplayFormat(&m_windraw, &primaryBMI);
  273.     m_nCompositionSurfaceCID = GetBitmapColor((LPBITMAPINFO)&primaryBMI);
  274.     // create a BMI to describe the composition surface
  275.     memset(&primaryBMI, 0, sizeof(BMI));
  276.     memcpy(&m_compositionSize, &m_pSite->m_size, sizeof(HXxSize)); /* Flawfinder: ignore */
  277.     // find out how big we want to allocate.
  278.     if (m_pSite->IsFullScreen())
  279.     {
  280.         m_allocatedCompositionSize.cx = GetSystemMetrics(SM_CXSCREEN);
  281.         m_allocatedCompositionSize.cy = GetSystemMetrics(SM_CYSCREEN);
  282.     }
  283.     else
  284.     {
  285.         m_allocatedCompositionSize.cx = m_compositionSize.cx;
  286.         m_allocatedCompositionSize.cy = m_compositionSize.cy;
  287.     }
  288.     if (m_compositionSize.cx > m_allocatedCompositionSize.cx  || m_compositionSize.cy > m_allocatedCompositionSize.cy)
  289.     {
  290.         m_allocatedCompositionSize.cx = m_compositionSize.cx;
  291.         m_allocatedCompositionSize.cy = m_compositionSize.cy;
  292.     }
  293.     MakeBitmap((LPBITMAPINFO)&primaryBMI, sizeof(BMI), m_nCompositionSurfaceCID, m_allocatedCompositionSize.cx, m_allocatedCompositionSize.cy, NULL, NULL);
  294.     // now attempt to create the surface
  295.     memset(&m_compositionSurface, 0, sizeof(WINDRAWSURFACE));
  296.     /*
  297. *  Now are we in 8 bit color mode? If so we will need to make a palette.
  298. */
  299.     if (m_nCompositionSurfaceCID == CID_RGB8)
  300.     {
  301.         HDC hDC;
  302.         int n = 0;
  303.         hDC = GetDC (NULL);
  304.         n = GetSystemPaletteEntries (hDC, 0, 256, (LPPALETTEENTRY) primaryBMI.dwPalette);
  305.         ReleaseDC (NULL,hDC);
  306.     }
  307.     if (NOERROR == WinDraw2_CreateSurface(&m_windraw, &m_compositionSurface, &primaryBMI, m_fSurfaceType, 0, 0))
  308.     {
  309.         retVal = HXR_OK;
  310.         m_bCompositionSurfaceCreated = TRUE;
  311.     }
  312.     primaryBMI.bmiHeader.biWidth    = 1;
  313.     primaryBMI.bmiHeader.biHeight   = 1;
  314.     return retVal;
  315. }
  316. HX_RESULT CWinBaseRootSurface::_DestroyCompositionSurface()
  317. {
  318.     HX_RESULT retVal = HXR_OK;
  319.     if (m_bCompositionSurfaceCreated)
  320.     {
  321. if (NOERROR == WinDraw2_ReleaseSurface(&m_windraw, &m_compositionSurface))
  322. {
  323. m_bCompositionSurfaceCreated = FALSE;
  324. retVal = HXR_OK;
  325. }
  326. else
  327. {
  328. retVal = HXR_FAIL;
  329. }
  330.     }
  331.     return retVal;
  332. }
  333. HX_RESULT CWinBaseRootSurface::_MinimalUnlock(HXxWindow* pWindow)
  334. {
  335.     if( m_pSite->IsCompositionLocked() )
  336.     {
  337. #if 0
  338.         if (m_pUnlockingSite && m_pUnlockingSite->HasFocusRect())
  339.         {
  340.             DrawFocusRect(&m_compositionSurface,
  341.                           m_nCompositionSurfaceCID,
  342.                           &m_allocatedCompositionSize,
  343.                           m_pCompositionSurface,
  344.                           m_pUnlockingSite);
  345.         }
  346. #endif
  347.         
  348.         WinDrawSurface_Unlock(&m_windraw, &m_compositionSurface, 0);
  349.         return HXR_OK;
  350.     }
  351.     
  352. #if 0    
  353.     if (m_pUnlockingSite && m_pUnlockingSite->HasFocusRect())
  354.     {
  355.         DrawFocusRect(&m_compositionSurface,
  356.                       m_nCompositionSurfaceCID,
  357.                       &m_allocatedCompositionSize,
  358.                       m_pCompositionSurface,
  359.                       m_pUnlockingSite);
  360.     }
  361. #endif
  362.     
  363.     HX_RESULT retVal = HXR_FAIL;
  364.     if (NOERROR == WinDrawSurface_Unlock(&m_windraw, &m_compositionSurface, 0))
  365.     {
  366.         m_pCompositionSurface = NULL;
  367.         if (!m_bBltLock)
  368.         {
  369.             // Assuming that no windowed renderer uses video services this will work.
  370.             // Should fix this so that windowed renderers can use video services.
  371. /*
  372.             if (m_hLastClipper != (HWND) pWindow->window)
  373.             {
  374.                 m_hLastClipper = (HWND) pWindow->window;
  375.                 WinDrawSurface_SetClipper(&m_windraw, (HWND) pWindow->window);
  376.             }
  377. */
  378. /*           if( m_boundsRect.bottom > m_boundsRect.top && m_boundsRect.left   < m_boundsRect.right)
  379.             {
  380.                 //              {
  381.                 //                 char szBuff[256];
  382.                 //                 sprintf( szBuff,"Bounding Rect: (%d, %d) --- (%d, %d)n",
  383.                 //                          m_boundsRect.left, m_boundsRect.top,
  384.                 //                          m_boundsRect.right, m_boundsRect.bottom);
  385.                 //                 _DumpString(szBuff);
  386.                 //              } 
  387.                 if (NOERROR == WinDrawSurface_Blt(&m_windraw, &m_compositionSurface, (RECT*)&m_boundsRect, (RECT*)&m_boundsRect))
  388.                 {
  389.                    retVal = HXR_OK;
  390.                 }
  391.             }  */
  392.             if (m_pBltRects.GetCount())
  393.             {
  394.                 while(m_pBltRects.GetCount())
  395.                 {
  396.                     HXxRect* pRect = (HXxRect*) m_pBltRects.RemoveHead();
  397.                     if (NOERROR == WinDrawSurface_Blt(&m_windraw, &m_compositionSurface, (RECT*)pRect, (RECT*)pRect))
  398.                     {
  399.                         retVal = HXR_OK;
  400.                     }
  401.                     HX_DELETE(pRect);
  402.         
  403.                 }
  404.             }
  405.         }
  406.     }
  407.     return retVal;
  408. }
  409. HX_RESULT CWinBaseRootSurface::ScratchLock(UCHAR** pBits, INT32* pPitch)
  410. {
  411.     HX_RESULT retVal = HXR_FAIL;
  412.     if (NOERROR == WinDrawSurface_Lock(&m_windraw, &m_scratchSurface, 0, 
  413. (void**) &m_pScratchSurface, (LONG*)&m_nScratchPitch))
  414.     {
  415.     retVal = HXR_OK;
  416.     HX_ASSERT(m_pScratchSurface);
  417.     *pBits = m_pScratchSurface;
  418.     *pPitch = m_nScratchPitch;
  419.     }
  420.     return retVal;
  421. }
  422. HX_RESULT CWinBaseRootSurface::ScratchUnlock(UCHAR* pBits)
  423. {
  424.     HX_RESULT retVal = HXR_FAIL;
  425.     if (NOERROR == WinDrawSurface_Unlock(&m_windraw, &m_scratchSurface, 0))
  426.     {
  427. m_pScratchSurface = NULL;
  428.     }
  429.     return retVal;
  430. }
  431. HX_RESULT CWinBaseRootSurface::CreateScratchSurface(int nCompositionSurfaceCID, HXxSize* pSize)
  432. {
  433.     HX_RESULT retVal = HXR_FAIL;
  434.     if (m_bScratchSurfaceCreated &&
  435. m_nScratchSurfaceCID == nCompositionSurfaceCID &&
  436. pSize->cx <= m_allocatedScratchSize.cx &&
  437. pSize->cy <= m_allocatedScratchSize.cy)
  438.     {
  439. if (m_scratchSize.cx != pSize->cx || m_scratchSize.cy != pSize->cy)
  440. {
  441. memcpy(&m_scratchSize, pSize, sizeof(HXxSize)); /* Flawfinder: ignore */
  442. }
  443. return HXR_OK;
  444.     }
  445.     else
  446.     {
  447. DestroyScratchSurface();
  448.     }
  449.     HX_ASSERT(m_bScratchSurfaceCreated == FALSE);
  450.     m_nScratchSurfaceCID = nCompositionSurfaceCID;
  451.     // create a BMI to describe the composition surface
  452.     memcpy(&m_scratchSize, pSize, sizeof(HXxSize)); /* Flawfinder: ignore */
  453.     memcpy(&m_allocatedScratchSize, pSize, sizeof(HXxSize)); /* Flawfinder: ignore */
  454.     BMI primaryBMI;
  455.     memset(&primaryBMI, 0, sizeof(BMI));
  456.     MakeBitmap((LPBITMAPINFO)&primaryBMI, sizeof(BMI), m_nScratchSurfaceCID, m_allocatedScratchSize.cx, m_allocatedScratchSize.cy, NULL, NULL);
  457.     // now attempt to create the surface
  458.     memset(&m_scratchSurface, 0, sizeof(WINDRAWSURFACE));
  459.     if (NOERROR == WinDraw2_CreateSurface(&m_windraw, &m_scratchSurface, &primaryBMI, m_fSurfaceType, 0, 0))
  460.     {
  461. retVal = HXR_OK;
  462. m_bScratchSurfaceCreated = TRUE;
  463.     }
  464.     return retVal;
  465. }
  466. HX_RESULT CWinBaseRootSurface::DestroyScratchSurface()
  467. {
  468.     HX_RESULT retVal = HXR_OK;
  469.     if (m_bScratchSurfaceCreated)
  470.     {
  471. if (NOERROR == WinDraw2_ReleaseSurface(&m_windraw, &m_scratchSurface))
  472. {
  473. m_bScratchSurfaceCreated = FALSE;
  474. retVal = HXR_OK;
  475. }
  476. else
  477. {
  478. retVal = HXR_FAIL;
  479. }
  480.     }
  481.     return retVal;
  482. }
  483. void CWinBaseRootSurface::SetFullScreen()
  484. {
  485.     m_bBltLock = FALSE;
  486.     RECT boundRect = {0,0,0,0};
  487.     boundRect.right = GetSystemMetrics(SM_CXSCREEN);
  488.     boundRect.bottom    = GetSystemMetrics(SM_CYSCREEN);
  489.     WinDrawSurface_Blt(&m_windraw, &m_compositionSurface, (RECT*)&boundRect, (RECT*)&boundRect);
  490. }
  491. void CWinBaseRootSurface::PrepareExitFullScreen()
  492. {
  493.     memcpy(&m_compositionSize, &m_pSite->m_size, sizeof(HXxSize)); /* Flawfinder: ignore */
  494. }
  495. void CWinBaseRootSurface::RestoreResolution()
  496. {
  497.     WinDraw2_RestoreResolution(&m_windraw);
  498. }
  499. void CWinBaseRootSurface::_AdjustLastAppendedRectangle(REF(CHXSimpleList) rectList)
  500. {
  501. }
  502. void CWinBaseRootSurface::_PreFlightBlt(HXxRect& dst)
  503. {
  504. }
  505. void CWinBaseRootSurface::PrepareFullScreen()
  506. {
  507.     HDC hDC;
  508.     WinDrawSurface_GetDC(&m_windraw, &m_compositionSurface, &hDC);
  509.     HBRUSH blackBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
  510.     HBRUSH oldBrush = (HBRUSH)SelectObject(hDC, blackBrush);
  511.     HPEN nullPen = (HPEN)GetStockObject(NULL_PEN);
  512.     HPEN oldPen = (HPEN)SelectObject(hDC, nullPen);
  513.     Rectangle(hDC, 0,0, m_allocatedCompositionSize.cx, m_allocatedCompositionSize.cy);
  514.     SelectObject(hDC, oldBrush);
  515.     SelectObject(hDC, oldPen);
  516.     WinDrawSurface_ReleaseDC(&m_windraw, &m_compositionSurface, hDC);
  517.     HXxWindow* pWindow = m_pSite->GetWindow();
  518.     if (pWindow && pWindow->window)
  519.     {
  520. HWND hwnd = (HWND) pWindow->window;
  521. hDC = GetDC(hwnd);
  522. RECT destRect;
  523. GetClientRect(hwnd, &destRect);
  524. oldBrush = (HBRUSH)SelectObject(hDC, blackBrush);
  525. oldPen = (HPEN)SelectObject(hDC, nullPen);
  526. Rectangle(hDC, 0, 0, destRect.right+1, destRect.bottom+1);
  527. SelectObject(hDC, oldBrush);
  528. SelectObject(hDC, oldPen);
  529. ReleaseDC(hwnd, hDC);
  530.     }
  531.     m_bBltLock = TRUE;
  532. }
  533. void CWinBaseRootSurface::GetDisplayModes(CModesDesc* pModesDesc, INT32* nNumModes)
  534. {
  535.     OpenWindraw();
  536.     WinDraw2_GetModes(&m_windraw, pModesDesc, (UINT32*)nNumModes);
  537. }
  538. void CWinBaseRootSurface::SetResolution(int width, int height, int depth, void* hwnd)
  539. {
  540.     OpenWindraw();
  541.     WinDraw2_SetResolution(&m_windraw, width, height, depth, (HWND)hwnd);
  542.     m_pCompMutex->Lock();
  543.     _DestroyCompositionSurface();
  544.     _CreateCompositionSurface();
  545.     m_pCompMutex->Unlock();
  546. }
  547. BOOL CWinBaseRootSurface::_OptimizedSurfaceOpened()
  548. {
  549.     return m_bWindrawOpened;
  550. }
  551. void CWinBaseRootSurface::SelectFont(HDC hDC)
  552. {
  553.     if (!m_hFont)
  554.     {
  555. int oldMappingMode = SetMapMode( hDC, MM_TEXT );
  556. int nHeight = -MulDiv(50, GetDeviceCaps(hDC, LOGPIXELSY), 72);
  557. m_hFont = CreateFont(nHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Ariel");
  558. SetMapMode( hDC, oldMappingMode);
  559.     }
  560.     m_hOldFont = (HFONT)SelectObject(hDC, m_hFont);
  561. }
  562. void CWinBaseRootSurface::UnSelectFont(HDC hDC)
  563. {
  564.      SelectObject(hDC, m_hOldFont);
  565. }
  566. void CWinBaseRootSurface::CreateTextAlpha(COverlay* pOverlay)
  567. {
  568.     /*
  569.      * The default function for text overlays is that anywhere 
  570.      *  that the pixels are set to a value the alpha will be set to 
  571.      *  128, everywhere else it will be set to 0
  572.      */ 
  573.     UINT32* pPixels = (UINT32*)pOverlay->LockOverlay();
  574.     UCHAR*  pAlpha  = pOverlay->GetAlpha();
  575.     HXxSize size;
  576.     pOverlay->GetSize(size);
  577.     int x,y;
  578.     int nCID = pOverlay->GetCID();
  579.     UINT32 rgbValue = 0;
  580.     int state =0;
  581.     switch(nCID)
  582.     {
  583. case CID_RGB32:
  584. case CID_RGB24:
  585. for(y=0; y<size.cy; y++)
  586. {
  587.     for(x=0;x<size.cx;x++, pAlpha++)
  588.     {
  589. switch(state)
  590. {
  591.     case 0:
  592.     {
  593. rgbValue = (*pPixels && 0xFFFFFF00)>>8;
  594. state = 1;
  595. break;
  596.     }
  597.     case 1:
  598.     {
  599.      rgbValue = ((*pPixels && 0x000000FF)<<16);
  600. pPixels++;
  601. rgbValue += ((*pPixels && 0xFFFFF0000)>>16);
  602. state = 2;
  603. break;
  604.     }
  605.     case 2:
  606.     {
  607.      rgbValue = ((*pPixels && 0x0000FFFF)<<8);
  608. pPixels++;
  609. rgbValue += ((*pPixels && 0xFF000000)>>24);
  610. state = 3;
  611. break;
  612.     }
  613.     case 3:
  614.     {
  615.      rgbValue = ((*pPixels && 0x00FFFFFF));
  616. pPixels++;
  617. state = 0;
  618. break;
  619.     }
  620. }
  621. *pAlpha = rgbValue ? 255 : 0;
  622.     }
  623. }
  624. break;
  625.     }
  626.     pOverlay->UnlockOverlay();
  627. }
  628. #if 0
  629. void CWinBaseRootSurface::DrawFocusRect(WINDRAWSURFACE *pSurface,
  630.                                         int nSurfaceCID,
  631.                                         HXxSize *pSurfaceSize,
  632.                                         UCHAR *pVidMem,
  633.                                         CHXBaseSite* pSite)
  634. {
  635.     // Draw the focus for this site
  636.     HXBitmapInfoHeader info;
  637.     memset(&info, 0, sizeof(info));
  638.     MakeBitmap((LPBITMAPINFO)&info, sizeof(info), nSurfaceCID, 
  639.             pSurfaceSize->cx, pSurfaceSize->cy, NULL, NULL);
  640.     HDC hdc = 0;
  641.     WinDrawSurface_GetDC(&m_windraw, pSurface, &hdc);
  642.     HXxRect rc = {0,0,pSurfaceSize->cx, pSurfaceSize->cy};
  643.     pSite->_DrawFocusRect(pVidMem,
  644.                           &info,
  645.                           &rc,
  646.                           (void*)&hdc);
  647.     WinDrawSurface_ReleaseDC(&m_windraw, pSurface, hdc);
  648. }
  649. #endif
  650. void CWinBaseRootSurface::DrawText()
  651. {
  652.     SIZE textSize; 
  653.     m_bShowingText = TRUE;
  654.     HXxSize overlaySize;
  655.     COverlay* pOverlay;
  656.     if (!m_overlayMgr.GetOverlay(TEXTOVERLAY, (COverlay**)&pOverlay))
  657.     {
  658. HDC hDC = GetDC(NULL);
  659. SelectFont(hDC);
  660. GetTextExtentPoint(hDC, "XXX", 4, &textSize);
  661. UnSelectFont(hDC);
  662. ReleaseDC(0, hDC);
  663. overlaySize.cx = m_allocatedCompositionSize.cx;
  664. overlaySize.cy = textSize.cy+4;
  665. pOverlay = new COverlay(&m_windraw);
  666. pOverlay->CreateOverlay(overlaySize, m_nCompositionSurfaceCID);
  667. m_overlayMgr.AddOverlay(TEXTOVERLAY, pOverlay);
  668.     }
  669.     else
  670.     {
  671. pOverlay->GetSize(overlaySize);
  672. if (overlaySize.cx < m_allocatedCompositionSize.cx)
  673. {
  674. m_overlayMgr.RemoveOverlay(TEXTOVERLAY, &m_compositionSurface);
  675. overlaySize.cx = m_allocatedCompositionSize.cx;
  676. pOverlay->CreateOverlay(overlaySize, m_nCompositionSurfaceCID);
  677. m_overlayMgr.AddOverlay(TEXTOVERLAY, pOverlay);
  678. }
  679.     }
  680.     RECT boundsRect;
  681.     boundsRect.left = 0;
  682.     boundsRect.top = 0;
  683.     boundsRect.right = m_compositionSize.cx;
  684.     boundsRect.bottom = textSize.cy;
  685.     /*
  686. * create ther drawing surface
  687. */ 
  688.     HDC hMemDC = NULL;
  689.     pOverlay->GetDC(&hMemDC);
  690.     if (!m_hBrush)
  691.     {
  692. LOGBRUSH brush;
  693. brush.lbStyle = BS_SOLID;
  694. brush.lbColor = m_nTextBackgroundColor;
  695. brush.lbHatch = 0;
  696. m_hBrush = CreateBrushIndirect(&brush);
  697.     }
  698.     if (!m_hPen)
  699.     {
  700. m_hPen = CreatePen(PS_SOLID, 0, m_textColor);
  701.     }
  702.     
  703.     HBRUSH hOldBrush = (HBRUSH)SelectObject(hMemDC, m_hBrush);
  704.     HPEN hOldPen = (HPEN)SelectObject(hMemDC, m_hPen);
  705.     /*
  706. * figure out how much text we should use.
  707. */ 
  708.     
  709.     CHXString finalString = m_sStatusText;
  710.     HXxPoint textOffset;
  711.     SelectFont(hMemDC);
  712.     int length = m_sStatusText.GetLength();
  713.     GetTextExtentPoint(hMemDC, (const char*)m_sStatusText, m_sStatusText.GetLength(), &textSize);
  714.     if (textSize.cx > (boundsRect.right - boundsRect.left - 4))
  715.     {
  716. /*
  717. *  we will loop to find out where to put the elipise
  718. */ 
  719. for (int i = 1; i <= m_sStatusText.GetLength(); i++)
  720. {
  721. GetTextExtentPoint(hMemDC, (const char*)m_sStatusText, i, &textSize);
  722. if (textSize.cx > (boundsRect.right - boundsRect.left - 4))
  723. {
  724. for(int j = i - 1; j > 0 ; j--)
  725. {
  726. finalString = m_sStatusText.Left(j);
  727. finalString = finalString + "...";
  728. GetTextExtentPoint(hMemDC, (const char*)finalString, finalString.GetLength(), &textSize);
  729. if (textSize.cx > (boundsRect.right - boundsRect.left - 4))
  730. {
  731. continue;
  732. }
  733. break;
  734. }
  735. textOffset.x = 3;
  736. textOffset.y = 3;
  737. }
  738. }
  739.     }
  740.     else
  741.     {
  742. textOffset.x = (m_compositionSize.cx - textSize.cx) / 2;
  743. textOffset.y = 3;
  744.     }
  745.     /*
  746. * Do the drawing
  747. */ 
  748.     RECT rectBounds;
  749.     rectBounds.left = (m_compositionSize.cx - textSize.cx)/2 - 2;
  750.     rectBounds.right = (m_compositionSize.cx + textSize.cx)/2 + 2;
  751.     rectBounds.top = 0;
  752.     rectBounds.bottom = textSize.cy+4;
  753.     int delta = 2;
  754.     BOOL ret = Rectangle(hMemDC, rectBounds.top - delta, rectBounds.left - delta, rectBounds.bottom + delta, rectBounds.right + delta);
  755.     COLORREF oldColor = SetTextColor(hMemDC, m_textColor);
  756.     COLORREF oldBkColor = SetBkColor(hMemDC, m_nTextBackgroundColor);
  757.     ret = TextOut(hMemDC, textOffset.x, textOffset.y, finalString, finalString.GetLength());
  758.     SetBkColor(hMemDC, oldBkColor);
  759.     SetTextColor(hMemDC, oldColor);
  760.     UnSelectFont(hMemDC);
  761.     SelectObject(hMemDC, hOldBrush);
  762.     SelectObject(hMemDC, hOldPen);
  763.     GdiFlush();
  764.     pOverlay->ReleaseDC(hMemDC);
  765.     pOverlay->SetSrcRect((HXxRect&)rectBounds);
  766.     CreateTextAlpha(pOverlay);
  767.     rectBounds.top = m_compositionSize.cy - (textSize.cy+4);
  768.     rectBounds.bottom = m_compositionSize.cy;
  769.     pOverlay->SetDestRect((HXxRect&)rectBounds, &m_compositionSurface);
  770. }
  771. void CWinBaseRootSurface::_FillBorders()
  772. {
  773.    HXxWindow* pWindow = m_pSite->GetWindow();
  774.    if (pWindow && pWindow->window)
  775.    {
  776.       HWND hwnd = (HWND) pWindow->window;
  777.       HDC hDC = GetDC(hwnd);
  778.       RECT destRect;
  779.       GetClientRect(hwnd, &destRect);
  780.       HXxSize size;
  781.       m_pSite->GetSize(size);
  782.       HBRUSH blackBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
  783.       HBRUSH oldBrush = (HBRUSH)SelectObject(hDC, blackBrush);
  784.       HPEN nullPen = (HPEN)GetStockObject(NULL_PEN);
  785.       HPEN oldPen = (HPEN)SelectObject(hDC, nullPen);
  786.       if (size.cx < destRect.right)
  787.       {
  788.          Rectangle(hDC, 0, 0, (destRect.right - size.cx + 1) / 2 + 1, destRect.bottom+1);
  789.          Rectangle(hDC, destRect.right - ((destRect.right - size.cx + 1) / 2), 0, destRect.right+1, destRect.bottom+1);
  790.       }
  791.       else
  792.       {
  793.          Rectangle(hDC, 0, 0, destRect.right+1, (destRect.bottom - size.cy + 1) / 2 + 1);
  794.          Rectangle(hDC, 0, destRect.bottom - ((destRect.bottom - size.cy + 1) / 2), destRect.right+1, destRect.bottom+1);
  795.       }
  796.       SelectObject(hDC, oldBrush);
  797.       SelectObject(hDC, oldPen);
  798.       ReleaseDC(hwnd, hDC);
  799.    }
  800. }
  801. BOOL CWinBaseRootSurface::_IsHardwareAccelerationAvail()
  802. {
  803.     return WinDraw2_IsDDAvailable(&m_windrawCaps);
  804. }
  805. BOOL CWinBaseRootSurface::_AcquireHardwareAcceleration()
  806. {
  807.     if (!m_bWindrawOpened)
  808.         return FALSE;
  809.     m_pCompMutex->Lock();
  810.     
  811.     // Close accelerated windraw instance
  812.     if (m_bWindrawCapsOpened)
  813.     {
  814. WinDraw2_Close(&m_windrawCaps);
  815. memset(&m_windrawCaps, 0, sizeof(m_windrawCaps));
  816. m_bWindrawCapsOpened = FALSE;
  817.     }
  818.     _DestroyCompositionSurface();
  819.     
  820.     // Close the non accelrated windraw instance
  821.     WinDraw2_Close(&m_windraw);
  822.     m_bWindrawOpened = FALSE;
  823.     // Turn on acceleration
  824.     m_fSurfaceType |= HX_ACCELERATION_ON;
  825.     
  826.     if (m_bUseCardMemory)
  827.         m_fSurfaceType |= HX_USE_VIDEO_MEMORY;
  828.     else
  829.         m_fSurfaceType |= HX_USE_SYSTEM_MEMORY;
  830.     
  831.     _CreateCompositionSurface();
  832.     m_pCompMutex->Unlock();
  833.     
  834.     return TRUE;
  835. }
  836. BOOL CWinBaseRootSurface::_LoseHardwareAcceleration()
  837. {
  838.     if (!m_bWindrawOpened)
  839.         return FALSE;
  840.     m_pCompMutex->Lock();
  841.     _DestroyCompositionSurface();
  842.     m_overlayMgr.RemoveAll();
  843.     
  844.     m_windrawCaps = m_windraw;
  845.     
  846.     memset(&m_windraw, 0, sizeof(m_windraw));
  847.     m_bWindrawOpened = FALSE;
  848.     
  849.     // Preserve the DD instance
  850.     m_bWindrawCapsOpened = TRUE;
  851.     // Turn off acceleration
  852.     m_fSurfaceType &= ~HX_ACCELERATION_ON;
  853.     m_fSurfaceType &= ~HX_USE_VIDEO_MEMORY;
  854.     m_fSurfaceType &= ~HX_USE_SYSTEM_MEMORY;
  855.     
  856.     _CreateCompositionSurface();
  857.     m_pCompMutex->Unlock();
  858.     return TRUE;
  859. }
  860. BOOL CWinBaseRootSurface::_EnableHardwareAcceleration()
  861. {
  862.     // If hardware acceleration is disabled, enabled it
  863.     if ((m_fSurfaceType & HX_ACCELERATION_ON) != HX_ACCELERATION_ON)
  864.     {
  865.         BOOL bCreateCompSurface = FALSE;
  866.         m_pCompMutex->Lock();
  867.         
  868.         // If we have an "unaccelerated" composition surface, destroy it
  869.         if(HXR_OK == _DestroyCompositionSurface())
  870.             bCreateCompSurface = TRUE;
  871.         // Close rgb windraw instance
  872.         if (m_bWindrawOpened)
  873.         {
  874.             m_overlayMgr.RemoveAll();
  875.             WinDraw2_Close(&m_windraw);
  876.             m_bWindrawOpened = FALSE;
  877.         }
  878.         // Turn on acceleration
  879.         m_fSurfaceType |= HX_ACCELERATION_ON;
  880.     
  881.         if (m_bUseCardMemory)
  882.             m_fSurfaceType |= HX_USE_VIDEO_MEMORY;
  883.         else
  884.             m_fSurfaceType |= HX_USE_SYSTEM_MEMORY;
  885.         // Create an "accelerated" composition surface if we need one
  886.         if(bCreateCompSurface)
  887.             _CreateCompositionSurface();
  888.         
  889.         m_pCompMutex->Unlock();
  890.     }
  891.     
  892.     return TRUE;
  893. }
  894. BOOL CWinBaseRootSurface::_DisableHardwareAcceleration()
  895. {
  896.     // If hardware acceleration is enabled, disable it
  897.     if ((m_fSurfaceType & HX_ACCELERATION_ON) == HX_ACCELERATION_ON)
  898.     {
  899.         BOOL bCreateCompSurface = FALSE;
  900.         m_pCompMutex->Lock();
  901.         
  902.         // If we have an "accelerated" composition surface, destroy it
  903.         if(HXR_OK == _DestroyCompositionSurface())
  904.             bCreateCompSurface = TRUE;
  905.         
  906.         // Close yuv windraw instance
  907.         if (m_bWindrawOpened)
  908.         {
  909.             m_overlayMgr.RemoveAll();
  910.             WinDraw2_Close(&m_windraw);
  911.             m_bWindrawOpened = FALSE;
  912.         }
  913.         // Close yuv caps windraw instance
  914.         if (m_bWindrawCapsOpened)
  915.         {
  916.             WinDraw2_Close(&m_windrawCaps);
  917.             m_bWindrawCapsOpened = FALSE;
  918.         }
  919.         // Turn off acceleration
  920.         m_fSurfaceType &= ~HX_ACCELERATION_ON;
  921.         m_fSurfaceType &= ~HX_USE_VIDEO_MEMORY;
  922.         m_fSurfaceType &= ~HX_USE_SYSTEM_MEMORY;
  923.         // Create an "unaccelerated" composition surface if we need one
  924.         if(bCreateCompSurface)
  925.             _CreateCompositionSurface();
  926.         m_pCompMutex->Unlock();
  927.     }
  928.     return TRUE;
  929. }
  930. /**********************************************************************
  931. *
  932. * COverlayMgr
  933. *
  934. *   A class which manages the internals of video overlays.
  935. *
  936. **********************************************************************/
  937. COverlayMgr::COverlayMgr()
  938. {
  939. }
  940. COverlayMgr::~COverlayMgr()
  941. {
  942.     RemoveAll();
  943. }
  944. BOOL COverlayMgr::GetOverlay(const char* pName, COverlay** pOverlay)
  945. {
  946.     return m_overlayMap.Lookup(pName, (void*&)pOverlay);
  947. }
  948. void COverlayMgr::RemoveOverlay(const char* pName, WINDRAWSURFACE* pDestSurface)
  949. {
  950.     COverlay* pOverlay;
  951.     if (m_overlayMap.Lookup(pName, (void*&)pOverlay))
  952.     {
  953. m_overlayMap.RemoveKey(pName);
  954. pOverlay->RemoveOverlay(pDestSurface);
  955. HX_DELETE(pOverlay);
  956.     }
  957. }
  958. void COverlayMgr::RemoveAll()
  959. {
  960.     COverlay* pOverlay;
  961.     CHXMapStringToOb::Iterator i = m_overlayMap.Begin();
  962.     for(;i != m_overlayMap.End(); ++i)
  963.     {
  964. pOverlay = (COverlay*) *i;
  965. HX_DELETE(pOverlay);
  966.     }
  967.     m_overlayMap.RemoveAll();
  968. }
  969. void COverlayMgr::AddOverlay(const char* pName, COverlay* pOverlay)
  970. {
  971.     m_overlayMap.SetAt(pName, (void*)pOverlay);
  972. }
  973. void COverlayMgr::UpdateOverlays(HXxRect* pRect, WINDRAWSURFACE* pSrcSurface)
  974. {
  975.     CHXMapStringToOb::Iterator i = m_overlayMap.Begin();
  976.     for(;i!=m_overlayMap.End();++i)
  977.     {
  978. COverlay* pOverlay = (COverlay*)*i;
  979. pOverlay->UpdateOverlay(pRect, pSrcSurface);
  980.     }
  981. }
  982. /**********************************************************************
  983. *
  984. * COverlay
  985. *
  986. *   A class which manages the internals of video overlays.
  987. *
  988. **********************************************************************/
  989. COverlay::COverlay(WINDRAW* pWindraw)
  990. : m_nCID(0)
  991. , m_nAlpha(0)
  992. , m_pWindraw(0)
  993. {
  994.     m_pWindraw = pWindraw;
  995.     memset(&m_backgroundSurface, 0, sizeof(WINDRAWSURFACE));
  996.     memset(&m_overlaySurface, 0, sizeof(WINDRAWSURFACE));
  997.     memset(&m_destRect, 0, sizeof(HXxRect));
  998.     memset(&m_srcRect, 0, sizeof(HXxRect));
  999.     memset(&m_backgroundSrcRect, 0, sizeof(HXxRect));
  1000.     memset(&m_allocSize, 0, sizeof(HXxRect));
  1001. }
  1002. COverlay::~COverlay()
  1003. {
  1004.     WinDraw2_ReleaseSurface(m_pWindraw, &m_overlaySurface);
  1005.     WinDraw2_ReleaseSurface(m_pWindraw, &m_backgroundSurface);
  1006. }
  1007. void COverlay::CreateOverlay(REF(HXxSize) size, int nCID)
  1008. {
  1009.     BMI textBMI;
  1010.     m_nCID = nCID;
  1011.     memcpy(&m_allocSize, &size, sizeof(HXxSize)); /* Flawfinder: ignore */
  1012.     MakeBitmap((LPBITMAPINFO)&textBMI, sizeof(BITMAPINFO), m_nCID, size.cx, size.cy, NULL, NULL);
  1013.     HX_VERIFY(NOERROR == WinDraw2_CreateSurface(m_pWindraw, &m_overlaySurface, &textBMI, NULL, 0, 0));
  1014. }
  1015. void COverlay::SetSrcRect(REF(HXxRect) rect)
  1016. {
  1017.     memcpy(&m_srcRect, &rect, sizeof(HXxRect)); /* Flawfinder: ignore */
  1018. }
  1019. void COverlay::SetAlpha(int nAlpha)
  1020. {
  1021.     m_nAlpha = nAlpha;
  1022. }
  1023. void COverlay::GetSize(REF(HXxSize) size)
  1024. {
  1025.     memcpy(&size, &m_allocSize, sizeof(HXxSize)); /* Flawfinder: ignore */
  1026. }
  1027. UCHAR* COverlay::LockOverlay()
  1028. {
  1029.     UCHAR*  retVal;
  1030.     LONG    pitch;
  1031.     WinDrawSurface_Lock(m_pWindraw, &m_overlaySurface, 0, (void**)&retVal, &pitch);
  1032.     return retVal;
  1033. }
  1034. void COverlay::UnlockOverlay()
  1035. {
  1036.     WinDrawSurface_Unlock(m_pWindraw, &m_overlaySurface, 0);
  1037. }
  1038. UCHAR* COverlay::GetAlpha()
  1039. {
  1040.     UCHAR* retVal = NULL;
  1041.     WinDraw2_CreateAlphaSurface(m_pWindraw, &m_overlaySurface);
  1042.     WinDraw2_GetAlphaSurface(m_pWindraw, &m_overlaySurface, &retVal);
  1043.     return retVal;
  1044. }
  1045. int COverlay::GetCID()
  1046. {
  1047.     return m_nCID;
  1048. }
  1049. void COverlay::GetDC(HDC* phDC)
  1050. {
  1051.     WinDrawSurface_GetDC(m_pWindraw, &m_overlaySurface, phDC);
  1052. }
  1053. void COverlay::ReleaseDC(HDC hDC)
  1054. {
  1055.     WinDrawSurface_ReleaseDC(m_pWindraw, &m_overlaySurface, hDC);
  1056. }
  1057. void COverlay::SetDestRect(REF(HXxRect) rect, WINDRAWSURFACE* pDestSurface)
  1058. {
  1059. /*
  1060. * if the dest rect changes it is time to recreate the surface.
  1061. */ 
  1062.     if (memcmp(&m_destRect, &rect, sizeof(RECT)))
  1063.     {
  1064. /*
  1065. *  get a buffer of what is on the composition surface
  1066. */
  1067. if (rect.right - rect.left != m_destRect.right - m_destRect.left || 
  1068. rect.bottom - rect.top != m_destRect.bottom - m_destRect.top )
  1069. {
  1070. BMI textBMI;
  1071. MakeBitmap((LPBITMAPINFO)&textBMI, sizeof(BITMAPINFO), m_nCID, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL);
  1072. WinDraw2_ReleaseSurface(m_pWindraw, &m_backgroundSurface);
  1073. HX_VERIFY(NOERROR == WinDraw2_CreateSurface(m_pWindraw, &m_backgroundSurface, &textBMI, NULL, 0, 0));
  1074. }
  1075. memcpy(&m_destRect, &rect, sizeof(HXxRect)); /* Flawfinder: ignore */
  1076. memset(&m_backgroundSrcRect, 0, sizeof(RECT));
  1077. m_backgroundSrcRect.right   = rect.right - rect.left;
  1078. m_backgroundSrcRect.bottom  = rect.bottom - rect.top;
  1079. WinDrawSurface_BltIndirect(m_pWindraw, &m_backgroundSurface, pDestSurface, (RECT*)&m_backgroundSrcRect, (RECT*)&rect);
  1080.     }
  1081. }
  1082. void COverlay::DrawOverlay(WINDRAWSURFACE* pDestSurface)
  1083. {
  1084.     WinDrawSurface_BltIndirect(m_pWindraw, pDestSurface, &m_backgroundSurface, (RECT*)&m_backgroundSrcRect, (RECT*)&m_destRect);
  1085.     WinDrawSurface_BltIndirect(m_pWindraw, pDestSurface, &m_overlaySurface, (RECT*)&m_srcRect, (RECT*)&m_destRect);
  1086. }
  1087. void COverlay::RemoveOverlay(WINDRAWSURFACE* pDestSurface)
  1088. {
  1089.     WinDrawSurface_BltIndirect(m_pWindraw, pDestSurface, &m_backgroundSurface, (RECT*)&m_backgroundSrcRect, (RECT*)&m_destRect);
  1090. }
  1091. void COverlay::UpdateOverlay(HXxRect* pRect, WINDRAWSURFACE* pSrcSurface)
  1092. {
  1093.     RECT tempRect;
  1094.     if (IntersectRect( &tempRect, (RECT*)pRect, (RECT*) &m_destRect))
  1095.     {
  1096. /* yes they intersected */
  1097. RECT destRect;
  1098. destRect.left = tempRect.left     - m_destRect.left;
  1099. destRect.top = tempRect.top     - m_destRect.top;
  1100. destRect.right = tempRect.right    - m_destRect.left;
  1101. destRect.bottom = tempRect.bottom   - m_destRect.top;
  1102. /* update the background */
  1103. WinDrawSurface_BltIndirect(m_pWindraw, &m_backgroundSurface, pSrcSurface, &destRect, &tempRect);
  1104. destRect.right = tempRect.right;
  1105. destRect.left = tempRect.left;
  1106. /* Now blt */
  1107. WinDrawSurface_BltIndirect(m_pWindraw, pSrcSurface, &m_overlaySurface, (RECT*)&tempRect, &destRect);
  1108.     }
  1109. }