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

Symbian

开发平台:

Visual C++

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