⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macsurf.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: macsurf.cpp,v 1.5.20.3 2004/07/09 01:59:02 hubbe Exp $ *  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. *  * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks.  You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL.  Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. *  * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. *  * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. *  * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. *  * Technology Compatibility Kit Test Suite(s) Location: *    http://www.helixcommunity.org/content/tck *  * Contributor(s): *  * ***** END LICENSE BLOCK ***** *//**************************************************************************** *  *  $Id: macsurf.cpp,v 1.5.20.3 2004/07/09 01:59:02 hubbe Exp $ *   */#include "hxcom.h"#include "hxtypes.h"#include "hxwintyp.h"#include "hxmap.h"#include "hxslist.h"#include "ihxpckts.h"#include "hxwin.h"#include "hxengin.h"#include "hxsite2.h"#include "chxxtype.h"#include "hxvctrl.h"#include "hxvsurf.h"#include "hxcodec.h"#include "surface.h"#include "vidosurf.h"#include "sitetext.h"#include "chxpckts.h"#include "hxevent.h"#include "bltpatch.h"#ifndef _MAC_UNIX#include "hxmm.h"#endif#include "hxprefs.h"#include "hxevent.h"#include "hxthread.h"#include "platform/mac/macsurf.h"#include "platform/mac/macroot.h"#include "baseroot.h"#include "basesite.h"#include "platform/mac/macsite.h"#include "platform/mac/hx_moreprocesses.h"#ifndef _MACINTOSH#ifndef _MAC_UNIX#error This is the Macintosh platform specific implementation.#endif#endif#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE		static const char HX_THIS_FILE[] = __FILE__;#endifCHXSimpleList CMacSurface::zm_SurfaceList;void* CMacSurface::zm_pOverlayBuf = nil;long CMacSurface::zm_nOverlayRowBytes = 0;RgnHandle CMacSurface::zm_OverlayMaskRgn = NULL;BOOL CMacSurface::zm_bSafeToOverlayBlit = FALSE;CMacSurface* CMacSurface::zm_pOverlaySurface = nil;BOOL CMacSurface::zm_bOverlayRequiresKeyColor = FALSE;BOOL CMacSurface::zm_bOverlayRequiresDrawBand = FALSE;ImageSequence CMacSurface::zm_SequenceID = NULL;ImageDescriptionHandle CMacSurface::zm_ImageDescriptionHandle = NULL;long CMacSurface::zm_nOverlayBufferSize = 0;void* CMacSurface::zm_pHoldOverlayBuf = NULL;long CMacSurface::zm_nHoldOverlayBufSize = 0;#pragma options align=mac68kstruct BogusCodecDecompressParams{    CodecDecompressParams decompParams;    long dummy[100];    // XXXbobclark    // sheesh. OK, when ImageCodecNewImageBufferMemory() is    // called, memory can be corrupted. The address of a    // CodecDecompressParams is passed to the call, and it    // pokes memory past the end of the 210-byte structure.    // I've reproduced this in ATI's YUVSDK as well. ATI    // insists that it can't be their fault and they don't    // think it's Apple's fault either. Whatever. Memory    // is still getting corrupted. By including a bunch of    // dummy space, that corruption happens in a harmless    // place. Instead of, like it was doing for weeks, in    // some random variable that would cause strange behavior    // and/or crashes at ill-defined times.};typedef BogusCodecDecompressParams BogusCodecDecompressParams;ComponentInstanceRecord *gYUV = nil;BogusCodecDecompressParams bogusDecompParams;ImageSubCodecDecompressRecord drp;#pragma options align=reset/************************************************************************ *  Method: *    CMacSurface constructor */CMacSurface::CMacSurface(IUnknown* pContext, CHXBaseSite* pSite) : CBaseSurface(pContext, pSite){    zm_SurfaceList.AddTail(this);}/************************************************************************ *  Method: *    CHXMacSite destructor */CMacSurface::~CMacSurface(){        if (CMacSurface::zm_pOverlaySurface == this)    {	CleanUpOverlay();	CMacSurface::zm_pOverlaySurface = nil;		::DisposePtr((Ptr)zm_pHoldOverlayBuf);	zm_pHoldOverlayBuf = NULL;	zm_nHoldOverlayBufSize = 0;    }        LISTPOSITION pos = zm_SurfaceList.Find(this);    zm_SurfaceList.RemoveAt(pos);}/************************************************************************ *  Method: *    CMacSurface::_ReleaseSurface */voidCMacSurface::_ReleaseSurface(CBaseRootSurface* pSurface){}/************************************************************************ *  Method: *    CMacSurface::_DrawBlack */voidCMacSurface::_DrawBlack(void* pWindow){}/************************************************************************ *  Method: *    CMacSurface::__Sleep */voidCMacSurface::__Sleep(int milliseconds){}/************************************************************************ *  Method: *    CMacSurface::_BltToPrimary */HX_RESULTCMacSurface::_BltToPrimary(REF(HXxRect) rDestRect, REF(HXxRect) rSrcRect){    return HXR_OK;}/************************************************************************ *  Method: *    CMacSurface::_CreateBuffer */voidCMacSurface::_CreateBuffer(){}/************************************************************************ *  Method: *    CMacSurface::_GetCaps */HX_RESULTCMacSurface::_GetCaps(UINT32* pfSurfaceCaps){    // see if it supports stuff like overlay.        if (pfSurfaceCaps)    {	*pfSurfaceCaps = 0;	if (_OverlayAvailable())	{	    *pfSurfaceCaps |= HX_OVERLAY;	}    }    return HXR_OK;}/************************************************************************ *  Method: *    CMacSurface::_CreateOverlay */HX_RESULTCMacSurface::_CreateOverlay(BOOL bOverlay, int cid, int x, int y){    HX_ASSERT(_OverlayAvailable());    if (CMacSurface::zm_pOverlaySurface == nil)    {	CMacSurface::zm_pOverlaySurface = this;	// we don't want to construct the overlay here, uhhh, because	// we don't yet know WHERE it's gonna be. We'll construct it	// the first time we need it.    }    else if (CMacSurface::zm_pOverlaySurface == this)    {	CleanUpOverlay();    }    if (CMacSurface::zm_pOverlaySurface == this)    {	m_nBltMode = HX_OVERLAY_BLT;	m_surfaceSize.cx = x;	m_surfaceSize.cy = y;    }    return HXR_OK;}// xxxbobclark weird, it looks like the first time the color convertor is used,// it slams something weird into the mouse pointer. I'm just doing a quick// (unnoticeable really) cursor switch to obscure the garbagey stuff.BOOL gDumbCursorRedrawNeeded = FALSE;/************************************************************************ *  Method: *    CMacSurface::_LockInternalSurface */HX_RESULTCMacSurface::_LockInternalSurface(UCHAR** ppSurPtr, LONG32* pnSurfPitch, REF(HXxSize) srcSize){    HX_RESULT retVal = HXR_OK;        GrafPtr savePort = nil;        if (IsMacInCooperativeThread())    {	::GetPort(&savePort);	HXxWindow* pWindow = m_pSite->m_pTopLevelSite->GetWindow();	HX_ASSERT(pWindow);		if (!pWindow)	{	    return HXR_FAIL;	}		HX_ASSERT(pWindow->window);	::SetPort( GetWindowPort( (WindowPtr)pWindow->window ) );    }        if (zm_pOverlayBuf == nil)    {	CMacSurface::zm_pOverlaySurface = this;	m_nSurfaceCID = CID_YUY2;    }    if (CMacSurface::zm_pOverlaySurface == this)    {	static Point sLastPoint = {-1,-1};	static HXxSize sLastSize = {0,0};	static HXxSize sLastSrcSize = {0,0};	static Point sP = {-1,-1};	HX_ASSERT(m_pSite);		HXxSize s;		m_pSite->GetSize(s);		sP.h = 0;	sP.v = 0;	BOOL bOverlayRebuildingRequired = FALSE;		if (sLastPoint.h != sP.h || sLastPoint.v != sP.v) bOverlayRebuildingRequired = TRUE;	if (sLastSize.cx != s.cx || sLastSize.cy != s.cy) bOverlayRebuildingRequired = TRUE;	if (sLastSrcSize.cx != srcSize.cx || sLastSrcSize.cy != srcSize.cy) bOverlayRebuildingRequired = TRUE;	if (zm_pOverlayBuf == nil) bOverlayRebuildingRequired = TRUE;		// xxxbobclark this catch up workaround is necessary because with some	// parameters of the overlay while the TLC is resizing, a glitch can	// happen and blits start happening outside of our window onto the	// desktop.	// If (a) the overlay extends beyond the window or (b) a mask region	// is used when creating the overlay, then when the TLC resizes the	// following sequence of events takes place:	// 1. overlay (sequenceID) created.	// 2. blit happens (DecompressSequenceFrameWhen) successfully	// 3. All future blits fail with slamming the frame onto the	//    desktop area.	//	// But if we ensure that after the first successful blit we	// then rebuild the overlay, we never encounter the problem	// in the sequence of events. I need to revisit this!	// I created a stand-alone app that tried to repro the problem	// and I couldn't. I added window sizing code to CarbMini and	// couldn't repro the problem. I don't know if we're getting	// called when we're in a bad state in the middle of resizing	// or what.	//	// The whole notion of the image sequence technique is that when	// you know that your grafport is going to be consistent for awhile	// you can take advantage of that by using a sequence ID so each	// blit can rely on the parameters that remain consistent. What this	// workaround is doing is probably that something in the	// grafport has changed and we haven't detected it. What I don't	// know, but I should look into the sequence of events of first	// overlay rebuild, actual SizeWindow() command, second overlay blit	// that would slam to the desktop if we didn't kludge.	//	// Initially I thought that there were two possible kludges that	// would avoid the problem. One was to delay the Carbon Timer by	// a millisecond. The other was to use this "catch up" technique.	// It turns out that when I delayed the Carbon Timer, I was able	// to reproduce the problem by actively resizing the simple case,	// and most of the time using a more complex SMIL repro case.	// The "catch up" technique used to have a simple boolean for	// whether the kludge should kick in. Now it has a counter that's	// higher for more complicated SMIL presentations. I don't know	// what the magic number is, but using a boolean (i.e. "one")	// was too low in complex SMIL presentations, and the number of	// sites seems to work.	//	// xxxbobclark 20 Sep 02		static ULONG32 sbCatchUp = 0;		RgnHandle newMaskRgn = nil;		if (bOverlayRebuildingRequired)	{	    CHXMacSite* pSite = (CHXMacSite*)zm_pOverlaySurface->m_pSite;	    HXREGION* pEntireReg = HXCreateRegion();	    HXUnionRegion(pEntireReg, pSite->m_Region, pEntireReg);	    // xxxbobclark do this "manual clipping" thing to ensure that opaque	    // parents are clipped out.	    CHXMacSite* parentSite = (CHXMacSite*)pSite->GetParentSite();	    while (parentSite)	    {		HXIntersectRegion(pEntireReg, parentSite->m_RegionWithoutChildren, pEntireReg);		parentSite = (CHXMacSite*)parentSite->GetParentSite();	    }			    // xxxbobclark chunk of code snagged from CBaseSurface::FillColorKey.	    // Necessary because our overlay clip region needs to be able to	    // differentiate between clipped-out areas and alpha-blended areas.	    CHXMapPtrToPtr::Iterator ii;	    for( ii=pSite->m_AlphaBlendNotifiers.Begin() ;			 ii!=pSite->m_AlphaBlendNotifiers.End()  ;			 ++ii)	    {		CHXBaseSite* pPotentialAlphaBlendedSite = (CHXBaseSite*)*ii;		HXREGION* pReg = NULL;		CHXMapPtrToPtr::Iterator j = pPotentialAlphaBlendedSite->m_AlphaBlendSites.Begin();		CHXBaseSite* pTmpSite = NULL;		while( j != pPotentialAlphaBlendedSite->m_AlphaBlendSites.End() && pTmpSite != pSite )		{		    pTmpSite = (CHXBaseSite*)j.get_key();		    if( pTmpSite == pSite )		    {			pReg = (HXREGION*)*j;			HXUnionRegion( pEntireReg, pReg, pEntireReg );			break;		    }		    ++j;		}	    }	    // xxxbobclark is this involved in a linked overlay?	    // If so, we need to include the linked site's regions.	    CHXSimpleList::Iterator linkedSitesIter;	    for (	linkedSitesIter = m_LinkedSites.Begin();			linkedSitesIter != m_LinkedSites.End();			++linkedSitesIter)	    {		CHXBaseSite* pSite = (CHXBaseSite*)(*linkedSitesIter);		HXUnionRegion(pEntireReg, pSite->m_Region, pEntireReg);		CHXMapPtrToPtr::Iterator ii;		for( ii=pSite->m_AlphaBlendNotifiers.Begin() ;				ii!=pSite->m_AlphaBlendNotifiers.End()  ;				++ii)		{		    CHXBaseSite* pPotentialAlphaBlendedSite = (CHXBaseSite*)*ii;		    HXREGION* pReg = NULL;		    CHXMapPtrToPtr::Iterator j = pPotentialAlphaBlendedSite->m_AlphaBlendSites.Begin();		    CHXBaseSite* pTmpSite = NULL;		    while( j != pPotentialAlphaBlendedSite->m_AlphaBlendSites.End() && pTmpSite != pSite )		    {			pTmpSite = (CHXBaseSite*)j.get_key();			if( pTmpSite == pSite )			{			    pReg = (HXREGION*)*j;			    HXUnionRegion( pEntireReg, pReg, pEntireReg );			    break;			}			++j;		    }		}	    }	    newMaskRgn = CHXMacSite::_ConvertRegionToMacRegion(pEntireReg);            CHXMacSite* pMacSite = (CHXMacSite*)zm_pOverlaySurface->m_pSite;            // xxxbobclark should we shrink the region if we have scrollbars? I certainly think so!            if (pMacSite->m_hHScrollBar || pMacSite->m_hVScrollBar)            {                Rect rgnBounds;                ::GetRegionBounds(newMaskRgn, &rgnBounds);                if (pMacSite->m_hHScrollBar)                {                    rgnBounds.bottom -= 16;                }                if (pMacSite->m_hVScrollBar)                {                    rgnBounds.right -= 16;                }                RgnHandle rectRgn = ::NewRgn();                if (rectRgn)                {                    RectRgn(rectRgn, &rgnBounds);                    ::SectRgn(rectRgn, newMaskRgn, newMaskRgn);                    ::DisposeRgn(rectRgn);                }            }            	    OffsetRgn(newMaskRgn, -pEntireReg->extents.x1, -pEntireReg->extents.y1);	    HXDestroyRegion(pEntireReg);			    // xxxbobclark now intersect with current port's clip region and vis region.	    RgnHandle trimRgn = ::NewRgn();	    ::GetPortVisibleRegion(::GetQDGlobalsThePort(), trimRgn);	    ::SectRgn(newMaskRgn, trimRgn, newMaskRgn);	    if (1 /*pSite->m_bIsRealPlayerTLC*/)	    {		::GetClip(trimRgn);		::SectRgn(newMaskRgn, trimRgn, newMaskRgn);	    }	    else	    {		// xxxbobclark now intersect with PNxWindow's clip rect. Only if we're		// in an embedded player; this whole mechanism relies on browsers setting		// up clip regions before sending null events.		HXxWindow* pWindow = pSite->GetWindow();		if ((pWindow->x < pWindow->clipRect.left) || ((pWindow->x + pWindow->width)  > pWindow->clipRect.right) ||		        (pWindow->y < pWindow->clipRect.top)  || ((pWindow->y + pWindow->height) > pWindow->clipRect.bottom))		{		    bOverlayRebuildingRequired = TRUE;		}		::SetRectRgn(trimRgn, pWindow->clipRect.left, pWindow->clipRect.top, pWindow->clipRect.right, pWindow->clipRect.bottom);		// offset region		::OffsetRgn(trimRgn, -pWindow->x, -pWindow->y);		::SectRgn(newMaskRgn, trimRgn, newMaskRgn);	    }	    ::DisposeRgn(trimRgn);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -