1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/t_integ/src/t_pseudoappeng.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,335 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent
1.23 +*/
1.24 +
1.25 +#include <s32file.h>
1.26 +#include <hal.h>
1.27 +#include <libc/limits.h> //UINT_MAX
1.28 +
1.29 +#include "t_pseudoappeng.h"
1.30 +#include "t_pseudoapputils.h"
1.31 +#include "t_wservconsts.h"
1.32 +#include "t_winutils.h"
1.33 +#include <graphics/suerror.h>
1.34 +#include "t_pseudoappshared.h"
1.35 +
1.36 +//
1.37 +// class CTPseudoAppEng
1.38 +//
1.39 +CTPseudoAppEng::CTPseudoAppEng(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
1.40 +: CTimer(CActive::EPriorityStandard),
1.41 + iClient(aClient),
1.42 + iWindow(aWindow),
1.43 + iScreenDevice(aScreenDevice),
1.44 + iDrawing(EFalse)
1.45 + {
1.46 + }
1.47 +
1.48 +CTPseudoAppEng* CTPseudoAppEng::NewL(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
1.49 + {
1.50 + CTPseudoAppEng* self = new (ELeave) CTPseudoAppEng(aClient, aScreenDevice, aWindow);
1.51 + CleanupStack::PushL(self);
1.52 + self->ConstructL();
1.53 + CleanupStack::Pop(); // self;
1.54 + return self;
1.55 + }
1.56 +
1.57 +CTPseudoAppEng::~CTPseudoAppEng()
1.58 + {
1.59 + iSurfaceUpdateSession.Close();
1.60 +
1.61 + if(IsActive())
1.62 + {
1.63 + Cancel();
1.64 + }
1.65 +
1.66 + delete iPseudoAppShared;
1.67 + delete iUtils;
1.68 + }
1.69 +
1.70 +void CTPseudoAppEng::ConstructL()
1.71 + {
1.72 + CTimer::ConstructL();
1.73 +
1.74 + //Create CIniData class for reading in values form ini files
1.75 +#ifndef T_PSEUDOAPP1
1.76 + iUtils = CIniData::NewL(KWServPseudoAppConfigFile);
1.77 +#else
1.78 + iUtils = CIniData::NewL(KWServPseudoApp1ConfigFile);
1.79 +#endif //T_PSEUDOAPP1
1.80 +
1.81 + //Connect to the surface update server
1.82 + TInt err = iSurfaceUpdateSession.Connect();
1.83 + if (err!=KErrNone)
1.84 + {
1.85 + RDebug::Print(_L("error in connecting surface update session\n"));
1.86 + User::Exit(0);
1.87 + }
1.88 +
1.89 + User::LeaveIfError(HAL::Get(HALData::EFastCounterFrequency, iCounterFreq));
1.90 +
1.91 + //Enter the animation loop
1.92 + RDebug::Print(_L("Enter Animation Loop\n"));
1.93 +
1.94 + CActiveScheduler::Add(this);
1.95 + }
1.96 +
1.97 +void CTPseudoAppEng::StartDrawingL()
1.98 + {
1.99 + /* Read in the configuration fron the config file *
1.100 + * and check the validity of the parameters. If *
1.101 + * invalid, take remedial action *
1.102 + * Exit if the config is really unusable *
1.103 + * Window and animation classes are created if *
1.104 + * the configs are ok */
1.105 + RDebug::Print(_L("Import configuration for t_pseudoapp class and create test screen(s)\n"));
1.106 + ImportPseudoAppConfigL();
1.107 + RDebug::Print(_L("Test screen(s) created for t_pseudoapp\n"));
1.108 +
1.109 + if (iDrawing)
1.110 + {
1.111 + User::Panic(KTPseudoAppPanicTxt(), TPseudoAppEngAlreadyStarted);
1.112 + }
1.113 +
1.114 + iDrawing = ETrue;
1.115 +
1.116 + //A value of 0 will provoke a E32User-Cbase 46 panic
1.117 + After(TTimeIntervalMicroSeconds32(100000));
1.118 +
1.119 + //Set iStartTime to current time
1.120 + iStartTime.UniversalTime();
1.121 + }
1.122 +
1.123 +void CTPseudoAppEng::StopDrawing()
1.124 + {
1.125 + if (!iDrawing)
1.126 + {
1.127 + User::Panic(KTPseudoAppPanicTxt(), TPseudoAppEngAlreadyStopped);
1.128 + }
1.129 +
1.130 + // Cancel timer and display
1.131 + Cancel();
1.132 + iDrawing = EFalse;
1.133 + }
1.134 +
1.135 +void CTPseudoAppEng::TestFinishedL(const TDesC& aFileName)
1.136 + {
1.137 + RFs myFs;
1.138 + User::LeaveIfError(myFs.Connect());
1.139 + RFileWriteStream writer;
1.140 + writer.PushL(); // writer on cleanup stack
1.141 + User::LeaveIfError(writer.Replace(myFs, aFileName, EFileWrite));
1.142 + writer << _L("Surfaces Test Finished");
1.143 + writer.CommitL();
1.144 + CleanupStack::PopAndDestroy(&writer);
1.145 + myFs.Close();
1.146 + }
1.147 +
1.148 +void CTPseudoAppEng::WriteResultsL(const TDesC& aFileName)
1.149 + {
1.150 + RFs myFs;
1.151 + User::LeaveIfError(myFs.Connect());
1.152 +
1.153 + TInt err = myFs.MkDirAll(aFileName);
1.154 +
1.155 + if (err==KErrNone || err==KErrAlreadyExists)
1.156 + {
1.157 + RFileWriteStream writer;
1.158 + writer.PushL(); // writer on cleanup stack
1.159 +
1.160 + User::LeaveIfError(writer.Replace(myFs, aFileName, EFileStreamText|EFileWrite));
1.161 + writer.CommitL();
1.162 + CleanupStack::PopAndDestroy(&writer); // writer
1.163 +
1.164 + CIniData* myData = CIniData::NewL(aFileName);
1.165 + CleanupStack::PushL(myData);
1.166 +
1.167 + TBuf<255> tempStore;
1.168 + _LIT(KIntData, "%d");
1.169 + _LIT(KRealData, "%4.1f");
1.170 +
1.171 + //Write out the test result, which is essentially a pass if the code reaches here
1.172 + tempStore.Format(KIntData, 1);
1.173 + TInt err = myData->AddValue(KDefaultSectionName, KGraphicsWservSurfaceTestResult, tempStore);
1.174 + User::LeaveIfError(err);
1.175 + myData->WriteToFileL();
1.176 +
1.177 + //Write out the theoretical maximum frame rate
1.178 + TReal frameRate = (iCounterFreq*static_cast<TReal>(iFrameDuration))/iGceTestResults.iTotalCompoTime;
1.179 +
1.180 + tempStore.Format(KRealData, frameRate);
1.181 + err = myData->AddValue(KDefaultSectionName, KGraphicsWservSurfaceFrameRate, tempStore);
1.182 + myData->WriteToFileL();
1.183 +
1.184 + //Write out the total test time
1.185 + TReal compoTime = static_cast<TReal>(iGceTestResults.iElapsedTime)/1000;
1.186 +
1.187 + tempStore.Format(KRealData, compoTime);
1.188 + err = myData->AddValue(KDefaultSectionName, KGraphicsWservSurfaceTotalTestTime, tempStore);
1.189 + myData->WriteToFileL();
1.190 +
1.191 + CleanupStack::PopAndDestroy(myData);
1.192 + }
1.193 +
1.194 + myFs.Close();
1.195 + }
1.196 +
1.197 +// Timer's RunL()
1.198 +void CTPseudoAppEng::RunL()
1.199 + {
1.200 + if(iFrameCounter != iFrameDuration)
1.201 + {
1.202 + //If no surface update is required, aSurfaceId will remain as 0
1.203 + TSurfaceId temp;
1.204 + iSurfDetails.aSurfaceId = temp.CreateNullId() ;
1.205 +
1.206 + while(iScreenCounter < iPseudoAppShared->iTestScreens.Count())
1.207 + {
1.208 + iPseudoAppShared->iTestScreens[iScreenCounter]->UpdateL(iSurfDetails);
1.209 + iScreenCounter++;
1.210 + break;
1.211 + }
1.212 +
1.213 + if(!iSurfDetails.aSurfaceId.IsNull())
1.214 + {
1.215 + if(iUseGlobalUpdate)
1.216 + {
1.217 + SendUpdateRequest(KAllScreens);
1.218 + }
1.219 + else
1.220 + {
1.221 + SendUpdateRequest(iScreenCounter - 1);
1.222 + }
1.223 + }
1.224 +
1.225 + if(iScreenCounter == iPseudoAppShared->iTestScreens.Count())
1.226 + {
1.227 + iScreenCounter = 0;
1.228 + iFrameCounter++;
1.229 + }
1.230 +
1.231 + // Renew request
1.232 + After(TTimeIntervalMicroSeconds32(iFrameDelay));
1.233 + }
1.234 + else
1.235 + {
1.236 +#ifndef T_PSEUDOAPP1
1.237 + WriteResultsL(KWServPseudoAppResultFile);
1.238 + TestFinishedL(KWServPseudoAppFinishFile);
1.239 +#else
1.240 + WriteResultsL(KWServPseudoApp1ResultFile);
1.241 + TestFinishedL(KWServPseudoApp1FinishFile);
1.242 +#endif //T_PSEUDOAPP1
1.243 + }
1.244 + }
1.245 +
1.246 +// Timer's DoCancel()
1.247 +void CTPseudoAppEng::DoCancel()
1.248 + {
1.249 + // Cancel timer
1.250 + CTimer::DoCancel();
1.251 + }
1.252 +
1.253 +TBool CTPseudoAppEng::Drawing()
1.254 + {
1.255 + return iDrawing;
1.256 + }
1.257 +
1.258 +void CTPseudoAppEng::SendUpdateRequest(TInt /*aScreen*/)
1.259 + {
1.260 + //Submit update
1.261 + TRect rc[1] =
1.262 + {
1.263 + TRect(0, 0, iSurfDetails.aSurfaceSize.iWidth, iSurfDetails.aSurfaceSize.iHeight)
1.264 + };
1.265 +
1.266 + RRegion region(1, rc);
1.267 +
1.268 + //Use timestamp notification to measure frame rate
1.269 + TRequestStatus status;
1.270 +
1.271 + TTimeStamp timeStamp;
1.272 + iSurfaceUpdateSession.NotifyWhenDisplayed(status, timeStamp);
1.273 + iTimeStampBefore = User::FastCounter();
1.274 +
1.275 + TInt ret = iSurfaceUpdateSession.SubmitUpdate(KAllScreens, iSurfDetails.aSurfaceId, iSurfDetails.aBufferNumber, ®ion);
1.276 +
1.277 + User::WaitForRequest(status);
1.278 +
1.279 + TUint64 time = timeStamp();
1.280 +
1.281 + if(time < iTimeStampBefore)
1.282 + {
1.283 + time += UINT_MAX;
1.284 + }
1.285 +
1.286 + iTotalCompositionTime += (time - iTimeStampBefore);
1.287 +
1.288 + TTime currentTime;
1.289 + currentTime.UniversalTime();
1.290 + TTimeIntervalMicroSeconds elapsedTime = currentTime.MicroSecondsFrom(iStartTime);
1.291 +
1.292 + iGceTestResults.iElapsedTime = (TUint32)(elapsedTime.Int64()/1000);
1.293 + iGceTestResults.iTotalCompoTime = (TUint32)(iTotalCompositionTime);
1.294 +
1.295 + if(ret != KErrNone)
1.296 + {
1.297 + RDebug::Print(_L("Error submitting update request\n"));
1.298 + }
1.299 + }
1.300 +
1.301 +void CTPseudoAppEng::ImportPseudoAppConfigL()
1.302 + {
1.303 + TDisplayMode mode;
1.304 + TSize aScreenSize;
1.305 + TInt numberOfScreens;
1.306 +
1.307 + READ_INI1(number_of_screens, numberOfScreens, iUtils);
1.308 +
1.309 + iPseudoAppShared = new(ELeave) CTPseudoAppShared;
1.310 + for(TInt i=0; i<numberOfScreens; i++)
1.311 + {
1.312 + RDebug::Print(_L("Set up screen %d\n"), i);
1.313 + TImportPseudoAppConfig::ImportPseudoAppConfigL(i, iFrameDuration, iFrameDelay, mode, aScreenSize, iUtils);
1.314 +#ifndef T_PSEUDOAPP1
1.315 + iPseudoAppShared->AddTestScreenL(i, mode, iFrameDuration, aScreenSize, &iGceTestResults, KWServPseudoAppConfigFile);
1.316 +#else
1.317 + iPseudoAppShared->AddTestScreenL(i, mode, iFrameDuration, aScreenSize, &iGceTestResults, KWServPseudoApp1ConfigFile);
1.318 +#endif //T_PSEUDOAPP1
1.319 + }
1.320 + READ_INI2A(KNullDesC, use_global_surface_update, True, False, iUseGlobalUpdate, ETrue, EFalse, iUtils);
1.321 + }
1.322 +
1.323 +void CTPseudoAppEng::RotateL()
1.324 + {
1.325 + if (iPseudoAppShared)
1.326 + {
1.327 + for(TInt i=0; i<iPseudoAppShared->iTestScreens.Count(); i++)
1.328 + {
1.329 + if (iPseudoAppShared->iTestScreens[i])
1.330 + {
1.331 + if(iPseudoAppShared->iTestScreens[i]->Rotation())
1.332 + {
1.333 + iPseudoAppShared->iTestScreens[i]->RotateL(i, iFrameCounter);
1.334 + }
1.335 + }
1.336 + }
1.337 + }
1.338 + }