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

📄 dsa_old.cpp

📁 SDL库 在进行视频显示程序spcaview安装时必须的库文件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "dsa.h"#include "sdlepocapi.h"#include <cdsb.h>LOCAL_C TInt BytesPerPixel(TDisplayMode aMode)	{	return ((TDisplayModeUtils::NumDisplayModeBitsPerPixel(aMode) - 1) >> 3) + 1; 	}////////////////////////////////////////////////////////////////////////////////////////////////  NONSHARABLE_CLASS(CDsaA) : public CDsa	{	public:		CDsaA(RWsSession& aSession);	private:		~CDsaA();		TUint8* LockSurface();		void UnlockHWSurfaceRequestComplete();		void UnlockHwSurface();		void CreateSurfaceL();		void Wipe(TInt aLength);		void RecreateL();		void Free();		TInt ExternalUpdate() {return 0;}	private:		CFbsBitmap* iBmp;		};		CDsaA::CDsaA(RWsSession& aSession) : CDsa(aSession)	{	}	void CDsaA::Free()	{	delete iBmp;	iBmp = NULL;	}CDsaA::~CDsaA()	{	__ASSERT_DEBUG(iBmp == NULL, PANIC(KErrNotReady));	}	TUint8* CDsaA::LockSurface()	{	iBmp->LockHeap();	return reinterpret_cast<TUint8*>(iBmp->DataAddress());	}void CDsaA::UnlockHWSurfaceRequestComplete()	{	PANIC(KErrNotSupported);	}void CDsaA::UnlockHwSurface()	{	iBmp->UnlockHeap();	SetUpdating(EFalse);	Dsa().Gc()->BitBlt(HwRect().iTl, iBmp);	Dsa().ScreenDevice()->Update();	}void CDsaA::CreateSurfaceL()	{	delete iBmp;	iBmp = NULL;	iBmp  = new (ELeave) CFbsBitmap();	User::LeaveIfError(iBmp->Create(HwRect().Size(), DisplayMode()));	}void CDsaA::Wipe(TInt aLength) //dont call in drawing	{	iBmp->LockHeap();	Mem::FillZ(iBmp->DataAddress(), aLength);	iBmp->UnlockHeap();	}	void CDsaA::RecreateL()	{	}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////NONSHARABLE_CLASS(MDsbObs)	{	public:		virtual void SurfaceReady() = 0;		virtual CDirectScreenBitmap& Dsb() = 0;	};	NONSHARABLE_CLASS(CDsbSurface) : public CActive	{	public:		CDsbSurface(MDsbObs& aDsb);		TUint8* Address();		void Complete();		~CDsbSurface();	private:		void RunL();		void DoCancel();	private:		MDsbObs& iDsb; 		TUint8* iAddress;	};	CDsbSurface::CDsbSurface(MDsbObs& aDsb) : CActive(CActive::EPriorityHigh) , iDsb(aDsb)	{	CActiveScheduler::Add(this);	}CDsbSurface::~CDsbSurface()	{	Cancel();	}	void CDsbSurface::Complete()	{	if(iAddress != NULL && !IsActive())		{		iAddress = NULL;		SetActive();		iDsb.Dsb().EndUpdate(iStatus);		}	}	TUint8* CDsbSurface::Address()	{	if(iAddress == NULL && !IsActive())		{		TAcceleratedBitmapInfo info;		if(KErrNone == iDsb.Dsb().BeginUpdate(info))			iAddress = info.iAddress;		}	return iAddress;	}	void CDsbSurface::RunL()	{	iDsb.SurfaceReady();	}void CDsbSurface::DoCancel()	{	//empty	}		NONSHARABLE_CLASS(CDsaB) : public CDsa, public MDsbObs	{	public:		CDsaB(RWsSession& aSession);	private:		~CDsaB();		TUint8* LockSurface();		void UnlockHWSurfaceRequestComplete();		void UnlockHwSurface();		void CreateSurfaceL();		void Wipe(TInt aLength);		void RecreateL();		void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);		void Free();		CDirectScreenBitmap& Dsb();		void SurfaceReady();		TInt ExternalUpdate() {return 0;}	private:		CDsbSurface* iSurface1;		CDsbSurface* iSurface2;		CDirectScreenBitmap* iDsb;	};CDsaB::CDsaB(RWsSession& aSession) : CDsa(aSession)	{	}void CDsaB::Free()	{	}	void CDsaB::UnlockHWSurfaceRequestComplete()	{	iSurface1->Complete();	iSurface2->Complete();	}	void CDsaB::CreateSurfaceL()	{	}	void CDsaB::Wipe(TInt aLength) //dont call in drawing	{	TUint8* addr = LockSurface();	if(addr != NULL) 		{		Mem::FillZ(addr, aLength);		UnlockHwSurface();		}	}void CDsaB::UnlockHwSurface()	{	EpocSdlEnv::Request(CDsa::ERequestUpdate);	}	TUint8* CDsaB::LockSurface()	{	TUint8* addr =  iSurface1->Address();	if(addr == NULL)		addr =  iSurface2->Address();	SetUpdating(addr == NULL);	return addr;	}	void CDsaB::SurfaceReady()		{	SetUpdating(EFalse);	}CDirectScreenBitmap& CDsaB::Dsb()	{	return *iDsb;	}	void CDsaB::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)	{	if(iDsb == NULL)		iDsb = CDirectScreenBitmap::NewL();		CDsa::ConstructL(aWindow, aDevice);	iSurface1 = new (ELeave) CDsbSurface(*this);	iSurface2 = new (ELeave) CDsbSurface(*this);	}	CDsaB::~CDsaB()	{	delete iSurface1;	delete iSurface2;	delete iDsb;	}	void CDsaB::RecreateL()	{    iDsb->Close();    iDsb->Create(HwRect(), CDirectScreenBitmap::EDoubleBuffer);	}/////////////////////////////////////////////////////////////////////////////////////////////////////	TSize CDsa::WindowSize() const	{	TSize size = HwRect().Size();	if(iStateFlags & EOrientation90)		{		const TInt tmp = size.iWidth;		size.iWidth = size.iHeight;		size.iHeight = tmp;		}	return size;	}	void CDsa::SetSuspend()	{	iStateFlags |= ESdlThreadSuspend;	}void CDsa::ReleaseStop()	{	iStateFlags &= ~ESdlThreadExplicitStop;	}TBool CDsa::Stopped() const	{	return (iStateFlags & ESdlThreadExplicitStop);	}void CDsa::SetOrientation(CSDL::TOrientationMode aOrientation)	{	TInt flags = 0;	switch(aOrientation)		{		case CSDL::EOrientation90:			flags = EOrientation90;			break;		case CSDL::EOrientation180:			flags = EOrientation180;			break;		case CSDL::EOrientation270:			flags = EOrientation90 | EOrientation180;			break;		case CSDL::EOrientation0:			flags = 0;			break;		}	if(flags != (iStateFlags & EOrientationFlags))		{		iStateFlags |= EOrientationChanged;		iNewFlags = flags; //cannot be set during drawing...		}	}CDsa::~CDsa()    {    if(iDsa != NULL)        {        iDsa->Cancel();        }    delete iDsa;    User::Free(iLut256);    }         void CDsa::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)    {    if(iDsa != NULL)    	{    	iDsa->Cancel();    	delete iDsa;    	iDsa = NULL;    	}    	    	    iDsa = CDirectScreenAccess::NewL(    				iSession,					aDevice,					aWindow,					*this);					if(iLut256 == NULL)		iLut256 = (TUint32*) User::AllocL(256 * sizeof(TUint32));	iTargetMode = aWindow.DisplayMode();	iTargetBpp = BytesPerPixel(DisplayMode());	iTargetRect = TRect(aWindow.Position(), aWindow.Size());    RestartL();    }void CDsa::LockPalette(TBool aLock)	{	if(aLock)		iStateFlags |= EPaletteLocked;	else		iStateFlags &= ~EPaletteLocked;	}TInt CDsa::SetPalette(TInt aFirst, TInt aCount, TUint32* aPalette)	{	if(iLut256 == NULL)		return KErrNotFound;	const TInt count = aCount - aFirst;	if(count > 256)		return KErrArgument;	if(iStateFlags & EPaletteLocked)		return KErrNone;	for(TInt i = aFirst; i < count; i++) //not so busy here:-)		{		iLut256[i] = aPalette[i];		}	return KErrNone;	}			void CDsa::RestartL()    {    //const TBool active = iDsa->IsActive();        //if(!active)    iDsa->StartL();        RRegion* r = iDsa->DrawingRegion();    iDsa->Gc()->SetClippingRegion(r);    TRect rect = r->BoundingRect();       if(rect.IsEmpty())    	{    	return;    	}    	    iScreenRect = rect; //to ensure properly set, albeit may not(?) match to value SDL has - therefore may has to clip		RecreateL();    iStateFlags |= ERunning;//    iScanLineWidth = iTargetBpp * HwRect().Width();    ReleaseStop();    if(iStateFlags & ESdlThreadSuspend)    	{    	EpocSdlEnv::Resume();    	iStateFlags &= ~ ESdlThreadSuspend;    	}    }    CDsa::CDsa(RWsSession& aSession) :  	iSession(aSession),  	iStateFlags(0)	{//	CActiveScheduler::Add(this);	iCFTable[0] = CopyMem;	iCFTable[1] = CopyMemFlipReversed;	iCFTable[2] = CopyMemReversed;	iCFTable[3] = CopyMemFlip;			iCFTable[4] = Copy256;	iCFTable[5] = Copy256FlipReversed;	iCFTable[6] = Copy256Reversed;	iCFTable[7] = Copy256Flip;				iCFTable[8] = CopySlow;	iCFTable[9] = CopySlowFlipReversed;	iCFTable[10] = CopySlowReversed;	iCFTable[11] = CopySlowFlip;		}	RWsSession& CDsa::Session()	{	return iSession;	}TUint8* CDsa::LockHwSurface()	{	if((iStateFlags & EUpdating) == 0) //else frame is skipped		{		return LockSurface();		}	return NULL; 	}/*	void CDsa::RunL()	{	iStateFlags &= ~EUpdating;	}			void CDsa::DoCancel()	{	iStateFlags &= ~EUpdating;	//nothing can do, just wait?	}*/		TInt CDsa::AllocSurface(TBool aHwSurface, const TSize& aSize, TDisplayMode aMode)	{	if(aHwSurface && aMode != DisplayMode())		return KErrArgument;		iSourceMode = aMode;		iSourceBpp = BytesPerPixel(aMode);		const TSize size = WindowSize();	if(aSize.iWidth > size.iWidth)		return KErrTooBig;	if(aSize.iHeight > size.iHeight)		return KErrTooBig;		TRAPD(err, CreateSurfaceL());	if(err != KErrNone)		return err;	SetCopyFunction();		EpocSdlEnv::ObserverEvent(MSDLObserver::EEventWindowReserved);		return KErrNone;	}	/*void SaveBmp(const TDesC& aName, const TAny* aData, TInt aLength, const TSize& aSz, TDisplayMode aMode)	{	CFbsBitmap* s = new CFbsBitmap();	s->Create(aSz, aMode);	s->LockHeap();	TUint32* addr = s->DataAddress();	Mem::Copy(addr, aData, aLength);	s->UnlockHeap();	s->Save(aName);	s->Reset();	delete s;	}	void SaveBmp(const TDesC& aName, const TUint32* aData, const TSize& aSz)	{	CFbsBitmap* s = new CFbsBitmap();	s->Create(aSz, EColor64K);	TBitmapUtil bmp(s);	bmp.Begin(TPoint(0, 0));	for(TInt j = 0; j < aSz.iHeight; j++)		{		bmp.SetPos(TPoint(0, j));		for(TInt i = 0; i < aSz.iWidth; i++)			{			bmp.SetPixel(*aData);			aData++;			bmp.IncXPos();			}		}	bmp.End();	s->Save(aName);	s->Reset();	delete s;	}		TBuf<16> FooName(TInt aFoo)	{	TBuf<16> b;	b.Format(_L("C:\\pic%d.mbm"), aFoo);	return b;	}*/void CDsa::ClipCopy(TUint8* aTarget, const TUint8* aSource, const TRect& aRect, const TRect& aTargetPos) const	{	TUint8* target = aTarget;	const TUint8* source = aSource;	const TInt lineWidth = aRect.Width();	source += iSourceBpp * (aRect.iTl.iY * lineWidth); 	TInt sourceStartOffset = iSourceBpp *  aRect.iTl.iX;	source += sourceStartOffset;	target += iTargetBpp * ((aTargetPos.iTl.iY + aRect.iTl.iY ) * lineWidth); 	TInt targetStartOffset = iTargetBpp * (aRect.iTl.iX + aTargetPos.iTl.iX);	target += targetStartOffset;	TUint32* targetPtr = reinterpret_cast<TUint32*>(target);	const TInt targetWidth = HwRect().Size().iWidth;	const TInt height = aRect.Height(); 		TInt lineMove = iStateFlags & EOrientation90 ? 1 : lineWidth;		if(iStateFlags & EOrientation180)		{				targetPtr += targetWidth *  (height - 1);			for(TInt i = 0; i < height; i++) //source is always smaller

⌨️ 快捷键说明

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