1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstest/uibench/s60/src/tests_zorder/cglplanets.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,109 @@
1.4 + // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 + // All rights reserved.
1.6 + // This component and the accompanying materials are made available
1.7 + // under the terms of "Eclipse Public License v1.0"
1.8 + // which accompanies this distribution, and is available
1.9 + // at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 + //
1.11 + // Initial Contributors:
1.12 + // Nokia Corporation - initial contribution.
1.13 + //
1.14 + // Contributors:
1.15 + //
1.16 + // Description:
1.17 + //
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Internal Symbian test code
1.23 +*/
1.24 +
1.25 +#include "cglplanets.h"
1.26 +#include "glplanetsapp.h"
1.27 +
1.28 +const TInt KTimeBetweenFrames = 100000; // 100 ms
1.29 +
1.30 +const TInt KBringToFront = 1;
1.31 +const TInt KTerminate = 2;
1.32 +
1.33 +
1.34 +CGLPlanets* CGLPlanets::NewL(RWindow& aWindow, TPtrC aBackgroundColor, CGLPlanetsAppUi* aApplication, TPtrC aParentQueueName)
1.35 + {
1.36 + CGLPlanets* self = new (ELeave)CGLPlanets(aWindow, aApplication);
1.37 + self->ConstructL(aBackgroundColor, aParentQueueName);
1.38 + return self;
1.39 + }
1.40 +
1.41 +CGLPlanets::CGLPlanets(RWindow& aWindow, CGLPlanetsAppUi* aApplication) : iWindow(aWindow),
1.42 + iApplication(aApplication)
1.43 + {
1.44 + // empty
1.45 + }
1.46 +
1.47 +CGLPlanets::~CGLPlanets()
1.48 + {
1.49 + delete iTimer;
1.50 + delete iEglEnvironment;
1.51 + delete iModel;
1.52 + iParentMsgQueue.Send(KTerminate);
1.53 + iParentMsgQueue.Close();
1.54 + iMsgQueue.Close();
1.55 + }
1.56 +
1.57 +
1.58 +
1.59 +void CGLPlanets::ConstructL(TPtrC aBackgroundColor, TPtrC aParentQueueName)
1.60 + {
1.61 + iTimer = CPeriodic::NewL(CActive::EPriorityIdle);
1.62 + iEglEnvironment = CEglEnvironment::NewL(iWindow);
1.63 + iModel = CModel::NewL(iEglEnvironment->Display(), iEglEnvironment->Surface(), aBackgroundColor);
1.64 + User::LeaveIfError(iMsgQueue.OpenGlobal(aBackgroundColor));
1.65 + User::LeaveIfError(iParentMsgQueue.OpenGlobal(aParentQueueName));
1.66 + // inform test app that the message queues are ready
1.67 + RProcess::Rendezvous(KErrNone);
1.68 + }
1.69 +
1.70 +void CGLPlanets::Start()
1.71 + {
1.72 + // redraw the screen periodically
1.73 + iTimer->Start(0, KTimeBetweenFrames, TCallBack(TimerCallBack, this));
1.74 + }
1.75 +
1.76 +TInt CGLPlanets::TimerCallBack(TAny* aGLPlanet)
1.77 + {
1.78 + static_cast<CGLPlanets*>(aGLPlanet)->Render();
1.79 + return KErrNone;
1.80 + }
1.81 +
1.82 +void CGLPlanets::Render()
1.83 + {
1.84 + TInt msg = 0;
1.85 + iMsgQueue.ReceiveBlocking(msg); // Receive info from the test
1.86 + iModel->DrawToBuffer(iTime++);
1.87 + iEglEnvironment->DrawToWindow();
1.88 + switch (msg)
1.89 + {
1.90 + case KBringToFront:
1.91 + {
1.92 + TUint32 then = User::FastCounter();
1.93 + iApplication->BringToFront();
1.94 + TUint32 now = User::FastCounter();
1.95 + TUint32 time = (now - then);
1.96 + iParentMsgQueue.Send(time);
1.97 + break;
1.98 + }
1.99 + case KTerminate:
1.100 + Stop();
1.101 + iApplication->Terminate();
1.102 + break;
1.103 + }
1.104 + }
1.105 +
1.106 +void CGLPlanets::Stop()
1.107 + {
1.108 + if(iTimer)
1.109 + {
1.110 + iTimer->Cancel();
1.111 + }
1.112 + }