sl@0: // Copyright (c) 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 - Internal Symbian test code sl@0: */ sl@0: sl@0: sl@0: #include "cmultiplesurfaces.h" sl@0: #include "tsmallwindowraster.h" sl@0: sl@0: sl@0: const TInt KTimeBetweenFrames = 100000; // checks every 100 ms for a new message sl@0: sl@0: // messages which are sent by the test step sl@0: const TInt KBringToFront = 1; sl@0: const TInt KTerminate = 2; sl@0: sl@0: // defines number of windows on the screen sl@0: const TInt KWindowsAcross = 1; sl@0: const TInt KWindowsDown = 1; sl@0: sl@0: _LIT(KSmallBitmap,"z:\\resource\\apps\\cover2.jpg"); // bitmap that is displayed by the windows sl@0: sl@0: sl@0: CMultipleSurfaces* CMultipleSurfaces::NewL(RWsSession& aWs, RWindowGroup& aWindowGroup, TPtrC childQueueName, CMultipleSurfacesAppUi* aMultipleSurfacesAppUi, TPtrC aParentQueueName) sl@0: { sl@0: CMultipleSurfaces* self = new (ELeave)CMultipleSurfaces(aWs, aWindowGroup, aMultipleSurfacesAppUi); sl@0: self->ConstructL(childQueueName, aParentQueueName); sl@0: return self; sl@0: } sl@0: sl@0: CMultipleSurfaces::CMultipleSurfaces(RWsSession& aWs, RWindowGroup& aWindowGroup, CMultipleSurfacesAppUi* aMultipleSurfacesAppUi) : sl@0: iWs(aWs), iWindowGroup(aWindowGroup), iMultipleSurfacesAppUi(aMultipleSurfacesAppUi) sl@0: { sl@0: // empty sl@0: } sl@0: sl@0: CMultipleSurfaces::~CMultipleSurfaces() sl@0: { sl@0: delete iTimer; sl@0: iParentMsgQueue.Send(KTerminate); sl@0: iParentMsgQueue.Close(); sl@0: iMsgQueue.Close(); sl@0: for (TInt w = 0; w < iSmallWindows.Count(); w++) sl@0: { sl@0: delete iSmallWindows[w]; sl@0: } sl@0: iSmallWindows.Close(); sl@0: } sl@0: sl@0: void CMultipleSurfaces::ConstructL(TPtrC childQueueName, TPtrC aParentQueueName) sl@0: { sl@0: iTimer = CPeriodic::NewL(CActive::EPriorityIdle); sl@0: // available screensize is reduced by the menu bar sl@0: TSize screenSize = iMultipleSurfacesAppUi->ClientRect().Size(); sl@0: sl@0: TSize windowSize; sl@0: windowSize.iHeight = screenSize.iHeight/KWindowsDown; sl@0: windowSize.iWidth = screenSize.iWidth/KWindowsAcross; sl@0: // adjust window size to make square windows sl@0: if (windowSize.iWidth > windowSize.iHeight) sl@0: { sl@0: windowSize.iWidth = windowSize.iHeight; sl@0: } sl@0: else sl@0: { sl@0: windowSize.iHeight = windowSize.iWidth; sl@0: } sl@0: sl@0: // available screensize is reduced by the menu bar sl@0: TPoint initialPosition(iMultipleSurfacesAppUi->ClientRect().iTl); sl@0: CSurfaceUtility* utility = CSurfaceUtility::NewL(); sl@0: CleanupStack::PushL(utility); sl@0: CTWindow* smallWindow; sl@0: for (TInt i = 0; i < KWindowsAcross; i++) sl@0: { sl@0: initialPosition.iX = 0; sl@0: for (TInt j = 0; j < KWindowsDown; j++) sl@0: { sl@0: smallWindow = CTSmallWindowRaster::NewL(iWs, iWindowGroup, initialPosition, windowSize); sl@0: CleanupStack::PushL(smallWindow); sl@0: smallWindow->LoadL(utility, KSmallBitmap()); sl@0: iSmallWindows.AppendL(smallWindow); sl@0: CleanupStack::Pop(smallWindow); sl@0: initialPosition.iX += windowSize.iWidth; sl@0: } sl@0: initialPosition.iY += windowSize.iHeight; sl@0: } sl@0: CleanupStack::PopAndDestroy(utility); sl@0: User::LeaveIfError(iMsgQueue.OpenGlobal(childQueueName)); sl@0: User::LeaveIfError(iParentMsgQueue.OpenGlobal(aParentQueueName)); sl@0: // inform test app that the message queues are ready sl@0: RProcess::Rendezvous(KErrNone); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: * Starts a timer which redraws the screen periodically. sl@0: */ sl@0: void CMultipleSurfaces::Start() sl@0: { sl@0: iTimer->Start(0, KTimeBetweenFrames, TCallBack(TimerCallBack, this)); sl@0: } sl@0: sl@0: TInt CMultipleSurfaces::TimerCallBack(TAny* MultipleSurfaces) sl@0: { sl@0: TRAPD(err, static_cast(MultipleSurfaces)->RenderL()); sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: * Meassures the time it takes to bring this application to the foreground. sl@0: * It receives a message from the test step which coordinates the switching. sl@0: */ sl@0: void CMultipleSurfaces::RenderL() sl@0: { sl@0: TInt msg = 0; sl@0: iMsgQueue.ReceiveBlocking(msg); sl@0: sl@0: for (TInt w = 0; w < iSmallWindows.Count(); w++) sl@0: { sl@0: iSmallWindows[w]->Move(0, 1); sl@0: iSmallWindows[w]->RenderL(); sl@0: } sl@0: iWs.Flush(); sl@0: iWs.Finish(); sl@0: sl@0: switch (msg) sl@0: { sl@0: case KBringToFront: sl@0: { sl@0: TUint32 timeStamp = User::FastCounter(); sl@0: iMultipleSurfacesAppUi->BringToFront(); sl@0: TUint32 time = User::FastCounter() - timeStamp; sl@0: iParentMsgQueue.Send(time); sl@0: break; sl@0: } sl@0: case KTerminate: sl@0: { sl@0: Stop(); sl@0: iMultipleSurfacesAppUi->Terminate(); sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Stops the timer. sl@0: */ sl@0: void CMultipleSurfaces::Stop() sl@0: { sl@0: if(iTimer) sl@0: { sl@0: iTimer->Cancel(); sl@0: } sl@0: }