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

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: viewport.cpp,v 1.3.20.1 2004/07/09 02:05:58 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 "hxtypes.h"
  50. #include "hxcom.h"
  51. #include "hxresult.h"
  52. #include "hxengin.h"
  53. #include "hxcore.h"
  54. #include "hxslist.h"
  55. #include "hxmap.h"
  56. #include "hxgroup.h"
  57. #include "hxplay.h"
  58. #include "hxcleng.h"
  59. #include "viewport.h"
  60. #include "hxheap.h"
  61. #ifdef _DEBUG
  62. #undef HX_THIS_FILE
  63. static const char HX_THIS_FILE[] = __FILE__;
  64. #endif
  65. #ifndef _UNIX /* probably a chinstrap tlc :) */
  66. #define XXXMEH_VIEWPORT_HACK 1
  67. #endif
  68. HXViewPort::HXViewPort(HXViewPortManager* pViewPortManager,
  69.  IHXValues* pValues,
  70.  const char* pszName)
  71.  : m_lRefCount(0)
  72.  , m_pszName(pszName)
  73.  , m_pParent(pViewPortManager)
  74.  , m_pValues(pValues)
  75. {   
  76.     if (m_pValues)
  77.     {
  78. m_pValues->AddRef();
  79.     }
  80. }
  81. HXViewPort::~HXViewPort()
  82. {
  83.     HX_RELEASE(m_pValues);
  84. }
  85. STDMETHODIMP
  86. HXViewPort::QueryInterface(REFIID riid, void**ppvObj)
  87. {
  88.     QInterfaceList qiList[] =
  89.         {
  90.             { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)this },
  91.             { GET_IIDHANDLE(IID_IHXViewPort), (IHXViewPort*)this },
  92.         };
  93.     
  94.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  95. }
  96. /////////////////////////////////////////////////////////////////////////
  97. //  Method:
  98. // IUnknown::AddRef
  99. //  Purpose:
  100. // Everyone usually implements this the same... feel free to use
  101. // this implementation.
  102. //
  103. STDMETHODIMP_(ULONG32) 
  104. HXViewPort::AddRef()
  105. {
  106.     return InterlockedIncrement(&m_lRefCount);
  107. }
  108. /////////////////////////////////////////////////////////////////////////
  109. //  Method:
  110. // IUnknown::Release
  111. //  Purpose:
  112. // Everyone usually implements this the same... feel free to use
  113. // this implementation.
  114. //
  115. STDMETHODIMP_(ULONG32) 
  116. HXViewPort::Release()
  117. {
  118.     if (InterlockedDecrement(&m_lRefCount) > 0)
  119.     {
  120.         return m_lRefCount;
  121.     }
  122.     delete this;
  123.     return 0;
  124. }
  125. /************************************************************************
  126.  * Method:
  127.  *     IHXViewPort::GetName
  128.  * Purpose:
  129.  *     get name of the viewport
  130.  */
  131. STDMETHODIMP_(const char*)
  132. HXViewPort::GetName()
  133. {
  134.     return m_pszName;
  135. }
  136. /************************************************************************
  137.  * Method:
  138.  *     IHXViewPort::GetProperties
  139.  * Purpose:
  140.  *     get properties of the viewport
  141.  */
  142. STDMETHODIMP
  143. HXViewPort::GetProperties(REF(IHXValues*)   pValues)
  144. {
  145.     pValues = m_pValues;
  146.     if (pValues)
  147.     {
  148. pValues->AddRef();
  149.     }
  150.     return HXR_OK;
  151. }
  152. /************************************************************************
  153.  * Method:
  154.  *     IHXViewPort::Show
  155.  * Purpose:
  156.  *     show viewport
  157.  */
  158. STDMETHODIMP
  159. HXViewPort::Show()
  160. {
  161.     return m_pParent->OnViewPortShow(m_pszName);
  162. }
  163. /************************************************************************
  164.  * Method:
  165.  *     IHXViewPort::Hide
  166.  * Purpose:
  167.  *     hide viewport
  168.  */
  169. STDMETHODIMP
  170. HXViewPort::Hide()
  171. {
  172.     return m_pParent->OnViewPortHide(m_pszName);
  173. }
  174. /************************************************************************
  175.  * Method:
  176.  *     IHXViewPort::SetFocus
  177.  * Purpose:
  178.  *     set focus on viewport
  179.  */
  180. STDMETHODIMP
  181. HXViewPort::SetFocus()
  182. {
  183.     return m_pParent->OnViewPortFocus(m_pszName);
  184. }
  185. /************************************************************************
  186.  * Method:
  187.  *     IHXViewPort::SetZOrder
  188.  * Purpose:
  189.  *     set Z order on viewport
  190.  */
  191. STDMETHODIMP
  192. HXViewPort::SetZOrder(UINT32 ulZOrder)
  193. {
  194.     return m_pParent->OnViewPortZOrder(m_pszName, ulZOrder);
  195. }
  196. HXViewPortManager::HXViewPortManager(HXPlayer* pPlayer)
  197. :   m_lRefCount(0)
  198. ,   m_pPlayer(pPlayer)
  199. ,   m_pViewPortMap(NULL)
  200. ,   m_pViewPortSinkList(NULL)
  201. ,   m_pViewPortSupplier(NULL)
  202. {
  203.     if (m_pPlayer)
  204.         m_pPlayer->AddRef();
  205. }
  206. HXViewPortManager::~HXViewPortManager()
  207. {
  208.     Close();
  209. }
  210. STDMETHODIMP
  211. HXViewPortManager::QueryInterface(REFIID riid, void**ppvObj)
  212. {
  213.     QInterfaceList qiList[] =
  214.         {
  215.             { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)this },
  216.             { GET_IIDHANDLE(IID_IHXViewPortManager), (IHXViewPortManager*)this },
  217.         };
  218.     
  219.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  220. }
  221. /////////////////////////////////////////////////////////////////////////
  222. //  Method:
  223. // IUnknown::AddRef
  224. //  Purpose:
  225. // Everyone usually implements this the same... feel free to use
  226. // this implementation.
  227. //
  228. STDMETHODIMP_(ULONG32) 
  229. HXViewPortManager::AddRef()
  230. {
  231.     return InterlockedIncrement(&m_lRefCount);
  232. }
  233. /////////////////////////////////////////////////////////////////////////
  234. //  Method:
  235. // IUnknown::Release
  236. //  Purpose:
  237. // Everyone usually implements this the same... feel free to use
  238. // this implementation.
  239. //
  240. STDMETHODIMP_(ULONG32) 
  241. HXViewPortManager::Release()
  242. {
  243.     if (InterlockedDecrement(&m_lRefCount) > 0)
  244.     {
  245.         return m_lRefCount;
  246.     }
  247.     delete this;
  248.     return 0;
  249. }
  250. /************************************************************************
  251.  * Method:
  252.  *     IHXViewPortManager::OpenViewPort
  253.  * Purpose:
  254.  *     create viewport
  255.  */
  256. STDMETHODIMP
  257. HXViewPortManager::OpenViewPort(IHXValues* pValues, IHXSiteUser* pSiteUser)
  258. {
  259.     HX_RESULT rc = HXR_OK;
  260.     const char* pszViewPort = NULL;
  261.     IHXBuffer* pBuffer = NULL;
  262.     HXViewPort* pViewPort = NULL;
  263.     IHXViewPortSink* pViewPortSink = NULL;
  264.     CHXSimpleList::Iterator ndx;
  265.     if (!pValues)
  266.     {
  267. rc = HXR_FAILED;
  268. goto cleanup;
  269.     }
  270.     if (HXR_OK != pValues->GetPropertyCString("playto", pBuffer))
  271.     {
  272. rc = HXR_FAILED;
  273. goto cleanup;
  274.     }
  275.     pszViewPort = (const char*)pBuffer->GetBuffer();
  276.     pViewPort = new HXViewPort(this, pValues, pszViewPort);
  277.     pViewPort->AddRef();
  278.     if (!m_pViewPortMap)  
  279.     {
  280. m_pViewPortMap = new CHXMapStringToOb();
  281.     }
  282.     m_pViewPortMap->SetAt(pszViewPort, (void*)pViewPort);
  283. #ifdef XXXMEH_VIEWPORT_HACK
  284.     // XXXMEH - hack for now until we get TLC support for
  285.     // IHXViewPortSupplier. If we don't get support from
  286.     // the TLC for IHXViewPortSupplier, then QI the SMIL
  287.     // renderer for it. We also have to check it every time
  288.     // to see if it has changed. This is because the core
  289.     // may change the persistent component and not let us
  290.     // know about it.
  291.     {
  292.         if (m_pViewPortSinkList)
  293.         {
  294.             LISTPOSITION pos = m_pViewPortSinkList->GetHeadPosition();
  295.             while (pos)
  296.             {
  297.                 IHXViewPortSink* pSink =
  298.                     (IHXViewPortSink*) m_pViewPortSinkList->GetNext(pos);
  299.                 if (pSink)
  300.                 {
  301.                     // QI for IHXViewPortSupplier
  302.                     IHXViewPortSupplier* pSupplier = NULL;
  303.                     pSink->QueryInterface(IID_IHXViewPortSupplier, (void**) &pSupplier);
  304.                     if (pSupplier != m_pViewPortSupplier)
  305.                     {
  306.                         HX_RELEASE(m_pViewPortSupplier);
  307.                         m_pViewPortSupplier = pSupplier;
  308.                         m_pViewPortSupplier->AddRef();
  309.                         HX_RELEASE(pSupplier);
  310.                         break;
  311.                     }
  312.                     HX_RELEASE(pSupplier);
  313.                 }
  314.             }
  315.         }
  316.     }
  317. #else
  318.     if (m_pPlayer && !m_pViewPortSupplier)
  319.     {
  320. if (HXR_OK != m_pPlayer->QueryInterface(IID_IHXViewPortSupplier, (void**)&m_pViewPortSupplier))
  321. {
  322.     m_pViewPortSupplier = NULL;
  323. }
  324.     }
  325. #endif
  326.     if (m_pViewPortSupplier)
  327.     {
  328. m_pViewPortSupplier->OnViewPortOpen(pValues, pSiteUser);
  329. if (m_pViewPortSinkList)
  330. {
  331.     ndx = m_pViewPortSinkList->Begin();
  332.     for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  333.     {
  334. pViewPortSink = (IHXViewPortSink*) (*ndx);
  335. pViewPortSink->ViewPortOpened(pszViewPort);
  336.     }
  337. }
  338.     }
  339. cleanup:
  340.    HX_RELEASE(pBuffer);
  341.    
  342.    return rc;
  343. }
  344. /************************************************************************
  345.  * Method:
  346.  *     IHXViewPortManager::GetViewPort
  347.  * Purpose:
  348.  *     get viewport
  349.  */
  350. STDMETHODIMP
  351. HXViewPortManager::GetViewPort(const char* pszViewPort,
  352. REF(IHXViewPort*) pViewPort)
  353. {
  354.     HX_RESULT rc = HXR_OK;
  355.     pViewPort = NULL;
  356.     if (!m_pViewPortMap)
  357.     {
  358. rc = HXR_FAILED;
  359. goto cleanup;
  360.     }
  361.     if (!m_pViewPortMap->Lookup(pszViewPort, (void*&)pViewPort))
  362.     {
  363. rc = HXR_FAILED;
  364. goto cleanup;
  365.     }
  366.     pViewPort->AddRef();
  367. cleanup:
  368.     return rc;
  369. }
  370. /************************************************************************
  371.  * Method:
  372.  *     IHXViewPortManager::CloseViewPort
  373.  * Purpose:
  374.  *     remove viewport
  375.  */
  376. STDMETHODIMP
  377. HXViewPortManager::CloseViewPort(const char* pszViewPort)
  378. {
  379.     HX_RESULT rc = HXR_OK;
  380.     IHXViewPort* pViewPort = NULL;
  381.     IHXViewPortSink* pViewPortSink = NULL;
  382.     CHXSimpleList::Iterator ndx;
  383.     if (m_pViewPortMap &&
  384. m_pViewPortMap->Lookup(pszViewPort, (void*&)pViewPort))
  385.     {
  386. m_pViewPortMap->RemoveKey(pszViewPort);
  387. HX_RELEASE(pViewPort);
  388.     }
  389.     if (m_pViewPortSupplier)
  390.     {
  391. m_pViewPortSupplier->OnViewPortClose(pszViewPort);
  392. if (m_pViewPortSinkList)
  393. {
  394.     ndx = m_pViewPortSinkList->Begin();
  395.     for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  396.     {
  397. pViewPortSink = (IHXViewPortSink*) (*ndx);
  398. pViewPortSink->ViewPortClosed(pszViewPort);
  399.     }
  400. }
  401.     }
  402.     return rc;
  403. }
  404. /************************************************************************
  405.  * Method:
  406.  *     IHXViewPortManager::AddViewPortSink
  407.  * Purpose:
  408.  *     add viewport sinker
  409.  */
  410. STDMETHODIMP
  411. HXViewPortManager::AddViewPortSink(IHXViewPortSink*  pViewPortSink)
  412. {
  413.     HX_RESULT rc = HXR_OK;
  414.     if (!m_pViewPortSinkList)
  415.     {
  416. m_pViewPortSinkList = new CHXSimpleList();
  417.     }
  418.     m_pViewPortSinkList->AddTail(pViewPortSink);
  419.     pViewPortSink->AddRef();
  420.     return rc;
  421. }
  422. /************************************************************************
  423.  * Method:
  424.  *     IHXViewPortManager::RemoveViewPortSink
  425.  * Purpose:
  426.  *     remove viewport sinker
  427.  */
  428. STDMETHODIMP
  429. HXViewPortManager::RemoveViewPortSink(IHXViewPortSink*  pViewPortSink)
  430. {
  431.     if (!m_pViewPortSinkList)
  432.     {
  433. return HXR_UNEXPECTED;
  434.     }
  435.     LISTPOSITION lPosition = m_pViewPortSinkList->Find(pViewPortSink);
  436.     if (!lPosition)
  437.     {
  438. return HXR_UNEXPECTED;
  439.     }
  440.     m_pViewPortSinkList->RemoveAt(lPosition);
  441.     HX_RELEASE(pViewPortSink);
  442.     
  443.     return HXR_OK;
  444. }
  445. HX_RESULT
  446. HXViewPortManager::OnViewPortShow(const char* pszViewPortName)
  447. {
  448.     HX_RESULT rc = HXR_OK;
  449.     IHXViewPortSink* pViewPortSink = NULL;
  450.     CHXSimpleList::Iterator ndx;
  451.     if (!m_pViewPortSupplier)
  452.     {
  453. rc = HXR_FAILED;
  454. goto cleanup;
  455.     }
  456.     m_pViewPortSupplier->OnViewPortShow(pszViewPortName);
  457.     if (m_pViewPortSinkList)
  458.     {
  459. ndx = m_pViewPortSinkList->Begin();
  460. for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  461. {
  462.     pViewPortSink = (IHXViewPortSink*) (*ndx);
  463.     pViewPortSink->ViewPortShown(pszViewPortName);
  464. }
  465.     }
  466. cleanup:
  467.     return rc;
  468. }
  469. HX_RESULT
  470. HXViewPortManager::OnViewPortHide(const char* pszViewPortName)
  471. {
  472.     HX_RESULT rc = HXR_OK;
  473.     IHXViewPortSink* pViewPortSink = NULL;
  474.     CHXSimpleList::Iterator ndx;
  475.     if (!m_pViewPortSupplier)
  476.     {
  477. rc = HXR_FAILED;
  478. goto cleanup;
  479.     }
  480.     m_pViewPortSupplier->OnViewPortHide(pszViewPortName);
  481.     if (m_pViewPortSinkList)
  482.     {
  483. ndx = m_pViewPortSinkList->Begin();
  484. for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  485. {
  486.     pViewPortSink = (IHXViewPortSink*) (*ndx);
  487.     pViewPortSink->ViewPortHidden(pszViewPortName);
  488. }
  489.     }
  490. cleanup:
  491.     return rc;
  492. }
  493. HX_RESULT
  494. HXViewPortManager::OnViewPortFocus(const char* pszViewPortName)
  495. {
  496.     HX_RESULT rc = HXR_OK;
  497.     IHXViewPortSink* pViewPortSink = NULL;
  498.     CHXSimpleList::Iterator ndx;
  499.     if (!m_pViewPortSupplier)
  500.     {
  501. rc = HXR_FAILED;
  502. goto cleanup;
  503.     }
  504.     m_pViewPortSupplier->OnViewPortFocus(pszViewPortName);
  505.     if (m_pViewPortSinkList)
  506.     {
  507. ndx = m_pViewPortSinkList->Begin();
  508. for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  509. {
  510.     pViewPortSink = (IHXViewPortSink*) (*ndx);
  511.     pViewPortSink->ViewPortFocusSet(pszViewPortName);
  512. }
  513.     }
  514. cleanup:
  515.     return rc;
  516. }
  517. HX_RESULT
  518. HXViewPortManager::OnViewPortZOrder(const char* pszViewPortName, 
  519.      UINT32 ulZOrder)
  520. {
  521.     HX_RESULT rc = HXR_OK;
  522.     IHXViewPortSink* pViewPortSink = NULL;
  523.     CHXSimpleList::Iterator ndx;
  524.     if (!m_pViewPortSupplier)
  525.     {
  526. rc = HXR_FAILED;
  527. goto cleanup;
  528.     }
  529.     m_pViewPortSupplier->OnViewPortZOrder(pszViewPortName, ulZOrder);
  530.     if (m_pViewPortSinkList)
  531.     {
  532. ndx = m_pViewPortSinkList->Begin();
  533. for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  534. {
  535.     pViewPortSink = (IHXViewPortSink*) (*ndx);
  536.     pViewPortSink->ViewPortZOrderSet(pszViewPortName, ulZOrder);
  537. }
  538.     }
  539. cleanup:
  540.     return rc;
  541. }
  542. void
  543. HXViewPortManager::Close()
  544. {
  545.     if (m_pViewPortMap)
  546.     {
  547. CHXMapStringToOb::Iterator ndx = m_pViewPortMap->Begin();
  548. for (; ndx != m_pViewPortMap->End(); ++ndx)
  549. {
  550.     HXViewPort* pViewPort = (HXViewPort*)(*ndx);
  551.     HX_RELEASE(pViewPort);
  552. }
  553.     }
  554.     HX_DELETE(m_pViewPortMap);
  555.     if (m_pViewPortSinkList)
  556.     {
  557. CHXSimpleList::Iterator ndx = m_pViewPortSinkList->Begin();
  558. for (; ndx != m_pViewPortSinkList->End(); ++ndx)
  559. {
  560.     IHXViewPortSink* pViewPortSink = (IHXViewPortSink*)(*ndx);
  561.     HX_RELEASE(pViewPortSink);
  562. }
  563.     }
  564.     HX_DELETE(m_pViewPortSinkList);
  565.     HX_RELEASE(m_pViewPortSupplier);
  566.     HX_RELEASE(m_pPlayer);
  567. }