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

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