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

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 "hxthread.h"
  42. #if defined(_WINDOWS)
  43. #include "winroot.h" // must be included before colormap.h
  44. #endif
  45. #include "baseroot.h"
  46. #include "coloracc.h"
  47. #include "colormap.h"
  48. //XXXgfw just to cletbiean up the code. We still *REALLY* need to clean
  49. //this up.
  50. #ifdef _WIN32
  51. #define GETBITMAPCOLOR(x) GetBitmapColor( (LPBITMAPINFO)(x) )
  52. #else
  53. #define GETBITMAPCOLOR(x) GetBitmapColor( (HXBitmapInfo*)(x))
  54. #endif
  55. #ifdef _WIN32
  56. #define GETBITMAPPITCH(x) GetBitmapPitch( (LPBITMAPINFO)(x) )
  57. #else
  58. #define GETBITMAPPITCH(x) GetBitmapPitch( (HXBitmapInfo*)(x))
  59. #endif
  60. #include "basesurf.h"
  61. #include "basesite.h"
  62. #include "hxprefs.h"
  63. #include "hxtick.h"
  64. #if defined(_UNIX) && !defined(_MAC_UNIX)
  65. #  include "unixroot.h"
  66. #endif
  67. #if defined(_MACINTOSH) || defined(_MAC_UNIX)
  68. #include "platform/mac/macroot.h"
  69. #endif
  70. #include "sitefact.h"
  71. #if defined(HELIX_FEATURE_PREFERENCES)
  72. #include "hxprefs.h"
  73. #include "hxprefutil.h"
  74. #endif /* HELIX_FEATURE_PREFERENCES */
  75. #ifdef _DEBUG
  76. #undef HX_THIS_FILE
  77. static const char HX_THIS_FILE[] = __FILE__;
  78. #endif
  79. #define RED     0x00ff0000
  80. #define GREEN   0x0000ff00
  81. #define BLUE    0x000000ff
  82. //#define _CHECK_CONVERSION_DATA
  83. //#define _WORKAROUND_YUV_RGB_16BIT_HXCOLOR_BUG
  84. CBaseRootSurface::CBaseRootSurface(IUnknown* pContext, CHXBaseSite* pSite)
  85.     : m_lRefCount(0)
  86.     , m_pContext(pContext)
  87.     , m_pSite(pSite)
  88.     , m_fSurfaceType(0)
  89.     , m_pMutex(NULL)
  90.     , m_pCompMutex(NULL)
  91.     , m_nBLTMode(0)
  92.     , m_pCompositionSurface(NULL)
  93.     , m_bCompositionSurfaceCreated(FALSE)
  94. #ifdef _WINDOWS
  95.     , m_pPlayer(NULL)
  96. #endif
  97.     , m_bUseCardMemory(FALSE)
  98.     , m_pUnlockingSite(NULL)
  99.     , zm_pColorAcc(NULL)
  100. {
  101. #ifdef _BLT_IN_DEBUG
  102.    m_nBLTMode = HX_WINDOWLESS_DEBUG;
  103. #else
  104.    m_nBLTMode = HX_WINDOWLESS_MINIMAL;
  105. #endif
  106.    HX_ASSERT( m_pContext );
  107.    HX_ASSERT( m_pSite );
  108.    m_pContext->AddRef();
  109.    m_pSite->AddRef();
  110. #if defined(THREADS_SUPPORTED) || defined(_UNIX_THREADS_SUPPORTED)
  111.    HXMutex::MakeMutex(m_pMutex);
  112.    HXMutex::MakeMutex(m_pCompMutex);
  113. #else
  114.    HXMutex::MakeStubMutex(m_pMutex);
  115.    HXMutex::MakeStubMutex(m_pCompMutex);
  116. #endif
  117.     CreateColorAccess(pContext);
  118.     zm_pColorAcc->InitColorConverter();
  119.    /*
  120.     *  Determine what level of Video 'Acceleration' we want to use.
  121.     */
  122.    // XXXAH    we will want to unify all of the OSes to use the same value.
  123.    //          Something like VideoAcceleration or something.
  124.    //          For now ... "Don't break windows" (tm).
  125.    BOOL    bUseWindraw     = TRUE;
  126.    IHXPreferences*    pPreferences    = NULL;
  127.    IHXBuffer*         pBuffer         = NULL;
  128.    if (HXR_OK == m_pContext->QueryInterface(IID_IHXPreferences,(void**)&pPreferences))
  129.    {
  130.        ReadPrefBOOL(pPreferences, "UseWinDraw", bUseWindraw);
  131.        ReadPrefBOOL(pPreferences, "UseCardMemory", m_bUseCardMemory);
  132.        HX_RELEASE(pBuffer);
  133.    }
  134.    HX_RELEASE(pPreferences);
  135.    if (bUseWindraw)
  136.    {
  137.       m_fSurfaceType  = HX_ACCELERATION_ON;
  138.       if (m_bUseCardMemory)
  139.       {
  140.          m_fSurfaceType |= HX_USE_VIDEO_MEMORY;
  141.       }
  142.       else
  143.       {
  144.          m_fSurfaceType |= HX_USE_SYSTEM_MEMORY;
  145.       }
  146.    }
  147.    m_boundsRect.left   = 65536;
  148.    m_boundsRect.top    = 65536;
  149.    m_boundsRect.right  = 0;
  150.    m_boundsRect.bottom = 0;
  151. }
  152. CBaseRootSurface::~CBaseRootSurface()
  153. {
  154.    /*
  155.     * Clean up the color access functions
  156.     */
  157.    HX_DELETE(zm_pColorAcc);
  158. #ifdef _WINDOWS
  159.    HX_RELEASE(m_pPlayer);
  160. #endif
  161.    HX_DELETE(m_pMutex);
  162.    HX_DELETE(m_pCompMutex);
  163.    HX_RELEASE(m_pContext);
  164.    HX_RELEASE(m_pSite);
  165.    while(m_pBltRects.GetCount())
  166.    {
  167.         HXxRect* pRect = (HXxRect*) m_pBltRects.RemoveHead();
  168.         HX_DELETE(pRect);
  169.    }
  170. }
  171. /************************************************************************
  172.  *  Method:
  173.  *    IUnknown::QueryInterface
  174.  */
  175. STDMETHODIMP CBaseRootSurface::QueryInterface(REFIID riid, void** ppvObj)
  176. {
  177.    if (IsEqualIID(riid, IID_IUnknown))
  178.    {
  179.       AddRef();
  180.       *ppvObj = (IUnknown*)(IHXVideoSurface*)this;
  181.       return HXR_OK;
  182.    }
  183.    *ppvObj = NULL;
  184.    return HXR_NOINTERFACE;
  185. }
  186. /************************************************************************
  187.  *  Method:
  188.  *    IUnknown::AddRef
  189.  */
  190. STDMETHODIMP_(ULONG32)
  191.    CBaseRootSurface::AddRef()
  192. {
  193.    return InterlockedIncrement(&m_lRefCount);
  194. }
  195. /************************************************************************
  196.  *  Method:
  197.  *    IUnknown::Release
  198.  */
  199. STDMETHODIMP_(ULONG32)
  200.    CBaseRootSurface::Release()
  201. {
  202.    if (InterlockedDecrement(&m_lRefCount) > 0)
  203.    {
  204.       return m_lRefCount;
  205.    }
  206.    delete this;
  207.    return 0;
  208. }
  209. void CBaseRootSurface::BltComposition()
  210. {
  211.     HXxRect rSrcRect;
  212.     rSrcRect.top    = 0;
  213.     rSrcRect.left   = 0;
  214.     rSrcRect.right  = m_compositionSize.cx;
  215.     rSrcRect.bottom = m_compositionSize.cy;
  216.     //Blt the entire presentation.
  217.     m_boundsRect.right   = m_compositionSize.cx;
  218.     m_boundsRect.bottom  = m_compositionSize.cy;
  219.     m_boundsRect.left    = 0;
  220.     m_boundsRect.top     = 0;
  221.     if( IsCompositionEnabled() )
  222.     {
  223. #if defined(_WINDOWS)
  224.         _MinimalUnlock(m_pSite->GetWindow());
  225. #else
  226.         _MinimalBlt(rSrcRect, rSrcRect);
  227. #endif
  228.     }
  229. }
  230. STDMETHODIMP CBaseRootSurface::Blt( UCHAR*               pImageData,
  231.                                     HXBitmapInfoHeader* pBitmapInfo,
  232.                                     REF(HXxRect)         rDestRect,
  233.                                     REF(HXxRect)         rSrcRect,
  234.     CHXBaseSite*  pSite)
  235. {
  236.    HX_RESULT retVal = HXR_FAIL;
  237.    if( NULL == pImageData || NULL == pBitmapInfo )
  238.        return retVal;
  239.    switch (m_nBLTMode)
  240.    {
  241.       case HX_WINDOWLESS_DEBUG:
  242.          retVal = DebugBlt(pImageData, pBitmapInfo, rDestRect, rSrcRect);
  243.          break;
  244.       case HX_WINDOWLESS_MINIMAL:
  245.          retVal = MinimalBlt(pImageData, pBitmapInfo, rDestRect, rSrcRect, pSite);
  246.          break;
  247.    }
  248.    return retVal;
  249. }
  250. HX_RESULT CBaseRootSurface::DebugBlt( UCHAR*               pImageData,
  251.                                       HXBitmapInfoHeader* pBitmapInfo,
  252.                                       REF(HXxRect)         rDestRect,
  253.                                       REF(HXxRect)         rSrcRect)
  254. {
  255.    // Use OS services to draw solid boxes with outlines. Just to see
  256.    // what kind of freakiness is going on.
  257.    return _DebugBlt(pImageData, pBitmapInfo, rDestRect, rSrcRect);
  258. }
  259. HX_RESULT CBaseRootSurface::MinimalBlt( UCHAR*               pImageData,
  260.                                         HXBitmapInfoHeader* pBitmapInfo,
  261.                                         REF(HXxRect)         rDestRect,
  262.                                         REF(HXxRect)         rSrcRect,
  263. CHXBaseSite*      pSite)
  264. {
  265.    // color convert into the surface
  266.    HX_RESULT retVal = HXR_FAIL;
  267.    int cidIn   = GETBITMAPCOLOR(pBitmapInfo);
  268.    int pitchIn = GETBITMAPPITCH(pBitmapInfo);
  269.    int nRet = 0;
  270. #ifdef _WINDOWS
  271.    zm_pColorAcc->SetPlayer(GetPlayer());
  272. #endif
  273.    BOOL bConverter = zm_pColorAcc->CheckColorConverter(cidIn, m_nCompositionSurfaceCID);
  274.    pSite->ColorConverterRequest(cidIn, m_nCompositionSurfaceCID, bConverter);
  275.    int dxDst = rDestRect.right  - rDestRect.left;
  276.    int dyDst = rDestRect.bottom - rDestRect.top;
  277.    int dxSrc = rSrcRect.right   - rSrcRect.left;
  278.    int dySrc = rSrcRect.bottom  - rSrcRect.top;
  279.    //Please do not freak out the color converter!
  280.    if (dxSrc > pBitmapInfo->biWidth)
  281.    {
  282.       dxSrc = pBitmapInfo->biWidth;
  283.    }
  284.    if (dySrc > pBitmapInfo->biHeight)
  285.    {
  286.       dySrc = pBitmapInfo->biHeight;
  287.    }
  288.    //At this point I should be checking to see if the bitmap is going
  289.    //to be stretched. If so I should consider using Direct Draw to do
  290.    //the stretching.
  291.    //If our input is YUV and not I420 it is unlikely that we will have
  292.    //a color converter. So we will convert to I420 1st. Yeah, yeah, it
  293.    //blows. Big deal.  For the moment we only look for an input in the
  294.    //form of YUY2, XING's format.
  295.    if(!bConverter)
  296.    {
  297.         UINT32 width, height;
  298.         _GetYUVScratchWidthHeight(&width, &height);
  299.         if (width != (UINT32) pBitmapInfo->biWidth || height != (UINT32) pBitmapInfo->biHeight)
  300.         {
  301.             _CreateYUVScratchSurface(pBitmapInfo->biWidth, pBitmapInfo->biHeight);
  302.         }
  303.         UCHAR* pYUVBits;
  304.         INT32  nYUVPitch;
  305.         _GetYUVScratchSurfacePointer(&pYUVBits, &nYUVPitch);
  306.         if (pYUVBits)
  307.         {
  308.             #ifdef _WINDOWS
  309.             zm_pColorAcc->SetPlayer(GetPlayer());
  310.             #endif
  311.             bConverter = zm_pColorAcc->CheckColorConverter(cidIn, 0);
  312.             pSite->ColorConverterRequest(cidIn, 0, bConverter);
  313.             if (bConverter)
  314.             {
  315.                 nRet = zm_pColorAcc->ColorConvert(0, pYUVBits,
  316.                                  pBitmapInfo->biWidth, pBitmapInfo->biHeight,
  317.                                  nYUVPitch, 0, 0,
  318.                                  pBitmapInfo->biWidth, pBitmapInfo->biHeight,
  319.                                  cidIn, pImageData, pBitmapInfo->biWidth,
  320.                                  pBitmapInfo->biHeight, pitchIn,
  321.                                  0, 0, pBitmapInfo->biWidth, pBitmapInfo->biHeight);
  322.                 if (nRet == -1)
  323.                 {
  324.                     retVal = HXR_FAIL;
  325.                     bConverter = FALSE;
  326.                 }
  327.                 else
  328.                 {
  329.                     cidIn       = 0;
  330.                     pImageData  = pYUVBits;
  331.                     pitchIn     = nYUVPitch;
  332.                     bConverter = zm_pColorAcc->CheckColorConverter(cidIn, m_nCompositionSurfaceCID);
  333.                     pSite->ColorConverterRequest(cidIn, m_nCompositionSurfaceCID, bConverter);
  334.                 }
  335.             }
  336.             else
  337.                 retVal = HXR_FAIL;
  338.         }
  339.    }
  340.    if (bConverter)
  341.    {
  342.       m_pSite->CheckColorSettings();
  343. #ifdef _CHECK_CONVERSION_DATA
  344.       FILE* f1 = ::fopen("/tmp/ConversionData.txt", "a+"); /* Flawfinder: ignore */
  345.       ::fprintf(f1, "ColorConversion (%d -> %d) (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d %d)n",
  346.                 cidIn, m_nCompositionSurfaceCID, m_pCompositionSurface,
  347.                 m_allocatedCompositionSize.cx, m_allocatedCompositionSize.cy,
  348.                 m_nCompositionPitch, rDestRect.left, rDestRect.top,
  349.                 dxDst, dyDst, pImageData, pBitmapInfo->biWidth,
  350.                 pBitmapInfo->biHeight, pitchIn,
  351.                 rSrcRect.left, rSrcRect.top, dxSrc, dySrc);
  352.       ::fclose(f1);
  353. #endif
  354.       int returnVal = E_FAIL;
  355.       if (returnVal!=NOERROR)
  356.       {
  357. #ifdef _WORKAROUND_YUV_RGB_16BIT_HXCOLOR_BUG
  358.          /* working around a bug in the color convertor for strecth
  359.           * larger than doubel size for YUV to RGB 16 bit conversion */
  360. //          BOOL bUseScratch = HXDebugOptionEnabled("zUseScratch");
  361.          if (IsYUV(cidIn) && (rSrcRect.left || rSrcRect.top))
  362.          {
  363.             // The color converter does not like it when we are going
  364.             // from YUV->RGB with sub rects.  To work around this we
  365.             // will convert THE WHOLE THING to RGB. Then we will use
  366.             // the RGB converter to select the portion that we
  367.             // want. BWHAHAHA!^ This sucks, HUGE.
  368.             HXxSize tempSize;
  369.             tempSize.cx = pBitmapInfo->biWidth;
  370.             tempSize.cy = pBitmapInfo->biHeight;
  371.             CreateScratchSurface(m_nCompositionSurfaceCID, &tempSize);
  372.             UCHAR*  pScratchBits;
  373.             INT32   nScratchPitch;
  374.             ScratchLock(&pScratchBits, &nScratchPitch);
  375.             // if somehow scratch surface creation failed
  376.             if (!pScratchBits)
  377.             {
  378.                goto regularConvert;
  379.             }
  380.             returnVal = zm_pColorAcc->ColorConvert(
  381.                                          m_nCompositionSurfaceCID,
  382.                                          pScratchBits,
  383.                                          m_allocatedScratchSize.cx,
  384.                                          m_allocatedScratchSize.cy,
  385.                                          nScratchPitch, 0, 0,
  386.                                          pBitmapInfo->biWidth,
  387.                                          pBitmapInfo->biHeight,
  388.                                          cidIn, pImageData,
  389.                                          pBitmapInfo->biWidth,
  390.                                          pBitmapInfo->biHeight, pitchIn,
  391.                                          0, 0, pBitmapInfo->biWidth,
  392.                                          pBitmapInfo->biHeight);
  393.             ScratchUnlock(pScratchBits);
  394.             // Instead of using the RGB color converter we will simply
  395.             // use OS services to BLT to the surface at this point (since
  396.             // it MAY be faster at blt-ing than we are. HOWEVER, it may
  397.             // be faster by using pixel rep to stretch. This will cause
  398.             // visually unsatisifing blts.  But then again ... DO NOT
  399.             // BREAK WINDOWS. XXXAH we may want to use the color
  400.             // converter here.
  401.             if (returnVal != -1)
  402.                 _BltFromScratchToComposition(rDestRect, rSrcRect);
  403.          }
  404.          else if ((IsYUV(cidIn) &&
  405.                    (m_nCompositionSurfaceCID == CID_RGB565 ||
  406.                     m_nCompositionSurfaceCID == CID_RGB555) &&
  407.                    (dxDst > 2*dxSrc  ||
  408.                     dyDst > 2*dySrc))) // || bUseScratch)
  409.          {
  410.             HXxSize tempSize;
  411.             tempSize.cx = dxSrc;
  412.             tempSize.cy = dySrc;
  413.             CreateScratchSurface(m_nCompositionSurfaceCID, &tempSize);
  414.             UCHAR*  pScratchBits;
  415.             INT32   nScratchPitch;
  416.             ScratchLock(&pScratchBits, &nScratchPitch);
  417.             // if somehow scratch surface creation failed
  418.             if (!pScratchBits)
  419.             {
  420.                goto regularConvert;
  421.             }
  422.             returnVal = zm_pColorAcc->ColorConvert(
  423.                                          m_nCompositionSurfaceCID,
  424.                                          pScratchBits,
  425.                                          m_allocatedScratchSize.cx,
  426.                                          m_allocatedScratchSize.cy,
  427.                                          nScratchPitch,
  428.                                          rSrcRect.left, rSrcRect.top,
  429.                                          dxSrc, dySrc,
  430.                                          cidIn, pImageData,
  431.                                          pBitmapInfo->biWidth,
  432.                                          pBitmapInfo->biHeight,
  433.                                          pitchIn,
  434.                                          rSrcRect.left, rSrcRect.top,
  435.                                          dxSrc, dySrc);
  436.             ScratchUnlock(pScratchBits);
  437.             if (returnVal != -1)
  438.                 _BltFromScratchToComposition(rDestRect, rSrcRect);
  439.          }
  440.          else
  441. #endif /*_WORKAROUND_YUV_RGB_16BIT_HXCOLOR_BUG*/
  442.          {
  443.            regularConvert:
  444.             int nCompPitch = m_nCompositionPitch;
  445.             returnVal = zm_pColorAcc->ColorConvert(
  446.                                           m_nCompositionSurfaceCID,
  447.                                           m_pCompositionSurface,
  448.                                           m_allocatedCompositionSize.cx,
  449.                                           m_allocatedCompositionSize.cy,
  450.                                           nCompPitch,
  451.                                           rDestRect.left, rDestRect.top,
  452.                                           dxDst, dyDst,
  453.                                           cidIn,
  454.                                           pImageData, pBitmapInfo->biWidth,
  455.                                           pBitmapInfo->biHeight, pitchIn,
  456.                                           rSrcRect.left, rSrcRect.top, dxSrc, dySrc);
  457.             //XXXgfw this is weird. We only want to redraw the Dest
  458.             //Rect right? The src is mostly always zero..
  459.             if( !m_pSite->IsCompositionLocked() && returnVal != -1)
  460.                 _MinimalBlt(rSrcRect, rDestRect);
  461.          }
  462.       }
  463.       if (!returnVal)
  464.       {
  465.          retVal = HXR_OK;
  466.          ModifyBoundsRect(&rDestRect);
  467.       }
  468.    }
  469.    else
  470.    {
  471. #ifndef _WINDOWS
  472.       HX_ASSERT(!"Failed to get a color convertor!!!");
  473. #endif
  474.    }
  475.    return retVal;
  476. }
  477. void CBaseRootSurface::_MinimalBlt(HXxRect&, HXxRect&)
  478. {}
  479. void CBaseRootSurface::DrawFocusRect(int nSurfaceCID,
  480.                                      HXxSize *pSurfaceSize,
  481.                                      UCHAR *pVidMem,
  482.                                      CHXBaseSite* pSite)
  483. {
  484.     // Draw the focus for this site
  485.     HXBitmapInfoHeader info;
  486.     memset(&info, 0, sizeof(info));
  487. #ifdef _WIN32
  488.     BITMAPINFO bmiInfo;
  489.     memset(&bmiInfo, 0, sizeof(bmiInfo));
  490.     MakeBitmap(&bmiInfo, sizeof(info), nSurfaceCID,
  491.             pSurfaceSize->cx, pSurfaceSize->cy, NULL, 0);
  492.     info = *((HXBitmapInfoHeader*)&bmiInfo.bmiHeader);
  493. #else
  494.     HXBitmapInfo bmiInfo;
  495.     memset(&bmiInfo, 0, sizeof(bmiInfo));
  496.     MakeBitmap(&bmiInfo, sizeof(info), nSurfaceCID,
  497.             pSurfaceSize->cx, pSurfaceSize->cy, NULL, 0);
  498.     info = *((HXBitmapInfoHeader*)&bmiInfo.bmiHeader);
  499. #endif
  500.     HXxRect rc = {0,0,pSurfaceSize->cx, pSurfaceSize->cy};
  501.     pSite->_DrawFocusRect(pVidMem,
  502.                           &info,
  503.                           &rc);
  504. }
  505. HX_RESULT CBaseRootSurface::Lock(UINT32 nID)
  506. {
  507.    m_pMutex->Lock();
  508.    HX_RESULT retVal = HXR_FAIL;
  509.    switch (m_nBLTMode)
  510.    {
  511.       case HX_WINDOWLESS_DEBUG:
  512.          retVal = HXR_OK;
  513.          break;
  514.       case HX_WINDOWLESS_MINIMAL:
  515.          retVal = MinimalLock();
  516.          break;
  517.    }
  518.    if (HXR_OK != retVal)
  519.    {
  520.       m_pMutex->Unlock();
  521.    }
  522.    return retVal;
  523. }
  524. HX_RESULT CBaseRootSurface::Unlock(UINT32 nID, HXxWindow* pWindow, CHXBaseSite* pSite)
  525. {
  526.    HX_RESULT retVal = HXR_FAIL;
  527.    m_pUnlockingSite = pSite;
  528.    switch (m_nBLTMode)
  529.    {
  530.       case HX_WINDOWLESS_DEBUG:
  531.          retVal = HXR_OK;
  532.          break;
  533.       case HX_WINDOWLESS_MINIMAL:
  534.          retVal = MinimalUnlock(pWindow);
  535.          break;
  536.    }
  537.    m_pUnlockingSite = NULL;
  538.    m_pMutex->Unlock();
  539.    return retVal;
  540. }
  541. HX_RESULT CBaseRootSurface::MinimalUnlock(HXxWindow* pWindow)
  542. {
  543.    // XXXAH yeah I know this sucks, but the call is ALL OS services.
  544.     HX_RESULT retVal = HXR_OK;
  545.     retVal = _MinimalUnlock(pWindow);
  546. //     m_pCompositionSurface   = 0;
  547. //     m_nCompositionPitch     = 0;
  548.    return retVal;
  549. }
  550. HX_RESULT CBaseRootSurface::MinimalLock()
  551. {
  552.    HX_RESULT retVal = HXR_FAIL;
  553.    HXxSize size;
  554.    memcpy(&size, &m_pSite->m_size, sizeof(HXxSize)); /* Flawfinder: ignore */
  555.     if (HXR_OK == SizeChanged())
  556.     {
  557.         if (HXR_OK == _LockComposition(&m_pCompositionSurface, &m_nCompositionPitch))
  558.         {
  559.             m_boundsRect.left   = 65536;
  560.             m_boundsRect.top    = 65536;
  561.             m_boundsRect.right  = 0;
  562.             m_boundsRect.bottom = 0;
  563.             retVal = HXR_OK;
  564.             while(m_pBltRects.GetCount())
  565.             {
  566.                 HXxRect* pRect = (HXxRect*) m_pBltRects.RemoveHead();
  567.                 HX_DELETE(pRect);
  568.             }
  569.             HX_ASSERT(m_pCompositionSurface);
  570.         }
  571.     }
  572.     return retVal;
  573. }
  574. void CBaseRootSurface::ModifyBoundsRect(HXxRect* pRect)
  575. {
  576.     if (pRect->left < m_boundsRect.left)
  577.     {
  578.       m_boundsRect.left = pRect->left;
  579.     }
  580.     if (pRect->top < m_boundsRect.top)
  581.     {
  582.       m_boundsRect.top = pRect->top;
  583.     }
  584.     if (pRect->right > m_boundsRect.right)
  585.     {
  586.       m_boundsRect.right= pRect->right;
  587.     }
  588.     if (pRect->bottom > m_boundsRect.bottom)
  589.     {
  590.       m_boundsRect.bottom= pRect->bottom;
  591.     }
  592.     HXxRect* pTempRect = new HXxRect();
  593.     *pTempRect = *pRect;
  594.     m_pBltRects.AddHead(pTempRect);
  595. }
  596. HX_RESULT CBaseRootSurface::SizeChanged()
  597. {
  598.    m_pMutex->Lock();
  599.    m_pCompMutex->Lock();
  600.    HX_RESULT retVal = HXR_FAIL;
  601.    HX_ASSERT(m_pSite);
  602.    memcpy(&m_compositionSize, &m_pSite->m_size, sizeof(HXxSize)); /* Flawfinder: ignore */
  603.    if (!m_bCompositionSurfaceCreated ||
  604.        (m_compositionSize.cx > m_allocatedCompositionSize.cx ||
  605.         m_compositionSize.cy > m_allocatedCompositionSize.cy)
  606.        )
  607.    {
  608.       if(HXR_OK == _DestroyCompositionSurface())
  609.       {
  610.          if(HXR_OK == _CreateCompositionSurface())
  611.          {
  612.             retVal = HXR_OK;
  613.          }
  614.       }
  615.    }
  616.    else
  617.    {
  618.       retVal = HXR_OK;
  619.    }
  620.    m_pCompMutex->Unlock();
  621.    m_pMutex->Unlock();
  622.    return retVal;
  623. }
  624. void CBaseRootSurface::LockCompMutex()
  625. {
  626.     if( m_pCompMutex)
  627.         m_pCompMutex->Lock();
  628. }
  629. void CBaseRootSurface::UnlockCompMutex()
  630. {
  631.     if(m_pCompMutex)
  632.         m_pCompMutex->Unlock();
  633. }
  634. void CBaseRootSurface::DestroySurfaces()
  635. {
  636.     m_pCompMutex->Lock();
  637.    _DestroyCompositionSurface();
  638.    m_pCompMutex->Unlock();
  639. }
  640. void CBaseRootSurface::ReInitSurfaces()
  641. {
  642.     m_pCompMutex->Lock();
  643.     if(HXR_OK == _DestroyCompositionSurface())
  644.     {
  645.         _CreateCompositionSurface();
  646.     }
  647.     m_pCompMutex->Unlock();
  648. }
  649. void CBaseRootSurface::FillBorders()
  650. {
  651.    _FillBorders();
  652. }
  653. void CBaseRootSurface::SetBltLock(BOOL bSet)
  654. {
  655.    //XXXgfw what does this do???? It just returns on windows????
  656. }
  657. BOOL CBaseRootSurface::IsCompositionEnabled()
  658. {
  659.    return m_bCompositionSurfaceCreated;
  660. }
  661. STDMETHODIMP CBaseRootSurface::BeginOptimizedBlt(HXBitmapInfoHeader* pBitmapInfo)
  662. {
  663. #ifdef _DEBUG
  664.    fprintf( stderr, "CBaseRootSurface::BeginOptimizedBlt needs to be written...n" );
  665. #endif
  666.    return HXR_NOTIMPL;
  667. }
  668. BOOL CBaseRootSurface::_OptimizedSurfaceOpened()
  669.    {
  670.        return TRUE;
  671.    }
  672. STDMETHODIMP CBaseRootSurface::OptimizedBlt( UCHAR* pImageBits,
  673.                                              REF(HXxRect) rDestRect,
  674.                                              REF(HXxRect) rSrcRect)
  675. {
  676. #ifdef _DEBUG
  677.    fprintf( stderr, "CBaseRootSurface::OptimizedBlt needs to be written...n" );
  678. #endif
  679.    return HXR_NOTIMPL;
  680. }
  681. STDMETHODIMP CBaseRootSurface::EndOptimizedBlt(void)
  682. {
  683. #ifdef _DEBUG
  684.    fprintf( stderr, "CBaseRootSurface::EndOptimizedBlt needs to be written...n" );
  685. #endif
  686.    return HXR_NOTIMPL;
  687. }
  688. STDMETHODIMP CBaseRootSurface::GetOptimizedFormat(REF(HX_COMPRESSION_TYPE) ulType)
  689. {
  690. #ifdef _DEBUG
  691.    fprintf( stderr, "CBaseRootSurface::GetOptimizedFormat needs to be written...n" );
  692. #endif
  693.    return HXR_NOTIMPL;
  694. }
  695. STDMETHODIMP CBaseRootSurface::GetPreferredFormat(REF(HX_COMPRESSION_TYPE) ulType)
  696. {
  697. #ifdef _DEBUG
  698.    fprintf( stderr, "CBaseRootSurface::GetPreferredFormat needs to be written...n" );
  699. #endif
  700.    return HXR_NOTIMPL;
  701. }
  702. void CBaseRootSurface::SetResolution( int x, int y, int depth, void* pWindow)
  703. {
  704.    HX_ASSERT( "Must override"==NULL );
  705. }
  706. void CBaseRootSurface::GetDisplayModes( CModesDesc* pModesDesc, INT32* nNumModes )
  707. {
  708.    HX_ASSERT( "Must override"==NULL );
  709. }
  710. BOOL CBaseRootSurface::_RectOnNthMonitor(HXxRect rect, UINT32 uMonitor, HXxRect& intersectRect)
  711. {
  712.     // until multiple monitor support exists, simply return the original rect.
  713.     // Override, if appropriate, in the platform-specific code.
  714.     intersectRect = rect;
  715.     return TRUE;
  716. }
  717. BOOL CBaseRootSurface::_IsHardwareAccelerationAvail()
  718. {
  719.     return FALSE;
  720. }
  721. BOOL CBaseRootSurface::_AcquireHardwareAcceleration()
  722. {
  723.     return FALSE;
  724. }
  725. BOOL CBaseRootSurface::_LoseHardwareAcceleration()
  726. {
  727.     return FALSE;
  728. }
  729. BOOL CBaseRootSurface::_EnableHardwareAcceleration()
  730. {
  731.     return FALSE;
  732. }
  733. BOOL CBaseRootSurface::_DisableHardwareAcceleration()
  734. {
  735.     return FALSE;
  736. }
  737. #ifdef _WINDOWS
  738. IHXPlayer* CBaseRootSurface::GetPlayer()
  739. {
  740.    if (!m_pPlayer)
  741.    {
  742.        IHXClientEngineMapper* pCleng = NULL;
  743.        m_pContext->QueryInterface(IID_IHXClientEngineMapper, (void**)&pCleng);
  744.        if (pCleng)
  745.        {
  746.             IUnknown* pUnknown = NULL;
  747.     if (HXR_OK != pCleng->GetPlayerBySite(m_pSite, pUnknown))
  748.             {
  749.                 // check our children
  750.                 CHXMapPtrToPtr::Iterator i = m_pSite->m_ChildrenMap.Begin();
  751.                 for ( ; i != m_pSite->m_ChildrenMap.End(); ++i)
  752.                 {
  753.                     CHXBaseSite* pSite = (CHXBaseSite*) *i;
  754.             if (HXR_OK == pCleng->GetPlayerBySite(pSite, pUnknown))
  755.                         break;
  756.                 }
  757.             }
  758.             if (pUnknown)
  759.             {
  760.         pUnknown->QueryInterface(IID_IHXPlayer, (void**)&m_pPlayer);
  761.         HX_RELEASE(pUnknown);
  762.             }
  763.        }
  764.    }
  765.    return m_pPlayer;
  766. }
  767. #endif