Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #include <libc/limits.h> //UINT_MAX
23 #include "t_fpsappeng.h"
24 #include "t_pseudoapputils.h"
26 const TInt KSurfaceWidth = 640;
27 const TInt KSurfaceHeight = 240;
28 const TUidPixelFormat KSurfaceFormat = EUidPixelFormatXRGB_8888;
29 const TInt KBytesPerPixel = 4; // Four bytes per pixel for the format above.
31 CFpsAppEng::CFpsAppEng(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
32 : CTimer(CActive::EPriorityStandard),
35 iScreenDevice(aScreenDevice)
39 CFpsAppEng* CFpsAppEng::NewL(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
41 CFpsAppEng* self = new (ELeave) CFpsAppEng(aClient, aScreenDevice, aWindow);
42 CleanupStack::PushL(self);
44 CleanupStack::Pop(); // self;
48 CFpsAppEng::~CFpsAppEng()
58 //Pause to allow the test step to kill the app
62 void CFpsAppEng::ConstructL()
66 iNoOfPixels = KSurfaceHeight*KSurfaceWidth;
67 iNoOfBytes = iNoOfPixels*KBytesPerPixel;
69 // Allocate a memory block
70 iBufPtr1 = reinterpret_cast<TUint32*>(User::AllocL(iNoOfBytes));
72 RDebug::Print(_L("Creating Surface manager..."));
73 CreateSurfaceManager();
74 RDebug::Print(_L("Creating Surface..."));
75 CreateSurface(iSurfaceId);
76 RDebug::Print(_L("Create Surface update session..."));
77 CreateSurfaceUpdateSessionL();
79 CActiveScheduler::Add(this);
82 void CFpsAppEng::StartDrawing()
84 //A value of 0 will provoke a E32User-Cbase 46 panic
85 After(TTimeIntervalMicroSeconds32(100000));
88 void CFpsAppEng::CreateSurfaceManager()
90 TInt ret = iSurfaceManager.Open();
93 RDebug::Print(_L("Creating surface manager OK"));
98 void CFpsAppEng::CreateSurface(TSurfaceId& aSurfaceId)
100 RSurfaceManager::TSurfaceCreationAttributesBuf attribs;
101 RSurfaceManager::TSurfaceCreationAttributes& surfaceCreationAtribs=attribs();
102 surfaceCreationAtribs.iSize.iWidth = KSurfaceWidth;
103 surfaceCreationAtribs.iSize.iHeight = KSurfaceHeight;
104 surfaceCreationAtribs.iBuffers = 2;
105 surfaceCreationAtribs.iPixelFormat = KSurfaceFormat;
106 surfaceCreationAtribs.iStride = KBytesPerPixel*KSurfaceWidth;
107 surfaceCreationAtribs.iOffsetToFirstBuffer = 0;
108 surfaceCreationAtribs.iAlignment = 4;
109 surfaceCreationAtribs.iContiguous = EFalse;
110 surfaceCreationAtribs.iMappable = ETrue;
112 TInt err = iSurfaceManager.CreateSurface(attribs, aSurfaceId);
115 err = iSurfaceManager.MapSurface(aSurfaceId, iChunk);
119 RDebug::Print(_L("Surface created: OK"));
122 iSurfacePtr = reinterpret_cast<TUint32*>(iChunk.Base());
123 err=iWindow.SetBackgroundSurface(aSurfaceId);
126 RDebug::Print(_L("ERROR: %d - Setting window background to the surface failed!"), err);
127 User::Panic(_L("Fps panic"), err);
131 void CFpsAppEng::CreateSurfaceUpdateSessionL()
133 TInt ret = iSurfaceUpdateSession.Connect();
135 if (ret==KErrAlreadyExists)
137 RDebug::Print(_L("Device driver already loaded"));
139 else if (ret==KErrNone)
141 RDebug::Print(_L("Connected to surface update server"));
145 RDebug::Print(_L("Fatal error connecting to surface update server"));
146 User::LeaveIfError(ret);
150 void CFpsAppEng::DestroySurface()
152 RDebug::Print(_L("Destroy Surface update session"));
153 iSurfaceUpdateSession.Close();
155 RDebug::Print(_L("Closing chunk"));
158 RDebug::Print(_L("Closing surface"));
159 TInt ret = iSurfaceManager.CloseSurface(iSurfaceId);
162 RDebug::Print(_L("Surface manager failed to close"));
165 RDebug::Print(_L("Close Surface Manager"));
166 iSurfaceManager.Close();
171 void CFpsAppEng::RunL()
176 for (j=0; j<iNoOfPixels; j++)
178 iBufPtr1[j]=0xFF00FF00;
185 for (j=0; j<iNoOfPixels; j++)
187 iBufPtr1[j]=0xFF0000FF;
193 Mem::Move(iSurfacePtr, iBufPtr1, iNoOfBytes);
194 __ASSERT_ALWAYS( KErrNone==iSurfaceUpdateSession.SubmitUpdate(KAllScreens, iSurfaceId, 0, NULL),User::Panic(_L("Fps App"), -1));
197 // After(TTimeIntervalMicroSeconds32(10000)); // 0.002sec, 100fps
198 // After(TTimeIntervalMicroSeconds32(20000)); // 0.02sec, 50fps
199 // After(TTimeIntervalMicroSeconds32(25000)); // 0.025sec, 40fps
200 After(TTimeIntervalMicroSeconds32(33333)); // 0.033sec, 30fps
201 // After(TTimeIntervalMicroSeconds32(50000)); // 0.050sec, 20fps
202 // After(TTimeIntervalMicroSeconds32(100000)); //0.01sec, 10fps
206 // Timer's DoCancel()
207 void CFpsAppEng::DoCancel()