sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent sl@0: */ sl@0: sl@0: #include "t_pseudoappcfbsbitmapanim.h" sl@0: #include "t_testsurfacerasterizer.h" sl@0: sl@0: EXPORT_C CCFbsBitmapAnimation* CCFbsBitmapAnimation::NewL(TDisplayMode aMode, const TSize& aAnimSize, const TSize& aSurfaceSize, sl@0: TPtrC& aBitmapFile, TInt aHorizontalRate, TInt aVerticalRate, sl@0: TPixelFormat aPixelFormat) sl@0: { sl@0: RDebug::Print(_L("Creating CCFbsBitmapAnimation class\n")); sl@0: CCFbsBitmapAnimation* self = new (ELeave) CCFbsBitmapAnimation(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aMode, aAnimSize, aSurfaceSize, aBitmapFile, aHorizontalRate, aVerticalRate, aPixelFormat); sl@0: CleanupStack::Pop(); // self; sl@0: return self; sl@0: } sl@0: sl@0: void CCFbsBitmapAnimation::ConstructL(TDisplayMode aMode, const TSize& aAnimSize, const TSize& aSurfaceSize, sl@0: TPtrC& aBitmapFile, TInt aHorizontalRate, TInt aVerticalRate, sl@0: TPixelFormat aPixelFormat) sl@0: { sl@0: RDebug::Print(_L("Creating full-screen bitmap\n")); sl@0: sl@0: iBitmapAnimFile.Set(aBitmapFile); sl@0: iHorizontalRate = aHorizontalRate; sl@0: iVerticalRate = aVerticalRate; sl@0: iAnimSize = aAnimSize; sl@0: iSurfaceSize = aSurfaceSize; sl@0: iPixelFormat = aPixelFormat; sl@0: iRotationSupported = ETrue; sl@0: sl@0: iFullSurfaceBitmap = new(ELeave) CFbsBitmap; sl@0: sl@0: if(iPixelFormat == EFormatYuv) sl@0: { sl@0: TSize sz(iSurfaceSize.iWidth/2, iSurfaceSize.iHeight); sl@0: iFullSurfaceBitmap->Create(sz, static_cast(aMode)); sl@0: } sl@0: else sl@0: { sl@0: iFullSurfaceBitmap->Create(iSurfaceSize, static_cast(aMode)); sl@0: } sl@0: iFullSurfaceBitmapDevice = CFbsBitmapDevice::NewL(iFullSurfaceBitmap); sl@0: iFullSurfaceBitmapGc = CFbsBitGc::NewL(); sl@0: iFullSurfaceBitmapGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); sl@0: } sl@0: sl@0: CCFbsBitmapAnimation::CCFbsBitmapAnimation() : CTestAnimation() sl@0: { sl@0: }; sl@0: sl@0: EXPORT_C CCFbsBitmapAnimation::~CCFbsBitmapAnimation() sl@0: { sl@0: delete iFullSurfaceBitmapGc; sl@0: delete iFullSurfaceBitmapDevice; sl@0: delete iFullSurfaceBitmap; sl@0: } sl@0: sl@0: EXPORT_C void CCFbsBitmapAnimation::Rotate(TSize /*aScreenSize*/) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CCFbsBitmapAnimation::DrawL(CTestSurfaceRasterizer* aSurfaceRasterizer, SurfaceDetails& aSurfDetails) sl@0: { sl@0: iFullSurfaceBitmapGc->Activate(iFullSurfaceBitmapDevice); sl@0: iFullSurfaceBitmapGc->Clear(); sl@0: sl@0: RedrawSurfaceL(); sl@0: sl@0: //Send the fullscreen bitmap to the test rasterizer sl@0: iFullSurfaceBitmap->LockHeap(); sl@0: sl@0: TUint32* bitmapBufferPtr = iFullSurfaceBitmap->DataAddress(); sl@0: aSurfaceRasterizer->DrawRect(bitmapBufferPtr, aSurfDetails); sl@0: sl@0: iFullSurfaceBitmap->UnlockHeap(); sl@0: } sl@0: sl@0: EXPORT_C void CCFbsBitmapAnimation::SetFrameNumber(TInt aFrameNumber) sl@0: { sl@0: iFrameCounter = aFrameNumber; sl@0: } sl@0: sl@0: void CCFbsBitmapAnimation::RedrawSurfaceL() sl@0: { sl@0: CFbsBitmap bitmap; sl@0: User::LeaveIfError(bitmap.Load(iBitmapAnimFile, iFrameCounter)); sl@0: sl@0: const TSize nativeSize(bitmap.SizeInPixels()); sl@0: sl@0: const TSize fullScreenSize(iFullSurfaceBitmap->SizeInPixels()); sl@0: sl@0: if(iPixelFormat == EFormatYuv) sl@0: { sl@0: TInt noOfPixels=fullScreenSize.iWidth * fullScreenSize.iHeight; sl@0: TInt counter=noOfPixels; sl@0: TUint32* address = iFullSurfaceBitmap->DataAddress(); sl@0: for(TInt i=0; iDrawBitmap(TRect(TPoint(iXPos, iYPos), sz), &bitmap, TRect(TPoint(0,0), nativeSize)); sl@0: sl@0: //Wrap in x co-ord sl@0: if( (iXPos + iAnimSize.iWidth) > iSurfaceSize.iWidth) sl@0: { sl@0: iFullSurfaceBitmapGc->DrawBitmap(TRect(TPoint(iXPos - iSurfaceSize.iWidth, iYPos), sz), sl@0: &bitmap, TRect(TPoint(0,0), nativeSize)); sl@0: } sl@0: sl@0: //Wrap in y co-ord sl@0: if( (iYPos + iAnimSize.iHeight) > iSurfaceSize.iHeight) sl@0: { sl@0: iFullSurfaceBitmapGc->DrawBitmap(TRect(TPoint(iXPos, iYPos - iSurfaceSize.iHeight), sz), sl@0: &bitmap, TRect(TPoint(0,0), nativeSize)); sl@0: } sl@0: sl@0: //Wrap in both x and y co-ords sl@0: if( ((iXPos + iAnimSize.iWidth) > iSurfaceSize.iWidth) && ((iYPos + iAnimSize.iHeight) > iSurfaceSize.iHeight) ) sl@0: { sl@0: iFullSurfaceBitmapGc->DrawBitmap(TRect(TPoint(iXPos - iSurfaceSize.iWidth, iYPos - iSurfaceSize.iHeight), sz), sl@0: &bitmap, TRect(TPoint(0,0), nativeSize)); sl@0: } sl@0: sl@0: //Increment x and y positions and wrap if necessary sl@0: iXPos += iSurfaceSize.iWidth/iHorizontalRate; sl@0: iYPos += iSurfaceSize.iHeight/iVerticalRate; sl@0: iXPos = iXPos % iSurfaceSize.iWidth; sl@0: iYPos = iYPos % iSurfaceSize.iHeight; sl@0: sl@0: iFrameCounter++; sl@0: }