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.
sl@0
     1
 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
 // All rights reserved.
sl@0
     3
 // This component and the accompanying materials are made available
sl@0
     4
 // under the terms of "Eclipse Public License v1.0"
sl@0
     5
 // which accompanies this distribution, and is available
sl@0
     6
 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
 //
sl@0
     8
 // Initial Contributors:
sl@0
     9
 // Nokia Corporation - initial contribution.
sl@0
    10
 //
sl@0
    11
 // Contributors:
sl@0
    12
 //
sl@0
    13
 // Description:
sl@0
    14
 //
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent - Internal Symbian test code 
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include "cglplanets.h"
sl@0
    23
#include "glplanetsapp.h"
sl@0
    24
sl@0
    25
const TInt KTimeBetweenFrames = 100000; // 100 ms
sl@0
    26
sl@0
    27
const TInt KBringToFront = 1;
sl@0
    28
const TInt KTerminate = 2;
sl@0
    29
sl@0
    30
sl@0
    31
CGLPlanets* CGLPlanets::NewL(RWindow& aWindow, TPtrC aBackgroundColor, CGLPlanetsAppUi* aApplication, TPtrC aParentQueueName)
sl@0
    32
    {
sl@0
    33
    CGLPlanets* self = new (ELeave)CGLPlanets(aWindow, aApplication);
sl@0
    34
    self->ConstructL(aBackgroundColor, aParentQueueName);
sl@0
    35
    return self;
sl@0
    36
    }
sl@0
    37
sl@0
    38
CGLPlanets::CGLPlanets(RWindow& aWindow, CGLPlanetsAppUi* aApplication) : iWindow(aWindow),
sl@0
    39
        iApplication(aApplication)
sl@0
    40
	{
sl@0
    41
	// empty
sl@0
    42
	}
sl@0
    43
sl@0
    44
CGLPlanets::~CGLPlanets()
sl@0
    45
	{
sl@0
    46
	delete iTimer;
sl@0
    47
	delete iEglEnvironment;
sl@0
    48
	delete iModel;
sl@0
    49
	iParentMsgQueue.Send(KTerminate);
sl@0
    50
	iParentMsgQueue.Close();
sl@0
    51
	iMsgQueue.Close();
sl@0
    52
	}
sl@0
    53
sl@0
    54
sl@0
    55
sl@0
    56
void CGLPlanets::ConstructL(TPtrC aBackgroundColor, TPtrC aParentQueueName)
sl@0
    57
	{
sl@0
    58
	iTimer = CPeriodic::NewL(CActive::EPriorityIdle);
sl@0
    59
	iEglEnvironment = CEglEnvironment::NewL(iWindow);
sl@0
    60
	iModel = CModel::NewL(iEglEnvironment->Display(), iEglEnvironment->Surface(), aBackgroundColor);
sl@0
    61
	User::LeaveIfError(iMsgQueue.OpenGlobal(aBackgroundColor));
sl@0
    62
	User::LeaveIfError(iParentMsgQueue.OpenGlobal(aParentQueueName));
sl@0
    63
	// inform test app that the message queues are ready
sl@0
    64
	RProcess::Rendezvous(KErrNone);
sl@0
    65
	}
sl@0
    66
sl@0
    67
void CGLPlanets::Start()
sl@0
    68
	{
sl@0
    69
	// redraw the screen periodically
sl@0
    70
	iTimer->Start(0, KTimeBetweenFrames, TCallBack(TimerCallBack, this));
sl@0
    71
	}
sl@0
    72
sl@0
    73
TInt CGLPlanets::TimerCallBack(TAny* aGLPlanet)
sl@0
    74
	{
sl@0
    75
	static_cast<CGLPlanets*>(aGLPlanet)->Render();
sl@0
    76
	return KErrNone;
sl@0
    77
	}
sl@0
    78
sl@0
    79
void CGLPlanets::Render()
sl@0
    80
	{
sl@0
    81
	TInt msg = 0;
sl@0
    82
	iMsgQueue.ReceiveBlocking(msg); // Receive info from the test
sl@0
    83
	iModel->DrawToBuffer(iTime++);
sl@0
    84
	iEglEnvironment->DrawToWindow();
sl@0
    85
	switch (msg)
sl@0
    86
		{
sl@0
    87
		case KBringToFront:
sl@0
    88
			{
sl@0
    89
			TUint32 then = User::FastCounter();
sl@0
    90
			iApplication->BringToFront();
sl@0
    91
			TUint32 now = User::FastCounter();
sl@0
    92
			TUint32 time = (now - then);
sl@0
    93
			iParentMsgQueue.Send(time);
sl@0
    94
			break;
sl@0
    95
			}
sl@0
    96
		case KTerminate:
sl@0
    97
			Stop();
sl@0
    98
			iApplication->Terminate();
sl@0
    99
			break;
sl@0
   100
		}
sl@0
   101
	}
sl@0
   102
sl@0
   103
void CGLPlanets::Stop()
sl@0
   104
	{
sl@0
   105
	if(iTimer)
sl@0
   106
		{
sl@0
   107
		iTimer->Cancel();
sl@0
   108
		}	
sl@0
   109
	}