os/graphics/windowing/windowserver/test/t_integ/src/t_app1eng.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_app1eng.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,256 @@
     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 <iniparser.h>
    1.26 +#include "t_app1eng.h"
    1.27 +#include "t_inidata.h"
    1.28 +#include "t_wservconsts.h"
    1.29 +
    1.30 +
    1.31 +_LIT(KTApp1ScrMode,  "KTApp1ScrMode%d");
    1.32 +_LIT(KTApp1Rotation, "KTApp1Rotation%d");
    1.33 +_LIT(KTApp1PanicTxt,   "t_app1.exe");
    1.34 +
    1.35 +//
    1.36 +// class CTApp1Eng
    1.37 +//
    1.38 +CTApp1Eng::CTApp1Eng(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
    1.39 +: CTimer(CActive::EPriorityLow),
    1.40 +	iClient(aClient),
    1.41 +	iWindow(aWindow),
    1.42 +	iScreenDevice(aScreenDevice),
    1.43 +    iDrawing(EFalse),
    1.44 +    iRotationFlag(EFalse)
    1.45 +	{
    1.46 +	}
    1.47 +
    1.48 +CTApp1Eng* CTApp1Eng::NewL(RWsSession& aClient, CWsScreenDevice& aScreenDevice, RWindow& aWindow)
    1.49 +    {
    1.50 +    CTApp1Eng* self = new (ELeave) CTApp1Eng(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 +CTApp1Eng::~CTApp1Eng()
    1.58 +	{
    1.59 +    if(IsActive())
    1.60 +    	{
    1.61 +	    Cancel();
    1.62 +    	}
    1.63 +
    1.64 +    iRotationList.Close();
    1.65 +    iScrModeList.Close();
    1.66 +    iSemaphore.Close();
    1.67 +	}
    1.68 +
    1.69 +void CTApp1Eng::ConstructL()
    1.70 +	{
    1.71 +	CTimer::ConstructL();
    1.72 +	User::LeaveIfError(iScreenDevice.CreateContext(iGc));
    1.73 +
    1.74 +	HBufC* rotFlag = NULL;
    1.75 +	READ_STR(KTApp1RotationFlag, KWServTApp1ConfigFile, rotFlag);
    1.76 +
    1.77 +	// check to see if instead of the default behaviour of drawing to
    1.78 +	// window with alternate frames of red/blue, that the app is to
    1.79 +	// periodically cause the screen to rotate, which is all defined
    1.80 +	// in the configuration file created by the test step
    1.81 +	if (rotFlag!=NULL && rotFlag->Des().Compare(_L("ETrue")) == KErrNone)
    1.82 +		{
    1.83 +		delete rotFlag;
    1.84 +		iRotationFlag=ETrue;
    1.85 +
    1.86 +		// setup rotation and screen mode lists
    1.87 +		TBool moreData=ETrue;
    1.88 +		TInt index=0;
    1.89 +		TBuf<255> tempStore;
    1.90 +		CIniData * iniData = CIniData::NewL(KWServTApp1ConfigFile);
    1.91 +		CleanupStack::PushL(iniData);
    1.92 +
    1.93 +		// read in rotations to be performed
    1.94 +		while (moreData)
    1.95 +			{
    1.96 +			TInt scrMode;
    1.97 +			tempStore.Format(KTApp1ScrMode, ++index);
    1.98 +			moreData = iniData->FindVar(KDefaultSectionName, tempStore, scrMode);
    1.99 +			if (moreData)
   1.100 +				{
   1.101 +				TInt rotation;
   1.102 +				tempStore.Format(KTApp1Rotation, index);
   1.103 +				moreData = iniData->FindVar(KDefaultSectionName, tempStore, rotation);
   1.104 +				if (moreData)
   1.105 +					{
   1.106 +					RDebug::Print(_L("CTApp1Eng::ConstructL - Screen Mode: %d, Rotation: %d"),scrMode,rotation);
   1.107 +					iRotationList.AppendL(rotation);
   1.108 +					iScrModeList.AppendL(scrMode);
   1.109 +					}
   1.110 +				else
   1.111 +					{
   1.112 +					User::Panic(KTApp1PanicTxt(), KErrNotFound);
   1.113 +					}
   1.114 +				}
   1.115 +			else
   1.116 +				{
   1.117 +				moreData=EFalse;
   1.118 +				}
   1.119 +			}
   1.120 +
   1.121 +		CleanupStack::PopAndDestroy(iniData);
   1.122 +
   1.123 +		// setup the number of frames to be counted between each
   1.124 +		// screen rotation
   1.125 +		TInt iters = 0;
   1.126 +		READ_INT(KTApp1Iterations, KWServTApp1ConfigFile, iters);
   1.127 +		iRotationTimer = iters/(iRotationList.Count()+1);
   1.128 +		RDebug::Print(_L("CTApp1Eng::ConstructL - Rotation Timer: %d"), iRotationTimer);
   1.129 +
   1.130 +		if (iRotationList.Count()==0)
   1.131 +			{
   1.132 +			User::Panic(KTApp1PanicTxt(), KErrNotFound);
   1.133 +			}
   1.134 +		}
   1.135 +	User::LeaveIfError(iSemaphore.OpenGlobal(KWservDsaSemaphoreName));
   1.136 +
   1.137 +	CActiveScheduler::Add(this);
   1.138 +	}
   1.139 +
   1.140 +void CTApp1Eng::StartDrawing()
   1.141 +	{
   1.142 +	if (iDrawing)
   1.143 +		{
   1.144 +		User::Panic(KTApp1PanicTxt(), TApp1EngAlreadyStarted);
   1.145 +		}
   1.146 +
   1.147 +	iDrawing=ETrue;
   1.148 +
   1.149 +	After(TTimeIntervalMicroSeconds32(0));
   1.150 +	}
   1.151 +
   1.152 +void CTApp1Eng::StopDrawing()
   1.153 +	{
   1.154 +	if (!iDrawing)
   1.155 +		{
   1.156 +		User::Panic(KTApp1PanicTxt(), TApp1EngAlreadyStopped);
   1.157 +		}
   1.158 +
   1.159 +	// Cancel timer and display
   1.160 +	Cancel();
   1.161 +	iDrawing = EFalse;
   1.162 +	}
   1.163 +
   1.164 +
   1.165 +// Timer's RunL()
   1.166 +void CTApp1Eng::RunL()
   1.167 +	{
   1.168 +	iFrameCount++;
   1.169 +
   1.170 +	if (iFrameCount==1)
   1.171 +		{
   1.172 +		RDebug::Print(_L("CTApp1Eng::RunL - Rotation Flag: %d"), iRotationFlag);
   1.173 +		}
   1.174 +
   1.175 +	// just draw to window, with alternate frames of red and blue
   1.176 +	if (iRotationFlag==EFalse)
   1.177 +		{
   1.178 +		iGc->Activate(iWindow);
   1.179 +		TRect myRect(iWindow.Size());
   1.180 +		TRgb color(0,0,255);
   1.181 +
   1.182 +		if (iFrameCount%2)
   1.183 +			{
   1.184 +			color.SetRed(255);
   1.185 +			color.SetBlue(0);
   1.186 +			}
   1.187 +
   1.188 +	    iGc->SetBrushColor(color);
   1.189 +	    iWindow.SetBackgroundColor(color);
   1.190 +	    iGc->SetPenColor(color);
   1.191 +	    iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.192 +		iGc->DrawRect(myRect);
   1.193 +		iGc->Deactivate();
   1.194 +
   1.195 +		iDrawing=EFalse;
   1.196 +		iWindow.Invalidate();
   1.197 +		}
   1.198 +	// else rotate screen
   1.199 +	else
   1.200 +		{
   1.201 +		if (iFrameCount==iRotationTimer)
   1.202 +			{
   1.203 +			iSemaphore.Signal();
   1.204 +			iFrameCount=0;
   1.205 +
   1.206 +			if (iRotationCount<iRotationList.Count())
   1.207 +				{
   1.208 +				TInt rotation = iRotationList[iRotationCount];
   1.209 +				TInt scrMode = iScrModeList[iRotationCount];
   1.210 +
   1.211 +				switch (rotation)
   1.212 +					{
   1.213 +					case 0:
   1.214 +						{
   1.215 +						iScreenDevice.SetCurrentRotations(scrMode,CFbsBitGc::EGraphicsOrientationNormal);
   1.216 +						break;
   1.217 +						}
   1.218 +					case 90:
   1.219 +						{
   1.220 +						iScreenDevice.SetCurrentRotations(scrMode,CFbsBitGc::EGraphicsOrientationRotated90);
   1.221 +						iScreenDevice.SetScreenMode(scrMode);
   1.222 +						break;
   1.223 +						}
   1.224 +					case 180:
   1.225 +						{
   1.226 +						iScreenDevice.SetCurrentRotations(scrMode,CFbsBitGc::EGraphicsOrientationRotated180);
   1.227 +						break;
   1.228 +						}
   1.229 +					case 270:
   1.230 +						{
   1.231 +						iScreenDevice.SetCurrentRotations(scrMode,CFbsBitGc::EGraphicsOrientationRotated270);
   1.232 +						break;
   1.233 +						}
   1.234 +					default:
   1.235 +						{
   1.236 +						RDebug::Print(_L("CTApp1Eng::RunL - Invalid Rotation: %d"),rotation);
   1.237 +						User::Leave(KErrAbort);
   1.238 +						break;
   1.239 +						}
   1.240 +					}
   1.241 +				RDebug::Print(_L("CTApp1Eng::RunL - Screen Mode: %d, Rotation: %d"),scrMode, rotation);
   1.242 +				iScreenDevice.SetScreenMode(scrMode);
   1.243 +				}
   1.244 +
   1.245 +			iRotationCount++;
   1.246 +			}
   1.247 +
   1.248 +		After(TTimeIntervalMicroSeconds32(0));
   1.249 +		}
   1.250 +	}
   1.251 +
   1.252 +// Timer's DoCancel()
   1.253 +void CTApp1Eng::DoCancel()
   1.254 +	{
   1.255 +	// Cancel timer
   1.256 +	CTimer::DoCancel();
   1.257 +	}
   1.258 +
   1.259 +