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: #include "cglplanets.h" sl@0: #include "glplanetsapp.h" sl@0: sl@0: const TInt KTimeBetweenFrames = 100000; // 100 ms sl@0: sl@0: const TInt KBringToFront = 1; sl@0: const TInt KTerminate = 2; sl@0: sl@0: sl@0: CGLPlanets* CGLPlanets::NewL(RWindow& aWindow, TPtrC aBackgroundColor, CGLPlanetsAppUi* aApplication, TPtrC aParentQueueName) sl@0: { sl@0: CGLPlanets* self = new (ELeave)CGLPlanets(aWindow, aApplication); sl@0: self->ConstructL(aBackgroundColor, aParentQueueName); sl@0: return self; sl@0: } sl@0: sl@0: CGLPlanets::CGLPlanets(RWindow& aWindow, CGLPlanetsAppUi* aApplication) : iWindow(aWindow), sl@0: iApplication(aApplication) sl@0: { sl@0: // empty sl@0: } sl@0: sl@0: CGLPlanets::~CGLPlanets() sl@0: { sl@0: delete iTimer; sl@0: delete iEglEnvironment; sl@0: delete iModel; sl@0: iParentMsgQueue.Send(KTerminate); sl@0: iParentMsgQueue.Close(); sl@0: iMsgQueue.Close(); sl@0: } sl@0: sl@0: sl@0: sl@0: void CGLPlanets::ConstructL(TPtrC aBackgroundColor, TPtrC aParentQueueName) sl@0: { sl@0: iTimer = CPeriodic::NewL(CActive::EPriorityIdle); sl@0: iEglEnvironment = CEglEnvironment::NewL(iWindow); sl@0: iModel = CModel::NewL(iEglEnvironment->Display(), iEglEnvironment->Surface(), aBackgroundColor); sl@0: User::LeaveIfError(iMsgQueue.OpenGlobal(aBackgroundColor)); 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: void CGLPlanets::Start() sl@0: { sl@0: // redraw the screen periodically sl@0: iTimer->Start(0, KTimeBetweenFrames, TCallBack(TimerCallBack, this)); sl@0: } sl@0: sl@0: TInt CGLPlanets::TimerCallBack(TAny* aGLPlanet) sl@0: { sl@0: static_cast(aGLPlanet)->Render(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CGLPlanets::Render() sl@0: { sl@0: TInt msg = 0; sl@0: iMsgQueue.ReceiveBlocking(msg); // Receive info from the test sl@0: iModel->DrawToBuffer(iTime++); sl@0: iEglEnvironment->DrawToWindow(); sl@0: switch (msg) sl@0: { sl@0: case KBringToFront: sl@0: { sl@0: TUint32 then = User::FastCounter(); sl@0: iApplication->BringToFront(); sl@0: TUint32 now = User::FastCounter(); sl@0: TUint32 time = (now - then); sl@0: iParentMsgQueue.Send(time); sl@0: break; sl@0: } sl@0: case KTerminate: sl@0: Stop(); sl@0: iApplication->Terminate(); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CGLPlanets::Stop() sl@0: { sl@0: if(iTimer) sl@0: { sl@0: iTimer->Cancel(); sl@0: } sl@0: }