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 //UINT_MAX sl@0: #include "t_fpsappeng.h" sl@0: #include "t_pseudoapputils.h" sl@0: sl@0: const TInt KSurfaceWidth = 640; sl@0: const TInt KSurfaceHeight = 240; sl@0: const TUidPixelFormat KSurfaceFormat = EUidPixelFormatXRGB_8888; sl@0: const TInt KBytesPerPixel = 4; // Four bytes per pixel for the format above. sl@0: sl@0: CFpsAppEng::CFpsAppEng(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow) sl@0: : CTimer(CActive::EPriorityStandard), sl@0: iClient(aClient), sl@0: iWindow(aWindow), sl@0: iScreenDevice(aScreenDevice) sl@0: { sl@0: } sl@0: sl@0: CFpsAppEng* CFpsAppEng::NewL(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow) sl@0: { sl@0: CFpsAppEng* self = new (ELeave) CFpsAppEng(aClient, aScreenDevice, aWindow); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); // self; sl@0: return self; sl@0: } sl@0: sl@0: CFpsAppEng::~CFpsAppEng() sl@0: { sl@0: if(IsActive()) sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: User::Free(iBufPtr1); sl@0: DestroySurface(); sl@0: sl@0: //Pause to allow the test step to kill the app sl@0: User::After(1000000); sl@0: } sl@0: sl@0: void CFpsAppEng::ConstructL() sl@0: { sl@0: CTimer::ConstructL(); sl@0: sl@0: iNoOfPixels = KSurfaceHeight*KSurfaceWidth; sl@0: iNoOfBytes = iNoOfPixels*KBytesPerPixel; sl@0: sl@0: // Allocate a memory block sl@0: iBufPtr1 = reinterpret_cast(User::AllocL(iNoOfBytes)); sl@0: sl@0: RDebug::Print(_L("Creating Surface manager...")); sl@0: CreateSurfaceManager(); sl@0: RDebug::Print(_L("Creating Surface...")); sl@0: CreateSurface(iSurfaceId); sl@0: RDebug::Print(_L("Create Surface update session...")); sl@0: CreateSurfaceUpdateSessionL(); sl@0: sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: void CFpsAppEng::StartDrawing() sl@0: { sl@0: //A value of 0 will provoke a E32User-Cbase 46 panic sl@0: After(TTimeIntervalMicroSeconds32(100000)); sl@0: } sl@0: sl@0: void CFpsAppEng::CreateSurfaceManager() sl@0: { sl@0: TInt ret = iSurfaceManager.Open(); sl@0: if(ret==KErrNone) sl@0: { sl@0: RDebug::Print(_L("Creating surface manager OK")); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CFpsAppEng::CreateSurface(TSurfaceId& aSurfaceId) sl@0: { sl@0: RSurfaceManager::TSurfaceCreationAttributesBuf attribs; sl@0: RSurfaceManager::TSurfaceCreationAttributes& surfaceCreationAtribs=attribs(); sl@0: surfaceCreationAtribs.iSize.iWidth = KSurfaceWidth; sl@0: surfaceCreationAtribs.iSize.iHeight = KSurfaceHeight; sl@0: surfaceCreationAtribs.iBuffers = 2; sl@0: surfaceCreationAtribs.iPixelFormat = KSurfaceFormat; sl@0: surfaceCreationAtribs.iStride = KBytesPerPixel*KSurfaceWidth; sl@0: surfaceCreationAtribs.iOffsetToFirstBuffer = 0; sl@0: surfaceCreationAtribs.iAlignment = 4; sl@0: surfaceCreationAtribs.iContiguous = EFalse; sl@0: surfaceCreationAtribs.iMappable = ETrue; sl@0: sl@0: TInt err = iSurfaceManager.CreateSurface(attribs, aSurfaceId); sl@0: if (err == KErrNone) sl@0: { sl@0: err = iSurfaceManager.MapSurface(aSurfaceId, iChunk); sl@0: } sl@0: if (err == KErrNone) sl@0: { sl@0: RDebug::Print(_L("Surface created: OK")); sl@0: } sl@0: sl@0: iSurfacePtr = reinterpret_cast(iChunk.Base()); sl@0: err=iWindow.SetBackgroundSurface(aSurfaceId); sl@0: if ( err!=KErrNone) sl@0: { sl@0: RDebug::Print(_L("ERROR: %d - Setting window background to the surface failed!"), err); sl@0: User::Panic(_L("Fps panic"), err); sl@0: } sl@0: } sl@0: sl@0: void CFpsAppEng::CreateSurfaceUpdateSessionL() sl@0: { sl@0: TInt ret = iSurfaceUpdateSession.Connect(); sl@0: sl@0: if (ret==KErrAlreadyExists) sl@0: { sl@0: RDebug::Print(_L("Device driver already loaded")); sl@0: } sl@0: else if (ret==KErrNone) sl@0: { sl@0: RDebug::Print(_L("Connected to surface update server")); sl@0: } sl@0: else sl@0: { sl@0: RDebug::Print(_L("Fatal error connecting to surface update server")); sl@0: User::LeaveIfError(ret); sl@0: } sl@0: } sl@0: sl@0: void CFpsAppEng::DestroySurface() sl@0: { sl@0: RDebug::Print(_L("Destroy Surface update session")); sl@0: iSurfaceUpdateSession.Close(); sl@0: sl@0: RDebug::Print(_L("Closing chunk")); sl@0: iChunk.Close(); sl@0: sl@0: RDebug::Print(_L("Closing surface")); sl@0: TInt ret = iSurfaceManager.CloseSurface(iSurfaceId); sl@0: if(ret!=KErrNone) sl@0: { sl@0: RDebug::Print(_L("Surface manager failed to close")); sl@0: } sl@0: sl@0: RDebug::Print(_L("Close Surface Manager")); sl@0: iSurfaceManager.Close(); sl@0: } sl@0: sl@0: sl@0: // Timer's RunL() sl@0: void CFpsAppEng::RunL() sl@0: { sl@0: TInt j; sl@0: if (iCol1) sl@0: { sl@0: for (j=0; j