os/graphics/graphicstest/uibench/s60/src/tests_zorder/cmultiplesurfaces.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @test
    19  @internalComponent - Internal Symbian test code 
    20 */
    21 
    22 
    23 #include "cmultiplesurfaces.h"
    24 #include "tsmallwindowraster.h"
    25 
    26 
    27 const TInt KTimeBetweenFrames = 100000; // checks every 100 ms for a new message
    28 
    29 // messages which are sent by the test step
    30 const TInt KBringToFront = 1;
    31 const TInt KTerminate = 2;
    32 
    33 // defines number of windows on the screen
    34 const TInt KWindowsAcross = 1;
    35 const TInt KWindowsDown = 1;
    36 
    37 _LIT(KSmallBitmap,"z:\\resource\\apps\\cover2.jpg"); // bitmap that is displayed by the windows
    38 
    39 
    40 CMultipleSurfaces* CMultipleSurfaces::NewL(RWsSession& aWs, RWindowGroup& aWindowGroup, TPtrC childQueueName, CMultipleSurfacesAppUi* aMultipleSurfacesAppUi, TPtrC aParentQueueName)
    41     {
    42     CMultipleSurfaces* self = new (ELeave)CMultipleSurfaces(aWs, aWindowGroup, aMultipleSurfacesAppUi);
    43     self->ConstructL(childQueueName, aParentQueueName);
    44     return self;
    45     }
    46 
    47 CMultipleSurfaces::CMultipleSurfaces(RWsSession& aWs, RWindowGroup& aWindowGroup, CMultipleSurfacesAppUi* aMultipleSurfacesAppUi) :
    48         iWs(aWs), iWindowGroup(aWindowGroup), iMultipleSurfacesAppUi(aMultipleSurfacesAppUi)
    49 	{
    50 	// empty
    51 	}
    52 
    53 CMultipleSurfaces::~CMultipleSurfaces()
    54     {
    55     delete iTimer;
    56     iParentMsgQueue.Send(KTerminate);
    57     iParentMsgQueue.Close();
    58     iMsgQueue.Close();
    59     for (TInt w = 0; w < iSmallWindows.Count(); w++)
    60         {
    61         delete iSmallWindows[w];
    62         }
    63     iSmallWindows.Close();
    64     }
    65 
    66 void CMultipleSurfaces::ConstructL(TPtrC childQueueName, TPtrC aParentQueueName)
    67     {
    68     iTimer = CPeriodic::NewL(CActive::EPriorityIdle);
    69     // available screensize is reduced by the menu bar
    70     TSize screenSize = iMultipleSurfacesAppUi->ClientRect().Size();
    71     
    72     TSize windowSize;
    73     windowSize.iHeight = screenSize.iHeight/KWindowsDown;
    74     windowSize.iWidth = screenSize.iWidth/KWindowsAcross;
    75     // adjust window size to make square windows
    76     if (windowSize.iWidth > windowSize.iHeight)
    77         {
    78         windowSize.iWidth = windowSize.iHeight;
    79         }
    80     else
    81         {
    82         windowSize.iHeight = windowSize.iWidth;
    83         }
    84     
    85     // available screensize is reduced by the menu bar
    86     TPoint initialPosition(iMultipleSurfacesAppUi->ClientRect().iTl);
    87     CSurfaceUtility* utility = CSurfaceUtility::NewL();
    88     CleanupStack::PushL(utility);
    89     CTWindow* smallWindow;
    90     for (TInt i = 0; i < KWindowsAcross; i++)
    91         {
    92         initialPosition.iX = 0;
    93         for (TInt j = 0; j < KWindowsDown; j++)
    94             {
    95             smallWindow = CTSmallWindowRaster::NewL(iWs, iWindowGroup, initialPosition, windowSize);
    96             CleanupStack::PushL(smallWindow);
    97             smallWindow->LoadL(utility, KSmallBitmap());
    98             iSmallWindows.AppendL(smallWindow);
    99             CleanupStack::Pop(smallWindow);
   100             initialPosition.iX += windowSize.iWidth;
   101             }
   102         initialPosition.iY += windowSize.iHeight;
   103         }
   104     CleanupStack::PopAndDestroy(utility);
   105     User::LeaveIfError(iMsgQueue.OpenGlobal(childQueueName));
   106     User::LeaveIfError(iParentMsgQueue.OpenGlobal(aParentQueueName));
   107     // inform test app that the message queues are ready
   108     RProcess::Rendezvous(KErrNone);
   109     }
   110 
   111 
   112 
   113 /**
   114  * Starts a timer which redraws the screen periodically.
   115  */
   116 void CMultipleSurfaces::Start()
   117 	{
   118 	iTimer->Start(0, KTimeBetweenFrames, TCallBack(TimerCallBack, this));
   119 	}
   120 
   121 TInt CMultipleSurfaces::TimerCallBack(TAny* MultipleSurfaces)
   122 	{
   123 	TRAPD(err, static_cast<CMultipleSurfaces*>(MultipleSurfaces)->RenderL());
   124 	return err;
   125 	}
   126 
   127 /**
   128  * Meassures the time it takes to bring this application to the foreground.
   129  * It receives a message from the test step which coordinates the switching.
   130  */
   131 void CMultipleSurfaces::RenderL()
   132 	{
   133 	TInt msg = 0;
   134     iMsgQueue.ReceiveBlocking(msg);
   135     
   136     for (TInt w = 0; w < iSmallWindows.Count(); w++)
   137         {
   138         iSmallWindows[w]->Move(0, 1);
   139         iSmallWindows[w]->RenderL();
   140         }
   141     iWs.Flush();
   142     iWs.Finish();	    
   143     
   144     switch (msg)
   145         {
   146         case KBringToFront:
   147             {
   148             TUint32 timeStamp = User::FastCounter();
   149             iMultipleSurfacesAppUi->BringToFront();
   150             TUint32 time = User::FastCounter() - timeStamp;
   151             iParentMsgQueue.Send(time);
   152             break;
   153             }
   154         case KTerminate:
   155             {
   156             Stop();
   157             iMultipleSurfacesAppUi->Terminate();
   158             break;
   159             }
   160         }    
   161 	}
   162 
   163 /**
   164  * Stops the timer.
   165  */
   166 void CMultipleSurfaces::Stop()
   167 	{
   168 	if(iTimer)
   169 		{
   170 		iTimer->Cancel();
   171 		}	
   172 	}