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 sl@0: #include sl@0: #include "t_inidata.h" sl@0: #include "t_wservconsts.h" sl@0: #include "t_dsaappeng.h" sl@0: #include "t_perfdata.h" sl@0: sl@0: sl@0: _LIT(KDsaPanicTxt, "t_dsaapp.exe"); sl@0: _LIT(KDsaRotationAbortCount, "KDsaRotationAbortCount"); sl@0: sl@0: // sl@0: // class CTDsaAppEng sl@0: // sl@0: CTDsaAppEng::CTDsaAppEng(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow) sl@0: : CTimer(CActive::EPriorityStandard), sl@0: iClient(aClient), sl@0: iScreenDevice(aScreenDevice), sl@0: iWindow(aWindow), sl@0: iDrawing(EFalse) sl@0: { sl@0: } sl@0: sl@0: CTDsaAppEng* CTDsaAppEng::NewL(RWsSession& aClient, CWsScreenDevice& aScreenDevice, sl@0: RWindow& aWindow) sl@0: { sl@0: CTDsaAppEng* self = new (ELeave) CTDsaAppEng(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: CTDsaAppEng::~CTDsaAppEng() sl@0: { sl@0: if(IsActive()) sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: delete iDirectScreenAccess; sl@0: iDirectScreenAccess = NULL; sl@0: delete iPerfData; sl@0: iPerfData = NULL; sl@0: iRegion->Close(); sl@0: iSemaphore.Close(); sl@0: } sl@0: sl@0: void CTDsaAppEng::ConstructL() sl@0: { sl@0: CTimer::ConstructL(); sl@0: iDirectScreenAccess = CDirectScreenAccess::NewL(iClient, iScreenDevice, iWindow, *this); sl@0: iPerfData = CTPerfData::NewL(); sl@0: READ_INT(KDsaAppIterations, KWServDsaAppConfigFile, iFinishTesting); sl@0: User::LeaveIfError(iSemaphore.CreateGlobal(KWservDsaSemaphoreName(), 0)); sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: void CTDsaAppEng::StartDrawing() sl@0: { sl@0: if (iDrawing) sl@0: { sl@0: User::Panic(KDsaPanicTxt, DirScrAccEngAlreadyStarted); sl@0: } sl@0: sl@0: TRAPD(dsaErr, iDirectScreenAccess->StartL()); sl@0: if(dsaErr == KErrNone) sl@0: { sl@0: sl@0: // Get graphics context for it sl@0: iGc = iDirectScreenAccess->Gc(); sl@0: sl@0: // Get region that DSA can draw in sl@0: iRegion = iDirectScreenAccess->DrawingRegion(); sl@0: sl@0: // Set the display to clip to this region sl@0: iGc->SetClippingRegion(iRegion); sl@0: sl@0: iDrawing = ETrue; sl@0: sl@0: // request a timer event after a defined interval sl@0: After(TTimeIntervalMicroSeconds32(0)); sl@0: } sl@0: } sl@0: sl@0: void CTDsaAppEng::StopDrawing() sl@0: { sl@0: if (!iDrawing) sl@0: { sl@0: User::Panic(KDsaPanicTxt, DirScrAccEngAlreadyStopped); sl@0: } sl@0: sl@0: // Cancel timer and display sl@0: Cancel(); sl@0: iDrawing = EFalse; sl@0: } sl@0: sl@0: // Implement MDirectScreenAccess sl@0: void CTDsaAppEng::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/) sl@0: { sl@0: // Restart display sl@0: TInt scrMode = iScreenDevice.CurrentScreenMode(); sl@0: TPixelsTwipsAndRotation sizeAndRotation; sl@0: iScreenDevice.GetScreenModeSizeAndRotation(scrMode, sizeAndRotation); sl@0: sl@0: RDebug::Print(_L("CTDsaAppEng::Restart - Screen Mode: %d"), scrMode); sl@0: RDebug::Print(_L("CTDsaAppEng::Restart - Previous Rotation: %d"), iPrevRotation); sl@0: RDebug::Print(_L("CTDsaAppEng::Restart - Rotation: %d"), sizeAndRotation.iRotation); sl@0: RDebug::Print(_L("CTDsaAppEng::Restart - Height: %d"), sizeAndRotation.iPixelSize.iHeight); sl@0: RDebug::Print(_L("CTDsaAppEng::Restart - Width: %d"), sizeAndRotation.iPixelSize.iWidth); sl@0: sl@0: // since RDirectScreenAccess::ETerminateRegion takes precedence over sl@0: // RDirectScreenAccess::ETerminateRotation a check of the current screen sl@0: // rotation against the previous rotation is performed to determine whether sl@0: // the abort reason is due to a rotation event sl@0: if (iPrevRotation!=sizeAndRotation.iRotation) sl@0: { sl@0: iRotationAbortCount++; sl@0: iPrevRotation=sizeAndRotation.iRotation; sl@0: } sl@0: sl@0: StartDrawing(); sl@0: } sl@0: sl@0: void CTDsaAppEng::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/) sl@0: { sl@0: // Cancel timer and display sl@0: StopDrawing(); sl@0: } sl@0: sl@0: void CTDsaAppEng::CreateTestFileL(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("DSA Test"); sl@0: writer.CommitL(); sl@0: CleanupStack::PopAndDestroy(&writer); sl@0: myFs.Close(); sl@0: } sl@0: sl@0: void CTDsaAppEng::WriteResultsL(const TDesC& aFileName) 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: tempStore.Format(KIntData,iRotationAbortCount); sl@0: TInt err2 = myData->AddValue(KDefaultSectionName, KDsaRotationAbortCount, tempStore); sl@0: if (err2) sl@0: { sl@0: RDebug::Print(_L("CTDsaAppEng::WriteResultsL - unable to add abort count to result file: %d"), err2); sl@0: } sl@0: myData->WriteToFileL(); sl@0: sl@0: CleanupStack::PopAndDestroy(myData); sl@0: } sl@0: sl@0: // Timer's RunL() sl@0: void CTDsaAppEng::RunL() sl@0: { sl@0: if (iFrameCount==0) sl@0: { sl@0: iPerfData->StartCounter(); sl@0: CreateTestFileL(KWServDsaAppStartFile()); sl@0: } sl@0: else sl@0: { sl@0: iPerfData->StopCounterL(); sl@0: iPerfData->StartCounter(); sl@0: } sl@0: sl@0: if (iFrameCount == 100 || iFrameCount == 200) sl@0: { sl@0: iSemaphore.Wait(); sl@0: } sl@0: sl@0: if (iFrameCount==iFinishTesting) sl@0: { sl@0: iDirectScreenAccess->Cancel(); sl@0: iPerfData->WriteResultsL(KWServDsaAppResultFile()); sl@0: TRAP_IGNORE(WriteResultsL(KWServDsaAppResultFile())); sl@0: TRAPD(err,CreateTestFileL(KWServDsaAppFinishFile())); sl@0: if (err) sl@0: { sl@0: User::Panic(KDsaPanicTxt, err); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: iFrameCount++; sl@0: sl@0: iDirectScreenAccess->ScreenDevice()->Update(); sl@0: iGc->Clear(); sl@0: TRgb color(0,0,255); sl@0: sl@0: if (iFrameCount%2) sl@0: { sl@0: color.SetRed(0); sl@0: color.SetBlue(0); sl@0: color.SetGreen(255); sl@0: } sl@0: sl@0: iGc->SetBrushColor(color); sl@0: iGc->SetPenColor(color); sl@0: iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: TRect myRect(iWindow.Size()); sl@0: iGc->DrawRect(myRect); sl@0: sl@0: // Renew request sl@0: After(TTimeIntervalMicroSeconds32(0)); sl@0: } sl@0: } sl@0: sl@0: // Timer's DoCancel() sl@0: void CTDsaAppEng::DoCancel() sl@0: { sl@0: // Cancel timer sl@0: CTimer::DoCancel(); sl@0: sl@0: // Cancel DSA sl@0: iDirectScreenAccess->Cancel(); sl@0: } sl@0: sl@0: