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

📄 macsurf.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 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 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (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.  
 *  
 * 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 2003/05/27 20:05:54 bobclark 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 "fauxcodec.h"

#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE		
static const char HX_THIS_FILE[] = __FILE__;
#endif

// xxxbobclark the notion is that if it's going to be
// a 1X blit, we'll use the faux codec method if there
// are 76800 pixels or more. If it's stretched in any
// way, it's a smaller threshhold: since using the faux
// codec method gives us stretching for free, that's a
// much larger gain than normal 1x color conversions.
// 76800 is used because that's 320x240.
#define USE_FAUX_CODEC_1X_THRESHHOLD 76800
#define USE_FAUX_CODEC_STRETCHED_THRESHHOLD 38400


CHXSimpleList 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;

BOOL CMacSurface::zm_bUsingFauxCodec = TRUE;
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=mac68k

struct 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
 */
void
CMacSurface::_ReleaseSurface(CBaseRootSurface* pSurface)
{
}


/************************************************************************
 *  Method:
 *    CMacSurface::_DrawBlack
 */
void
CMacSurface::_DrawBlack(void* pWindow)
{
}


/************************************************************************
 *  Method:
 *    CMacSurface::__Sleep
 */
void
CMacSurface::__Sleep(int milliseconds)
{
}


/************************************************************************
 *  Method:
 *    CMacSurface::_BltToPrimary
 */
HX_RESULT
CMacSurface::_BltToPrimary(REF(HXxRect) rDestRect, REF(HXxRect) rSrcRect)
{
    return HXR_OK;
}


/************************************************************************
 *  Method:
 *    CMacSurface::_CreateBuffer
 */
void
CMacSurface::_CreateBuffer()
{
}


/************************************************************************
 *  Method:
 *    CMacSurface::_GetCaps
 */
HX_RESULT
CMacSurface::_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_RESULT
CMacSurface::_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_RESULT
CMacSurface::_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

⌨️ 快捷键说明

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