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 sl@0: #include sl@0: #include //UINT_MAX sl@0: sl@0: #include "t_pseudoappeng.h" sl@0: #include "t_pseudoapputils.h" sl@0: #include "t_wservconsts.h" sl@0: #include "t_winutils.h" sl@0: #include sl@0: #include "t_pseudoappshared.h" sl@0: sl@0: // sl@0: // class CTPseudoAppEng sl@0: // sl@0: CTPseudoAppEng::CTPseudoAppEng(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: iDrawing(EFalse) sl@0: { sl@0: } sl@0: sl@0: CTPseudoAppEng* CTPseudoAppEng::NewL(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow) sl@0: { sl@0: CTPseudoAppEng* self = new (ELeave) CTPseudoAppEng(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: CTPseudoAppEng::~CTPseudoAppEng() sl@0: { sl@0: iSurfaceUpdateSession.Close(); sl@0: sl@0: if(IsActive()) sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: delete iPseudoAppShared; sl@0: delete iUtils; sl@0: } sl@0: sl@0: void CTPseudoAppEng::ConstructL() sl@0: { sl@0: CTimer::ConstructL(); sl@0: sl@0: //Create CIniData class for reading in values form ini files sl@0: #ifndef T_PSEUDOAPP1 sl@0: iUtils = CIniData::NewL(KWServPseudoAppConfigFile); sl@0: #else sl@0: iUtils = CIniData::NewL(KWServPseudoApp1ConfigFile); sl@0: #endif //T_PSEUDOAPP1 sl@0: sl@0: //Connect to the surface update server sl@0: TInt err = iSurfaceUpdateSession.Connect(); sl@0: if (err!=KErrNone) sl@0: { sl@0: RDebug::Print(_L("error in connecting surface update session\n")); sl@0: User::Exit(0); sl@0: } sl@0: sl@0: User::LeaveIfError(HAL::Get(HALData::EFastCounterFrequency, iCounterFreq)); sl@0: sl@0: //Enter the animation loop sl@0: RDebug::Print(_L("Enter Animation Loop\n")); sl@0: sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: void CTPseudoAppEng::StartDrawingL() sl@0: { sl@0: /* Read in the configuration fron the config file * sl@0: * and check the validity of the parameters. If * sl@0: * invalid, take remedial action * sl@0: * Exit if the config is really unusable * sl@0: * Window and animation classes are created if * sl@0: * the configs are ok */ sl@0: RDebug::Print(_L("Import configuration for t_pseudoapp class and create test screen(s)\n")); sl@0: ImportPseudoAppConfigL(); sl@0: RDebug::Print(_L("Test screen(s) created for t_pseudoapp\n")); sl@0: sl@0: if (iDrawing) sl@0: { sl@0: User::Panic(KTPseudoAppPanicTxt(), TPseudoAppEngAlreadyStarted); sl@0: } sl@0: sl@0: iDrawing = ETrue; sl@0: sl@0: //A value of 0 will provoke a E32User-Cbase 46 panic sl@0: After(TTimeIntervalMicroSeconds32(100000)); sl@0: sl@0: //Set iStartTime to current time sl@0: iStartTime.UniversalTime(); sl@0: } sl@0: sl@0: void CTPseudoAppEng::StopDrawing() sl@0: { sl@0: if (!iDrawing) sl@0: { sl@0: User::Panic(KTPseudoAppPanicTxt(), TPseudoAppEngAlreadyStopped); sl@0: } sl@0: sl@0: // Cancel timer and display sl@0: Cancel(); sl@0: iDrawing = EFalse; sl@0: } sl@0: sl@0: void CTPseudoAppEng::TestFinishedL(const TDesC& aFileName) sl@0: { sl@0: RFs myFs; sl@0: User::LeaveIfError(myFs.Connect()); sl@0: RFileWriteStream writer; sl@0: writer.PushL(); // writer on cleanup stack sl@0: User::LeaveIfError(writer.Replace(myFs, aFileName, EFileWrite)); sl@0: writer << _L("Surfaces Test Finished"); sl@0: writer.CommitL(); sl@0: CleanupStack::PopAndDestroy(&writer); sl@0: myFs.Close(); sl@0: } sl@0: sl@0: void CTPseudoAppEng::WriteResultsL(const TDesC& aFileName) sl@0: { sl@0: RFs myFs; sl@0: User::LeaveIfError(myFs.Connect()); sl@0: sl@0: TInt err = myFs.MkDirAll(aFileName); sl@0: sl@0: if (err==KErrNone || err==KErrAlreadyExists) sl@0: { sl@0: RFileWriteStream writer; sl@0: writer.PushL(); // writer on cleanup stack sl@0: sl@0: User::LeaveIfError(writer.Replace(myFs, aFileName, EFileStreamText|EFileWrite)); sl@0: writer.CommitL(); sl@0: CleanupStack::PopAndDestroy(&writer); // writer sl@0: sl@0: CIniData* myData = CIniData::NewL(aFileName); sl@0: CleanupStack::PushL(myData); sl@0: sl@0: TBuf<255> tempStore; sl@0: _LIT(KIntData, "%d"); sl@0: _LIT(KRealData, "%4.1f"); sl@0: sl@0: //Write out the test result, which is essentially a pass if the code reaches here sl@0: tempStore.Format(KIntData, 1); sl@0: TInt err = myData->AddValue(KDefaultSectionName, KGraphicsWservSurfaceTestResult, tempStore); sl@0: User::LeaveIfError(err); sl@0: myData->WriteToFileL(); sl@0: sl@0: //Write out the theoretical maximum frame rate sl@0: TReal frameRate = (iCounterFreq*static_cast(iFrameDuration))/iGceTestResults.iTotalCompoTime; sl@0: sl@0: tempStore.Format(KRealData, frameRate); sl@0: err = myData->AddValue(KDefaultSectionName, KGraphicsWservSurfaceFrameRate, tempStore); sl@0: myData->WriteToFileL(); sl@0: sl@0: //Write out the total test time sl@0: TReal compoTime = static_cast(iGceTestResults.iElapsedTime)/1000; sl@0: sl@0: tempStore.Format(KRealData, compoTime); sl@0: err = myData->AddValue(KDefaultSectionName, KGraphicsWservSurfaceTotalTestTime, tempStore); sl@0: myData->WriteToFileL(); sl@0: sl@0: CleanupStack::PopAndDestroy(myData); sl@0: } sl@0: sl@0: myFs.Close(); sl@0: } sl@0: sl@0: // Timer's RunL() sl@0: void CTPseudoAppEng::RunL() sl@0: { sl@0: if(iFrameCounter != iFrameDuration) sl@0: { sl@0: //If no surface update is required, aSurfaceId will remain as 0 sl@0: TSurfaceId temp; sl@0: iSurfDetails.aSurfaceId = temp.CreateNullId() ; sl@0: sl@0: while(iScreenCounter < iPseudoAppShared->iTestScreens.Count()) sl@0: { sl@0: iPseudoAppShared->iTestScreens[iScreenCounter]->UpdateL(iSurfDetails); sl@0: iScreenCounter++; sl@0: break; sl@0: } sl@0: sl@0: if(!iSurfDetails.aSurfaceId.IsNull()) sl@0: { sl@0: if(iUseGlobalUpdate) sl@0: { sl@0: SendUpdateRequest(KAllScreens); sl@0: } sl@0: else sl@0: { sl@0: SendUpdateRequest(iScreenCounter - 1); sl@0: } sl@0: } sl@0: sl@0: if(iScreenCounter == iPseudoAppShared->iTestScreens.Count()) sl@0: { sl@0: iScreenCounter = 0; sl@0: iFrameCounter++; sl@0: } sl@0: sl@0: // Renew request sl@0: After(TTimeIntervalMicroSeconds32(iFrameDelay)); sl@0: } sl@0: else sl@0: { sl@0: #ifndef T_PSEUDOAPP1 sl@0: WriteResultsL(KWServPseudoAppResultFile); sl@0: TestFinishedL(KWServPseudoAppFinishFile); sl@0: #else sl@0: WriteResultsL(KWServPseudoApp1ResultFile); sl@0: TestFinishedL(KWServPseudoApp1FinishFile); sl@0: #endif //T_PSEUDOAPP1 sl@0: } sl@0: } sl@0: sl@0: // Timer's DoCancel() sl@0: void CTPseudoAppEng::DoCancel() sl@0: { sl@0: // Cancel timer sl@0: CTimer::DoCancel(); sl@0: } sl@0: sl@0: TBool CTPseudoAppEng::Drawing() sl@0: { sl@0: return iDrawing; sl@0: } sl@0: sl@0: void CTPseudoAppEng::SendUpdateRequest(TInt /*aScreen*/) sl@0: { sl@0: //Submit update sl@0: TRect rc[1] = sl@0: { sl@0: TRect(0, 0, iSurfDetails.aSurfaceSize.iWidth, iSurfDetails.aSurfaceSize.iHeight) sl@0: }; sl@0: sl@0: RRegion region(1, rc); sl@0: sl@0: //Use timestamp notification to measure frame rate sl@0: TRequestStatus status; sl@0: sl@0: TTimeStamp timeStamp; sl@0: iSurfaceUpdateSession.NotifyWhenDisplayed(status, timeStamp); sl@0: iTimeStampBefore = User::FastCounter(); sl@0: sl@0: TInt ret = iSurfaceUpdateSession.SubmitUpdate(KAllScreens, iSurfDetails.aSurfaceId, iSurfDetails.aBufferNumber, ®ion); sl@0: sl@0: User::WaitForRequest(status); sl@0: sl@0: TUint64 time = timeStamp(); sl@0: sl@0: if(time < iTimeStampBefore) sl@0: { sl@0: time += UINT_MAX; sl@0: } sl@0: sl@0: iTotalCompositionTime += (time - iTimeStampBefore); sl@0: sl@0: TTime currentTime; sl@0: currentTime.UniversalTime(); sl@0: TTimeIntervalMicroSeconds elapsedTime = currentTime.MicroSecondsFrom(iStartTime); sl@0: sl@0: iGceTestResults.iElapsedTime = (TUint32)(elapsedTime.Int64()/1000); sl@0: iGceTestResults.iTotalCompoTime = (TUint32)(iTotalCompositionTime); sl@0: sl@0: if(ret != KErrNone) sl@0: { sl@0: RDebug::Print(_L("Error submitting update request\n")); sl@0: } sl@0: } sl@0: sl@0: void CTPseudoAppEng::ImportPseudoAppConfigL() sl@0: { sl@0: TDisplayMode mode; sl@0: TSize aScreenSize; sl@0: TInt numberOfScreens; sl@0: sl@0: READ_INI1(number_of_screens, numberOfScreens, iUtils); sl@0: sl@0: iPseudoAppShared = new(ELeave) CTPseudoAppShared; sl@0: for(TInt i=0; iAddTestScreenL(i, mode, iFrameDuration, aScreenSize, &iGceTestResults, KWServPseudoAppConfigFile); sl@0: #else sl@0: iPseudoAppShared->AddTestScreenL(i, mode, iFrameDuration, aScreenSize, &iGceTestResults, KWServPseudoApp1ConfigFile); sl@0: #endif //T_PSEUDOAPP1 sl@0: } sl@0: READ_INI2A(KNullDesC, use_global_surface_update, True, False, iUseGlobalUpdate, ETrue, EFalse, iUtils); sl@0: } sl@0: sl@0: void CTPseudoAppEng::RotateL() sl@0: { sl@0: if (iPseudoAppShared) sl@0: { sl@0: for(TInt i=0; iiTestScreens.Count(); i++) sl@0: { sl@0: if (iPseudoAppShared->iTestScreens[i]) sl@0: { sl@0: if(iPseudoAppShared->iTestScreens[i]->Rotation()) sl@0: { sl@0: iPseudoAppShared->iTestScreens[i]->RotateL(i, iFrameCounter); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: }