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

📄 dsa.cpp

📁 SDL库 在进行视频显示程序spcaview安装时必须的库文件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include "dsa.h"#include "sdlepocapi.h"#include <cdsb.h>LOCAL_C TInt BytesPerPixel(TDisplayMode aMode)	{	return ((TDisplayModeUtils::NumDisplayModeBitsPerPixel(aMode) - 1) >> 3) + 1; 	}template<class T>NONSHARABLE_CLASS(CBitmapSurface) : public T	{public:	CBitmapSurface(RWsSession& aSession);private:	void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);	~CBitmapSurface();	TUint8* LockSurface();	void UnlockHwSurface();	void CreateSurfaceL();	void Wipe(TInt aLength);	void Free();	void Update(CFbsBitmap& aBmp);	TInt ExternalUpdate();private:	CFbsBitmap* iBmp;	CFbsBitmap* iCopyBmp;	};	template<class T>void CBitmapSurface<T>::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)			{	delete iCopyBmp;	iCopyBmp = NULL;	iCopyBmp = new (ELeave) CFbsBitmap();	T::ConstructL(aWindow, aDevice);	}	template<class T>CBitmapSurface<T>::CBitmapSurface(RWsSession& aSession) : T(aSession)	{	}	template<class T>void CBitmapSurface<T>::Free()	{	delete iBmp;	iBmp = NULL;	T::Free();	}template<class T>CBitmapSurface<T>::~CBitmapSurface()	{	__ASSERT_DEBUG(iBmp == NULL, PANIC(KErrNotReady));	delete iCopyBmp;	}	template<class T>TUint8* CBitmapSurface<T>::LockSurface()	{	iBmp->LockHeap();	return reinterpret_cast<TUint8*>(iBmp->DataAddress());	}template<class T>void CBitmapSurface<T>::UnlockHwSurface()	{	iBmp->UnlockHeap();	T::SetUpdating(EFalse);	Update(*iBmp);	}	template<class T>	void CBitmapSurface<T>::Update(CFbsBitmap& aBmp)	{	if(!T::Blitter(aBmp))		{		if(T::SwSize() == T::HwRect().Size())			T::Gc().BitBlt(T::HwRect().iTl, &aBmp);		else			T::Gc().DrawBitmap(T::HwRect(), &aBmp);		}	T::DrawOverlays();	T::CompleteUpdate();		}	template<class T>	void CBitmapSurface<T>::CreateSurfaceL()	{	Free();	iBmp  = new (ELeave) CFbsBitmap();	User::LeaveIfError(iBmp->Create(T::SwSize(), T::DisplayMode()));	T::CreateSurfaceL(*iBmp);	}template<class T>void CBitmapSurface<T>::Wipe(TInt aLength) //dont call in drawing	{	iBmp->LockHeap();	Mem::FillZ(iBmp->DataAddress(), aLength);	iBmp->UnlockHeap();	}template<class T>		TInt CBitmapSurface<T>::ExternalUpdate()	{	if(iCopyBmp->Handle() == 0)		{		const TInt err = iCopyBmp->Duplicate(iBmp->Handle());		if(err != KErrNone)			return err;		}	Update(*iCopyBmp);	return KErrNone;	}//////////////////////////////////////////////////////////////////////NONSHARABLE_CLASS(CDsaBitgdi) : public CDsa	{public:	CDsaBitgdi(RWsSession& aSession);protected:	 void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);	 CBitmapContext& Gc();	 void CompleteUpdate();	 ~CDsaBitgdi();	 void CreateSurfaceL(CFbsBitmap& aBmp);	 void Free();	 void UnlockHWSurfaceRequestComplete();private:	 void Resume();	 	 CFbsBitGc* iGc;	 CFbsDevice* iDevice;	 CFbsBitmap* iBitGdiBmp;	 CWindowGc* iWinGc;	 RWindow* iWindow;	 TInt iHandle;	 };CDsaBitgdi::CDsaBitgdi(RWsSession& aSession) : CDsa(aSession)	{	}CDsaBitgdi::~CDsaBitgdi()	{	delete iWinGc;	delete iBitGdiBmp;	}void CDsaBitgdi::CompleteUpdate()	{	EpocSdlEnv::Request(CDsa::ERequestUpdate);	}	void CDsaBitgdi::UnlockHWSurfaceRequestComplete()	{	if(iHandle == 0)		return;		if(iBitGdiBmp == NULL)		{		iBitGdiBmp = new CFbsBitmap();		if(iBitGdiBmp == NULL)			return;		iBitGdiBmp->Duplicate(iHandle);		}		iWindow->Invalidate();		iWindow->BeginRedraw();	iWinGc->Activate(*iWindow);	iWinGc->BitBlt(TPoint(0, 0), iBitGdiBmp);	iWinGc->Deactivate();	iWindow->EndRedraw();	}		void CDsaBitgdi::Resume()	{	Start();	}	CBitmapContext& CDsaBitgdi::Gc() 	{ 	return *iGc; 	} 	 void CDsaBitgdi::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice) 	{ 	 	delete iBitGdiBmp; 	iBitGdiBmp = NULL; 	delete iWinGc; 	iWinGc = NULL; 	iHandle = 0; 	 	iWindow = &aWindow; 	User::LeaveIfError(aDevice.CreateContext(iWinGc)); 	CDsa::ConstructL(aWindow, aDevice); 	Start(); 	} 	void CDsaBitgdi::CreateSurfaceL(CFbsBitmap& aBmp)		{	iDevice = CFbsBitmapDevice::NewL(&aBmp);	User::LeaveIfError(iDevice->CreateContext(iGc));	iHandle = aBmp.Handle();	}	void CDsaBitgdi::Free()	{	delete iGc;	iGc = NULL;	delete iDevice;	iDevice = NULL;	}	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////NONSHARABLE_CLASS(CDsaBase) : public CDsa, public MDirectScreenAccess	{protected:		inline CDirectScreenAccess& Dsa() const;	CDsaBase(RWsSession& aSession);	~CDsaBase();	void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);	void Stop();	void Resume();	CBitmapContext& Gc();protected:    CDirectScreenAccess*  iDsa;private:	void AbortNow(RDirectScreenAccess::TTerminationReasons aReason);	void Restart(RDirectScreenAccess::TTerminationReasons aReason);private:	void RestartL();	};inline CDirectScreenAccess& CDsaBase::Dsa() const	{	return *iDsa;	}	CDsaBase::CDsaBase(RWsSession& aSession) : CDsa(aSession)	{	}	CBitmapContext& CDsaBase::Gc()	{	return *Dsa().Gc();	}	void CDsaBase::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)    {    CDsa::ConstructL(aWindow, aDevice);    if(iDsa != NULL)    	{    	iDsa->Cancel();    	delete iDsa;    	iDsa = NULL;    	}    	    iDsa = CDirectScreenAccess::NewL(    				Session(),					aDevice,					aWindow,					*this);				    RestartL();    }		void CDsaBase::Resume()		{	if(Stopped())		Restart(RDirectScreenAccess::ETerminateRegion);	}		CDsaBase::~CDsaBase()	{	if(iDsa != NULL)        {        iDsa->Cancel();        }    delete iDsa;	}		void CDsaBase::RestartL()    {           iDsa->StartL();	        const RRegion* r = iDsa->DrawingRegion();    const TRect rect = r->BoundingRect();    iDsa->Gc()->SetClippingRegion(r);	       if(rect != ScreenRect())    	{    	return ;	   	 	}   	 	        	SetTargetRect();	RecreateL();		Start();            }void CDsaBase::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)	{	Stop();	}	void CDsaBase::Restart(RDirectScreenAccess::TTerminationReasons aReason)	{	if(aReason == RDirectScreenAccess::ETerminateRegion) //auto restart		{														TRAPD(err, RestartL());		PANIC_IF_ERROR(err);		}	}		void CDsaBase::Stop()	{	CDsa::Stop();	iDsa->Cancel();	}		       ///////////////////////////////////////////////////////////////////////   /////////////////////////////////////////////////////////////////////// NONSHARABLE_CLASS(TDsa)	{	public:		inline TDsa(const CDsa& aDsa);		inline TBool IsFlip() const;		inline TBool IsTurn() const;		inline const TSize& SwSize() const;		inline void Copy(TUint32* aTarget, const TUint8* aSrc, TInt aBytes, TInt aHeight) const;	private:		const CDsa& iDsa;	};inline TDsa::TDsa(const CDsa& aDsa) : iDsa(aDsa)	{		}inline TBool TDsa::IsTurn() const	{	return iDsa.iStateFlags & CDsa::EOrientation90;	}	inline TBool TDsa::IsFlip() const	{	return iDsa.iStateFlags & CDsa::EOrientation180;	}		inline const TSize& TDsa::SwSize() const	{	return iDsa.SwSize();	}		inline void TDsa::Copy(TUint32* aTarget, const TUint8* aSrc, TInt aBytes, TInt aHeight) const	{	iDsa.iCopyFunction(iDsa, aTarget, aSrc, aBytes, aHeight);	}	template<class T, class S>	void ClipCopy(const TDsa& iDsa, TUint8* aTarget, 					const TUint8* aSource, 					const TRect& aUpdateRect, 					const TRect& aSourceRect)	{	const S* source = reinterpret_cast<const S*>(aSource);	const TInt lineWidth = aSourceRect.Width();		source += (aUpdateRect.iTl.iY * lineWidth); 	const TInt sourceStartOffset = aUpdateRect.iTl.iX;	source += sourceStartOffset;		T* targetPtr = reinterpret_cast<T*>(aTarget);		const TInt scanLineWidth = iDsa.SwSize().iWidth;		targetPtr += (aSourceRect.iTl.iY + aUpdateRect.iTl.iY ) * scanLineWidth; 	const TInt targetStartOffset = (aUpdateRect.iTl.iX + aSourceRect.iTl.iX);		targetPtr += targetStartOffset;			const TInt height = aUpdateRect.Height(); 			const TInt lineMove = iDsa.IsTurn() ? 1 : lineWidth;	const TInt copyLen = aUpdateRect.Width();			if(iDsa.IsFlip())		{				targetPtr += scanLineWidth *  (height - 1);			for(TInt i = 0; i < height; i++) //source is always smaller			{			iDsa.Copy(reinterpret_cast<TUint32*>(targetPtr), reinterpret_cast<const TUint8*>(source), copyLen, height);			source += lineMove;			targetPtr -= scanLineWidth;			}		}	else		{						for(TInt i = 0; i < height; i++) //source is always smaller			{			iDsa.Copy(reinterpret_cast<TUint32*>(targetPtr), reinterpret_cast<const TUint8*>(source), copyLen, height);			source += lineMove;			targetPtr += scanLineWidth; // >> 2;			}		}	}	 NONSHARABLE_CLASS(CDsaA) : public CDsaBase	{	public:		CDsaA(RWsSession& aSession);	protected:		void ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice);		void CompleteUpdate();		void CreateSurfaceL(CFbsBitmap& aBmp);		void Free();		void UnlockHWSurfaceRequestComplete();		};		CDsaA::CDsaA(RWsSession& aSession) : CDsaBase(aSession)	{	}	void CDsaA::ConstructL(RWindow& aWindow, CWsScreenDevice& aDevice)			{	CDsaBase::ConstructL(aWindow, aDevice);	}	void CDsaA::CompleteUpdate()	{	iDsa->ScreenDevice()->Update();	}	void CDsaA::CreateSurfaceL(CFbsBitmap& /*aBmp*/)	{	}	void CDsaA::Free()	{		}	void CDsaA::UnlockHWSurfaceRequestComplete()	{	PANIC(KErrNotSupported);	}				//////////////////////////////////////////////////////////////////////////////////////////////////////////////////NONSHARABLE_CLASS(MDsbObs)	{	public:		virtual void SurfaceReady() = 0;		virtual CDirectScreenBitmap& Dsb() = 0;	};	NONSHARABLE_CLASS(CDsbSurface) : public CActive	{

⌨️ 快捷键说明

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