os/graphics/windowing/windowserver/test/t_integ/src/t_dsaappeng.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/t_integ/src/t_dsaappeng.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,251 @@
     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 <eikenv.h>
    1.26 +#include <s32file.h>
    1.27 +#include <f32file.h>
    1.28 +#include <iniparser.h>
    1.29 +#include "t_inidata.h"
    1.30 +#include "t_wservconsts.h"
    1.31 +#include "t_dsaappeng.h"
    1.32 +#include "t_perfdata.h"
    1.33 +
    1.34 +
    1.35 +_LIT(KDsaPanicTxt,                  "t_dsaapp.exe");
    1.36 +_LIT(KDsaRotationAbortCount,        "KDsaRotationAbortCount");
    1.37 +
    1.38 +//
    1.39 +// class CTDsaAppEng
    1.40 +//
    1.41 +CTDsaAppEng::CTDsaAppEng(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
    1.42 +: CTimer(CActive::EPriorityStandard),
    1.43 +	iClient(aClient),
    1.44 +	iScreenDevice(aScreenDevice),
    1.45 +	iWindow(aWindow),
    1.46 +    iDrawing(EFalse)
    1.47 +	{    
    1.48 +	}
    1.49 +
    1.50 +CTDsaAppEng* CTDsaAppEng::NewL(RWsSession& aClient, CWsScreenDevice& aScreenDevice, 
    1.51 +                               RWindow& aWindow)
    1.52 +    {
    1.53 +    CTDsaAppEng* self = new (ELeave) CTDsaAppEng(aClient, aScreenDevice, aWindow);
    1.54 +    CleanupStack::PushL(self);
    1.55 +    self->ConstructL();
    1.56 +    CleanupStack::Pop(); // self;
    1.57 +    return self;
    1.58 +    }
    1.59 +
    1.60 +CTDsaAppEng::~CTDsaAppEng()
    1.61 +	{
    1.62 +    if(IsActive())
    1.63 +    	{
    1.64 +	    Cancel();
    1.65 +    	}
    1.66 +
    1.67 +	delete iDirectScreenAccess;	
    1.68 +	iDirectScreenAccess = NULL;
    1.69 +	delete iPerfData;
    1.70 +	iPerfData = NULL;
    1.71 +	iRegion->Close();
    1.72 +	iSemaphore.Close();
    1.73 +	}
    1.74 +
    1.75 +void CTDsaAppEng::ConstructL()
    1.76 +	{
    1.77 +	CTimer::ConstructL();
    1.78 +	iDirectScreenAccess = CDirectScreenAccess::NewL(iClient, iScreenDevice, iWindow, *this);
    1.79 +	iPerfData = CTPerfData::NewL();
    1.80 +	READ_INT(KDsaAppIterations, KWServDsaAppConfigFile, iFinishTesting);
    1.81 +	User::LeaveIfError(iSemaphore.CreateGlobal(KWservDsaSemaphoreName(), 0));
    1.82 +	CActiveScheduler::Add(this);
    1.83 +	}
    1.84 +
    1.85 +void CTDsaAppEng::StartDrawing()
    1.86 +	{
    1.87 +	if (iDrawing)
    1.88 +		{
    1.89 +		User::Panic(KDsaPanicTxt, DirScrAccEngAlreadyStarted);
    1.90 +		}
    1.91 +    
    1.92 + 	TRAPD(dsaErr, iDirectScreenAccess->StartL());
    1.93 +    if(dsaErr == KErrNone)
    1.94 +        {
    1.95 +
    1.96 +	    // Get graphics context for it
    1.97 +	    iGc = iDirectScreenAccess->Gc();
    1.98 +
    1.99 +	    // Get region that DSA can draw in
   1.100 +	    iRegion = iDirectScreenAccess->DrawingRegion();
   1.101 +
   1.102 +	    // Set the display to clip to this region
   1.103 +	    iGc->SetClippingRegion(iRegion);
   1.104 +
   1.105 +        iDrawing = ETrue;
   1.106 +
   1.107 +        // request a timer event after a defined interval
   1.108 +		After(TTimeIntervalMicroSeconds32(0));
   1.109 +        }
   1.110 +	}
   1.111 +
   1.112 +void CTDsaAppEng::StopDrawing()
   1.113 +	{
   1.114 +	if (!iDrawing)
   1.115 +		{
   1.116 +		User::Panic(KDsaPanicTxt, DirScrAccEngAlreadyStopped);
   1.117 +		}
   1.118 +	
   1.119 +	// Cancel timer and display
   1.120 +	Cancel();
   1.121 +	iDrawing = EFalse;
   1.122 +	}
   1.123 +	
   1.124 +// Implement MDirectScreenAccess
   1.125 +void CTDsaAppEng::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/)
   1.126 +	{
   1.127 +	// Restart display   
   1.128 +	TInt scrMode = iScreenDevice.CurrentScreenMode();
   1.129 +	TPixelsTwipsAndRotation sizeAndRotation;
   1.130 +	iScreenDevice.GetScreenModeSizeAndRotation(scrMode, sizeAndRotation);
   1.131 +	
   1.132 +	RDebug::Print(_L("CTDsaAppEng::Restart - Screen Mode: %d"), scrMode);
   1.133 +	RDebug::Print(_L("CTDsaAppEng::Restart - Previous Rotation: %d"), iPrevRotation);
   1.134 +	RDebug::Print(_L("CTDsaAppEng::Restart - Rotation: %d"), sizeAndRotation.iRotation);
   1.135 +	RDebug::Print(_L("CTDsaAppEng::Restart - Height: %d"), sizeAndRotation.iPixelSize.iHeight);
   1.136 +	RDebug::Print(_L("CTDsaAppEng::Restart - Width: %d"), sizeAndRotation.iPixelSize.iWidth);
   1.137 +	
   1.138 +	// since RDirectScreenAccess::ETerminateRegion takes precedence over 
   1.139 +	// RDirectScreenAccess::ETerminateRotation a check of the current screen
   1.140 +	// rotation against the previous rotation is performed to determine whether
   1.141 +	// the abort reason is due to a rotation event
   1.142 +	if (iPrevRotation!=sizeAndRotation.iRotation)
   1.143 +		{
   1.144 +		iRotationAbortCount++;
   1.145 +		iPrevRotation=sizeAndRotation.iRotation;
   1.146 +		}
   1.147 +		
   1.148 +	StartDrawing();    
   1.149 +	}
   1.150 +
   1.151 +void CTDsaAppEng::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
   1.152 +	{
   1.153 +	// Cancel timer and display
   1.154 +	StopDrawing();
   1.155 +	}
   1.156 +
   1.157 +void CTDsaAppEng::CreateTestFileL(const TDesC& aFileName)
   1.158 +	{
   1.159 +	RFs myFs;
   1.160 +	User::LeaveIfError(myFs.Connect());
   1.161 +	RFileWriteStream writer;
   1.162 +	writer.PushL(); // writer on cleanup stack
   1.163 +	User::LeaveIfError(writer.Replace(myFs, aFileName, EFileWrite));
   1.164 +	writer << _L("DSA Test");
   1.165 +	writer.CommitL();
   1.166 +	CleanupStack::PopAndDestroy(&writer);
   1.167 +	myFs.Close();
   1.168 +	}
   1.169 +
   1.170 +void CTDsaAppEng::WriteResultsL(const TDesC& aFileName)
   1.171 +	{
   1.172 +	CIniData* myData=CIniData::NewL(aFileName);
   1.173 +	CleanupStack::PushL(myData);
   1.174 +	
   1.175 +	TBuf<255> tempStore;
   1.176 +	_LIT(KIntData, "%d");
   1.177 +	tempStore.Format(KIntData,iRotationAbortCount);
   1.178 +	TInt err2 = myData->AddValue(KDefaultSectionName, KDsaRotationAbortCount, tempStore);
   1.179 +	if (err2)
   1.180 +		{
   1.181 +		RDebug::Print(_L("CTDsaAppEng::WriteResultsL - unable to add abort count to result file: %d"), err2);
   1.182 +		}
   1.183 +	myData->WriteToFileL();
   1.184 +		
   1.185 +	CleanupStack::PopAndDestroy(myData);
   1.186 +	}
   1.187 +
   1.188 +// Timer's RunL()
   1.189 +void CTDsaAppEng::RunL()
   1.190 +	{
   1.191 +	if (iFrameCount==0)
   1.192 +		{
   1.193 +		iPerfData->StartCounter();
   1.194 +		CreateTestFileL(KWServDsaAppStartFile());
   1.195 +		}
   1.196 +	else
   1.197 +		{
   1.198 +		iPerfData->StopCounterL();
   1.199 +		iPerfData->StartCounter();
   1.200 +		}
   1.201 +	
   1.202 +	if (iFrameCount == 100 || iFrameCount == 200)
   1.203 +		{
   1.204 +		iSemaphore.Wait();
   1.205 +		}
   1.206 +		
   1.207 +	if (iFrameCount==iFinishTesting)
   1.208 +		{
   1.209 +		iDirectScreenAccess->Cancel();
   1.210 +		iPerfData->WriteResultsL(KWServDsaAppResultFile());
   1.211 +		TRAP_IGNORE(WriteResultsL(KWServDsaAppResultFile()));
   1.212 +		TRAPD(err,CreateTestFileL(KWServDsaAppFinishFile()));
   1.213 +		if (err)
   1.214 +			{
   1.215 +			User::Panic(KDsaPanicTxt, err);
   1.216 +			}
   1.217 +		}
   1.218 +	else
   1.219 +		{
   1.220 +		iFrameCount++;
   1.221 +
   1.222 +	    iDirectScreenAccess->ScreenDevice()->Update();
   1.223 +	    iGc->Clear();
   1.224 +		TRgb color(0,0,255);
   1.225 +		
   1.226 +		if (iFrameCount%2)
   1.227 +			{
   1.228 +			color.SetRed(0);
   1.229 +			color.SetBlue(0);
   1.230 +			color.SetGreen(255);
   1.231 +			}
   1.232 +	    
   1.233 +	    iGc->SetBrushColor(color);
   1.234 +	    iGc->SetPenColor(color);
   1.235 +	    iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.236 +		TRect myRect(iWindow.Size());
   1.237 +		iGc->DrawRect(myRect);
   1.238 +
   1.239 +		// Renew request
   1.240 +		After(TTimeIntervalMicroSeconds32(0));
   1.241 +		}
   1.242 +	}
   1.243 +
   1.244 +// Timer's DoCancel()
   1.245 +void CTDsaAppEng::DoCancel()
   1.246 +	{
   1.247 +	// Cancel timer
   1.248 +	CTimer::DoCancel();
   1.249 +	
   1.250 +	// Cancel DSA
   1.251 +	iDirectScreenAccess->Cancel();    
   1.252 +	}
   1.253 +
   1.254 +