baseroot.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:27k
源码类别:

Symbian

开发平台:

Visual C++

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