os/graphics/graphicstest/uibench/s60/src/tests_zorder/cglplanets.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 #include "cglplanets.h"
    23 #include "glplanetsapp.h"
    24 
    25 const TInt KTimeBetweenFrames = 100000; // 100 ms
    26 
    27 const TInt KBringToFront = 1;
    28 const TInt KTerminate = 2;
    29 
    30 
    31 CGLPlanets* CGLPlanets::NewL(RWindow& aWindow, TPtrC aBackgroundColor, CGLPlanetsAppUi* aApplication, TPtrC aParentQueueName)
    32     {
    33     CGLPlanets* self = new (ELeave)CGLPlanets(aWindow, aApplication);
    34     self->ConstructL(aBackgroundColor, aParentQueueName);
    35     return self;
    36     }
    37 
    38 CGLPlanets::CGLPlanets(RWindow& aWindow, CGLPlanetsAppUi* aApplication) : iWindow(aWindow),
    39         iApplication(aApplication)
    40 	{
    41 	// empty
    42 	}
    43 
    44 CGLPlanets::~CGLPlanets()
    45 	{
    46 	delete iTimer;
    47 	delete iEglEnvironment;
    48 	delete iModel;
    49 	iParentMsgQueue.Send(KTerminate);
    50 	iParentMsgQueue.Close();
    51 	iMsgQueue.Close();
    52 	}
    53 
    54 
    55 
    56 void CGLPlanets::ConstructL(TPtrC aBackgroundColor, TPtrC aParentQueueName)
    57 	{
    58 	iTimer = CPeriodic::NewL(CActive::EPriorityIdle);
    59 	iEglEnvironment = CEglEnvironment::NewL(iWindow);
    60 	iModel = CModel::NewL(iEglEnvironment->Display(), iEglEnvironment->Surface(), aBackgroundColor);
    61 	User::LeaveIfError(iMsgQueue.OpenGlobal(aBackgroundColor));
    62 	User::LeaveIfError(iParentMsgQueue.OpenGlobal(aParentQueueName));
    63 	// inform test app that the message queues are ready
    64 	RProcess::Rendezvous(KErrNone);
    65 	}
    66 
    67 void CGLPlanets::Start()
    68 	{
    69 	// redraw the screen periodically
    70 	iTimer->Start(0, KTimeBetweenFrames, TCallBack(TimerCallBack, this));
    71 	}
    72 
    73 TInt CGLPlanets::TimerCallBack(TAny* aGLPlanet)
    74 	{
    75 	static_cast<CGLPlanets*>(aGLPlanet)->Render();
    76 	return KErrNone;
    77 	}
    78 
    79 void CGLPlanets::Render()
    80 	{
    81 	TInt msg = 0;
    82 	iMsgQueue.ReceiveBlocking(msg); // Receive info from the test
    83 	iModel->DrawToBuffer(iTime++);
    84 	iEglEnvironment->DrawToWindow();
    85 	switch (msg)
    86 		{
    87 		case KBringToFront:
    88 			{
    89 			TUint32 then = User::FastCounter();
    90 			iApplication->BringToFront();
    91 			TUint32 now = User::FastCounter();
    92 			TUint32 time = (now - then);
    93 			iParentMsgQueue.Send(time);
    94 			break;
    95 			}
    96 		case KTerminate:
    97 			Stop();
    98 			iApplication->Terminate();
    99 			break;
   100 		}
   101 	}
   102 
   103 void CGLPlanets::Stop()
   104 	{
   105 	if(iTimer)
   106 		{
   107 		iTimer->Cancel();
   108 		}	
   109 	}