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

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: minisymbiansurf.cpp,v 1.21.2.2 2004/07/09 01:59:11 hubbe 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 "minisite.h"
  50. #include "hxvsurf.h"
  51. #include "coloracc.h"
  52. #include "hxtick.h"
  53. #include "minisurf.h"
  54. #include "minisymbiansurf.h"
  55. #include "minisymbiansite.h"
  56. #include "minifmt.h"
  57. #include "nostatic/colorlib.h"
  58. #include <e32std.h>  //for User::InfoPrint()
  59. #include <eikenv.h> 
  60. #include <eikdef.h> 
  61. #include <gdi.h> 
  62. #include <fbs.h> 
  63. CMiniSymbianSurface::CMiniSymbianSurface(IUnknown* pContext, CMiniBaseSite* pSite)
  64.     :  CMiniBaseSurface(pContext, pSite),
  65.        m_nCompositionPitch(0),
  66.        m_pGC(NULL),
  67.        m_pBitMap(NULL),
  68.        m_DisplayMode(EColor4K),
  69.        m_pBS(NULL),
  70.        m_ulLastResetTime(0)
  71. {
  72.     memset(&m_surfaceSize, 0, sizeof(m_surfaceSize) );
  73.     memset(&m_ColorData, 0, sizeof(m_ColorData) );
  74. }
  75. CMiniSymbianSurface::~CMiniSymbianSurface()
  76. {
  77.     m_nCompositionPitch = 0;
  78.     memset(&m_surfaceSize, 0, sizeof( m_surfaceSize ) );
  79.     HX_DELETE(m_pBitMap);
  80.     if( m_pBS )
  81.         m_pBS->Disconnect();
  82.     HX_DELETE(m_pBS); 
  83. }
  84. color_data_t* CMiniSymbianSurface::GetColorData()
  85. {
  86.     return &m_ColorData;
  87. }
  88. HX_RESULT CMiniSymbianSurface::_CreateDestBuffer( int cidIn,
  89.                                                   int nWidth,
  90.                                                   int nHeight,
  91.                                                   int& nCount)
  92. {
  93.     
  94.     HX_ASSERT( m_pSite );
  95.     m_surfaceSize.cx = nWidth;
  96.     m_surfaceSize.cy = nHeight;
  97.     //Get our GC, and Region.
  98.     m_DisplayMode = EColor4K; //hardcoded for emulator right now.
  99.     HX_RESULT retVal = HXR_OK;
  100.     if( m_pImageHelper )
  101.     {
  102.         HXBitmapInfo bmiTemp;
  103.         m_pImageHelper->MakeBitmap( &bmiTemp,
  104.                                     sizeof(bmiTemp),
  105.                                     CID_RGB444,
  106.                                     m_surfaceSize.cx,
  107.                                     m_surfaceSize.cy,
  108.                                     NULL,
  109.                                     0);
  110.         m_nCompositionPitch = m_pImageHelper->GetBitmapPitch(&bmiTemp); 
  111.         HX_ASSERT( m_pImageHelper->GetBitmapColor(&bmiTemp) == CID_RGB444 ); 
  112.     }
  113.     else
  114.     {
  115.         retVal = HXR_OUTOFMEMORY;
  116.     }
  117.     //Create our bitmap.
  118.     if( !m_pBS )
  119.     {
  120.         m_pBS = new RFbsSession();
  121.         if(!m_pBS)
  122.         {
  123.             retVal = HXR_OUTOFMEMORY;
  124.         }
  125.         else
  126.         {
  127.             m_pBS->Connect();
  128.         }
  129.     }
  130.     HX_ASSERT(m_pBS);
  131.     if( retVal == HXR_OK )
  132.     {
  133.         HX_ASSERT(!m_pBitMap);
  134.         HX_DELETE(m_pBitMap);
  135.         m_pBitMap = new CFbsBitmap();
  136.         HX_ASSERT(m_pBitMap);
  137.         if(!m_pBitMap)
  138.         {
  139.             retVal = HXR_OUTOFMEMORY;
  140.         }
  141.         else
  142.         {
  143.             TInt err = m_pBitMap->Create(TSize(m_surfaceSize.cx,m_surfaceSize.cy), m_DisplayMode);
  144.             HX_ASSERT( err == KErrNone );
  145.             
  146.             if( err != KErrNone )
  147.             {
  148.                 retVal = HXR_OUTOFMEMORY;
  149.             }
  150.         }
  151.     }
  152.     HX_ASSERT(retVal==HXR_OK);
  153.     if( FAILED(retVal) )
  154.     {
  155.         if( m_pBS )
  156.         {
  157.             m_pBS->Disconnect();
  158.         }
  159.         HX_DELETE(m_pBS);
  160.         HX_DELETE(m_pBitMap);
  161.     }
  162.     return retVal;
  163. }
  164. HX_RESULT CMiniSymbianSurface::_LockDestBuffer( UCHAR** ppDestPtr,
  165.                                                 LONG32* pnDestPitch,
  166.                                                 int& cid,
  167.                                                 REF(HXxSize) srcSize,
  168.                                                 int nIndex)
  169. {
  170.     HX_RESULT res = HXR_OK;
  171.     HX_ASSERT(m_pBitMap != 0);
  172.     *ppDestPtr   = (UCHAR*)m_pBitMap->DataAddress();
  173.     *pnDestPitch = m_nCompositionPitch;
  174.     cid          = CID_RGB444;
  175.     return res;
  176. }
  177.          
  178. HX_RESULT CMiniSymbianSurface::_TransferToDestBuffer( UCHAR*   pSrcBuffer,
  179.                                                       HXBitmapInfoHeader* pBitmapInfo,
  180.                                                       HXxRect* prSrcRect,
  181.                                                       HXxRect* prDstRect,
  182.                                                       UCHAR*   pDstBuffer,
  183.                                                       LONG32   nDstPitch)
  184. {
  185.     HX_RESULT res = HXR_OK;
  186.     res =  CMiniBaseSurface::_TransferToDestBuffer( pSrcBuffer,
  187.                                                     pBitmapInfo,
  188.                                                     prSrcRect,
  189.                                                     prDstRect,
  190.                                                     pDstBuffer,
  191.                                                     nDstPitch);
  192.     HX_ASSERT(res == HXR_OK);
  193.     
  194.     return res;
  195. }
  196.          
  197. HX_RESULT CMiniSymbianSurface::_UnlockDestBuffer(UCHAR* pSurfPtr, int nIndex)
  198. {
  199.     //Nothing to do here for symbian.....
  200.     return HXR_OK;
  201. }
  202.          
  203. HX_RESULT CMiniSymbianSurface::_RenderDestBuffer( HXxRect* prSrcRect,
  204.                                                   HXxRect* prDestRect,
  205.                                                   int nIndex)
  206. {
  207.     HXxWindow* pHXWin  = m_pSite->GetWindow();
  208.     RWindow*   pWin    = (RWindow*)pHXWin->window;
  209.     TPoint     topleft = pWin->Position();
  210.     HX_RESULT  res     = HXR_OK;
  211.     HXxPoint   point;
  212.     RRegion*   clipReg = NULL;
  213.     CDirectScreenAccess* pDirectScreen = pHXWin->iDSA;
  214.     
  215.     HX_ASSERT(m_pSite);
  216. #if defined(HELIX_FEATURE_SMIL_SITE)    
  217.     point = *(m_pSite->GetOrigin());
  218. #else
  219.     m_pSite->GetPosition(point);
  220. #endif    
  221.     
  222.     //Force an update. This is required for WINS but it may not
  223.     //be needed on all hardware. It *is* needed for Nokia 3650.
  224.     CFbsScreenDevice*& pSD = pDirectScreen->ScreenDevice();
  225.     if( pSD )
  226.     {
  227.         m_pGC     = pDirectScreen->Gc();
  228.         clipReg   = pDirectScreen->DrawingRegion();
  229.         if( clipReg )
  230.         {
  231.             
  232. #if defined(HELIX_FEATURE_SMIL_SITE)
  233.             //Generate a TRegion from our site's region and only blt to the
  234.             //intersection of the two.
  235.             RRegion trTmp;
  236.             HXREGION* reg = m_pSite->GetRegion();
  237.             if( !HXEmptyRegion(reg))
  238.             {
  239.                 //Add each rectangle...
  240.                 for(int i =0; i< reg->numRects; i++)
  241.                 {
  242.                     TRect rect( reg->rects[i].x1+topleft.iX,
  243.                                 reg->rects[i].y1+topleft.iY,
  244.                                 reg->rects[i].x2+topleft.iX,
  245.                                 reg->rects[i].y2+topleft.iY
  246.                                 );
  247.                     trTmp.AddRect(rect);
  248.                 }
  249.                 trTmp.Intersect(*clipReg);
  250.             }
  251.             clipReg = &trTmp;
  252. #endif    
  253.             m_pGC->SetClippingRegion(clipReg); 
  254.             m_pGC->BitBlt(TPoint(point.x, point.y), m_pBitMap );
  255.             pSD->Update();
  256. #if defined(HELIX_FEATURE_SMIL_SITE)
  257.             trTmp.Close();
  258. #endif            
  259.         }
  260.     }
  261.     
  262.     return res;
  263. }
  264. void CMiniSymbianSurface::_KeepScreenAlive()
  265. {
  266.     ULONG32 ulNow = HX_GET_TICKCOUNT();
  267.     //While we are BLT'ing video frames make sure the screen doesn't
  268.     //dim on us. Do this every 10 seconds for now.
  269.     //XXXGfw need to query the timeout and base the calls on that #.
  270.     if( ulNow-m_ulLastResetTime > 10*1000)
  271.     {
  272.         User::ResetInactivityTime();
  273.         m_ulLastResetTime = ulNow;
  274.     }
  275. }
  276. HX_RESULT CMiniSymbianSurface::_DestroyDestBuffer(int cid, int nCount)
  277. {
  278.     HX_DELETE(m_pBitMap);
  279.     m_nCompositionPitch   = 0;
  280.     return HXR_OK;
  281. }
  282. int CMiniSymbianSurface::GetDstCID(int nIndex)
  283. {
  284.     //XXXgfw need more intelligent detection of screen depth.
  285.     return CID_RGB444;
  286. }