os/graphics/graphicsdeviceinterface/directgdi/test/tdirectgdieglcontent_server.cpp
Update contrib.
1 // Copyright (c) 2007-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "tdirectgdieglcontent_server.h"
17 #include "tdirectgdieglcontent_cube.h"
18 #include "tdirectgdieglcontent_clientserver.h"
19 #include "tdisplaymode_mapping.h"
22 #include <graphics/sgimage_sw.h>
27 CEglContent* CEglContent::NewL()
29 CEglContent* self = NewLC();
30 CleanupStack::Pop(self);
34 CEglContent* CEglContent::NewLC()
36 CEglContent* self = new(ELeave) CEglContent();
37 CleanupStack::PushL(self);
45 CEglContent::CEglContent() : CTimer(CActive::EPriorityStandard), iMode(ESync)
47 CActiveScheduler::Add(this);
53 void CEglContent::ConstructL()
57 iCube = CGLCube::NewL(EUidPixelFormatXRGB_8888, TSize(200, 200));
63 CEglContent::~CEglContent()
71 Handles an active object's request completion event.
73 void CEglContent::RunL()
75 if(iStatus.Int() == KErrNone)
78 iFrame = iFrame % KEglContentAsyncMaxFrames;
82 // issue request for next frame
83 After(KEglContentDelay);
89 Render next frame of animation.
90 Function returns when rendering is finished. Animation is set to next frame.
92 void CEglContent::RenderNextFrame()
94 iCube->Render(iFrame);
100 Set rendering mode to synchronous or asynchronous
101 @param aMode Rendering mode to set.
103 void CEglContent::SetMode(TMode aMode)
113 // cancel request for next frame
117 else if(aMode == EAsync)
122 // issue request for next frame
123 After(KEglContentDelay);
134 Get image id of current frame. Current image to render is switch to next.
135 @param aId Reference to drawable id class to store image id.
136 @return number of frame stored in image
138 TInt CEglContent::GetImage(TSgDrawableId& aId)
142 // if rendering mode is synchrounous, we need to render current frame
146 iCube->GetImage(aId);
148 if(iMode == EAsyncDebug)
150 // Added this as a panic can occur if After() is called while the server is active.
151 // Before this was added the server could get stuck in an active state
152 // occasionally when running the tests in SW mode.
156 // if rendering mode is asynchrounous debug, we start rendering next frame (only one) immediately
166 CServer2* CEglContentServer::NewLC()
168 CEglContentServer* self = new(ELeave) CEglContentServer;
169 CleanupStack::PushL(self);
175 1st phase constructor
177 CEglContentServer::CEglContentServer() : CServer2(0, ESharableSessions)
182 2nd phase construction - ensure the content renderer and server objects are running
184 void CEglContentServer::ConstructL()
186 StartL(KEglContentServerName);
187 iContent = CEglContent::NewL();
193 CEglContentServer::~CEglContentServer()
199 Cretae a new client session.
201 CSession2* CEglContentServer::NewSessionL(const TVersion&, const RMessage2&) const
203 return new(ELeave) CEglContentSession();
207 A new session is being created
209 void CEglContentServer::AddSession()
215 A session is being destroyed
217 void CEglContentServer::DropSession()
223 Get image in synchronous mode.
224 @param aId Reference to drawable id class to store image id.
226 void CEglContentServer::GetSyncImage(TSgDrawableId& aId)
230 iContent->SetMode(CEglContent::ESync);
231 iContent->GetImage(aId);
236 Get image in asynchronous mode.
237 @param aId Reference to drawable id class to store image id.
238 @return number of frame stored in image
240 TInt CEglContentServer::GetAsyncImage(TSgDrawableId& aId)
244 iContent->SetMode(CEglContent::EAsync);
245 return iContent->GetImage(aId);
251 Get image in asynchronous debug mode.
252 @param aId Reference to drawable id class to store image id.
253 @return number of frame stored in image
255 TInt CEglContentServer::GetAsyncImageDebug(TSgDrawableId& aId)
259 iContent->SetMode(CEglContent::EAsyncDebug);
260 return iContent->GetImage(aId);
266 1st phase constructor
268 CEglContentSession::CEglContentSession()
273 2nd phase construct for sessions - called by the CServer framework
275 void CEglContentSession::Create()
277 Server().AddSession();
283 CEglContentSession::~CEglContentSession()
285 Server().DropSession();
290 @return a reference to server object
292 CEglContentServer& CEglContentSession::Server()
294 return *static_cast<CEglContentServer*>(const_cast<CServer2*>(CSession2::Server()));
298 Handle a client request.
299 Leaving is handled by CEglContentSession::ServiceError() which reports
300 the error code to the client
302 void CEglContentSession::ServiceL(const RMessage2& aMessage)
304 switch(aMessage.Function())
306 case ETerminateServer:
308 aMessage.Complete(KErrNone);
309 CActiveScheduler::Stop();
314 // Get the current image synchronously, the frame
315 // number is not returned as the client will already know the frame number
316 // as it controls when a frame is drawn
318 Server().GetSyncImage(id);
319 TPckg<TSgDrawableId> idPckg(id);
320 aMessage.Write(0, idPckg);
321 aMessage.Complete(KErrNone);
326 // Get the current image and it's frame number, the drawing is
327 // asynchronous so the client needs to know which one this as it cannot tell otherwise
329 TInt fnum = Server().GetAsyncImage(id);
330 TPckg<TSgDrawableId> idPckg(id);
331 aMessage.Write(0, idPckg);
332 TPckg<TInt> fnumPckg(fnum);
333 aMessage.Write(1, fnumPckg);
334 aMessage.Complete(KErrNone);
337 case EGetAsyncImageDebug:
339 // Get the current image and it's frame number, the drawing is
340 // asynchronous so the client needs to know which one this as it cannot tell otherwise
342 TInt fnum = Server().GetAsyncImageDebug(id);
343 TPckg<TSgDrawableId> idPckg(id);
344 aMessage.Write(0, idPckg);
345 TPckg<TInt> fnumPckg(fnum);
346 aMessage.Write(1, fnumPckg);
347 aMessage.Complete(KErrNone);
352 PanicClient(aMessage, EPanicIllegalFunction);
358 Handle an error from CEglContentSession::ServiceL()
360 void CEglContentSession::ServiceError(const RMessage2& aMessage, TInt aError)
362 if(aError == KErrBadDescriptor)
363 PanicClient(aMessage, EPanicBadDescriptor);
364 CSession2::ServiceError(aMessage, aError);
369 RMessage::Panic() also completes the message.
371 void PanicClient(const RMessagePtr2& aMessage, TEglContentPanic aPanic)
373 aMessage.Panic(KEglContentServerName, aPanic);
377 Perform all server initialisation, in particular creation of the
378 scheduler and server and then run the scheduler
380 static void RunServerL()
382 // naming the server thread after the server helps to debug panics
383 User::LeaveIfError(RThread::RenameMe(KEglContentServerName));
385 // create and install the active scheduler we need
386 CActiveScheduler* s = new(ELeave) CActiveScheduler;
387 CleanupStack::PushL(s);
388 CActiveScheduler::Install(s);
390 // create the server (leave it on the cleanup stack)
391 CEglContentServer::NewLC();
393 // Initialisation complete, now signal the client
394 RProcess::Rendezvous(KErrNone);
397 CActiveScheduler::Start();
399 // Cleanup the server and scheduler
400 CleanupStack::PopAndDestroy(2);
404 Entry point of server executable.
406 GLDEF_C TInt E32Main()
409 RDebug::Print(_L("%S started"), &KEglContentServerName);
410 CTrapCleanup* cleanup = CTrapCleanup::New();
411 TInt r = KErrNoMemory;
414 TRAP(r, RunServerL());
417 RDebug::Print(_L("%S terminated"), &KEglContentServerName);