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

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 "minisite.h"
  36. #include "macblt.h"
  37. #include "coloracc.h"
  38. #if defined (HELIX_FEATURE_OPTIMIZED_VIDEO)
  39. #include "macyuvblt.h"
  40. #endif //HELIX_FEATURE_OPTIMIZED_VIDEO
  41. #if defined (HELIX_FEATURE_GDI_VIDEO)
  42. #include "macrgbblt.h"
  43. #endif //HELIX_FEATURE_GDI_VIDEO
  44. #include "minisurf.h"
  45. #include "mmacsurf.h"
  46. #define GET_OS_WINDOW() (HWND)(m_pSite->GetWindow()->window)
  47. CMiniMacSurface::CMiniMacSurface(IUnknown* pContext, CMiniBaseSite* pSite)
  48.  :  CMiniBaseSurface(pContext, pSite)
  49.  ,  m_pBlt(NULL)
  50.  ,  m_pRGBBlt(NULL)
  51.  ,  m_pYUVBlt(NULL)
  52. {
  53. }
  54. CMiniMacSurface::~CMiniMacSurface()
  55. {
  56.     _DestroyDestBuffer(0);
  57. }
  58. HX_RESULT CMiniMacSurface::_CreateDestBuffer(int cidIn,
  59.                                              int nWidth, int nHeight,
  60.                                              int& nCount)
  61. {
  62.     HX_RESULT hr = HXR_FAIL;
  63.     int cidOut;
  64.     int nCountIn = nCount;
  65.     // Try to create optimized surfaces and if it fails,
  66.     // try gdi.
  67.     for (int i=0; i<2; i++)
  68.     {
  69. #if defined (HELIX_FEATURE_OPTIMIZED_VIDEO)
  70.         // Only try optimized yuv the first time
  71.         if (i == 0 &&
  72.             !m_pBlt && 
  73.             !m_pYUVBlt)
  74.         {
  75.             m_pYUVBlt = new CMacYUVBlt();
  76.             m_pBlt = m_pYUVBlt;
  77.         }
  78. #endif //HELIX_FEATURE_OPTIMIZED_VIDEO
  79. #if defined (HELIX_FEATURE_GDI_VIDEO)
  80.         if (!m_pBlt && !m_pRGBBlt)
  81.         {
  82.             m_pRGBBlt = new CMacRGBBlt();
  83.             m_pBlt = m_pRGBBlt;
  84.         }
  85. #endif //HELIX_FEATURE_GDI_VIDEO
  86.     
  87.         if (m_pBlt)
  88.         {
  89.             hr =  m_pBlt->CreateSurface(cidIn, cidOut,
  90.                                         nWidth,nHeight,
  91.                                         0, GET_OS_WINDOW(),
  92.                                         nCountIn, nCount);
  93.         }
  94.         if (SUCCEEDED(hr))
  95.         {
  96.             break;
  97.         }
  98.         else
  99.         {
  100.             _DestroyDestBuffer(cidIn);
  101.         }
  102.     }
  103.     return hr;
  104. }
  105.   
  106. HX_RESULT CMiniMacSurface::_LockDestBuffer(UCHAR** ppDestPtr,
  107.                                            LONG32* pnDestPitch,
  108.                                            int& cid,
  109.                                            REF(HXxSize) dstSize,
  110.                                            int nIndex)
  111. {
  112.     return m_pBlt->LockSurface(ppDestPtr, pnDestPitch,
  113.                                cid, dstSize, nIndex);
  114. }
  115. HX_RESULT CMiniMacSurface::_TransferToDestBuffer(UCHAR* pSrcBuffer,
  116.                                                  HXBitmapInfoHeader* pBitmapInfo,
  117.                                                  HXxRect* prSrcRect,
  118.                                                  HXxRect* prDstRect,
  119.                                                  UCHAR* pDstBuffer,
  120.                                                  LONG32 nDstPitch)
  121. {
  122.     HXxSize rSrcSize = {pBitmapInfo->biWidth, pBitmapInfo->biHeight};
  123.     HX_RESULT hr = 
  124.     m_pBlt->FillSurface(m_nSrcCID,
  125.                         pSrcBuffer, &rSrcSize,
  126.                         prSrcRect,                                                                          
  127.                         pDstBuffer, nDstPitch,
  128.                         prDstRect);
  129.     if (FAILED(hr))
  130.     {
  131.     return CMiniBaseSurface::_TransferToDestBuffer(pSrcBuffer,
  132.                                                    pBitmapInfo,
  133.                                                    prSrcRect,
  134.                                                    prDstRect,
  135.                                                    pDstBuffer,
  136.                                                    nDstPitch);
  137.     }
  138.     return hr;
  139. }
  140. HX_RESULT CMiniMacSurface::_UnlockDestBuffer(UCHAR* pSurfPtr, int nIndex)
  141. {
  142.     return m_pBlt->UnlockSurface(pSurfPtr, nIndex);
  143. }
  144. HX_RESULT CMiniMacSurface::_RenderDestBuffer(HXxRect* prSrcRect,
  145.                                              HXxRect* prDstRect,
  146.                                              int nIndex)
  147. {
  148.     HX_RESULT hr = m_pBlt->RenderSurface(&m_dstBufSize,
  149.                                          prSrcRect,
  150.                                          prDstRect,
  151.                                          nIndex);
  152.     return hr;
  153. }
  154. HX_RESULT CMiniMacSurface::_DestroyDestBuffer(int cid, int nCount)
  155. {
  156.     HX_RESULT hr = HXR_OK;
  157.     
  158.     if (m_pBlt)
  159.     {
  160.         m_pBlt->DestroySurface(cid);
  161.         HX_DELETE(m_pRGBBlt);
  162.         HX_DELETE(m_pYUVBlt);
  163.         m_pBlt = NULL;
  164.     }
  165.     return hr;
  166. }
  167. int CMiniMacSurface::GetDstCID(int nIndex)
  168. {
  169.     return (m_pBlt ? m_pBlt->GetCID(nIndex) : CID_UNKNOWN);
  170. }