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

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
  36. #include "hxtypes.h"
  37. #include "hxwintyp.h"
  38. #include "hxcom.h"
  39. #include "hxwin.h"
  40. #include "hxevent.h"
  41. #include "hxvsurf.h"
  42. #include "ihxpckts.h"
  43. #include "hxcomm.h"
  44. #include "hxerror.h"
  45. #include "hlxclib/string.h"
  46. // pnmisc
  47. #include "hxtick.h"
  48. // smlrendr
  49. #include "siteuser.h"
  50. // pndebug
  51. #include "smlrmlog.h"
  52. #include "hxassert.h"
  53. #include "hxheap.h"
  54. #ifdef _DEBUG
  55. #undef HX_THIS_FILE
  56. static const char HX_THIS_FILE[] = __FILE__;
  57. #endif
  58. CSmilSiteUser::CSmilSiteUser(CSmilSiteUserResponse* pResponse,
  59.                              UINT32                 ulBackgroundColor,
  60.                              IUnknown*              pContext,
  61.                              BOOL                   bIsARoot,
  62.                              const char*            pszID)
  63. {
  64.     m_lRefCount                  = 0;
  65.     m_pResponse                  = pResponse;
  66.     m_ulBackgroundColor          = ulBackgroundColor;
  67.     m_bIsARoot                   = bIsARoot;
  68.     m_pSite                      = NULL;
  69.     m_pValues                    = NULL;
  70.     m_pszID                      = NULL;
  71.     m_ulLastMediaEndOverrideTime = 0;
  72.     m_pErrorMessages             = NULL;
  73.     m_pBitmapInfoHeader          = NULL;
  74.     m_pucBuffer                  = NULL;
  75.     m_ulLastBackgroundColor      = 0;
  76.     
  77.     HX_ASSERT(m_pResponse);
  78.     if (m_pResponse)
  79.     {
  80.         m_pResponse->AddRef();
  81.     }
  82.     if (pContext)
  83.     {
  84.         IHXCommonClassFactory* pFact = NULL;
  85.         pContext->QueryInterface(IID_IHXCommonClassFactory, (void**) &pFact);
  86.         if (pFact)
  87.         {
  88.             pFact->CreateInstance(CLSID_IHXValues, (void**) &m_pValues);
  89.         }
  90.         HX_RELEASE(pFact);
  91.         // QI for IHXErrorMessages - ok if we don't get it
  92.         pContext->QueryInterface(IID_IHXErrorMessages,
  93.                                  (void**) &m_pErrorMessages);
  94.     }
  95.     if (pszID)
  96.     {
  97.         m_pszID = new char [strlen(pszID) + 1];
  98.         if (m_pszID)
  99.         {
  100.             strcpy(m_pszID, pszID); /* Flawfinder: ignore */
  101.         }
  102.     }
  103.     // Allocate an HXBitmapInfoHeader
  104.     m_pBitmapInfoHeader = new HXBitmapInfoHeader;
  105.     if (m_pBitmapInfoHeader)
  106.     {
  107.         // Set up all the values
  108.         m_pBitmapInfoHeader->biSize          = 40;
  109.         m_pBitmapInfoHeader->biWidth         = 0;
  110.         m_pBitmapInfoHeader->biHeight        = 0;
  111.         m_pBitmapInfoHeader->biPlanes        = 1;
  112.         m_pBitmapInfoHeader->biBitCount      = 32;
  113.         m_pBitmapInfoHeader->biCompression   = HX_RGB;
  114.         m_pBitmapInfoHeader->biSizeImage     = 0;
  115.         m_pBitmapInfoHeader->biXPelsPerMeter = 0;
  116.         m_pBitmapInfoHeader->biYPelsPerMeter = 0;
  117.         m_pBitmapInfoHeader->biClrUsed       = 0;
  118.         m_pBitmapInfoHeader->biClrImportant  = 0;
  119.         m_pBitmapInfoHeader->rcolor          = 0;
  120.         m_pBitmapInfoHeader->gcolor          = 0;
  121.         m_pBitmapInfoHeader->bcolor          = 0;
  122.     }
  123. }
  124. CSmilSiteUser::~CSmilSiteUser()
  125. {
  126.     Close();
  127. }
  128. STDMETHODIMP CSmilSiteUser::QueryInterface(REFIID riid, void** ppvObj)
  129. {
  130.     HX_RESULT retVal = HXR_OK;
  131.     if(IsEqualIID(riid, IID_IUnknown))
  132.     {
  133.         AddRef();
  134.         *ppvObj = (IUnknown*) (IHXSiteUser*) this;
  135.     }
  136.     else if(IsEqualIID(riid, IID_IHXSiteUser))
  137.     {
  138.         AddRef();
  139.         *ppvObj = (IHXSiteUser*) this;
  140.     }
  141.     else if(IsEqualIID(riid, IID_IHXValues))
  142.     {
  143.         AddRef();
  144.         *ppvObj = (IHXValues*) this;
  145.     }
  146.     else
  147.     {
  148.         *ppvObj = NULL;
  149.         retVal  = HXR_NOINTERFACE;
  150.     }
  151.     return retVal;
  152. }
  153. STDMETHODIMP_(ULONG32) CSmilSiteUser::AddRef()
  154. {
  155.     return InterlockedIncrement(&m_lRefCount);
  156. }
  157. STDMETHODIMP_(ULONG32) CSmilSiteUser::Release()
  158. {
  159.     if(InterlockedDecrement(&m_lRefCount) > 0)
  160.     {
  161.         return m_lRefCount;
  162.     }
  163.     delete this;
  164.     return 0;
  165. }
  166. STDMETHODIMP CSmilSiteUser::AttachSite(IHXSite* pSite)
  167. {
  168.     HX_RESULT retVal = HXR_OK;
  169.     if (pSite && !m_pSite)
  170.     {
  171.         // Save the site
  172.         m_pSite = pSite;
  173.         m_pSite->AddRef();
  174.         
  175.         // See if we have a new site that supports sub rects.
  176.         IHXSubRectSite* pSubRectSite = NULL;
  177.         m_pSite->QueryInterface(IID_IHXSubRectSite, (void**) &pSubRectSite);
  178.         if(pSubRectSite)
  179.         {
  180.             // If so, since IHXSubRectSite inheirits from IHXSite, lets just
  181.             // swap the pointers and sign up for the service.
  182.             HX_RELEASE(m_pSite);
  183.             m_pSite = pSubRectSite;
  184.             pSubRectSite->SendSubRectMessages(TRUE);
  185.         }
  186.         // Call back to the response interface
  187.         if (m_pResponse)
  188.         {
  189.             retVal = m_pResponse->SiteUserAttachSite(this, m_pSite);
  190.         }
  191.     }
  192.     return retVal;
  193. }
  194. STDMETHODIMP CSmilSiteUser::DetachSite()
  195. {
  196.     HX_RESULT retVal = HXR_OK;
  197.     // Calling SiteUserDetachSite() may result in
  198.     // one of our own refs being released. Therefore,
  199.     // we will call AddRef() on ourselves until
  200.     // this method is finished.
  201.     AddRef();
  202.     // Call back to the response interface FIRST, since
  203.     // one of the actions of the response interface may
  204.     // be to delete children of this site.
  205.     if (m_pResponse)
  206.     {
  207.         retVal = m_pResponse->SiteUserDetachSite(this);
  208.     }
  209.     // Release the site
  210.     HX_RELEASE(m_pSite);
  211.     // Now we can safely release
  212.     Release();
  213.     return retVal;
  214. }
  215. STDMETHODIMP_(BOOL) CSmilSiteUser::NeedsWindowedSites()
  216. {
  217.     return FALSE;
  218. }
  219. STDMETHODIMP CSmilSiteUser::HandleEvent(HXxEvent* pEvent)
  220. {
  221.     HX_RESULT retVal = HXR_OK;
  222.     if (pEvent)
  223.     {
  224.         // Set defaults
  225.         pEvent->handled = FALSE;
  226.         pEvent->result  = HXR_OK;
  227.         // Switch based on event type
  228.         switch (pEvent->event)
  229.         {
  230.             case HX_SURFACE_UPDATE:
  231.                 {
  232.                     pEvent->result = SetupBuffer();
  233.                     if (SUCCEEDED(pEvent->result))
  234.                     {
  235.                         // Set up the src and dst rect
  236.                         HXxRect cSrcRect = {0,
  237.                                             0,
  238.                                             m_pBitmapInfoHeader->biWidth,
  239.                                             m_pBitmapInfoHeader->biHeight};
  240.                         HXxRect cDstRect = cSrcRect;
  241.                         // Do the blt
  242.                         IHXVideoSurface* pSurf = (IHXVideoSurface*) pEvent->param1;
  243.                         if(pSurf)
  244.                         {
  245.                             MLOG_LAYOUT(m_pErrorMessages,
  246.                                         "CSmilSiteUser::HandleEvent() HX_SURFACE_UPDATE "
  247.                                         "region=%s root=%lu tick=%lu color=0x%08xn",
  248.                                         m_pszID, m_bIsARoot, HX_GET_BETTERTICKCOUNT(), m_ulBackgroundColor);
  249.                             pSurf->AddRef();
  250.                             pEvent->result = pSurf->Blt(m_pucBuffer,
  251.                                                         m_pBitmapInfoHeader,
  252.                                                         cDstRect,
  253.                                                         cSrcRect);
  254.                             pSurf->Release();
  255.                             if (SUCCEEDED(pEvent->result))
  256.                             {
  257.                                 pEvent->handled = TRUE;
  258.                             }
  259.                         }
  260.                     }
  261.                 }
  262.                 break;
  263.             case HX_SURFACE_UPDATE2:
  264.                 {
  265.                     pEvent->result = SetupBuffer();
  266.                     if (SUCCEEDED(pEvent->result))
  267.                     {
  268.                         // Get the video surface and the expose info
  269.                         IHXSubRectVideoSurface* pSurf   = (IHXSubRectVideoSurface*) pEvent->param1;
  270.                         HXxExposeInfo*           pExpose = (HXxExposeInfo*) pEvent->param2;
  271.                         // Since there is no scaling, our SRC and DEST rects
  272.                         // are all the same. Since that is the case we can
  273.                         // just pass the rect pointer from the Expose event
  274.                         // into the BLT call.
  275.                         if (pSurf && pExpose)
  276.                         {
  277.                             MLOG_LAYOUT(m_pErrorMessages,
  278.                                         "CSmilSiteUser::HandleEvent() HX_SURFACE_UPDATE2 "
  279.                                         "region=%s root=%lu tick=%lu color=0x%08xn",
  280.                                         m_pszID, m_bIsARoot, HX_GET_BETTERTICKCOUNT(), m_ulBackgroundColor);
  281.                             pSurf->AddRef();
  282.                             pEvent->result = pSurf->BltSubRects(m_pucBuffer,
  283.                                                                 m_pBitmapInfoHeader,
  284.                                                                 pExpose->pRegion,
  285.                                                                 pExpose->pRegion, 1.0, 1.0);
  286.                             pSurf->Release();
  287.                             if (SUCCEEDED(pEvent->result))
  288.                             {
  289.                                 pEvent->handled = TRUE;
  290.                             }
  291.                         }
  292.                     }
  293.                 }
  294.                 break;
  295.             default:
  296.                 break;
  297.         }
  298.         // If we have not handled the event, then pass it
  299.         // on to the response interface
  300.         if (!pEvent->handled && m_pResponse)
  301.         {
  302.             m_pResponse->SiteUserHandleEvent(this, pEvent);
  303.         }
  304.     }
  305.     return retVal;
  306. }
  307. STDMETHODIMP CSmilSiteUser::SetPropertyULONG32(const char* pName, ULONG32 ulVal)
  308. {
  309.     HX_RESULT retVal = HXR_FAIL;
  310.     if (m_pValues)
  311.     {
  312.         retVal = m_pValues->SetPropertyULONG32(pName, ulVal);
  313.     }
  314.     return retVal;
  315. }
  316. STDMETHODIMP CSmilSiteUser::GetPropertyULONG32(const char* pName, REF(ULONG32) rulVal)
  317. {
  318.     HX_RESULT retVal = HXR_FAIL;
  319.     if (m_pValues)
  320.     {
  321.         retVal = m_pValues->GetPropertyULONG32(pName, rulVal);
  322.     }
  323.     return retVal;
  324. }
  325. STDMETHODIMP CSmilSiteUser::GetFirstPropertyULONG32(REF(const char*) rpName, REF(ULONG32) rulVal)
  326. {
  327.     HX_RESULT retVal = HXR_FAIL;
  328.     if (m_pValues)
  329.     {
  330.         retVal = m_pValues->GetFirstPropertyULONG32(rpName, rulVal);
  331.     }
  332.     return retVal;
  333. }
  334. STDMETHODIMP CSmilSiteUser::GetNextPropertyULONG32(REF(const char*) rpName, REF(ULONG32) rulVal)
  335. {
  336.     HX_RESULT retVal = HXR_FAIL;
  337.     if (m_pValues)
  338.     {
  339.         retVal = m_pValues->GetNextPropertyULONG32(rpName, rulVal);
  340.     }
  341.     return retVal;
  342. }
  343. STDMETHODIMP CSmilSiteUser::SetPropertyBuffer(const char* pName, IHXBuffer* pVal)
  344. {
  345.     HX_RESULT retVal = HXR_FAIL;
  346.     if (m_pValues)
  347.     {
  348.         retVal = m_pValues->SetPropertyBuffer(pName, pVal);
  349.     }
  350.     return retVal;
  351. }
  352. STDMETHODIMP CSmilSiteUser::GetPropertyBuffer(const char* pName, REF(IHXBuffer*) rpVal)
  353. {
  354.     HX_RESULT retVal = HXR_FAIL;
  355.     if (m_pValues)
  356.     {
  357.         retVal = m_pValues->GetPropertyBuffer(pName, rpVal);
  358.     }
  359.     return retVal;
  360. }
  361. STDMETHODIMP CSmilSiteUser::GetFirstPropertyBuffer(REF(const char*) rpName, REF(IHXBuffer*) rpVal)
  362. {
  363.     HX_RESULT retVal = HXR_FAIL;
  364.     if (m_pValues)
  365.     {
  366.         retVal = m_pValues->GetFirstPropertyBuffer(rpName, rpVal);
  367.     }
  368.     return retVal;
  369. }
  370. STDMETHODIMP CSmilSiteUser::GetNextPropertyBuffer(REF(const char*) rpName, REF(IHXBuffer*) rpVal)
  371. {
  372.     HX_RESULT retVal = HXR_FAIL;
  373.     if (m_pValues)
  374.     {
  375.         retVal = m_pValues->GetNextPropertyBuffer(rpName, rpVal);
  376.     }
  377.     return retVal;
  378. }
  379. STDMETHODIMP CSmilSiteUser::SetPropertyCString(const char* pName, IHXBuffer* pVal)
  380. {
  381.     HX_RESULT retVal = HXR_FAIL;
  382.     if (m_pValues)
  383.     {
  384.         retVal = m_pValues->SetPropertyCString(pName, pVal);
  385.     }
  386.     return retVal;
  387. }
  388. STDMETHODIMP CSmilSiteUser::GetPropertyCString(const char* pName, REF(IHXBuffer*) rpVal)
  389. {
  390.     HX_RESULT retVal = HXR_FAIL;
  391.     if (m_pValues)
  392.     {
  393.         retVal = m_pValues->GetPropertyCString(pName, rpVal);
  394.     }
  395.     return retVal;
  396. }
  397. STDMETHODIMP CSmilSiteUser::GetFirstPropertyCString(REF(const char*) rpName, REF(IHXBuffer*) rpVal)
  398. {
  399.     HX_RESULT retVal = HXR_FAIL;
  400.     if (m_pValues)
  401.     {
  402.         retVal = m_pValues->GetFirstPropertyCString(rpName, rpVal);
  403.     }
  404.     return retVal;
  405. }
  406. STDMETHODIMP CSmilSiteUser::GetNextPropertyCString(REF(const char*) rpName, REF(IHXBuffer*) rpVal)
  407. {
  408.     HX_RESULT retVal = HXR_FAIL;
  409.     if (m_pValues)
  410.     {
  411.         retVal = m_pValues->GetNextPropertyCString(rpName, rpVal);
  412.     }
  413.     return retVal;
  414. }
  415. STDMETHODIMP CSmilSiteUser::SetBackgroundColor(UINT32 ulBackgroundColor)
  416. {
  417.     HX_RESULT retVal = HXR_OK;
  418.     m_ulBackgroundColor = ulBackgroundColor;
  419.     return retVal;
  420. }
  421. STDMETHODIMP_(UINT32) CSmilSiteUser::GetBackgroundColor()
  422. {
  423.     return m_ulBackgroundColor;
  424. }
  425. STDMETHODIMP CSmilSiteUser::Close()
  426. {
  427.     HX_RESULT retVal = HXR_OK;
  428.     if (m_pResponse)
  429.     {
  430.         m_pResponse->Release();
  431.         m_pResponse = NULL;
  432.     }
  433.     HX_RELEASE(m_pSite);
  434.     HX_RELEASE(m_pValues);
  435.     HX_VECTOR_DELETE(m_pszID);
  436.     HX_RELEASE(m_pErrorMessages);
  437.     HX_VECTOR_DELETE(m_pBitmapInfoHeader);
  438.     HX_VECTOR_DELETE(m_pucBuffer);
  439.     return retVal;
  440. }
  441. STDMETHODIMP_(UINT32) CSmilSiteUser::GetLastMediaEndOverrideTime()
  442. {
  443.     return m_ulLastMediaEndOverrideTime;
  444. }
  445. STDMETHODIMP CSmilSiteUser::SetLastMediaEndOverrideTime(UINT32 ulTime)
  446. {
  447.     m_ulLastMediaEndOverrideTime = ulTime;
  448.     return HXR_OK;
  449. }
  450. STDMETHODIMP CSmilSiteUser::Redraw()
  451. {
  452.     HX_RESULT retVal = HXR_FAIL;
  453.     if (m_pSite)
  454.     {
  455.         // Get the current site size
  456.         HXxSize cSize = {0, 0};
  457.         m_pSite->GetSize(cSize);
  458.         // Create a damage rect
  459.         HXxRect cRect = {0, 0, cSize.cx, cSize.cy};
  460.         m_pSite->DamageRect(cRect);
  461.         m_pSite->ForceRedraw();
  462.         // Clear the return value
  463.         retVal = HXR_OK;
  464.     }
  465.     return retVal;
  466. }
  467. HX_RESULT CSmilSiteUser::SetupBuffer()
  468. {
  469.     HX_RESULT retVal = HXR_FAIL;
  470.     if (m_pSite && m_pBitmapInfoHeader)
  471.     {
  472.         // Set the color we are going to blt
  473.         UINT32 ulColor = m_ulBackgroundColor;
  474.         // If we are a root, then force the 
  475.         // background color to be non-transparent
  476.         if (m_bIsARoot)
  477.         {
  478.             ulColor &= 0x00FFFFFF;
  479.         }
  480.         // Get the site's current size
  481.         HXxSize cSize = {0, 0};
  482.         m_pSite->GetSize(cSize);
  483.         // Make sure the site has non-zero dimensions
  484.         if (cSize.cx > 0 && cSize.cy > 0)
  485.         {
  486.             // Do we need to allocate a buffer?
  487.             BOOL bAllocated = FALSE;
  488.             if (!m_pucBuffer                              ||
  489.                 m_pBitmapInfoHeader->biWidth  != cSize.cx ||
  490.                 m_pBitmapInfoHeader->biHeight != cSize.cy)
  491.             {
  492.                 UINT32 ulNumBytes = (UINT32) cSize.cx * cSize.cy * 4;
  493.                 HX_VECTOR_DELETE(m_pucBuffer);
  494.                 m_pucBuffer = new BYTE [ulNumBytes];
  495.                 if (m_pucBuffer)
  496.                 {
  497.                     m_pBitmapInfoHeader->biWidth     = cSize.cx;
  498.                     m_pBitmapInfoHeader->biHeight    = cSize.cy;
  499.                     m_pBitmapInfoHeader->biSizeImage = ulNumBytes;
  500.                     bAllocated                       = TRUE;
  501.                 }
  502.             }
  503.             if (m_pucBuffer)
  504.             {
  505.                 // Do we need to fill in the color?
  506.                 if (bAllocated ||
  507.                     m_ulLastBackgroundColor != ulColor)
  508.                 {
  509.                     // Fill in the buffer
  510.                     UINT32  ulNumPix = (UINT32) cSize.cx * cSize.cy;
  511.                     UINT32* pPix     = (UINT32*) m_pucBuffer;
  512.                     while (ulNumPix--)
  513.                     {
  514.                         *pPix++ = ulColor;
  515.                     }
  516.                     // Save this color
  517.                     m_ulLastBackgroundColor = ulColor;
  518.                     // Set the bitmap info header compression
  519.                     m_pBitmapInfoHeader->biCompression = (ulColor & 0xFF000000 ? HX_ARGB : HX_RGB);
  520.                 }
  521.                 // Clear the return value
  522.                 retVal = HXR_OK;
  523.             }
  524.         }
  525.     }
  526.     return retVal;
  527. }