1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstest/uibench/s60/src/tests_zorder/cmultiplesurfaces.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,172 @@
1.4 +// Copyright (c) 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 - Internal Symbian test code
1.23 +*/
1.24 +
1.25 +
1.26 +#include "cmultiplesurfaces.h"
1.27 +#include "tsmallwindowraster.h"
1.28 +
1.29 +
1.30 +const TInt KTimeBetweenFrames = 100000; // checks every 100 ms for a new message
1.31 +
1.32 +// messages which are sent by the test step
1.33 +const TInt KBringToFront = 1;
1.34 +const TInt KTerminate = 2;
1.35 +
1.36 +// defines number of windows on the screen
1.37 +const TInt KWindowsAcross = 1;
1.38 +const TInt KWindowsDown = 1;
1.39 +
1.40 +_LIT(KSmallBitmap,"z:\\resource\\apps\\cover2.jpg"); // bitmap that is displayed by the windows
1.41 +
1.42 +
1.43 +CMultipleSurfaces* CMultipleSurfaces::NewL(RWsSession& aWs, RWindowGroup& aWindowGroup, TPtrC childQueueName, CMultipleSurfacesAppUi* aMultipleSurfacesAppUi, TPtrC aParentQueueName)
1.44 + {
1.45 + CMultipleSurfaces* self = new (ELeave)CMultipleSurfaces(aWs, aWindowGroup, aMultipleSurfacesAppUi);
1.46 + self->ConstructL(childQueueName, aParentQueueName);
1.47 + return self;
1.48 + }
1.49 +
1.50 +CMultipleSurfaces::CMultipleSurfaces(RWsSession& aWs, RWindowGroup& aWindowGroup, CMultipleSurfacesAppUi* aMultipleSurfacesAppUi) :
1.51 + iWs(aWs), iWindowGroup(aWindowGroup), iMultipleSurfacesAppUi(aMultipleSurfacesAppUi)
1.52 + {
1.53 + // empty
1.54 + }
1.55 +
1.56 +CMultipleSurfaces::~CMultipleSurfaces()
1.57 + {
1.58 + delete iTimer;
1.59 + iParentMsgQueue.Send(KTerminate);
1.60 + iParentMsgQueue.Close();
1.61 + iMsgQueue.Close();
1.62 + for (TInt w = 0; w < iSmallWindows.Count(); w++)
1.63 + {
1.64 + delete iSmallWindows[w];
1.65 + }
1.66 + iSmallWindows.Close();
1.67 + }
1.68 +
1.69 +void CMultipleSurfaces::ConstructL(TPtrC childQueueName, TPtrC aParentQueueName)
1.70 + {
1.71 + iTimer = CPeriodic::NewL(CActive::EPriorityIdle);
1.72 + // available screensize is reduced by the menu bar
1.73 + TSize screenSize = iMultipleSurfacesAppUi->ClientRect().Size();
1.74 +
1.75 + TSize windowSize;
1.76 + windowSize.iHeight = screenSize.iHeight/KWindowsDown;
1.77 + windowSize.iWidth = screenSize.iWidth/KWindowsAcross;
1.78 + // adjust window size to make square windows
1.79 + if (windowSize.iWidth > windowSize.iHeight)
1.80 + {
1.81 + windowSize.iWidth = windowSize.iHeight;
1.82 + }
1.83 + else
1.84 + {
1.85 + windowSize.iHeight = windowSize.iWidth;
1.86 + }
1.87 +
1.88 + // available screensize is reduced by the menu bar
1.89 + TPoint initialPosition(iMultipleSurfacesAppUi->ClientRect().iTl);
1.90 + CSurfaceUtility* utility = CSurfaceUtility::NewL();
1.91 + CleanupStack::PushL(utility);
1.92 + CTWindow* smallWindow;
1.93 + for (TInt i = 0; i < KWindowsAcross; i++)
1.94 + {
1.95 + initialPosition.iX = 0;
1.96 + for (TInt j = 0; j < KWindowsDown; j++)
1.97 + {
1.98 + smallWindow = CTSmallWindowRaster::NewL(iWs, iWindowGroup, initialPosition, windowSize);
1.99 + CleanupStack::PushL(smallWindow);
1.100 + smallWindow->LoadL(utility, KSmallBitmap());
1.101 + iSmallWindows.AppendL(smallWindow);
1.102 + CleanupStack::Pop(smallWindow);
1.103 + initialPosition.iX += windowSize.iWidth;
1.104 + }
1.105 + initialPosition.iY += windowSize.iHeight;
1.106 + }
1.107 + CleanupStack::PopAndDestroy(utility);
1.108 + User::LeaveIfError(iMsgQueue.OpenGlobal(childQueueName));
1.109 + User::LeaveIfError(iParentMsgQueue.OpenGlobal(aParentQueueName));
1.110 + // inform test app that the message queues are ready
1.111 + RProcess::Rendezvous(KErrNone);
1.112 + }
1.113 +
1.114 +
1.115 +
1.116 +/**
1.117 + * Starts a timer which redraws the screen periodically.
1.118 + */
1.119 +void CMultipleSurfaces::Start()
1.120 + {
1.121 + iTimer->Start(0, KTimeBetweenFrames, TCallBack(TimerCallBack, this));
1.122 + }
1.123 +
1.124 +TInt CMultipleSurfaces::TimerCallBack(TAny* MultipleSurfaces)
1.125 + {
1.126 + TRAPD(err, static_cast<CMultipleSurfaces*>(MultipleSurfaces)->RenderL());
1.127 + return err;
1.128 + }
1.129 +
1.130 +/**
1.131 + * Meassures the time it takes to bring this application to the foreground.
1.132 + * It receives a message from the test step which coordinates the switching.
1.133 + */
1.134 +void CMultipleSurfaces::RenderL()
1.135 + {
1.136 + TInt msg = 0;
1.137 + iMsgQueue.ReceiveBlocking(msg);
1.138 +
1.139 + for (TInt w = 0; w < iSmallWindows.Count(); w++)
1.140 + {
1.141 + iSmallWindows[w]->Move(0, 1);
1.142 + iSmallWindows[w]->RenderL();
1.143 + }
1.144 + iWs.Flush();
1.145 + iWs.Finish();
1.146 +
1.147 + switch (msg)
1.148 + {
1.149 + case KBringToFront:
1.150 + {
1.151 + TUint32 timeStamp = User::FastCounter();
1.152 + iMultipleSurfacesAppUi->BringToFront();
1.153 + TUint32 time = User::FastCounter() - timeStamp;
1.154 + iParentMsgQueue.Send(time);
1.155 + break;
1.156 + }
1.157 + case KTerminate:
1.158 + {
1.159 + Stop();
1.160 + iMultipleSurfacesAppUi->Terminate();
1.161 + break;
1.162 + }
1.163 + }
1.164 + }
1.165 +
1.166 +/**
1.167 + * Stops the timer.
1.168 + */
1.169 +void CMultipleSurfaces::Stop()
1.170 + {
1.171 + if(iTimer)
1.172 + {
1.173 + iTimer->Cancel();
1.174 + }
1.175 + }