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.
25 #include <iniparser.h>
26 #include "t_inidata.h"
27 #include "t_wservconsts.h"
28 #include "t_dsaappeng.h"
29 #include "t_perfdata.h"
32 _LIT(KDsaPanicTxt, "t_dsaapp.exe");
33 _LIT(KDsaRotationAbortCount, "KDsaRotationAbortCount");
38 CTDsaAppEng::CTDsaAppEng(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
39 : CTimer(CActive::EPriorityStandard),
41 iScreenDevice(aScreenDevice),
47 CTDsaAppEng* CTDsaAppEng::NewL(RWsSession& aClient, CWsScreenDevice& aScreenDevice,
50 CTDsaAppEng* self = new (ELeave) CTDsaAppEng(aClient, aScreenDevice, aWindow);
51 CleanupStack::PushL(self);
53 CleanupStack::Pop(); // self;
57 CTDsaAppEng::~CTDsaAppEng()
64 delete iDirectScreenAccess;
65 iDirectScreenAccess = NULL;
72 void CTDsaAppEng::ConstructL()
75 iDirectScreenAccess = CDirectScreenAccess::NewL(iClient, iScreenDevice, iWindow, *this);
76 iPerfData = CTPerfData::NewL();
77 READ_INT(KDsaAppIterations, KWServDsaAppConfigFile, iFinishTesting);
78 User::LeaveIfError(iSemaphore.CreateGlobal(KWservDsaSemaphoreName(), 0));
79 CActiveScheduler::Add(this);
82 void CTDsaAppEng::StartDrawing()
86 User::Panic(KDsaPanicTxt, DirScrAccEngAlreadyStarted);
89 TRAPD(dsaErr, iDirectScreenAccess->StartL());
90 if(dsaErr == KErrNone)
93 // Get graphics context for it
94 iGc = iDirectScreenAccess->Gc();
96 // Get region that DSA can draw in
97 iRegion = iDirectScreenAccess->DrawingRegion();
99 // Set the display to clip to this region
100 iGc->SetClippingRegion(iRegion);
104 // request a timer event after a defined interval
105 After(TTimeIntervalMicroSeconds32(0));
109 void CTDsaAppEng::StopDrawing()
113 User::Panic(KDsaPanicTxt, DirScrAccEngAlreadyStopped);
116 // Cancel timer and display
121 // Implement MDirectScreenAccess
122 void CTDsaAppEng::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/)
125 TInt scrMode = iScreenDevice.CurrentScreenMode();
126 TPixelsTwipsAndRotation sizeAndRotation;
127 iScreenDevice.GetScreenModeSizeAndRotation(scrMode, sizeAndRotation);
129 RDebug::Print(_L("CTDsaAppEng::Restart - Screen Mode: %d"), scrMode);
130 RDebug::Print(_L("CTDsaAppEng::Restart - Previous Rotation: %d"), iPrevRotation);
131 RDebug::Print(_L("CTDsaAppEng::Restart - Rotation: %d"), sizeAndRotation.iRotation);
132 RDebug::Print(_L("CTDsaAppEng::Restart - Height: %d"), sizeAndRotation.iPixelSize.iHeight);
133 RDebug::Print(_L("CTDsaAppEng::Restart - Width: %d"), sizeAndRotation.iPixelSize.iWidth);
135 // since RDirectScreenAccess::ETerminateRegion takes precedence over
136 // RDirectScreenAccess::ETerminateRotation a check of the current screen
137 // rotation against the previous rotation is performed to determine whether
138 // the abort reason is due to a rotation event
139 if (iPrevRotation!=sizeAndRotation.iRotation)
141 iRotationAbortCount++;
142 iPrevRotation=sizeAndRotation.iRotation;
148 void CTDsaAppEng::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
150 // Cancel timer and display
154 void CTDsaAppEng::CreateTestFileL(const TDesC& aFileName)
157 User::LeaveIfError(myFs.Connect());
158 RFileWriteStream writer;
159 writer.PushL(); // writer on cleanup stack
160 User::LeaveIfError(writer.Replace(myFs, aFileName, EFileWrite));
161 writer << _L("DSA Test");
163 CleanupStack::PopAndDestroy(&writer);
167 void CTDsaAppEng::WriteResultsL(const TDesC& aFileName)
169 CIniData* myData=CIniData::NewL(aFileName);
170 CleanupStack::PushL(myData);
173 _LIT(KIntData, "%d");
174 tempStore.Format(KIntData,iRotationAbortCount);
175 TInt err2 = myData->AddValue(KDefaultSectionName, KDsaRotationAbortCount, tempStore);
178 RDebug::Print(_L("CTDsaAppEng::WriteResultsL - unable to add abort count to result file: %d"), err2);
180 myData->WriteToFileL();
182 CleanupStack::PopAndDestroy(myData);
186 void CTDsaAppEng::RunL()
190 iPerfData->StartCounter();
191 CreateTestFileL(KWServDsaAppStartFile());
195 iPerfData->StopCounterL();
196 iPerfData->StartCounter();
199 if (iFrameCount == 100 || iFrameCount == 200)
204 if (iFrameCount==iFinishTesting)
206 iDirectScreenAccess->Cancel();
207 iPerfData->WriteResultsL(KWServDsaAppResultFile());
208 TRAP_IGNORE(WriteResultsL(KWServDsaAppResultFile()));
209 TRAPD(err,CreateTestFileL(KWServDsaAppFinishFile()));
212 User::Panic(KDsaPanicTxt, err);
219 iDirectScreenAccess->ScreenDevice()->Update();
230 iGc->SetBrushColor(color);
231 iGc->SetPenColor(color);
232 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
233 TRect myRect(iWindow.Size());
234 iGc->DrawRect(myRect);
237 After(TTimeIntervalMicroSeconds32(0));
241 // Timer's DoCancel()
242 void CTDsaAppEng::DoCancel()
248 iDirectScreenAccess->Cancel();