os/graphics/graphicscomposition/surfaceupdate/inc/surfaceupdateserver.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicscomposition/surfaceupdate/inc/surfaceupdateserver.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,251 @@
     1.4 +// Copyright (c) 2006-2010 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 +#ifndef __SURFACEUPDATESERVER_H__
    1.20 +#define __SURFACEUPDATESERVER_H__
    1.21 +
    1.22 +/**
    1.23 +@file
    1.24 +@internalTechnology
    1.25 +*/
    1.26 +
    1.27 +#include <e32std.h>
    1.28 +#include <e32base.h>
    1.29 +#include <graphics/updateserverprovider.h>
    1.30 +#include <graphics/compositionsurfaceupdate.h>
    1.31 +
    1.32 +enum  TSurfaceUpdateServPanic
    1.33 +	{
    1.34 +	EUpdateServPanicBadRequest = 1,
    1.35 +	EUpdateServPanicNoMemory,
    1.36 +	EUpdateServPanicStartUp,
    1.37 +	EUpdateServPanicDataIntegrity,
    1.38 +	EUpdateServPanicRegister,
    1.39 +	EUpdateServPanicGlobalFastLock,
    1.40 +	};
    1.41 +
    1.42 +enum TSurfaceUpdateEvent
    1.43 +	{
    1.44 +	EUpdateServEventRegister = 1,
    1.45 +	EUpdateServEventTerminate //this event will only be used for test purpose
    1.46 +	};
    1.47 +	
    1.48 +class CSurfaceUpdateServer;
    1.49 +
    1.50 +/**
    1.51 +The class implements interface(s) required for content update
    1.52 +Intended to be used by Surface-update control flow
    1.53 +@see MSurfaceUpdateServerProvider
    1.54 +*/
    1.55 +class CSurfaceUpdateServerProvider : public CActive, public MSurfaceUpdateServerProvider
    1.56 +	{
    1.57 +public:
    1.58 +	static CSurfaceUpdateServerProvider* NewL(CActive::TPriority aPriority, CSurfaceUpdateServer* aServer);
    1.59 +	~CSurfaceUpdateServerProvider();
    1.60 +	//from MSurfaceUpdateServerProvider
    1.61 +	IMPORT_C TInt Register(TInt aScreen, CBase* aUpdateReceiver, TInt aPriority);
    1.62 +	//the following function is intended to be used for test purpose only, 
    1.63 +	//will have no effect in the release build 
    1.64 +	IMPORT_C void Terminate();
    1.65 +protected:
    1.66 +	CSurfaceUpdateServerProvider(CActive::TPriority aPriority, CSurfaceUpdateServer* aServer);
    1.67 +	void ConstructL();
    1.68 +	void RunL();
    1.69 +	void DoCancel();
    1.70 +protected:
    1.71 +	CSurfaceUpdateServer* iServer;
    1.72 +	TThreadId iThreadId;
    1.73 +	TInt iRegisterErr;
    1.74 +	CBase* iUpdateReceiver;
    1.75 +	TInt iScreen;
    1.76 +	TInt iPriority;
    1.77 +	RSemaphore iSemaphore;
    1.78 +	};
    1.79 +/**
    1.80 +Priority is used to identify the master screen for the surface. 
    1.81 +*/
    1.82 +class TUpdateReceiverPriorityEntry
    1.83 +	{
    1.84 +public:
    1.85 +	TInt iPriority; //Highest number signifies highest priority of the screen.
    1.86 +	MCompositionSurfaceUpdate* iUpdateReceiver; //doesn't own
    1.87 +	};
    1.88 +
    1.89 +
    1.90 +/**
    1.91 +The server maintains session with the clients. 
    1.92 +It starts during the initialization of the Compositor thread.  
    1.93 +*/
    1.94 +class CSurfaceUpdateServer : public CServer2
    1.95 +	{
    1.96 +friend class CSurfaceUpdateSession;
    1.97 +public:
    1.98 +	static CSurfaceUpdateServer* NewL();
    1.99 +	
   1.100 +	~CSurfaceUpdateServer();
   1.101 +
   1.102 +	TInt Register(TInt aScreen, CBase* aUpdateReceiver, TInt aPriority); 
   1.103 +	virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
   1.104 +	static void PanicServer(TSurfaceUpdateServPanic aPanic);
   1.105 +
   1.106 +	/**
   1.107 +	Provide surface update provider for usage by the content update receiver.
   1.108 +	
   1.109 +	@return surface update provider
   1.110 +	*/
   1.111 +	MSurfaceUpdateServerProvider* SurfaceUpdateProvider() const
   1.112 +		{
   1.113 +		return static_cast <MSurfaceUpdateServerProvider*> (iServerProvider);
   1.114 +		}
   1.115 +	static TInt ThreadFunction(TAny* aAny);
   1.116 +	// for DEF118736: [v9.5] turfaceupdatetestserver unexecuted
   1.117 +	// For test purposes, only if iNumberPendingNotification reaches zero, the surface update server can be shut.
   1.118 +	// The counter is incremented by one when the CUpdateReceiverNotification AO is set to self-destroyed in surface update session's destructor()
   1.119 +	// The counter is decremented by one before its self-destruction in CUpdateReceiverNotification AO's RunL()
   1.120 +#ifdef TEST_SURFACE_UPDATE
   1.121 +	TInt iNumberPendingNotification;
   1.122 +#endif
   1.123 +protected:
   1.124 +	void ConstructL();
   1.125 +	CSurfaceUpdateServer(CActive::TPriority aPriority);
   1.126 +	MCompositionSurfaceUpdate* UpdateReceiver(TInt aScreen) const;
   1.127 +	/**
   1.128 +	 @return content update receiver priority list   
   1.129 +	 */
   1.130 +	inline const RPointerArray<TUpdateReceiverPriorityEntry>& UpdateReceiverPriority() const;
   1.131 +	
   1.132 +	inline TInt NumUpdateReceivers() const;
   1.133 +	static TInt CompareUpdateReceiverPriority(const TUpdateReceiverPriorityEntry& aEntry1, const TUpdateReceiverPriorityEntry& aEntry2);
   1.134 +protected:
   1.135 +	RPointerArray<MCompositionSurfaceUpdate> iUpdateReceiver; //Screen number is the index for the access of the receiver entry in the array
   1.136 +	RPointerArray<TUpdateReceiverPriorityEntry> iUpdateReceiverPriorityOrder; //stored in priority order, the higher the priority of the receiver the closer to the beginning of the array
   1.137 +	CSurfaceUpdateServerProvider* iServerProvider;
   1.138 +	};
   1.139 +
   1.140 +
   1.141 +enum TNotificationType
   1.142 +	{
   1.143 +	EUpdateSrvReusable = 1, /**< When a notification batch doesn’t contain any active notifiers, i.e. they have been processed by the content update receiver, the batch will not be deleted but becomes available for the following reuse.*/
   1.144 +	EUpdateSrvAvailable,
   1.145 +	EUpdateSrvDisplayed,
   1.146 +	EUpdateSrvDisplayedXTimes,
   1.147 +	};
   1.148 +
   1.149 +class CSurfaceUpdateSession;
   1.150 +class CUpdateReceiverNotificationBatch;
   1.151 +
   1.152 +/**
   1.153 +Notification object. Content update receiver signals the server via this object of composition events.
   1.154 +*/
   1.155 +class CUpdateReceiverNotification : public CActive
   1.156 +	{
   1.157 +public:
   1.158 +	CUpdateReceiverNotification(CActive::TPriority aPriority, TInt aReceiverPriority, CUpdateReceiverNotificationBatch *aParentNotificationBatch);
   1.159 +	~CUpdateReceiverNotification();
   1.160 +	TRequestStatus& Status();
   1.161 +	void Activate();
   1.162 +protected:
   1.163 +	void DoCancel();
   1.164 +	virtual void RunL();
   1.165 +public:
   1.166 +	TUint32	iTimeStamp;
   1.167 +	TInt iUpdateReceiverPriority;
   1.168 +	TBool iSelfDestructWhenRun;
   1.169 +protected:
   1.170 +#ifdef TEST_SURFACE_UPDATE
   1.171 +	void DecNumberPendingNotifications();
   1.172 +#endif	
   1.173 +protected:
   1.174 +	CUpdateReceiverNotificationBatch *iParentNotificationBatch; //doesn't own
   1.175 +#ifdef TEST_SURFACE_UPDATE
   1.176 +	CSurfaceUpdateServer* iServer;
   1.177 +#endif
   1.178 +	};
   1.179 +
   1.180 +/**
   1.181 + The class manages the batch of notification objects with the same type and 
   1.182 + initiated by the particular SubmitUpdate request.
   1.183 +*/
   1.184 +class CUpdateReceiverNotificationBatch : public CBase
   1.185 +	{
   1.186 +public:
   1.187 +	CUpdateReceiverNotificationBatch(CSurfaceUpdateSession *aSession, TInt aNumReceivers);
   1.188 +	~CUpdateReceiverNotificationBatch();
   1.189 +	void ProcessNotificationEvent(CUpdateReceiverNotification* aReceiverNotification);
   1.190 +	TBool IsActive() const;
   1.191 +	CUpdateReceiverNotification* UpdateReceiverNotification(TInt aReceiverPriority = 0);
   1.192 +	void CheckForReuse();
   1.193 +	void SetNumUpdateReceivers(TInt aNumUpdateReceivers);
   1.194 +#ifdef TEST_SURFACE_UPDATE
   1.195 +	CSurfaceUpdateServer* Server();
   1.196 +	void IncNumberPendingNotifications();
   1.197 +#endif
   1.198 +public:
   1.199 +	RMessage2 iMsg;
   1.200 +	TNotificationType iType;
   1.201 +	RPointerArray<CUpdateReceiverNotification> iUpdateReceiverNotifications; //for multiple entries stored in priority order, the higher the priority of the receiver the closer to the beginning of the array
   1.202 +protected:
   1.203 +	CSurfaceUpdateSession *iSession; //doesn't own
   1.204 +	TInt iNumUpdateReceivers;
   1.205 +	TBool iCompleteWithSuccess;
   1.206 +	TInt iHighestPriority; //attributed to successful notification
   1.207 +	TUint32	iTimeStamp; //attributed to successful notification
   1.208 +	};
   1.209 +
   1.210 +/**
   1.211 +Maintain the channel between clients and the server. 
   1.212 +Functions are provided will respond appropriately to client messages. 
   1.213 +*/
   1.214 +class CSurfaceUpdateSession : public CSession2
   1.215 +	{
   1.216 +public:
   1.217 +	CSurfaceUpdateSession(const RPointerArray<TUpdateReceiverPriorityEntry>& aReceiverEntryList);
   1.218 +	~CSurfaceUpdateSession();
   1.219 +	void SubmitUpdate(const RMessage2& aMessage);
   1.220 +	void NotifyWhenAvailable(const RMessage2& aMessage);
   1.221 +	void NotifyWhenDisplayed(const RMessage2& aMessage);
   1.222 +	void NotifyWhenDisplayedXTimes(const RMessage2& aMessage);
   1.223 +	void CancelAllUpdateNotifications();
   1.224 +protected:
   1.225 +	void DoSubmitUpdateL(const RMessage2& aMessage);
   1.226 +	void StoreNotification(CUpdateReceiverNotificationBatch*& aNotifier, const RMessage2& aMessage, TNotificationType aType);
   1.227 +	virtual void ServiceL(const RMessage2& aMessage);
   1.228 +	void PanicClient(const RMessage2& aMessage, TInt aPanic) const;
   1.229 +	CUpdateReceiverNotificationBatch* UpdateReceiverNotificationBatchL();
   1.230 +	void IssueRequestComplete(TInt aErr);
   1.231 +	void DispatchUpdate(const TSurfaceId& aSurfaceId, TInt aBuffer, RRegion* aRegion, TInt* aDisplayedXTimes,  MCompositionSurfaceUpdate* aReceiver = NULL );
   1.232 +#ifdef TEST_SURFACE_UPDATE
   1.233 +	void SetHeapFailure(const RMessage2& aMessage);
   1.234 +#endif	
   1.235 +private:
   1.236 +	RPointerArray<CUpdateReceiverNotificationBatch> iUpdateReceiverNotificationBatches;
   1.237 +	CUpdateReceiverNotificationBatch* iAvailable;	
   1.238 +	CUpdateReceiverNotificationBatch* iDisplayed;	
   1.239 +	CUpdateReceiverNotificationBatch* iDisplayedXTimes;
   1.240 +	const RPointerArray<TUpdateReceiverPriorityEntry>& iUpdateReceiverEntryList; //doesn't own
   1.241 +	enum 
   1.242 +		{
   1.243 +		EUpdateMethodNone,
   1.244 +		EUpdateMethodPerScreen,
   1.245 +		EUpdateMethodGlobal,
   1.246 +		} iUpdateMethod;
   1.247 +	};
   1.248 +
   1.249 +inline const RPointerArray<TUpdateReceiverPriorityEntry>& CSurfaceUpdateServer::UpdateReceiverPriority() const
   1.250 +	{
   1.251 +	return iUpdateReceiverPriorityOrder;
   1.252 +	}
   1.253 +
   1.254 +#endif