graphicscomposition/surfaceupdate/inc/surfaceupdateserver.h
changeset 0 5d03bc08d59c
child 98 bf7481649c98
child 163 bbf46f59e123
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2006-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __SURFACEUPDATESERVER_H__
       
    17 #define __SURFACEUPDATESERVER_H__
       
    18 
       
    19 /**
       
    20 @file
       
    21 @internalTechnology
       
    22 */
       
    23 
       
    24 #include <e32std.h>
       
    25 #include <e32base.h>
       
    26 #include <graphics/updateserverprovider.h>
       
    27 #include <graphics/compositionsurfaceupdate.h>
       
    28 
       
    29 enum  TSurfaceUpdateServPanic
       
    30 	{
       
    31 	EUpdateServPanicBadRequest = 1,
       
    32 	EUpdateServPanicNoMemory,
       
    33 	EUpdateServPanicStartUp,
       
    34 	EUpdateServPanicDataIntegrity,
       
    35 	EUpdateServPanicRegister,
       
    36 	};
       
    37 
       
    38 enum TSurfaceUpdateEvent
       
    39 	{
       
    40 	EUpdateServEventRegister = 1,
       
    41 	EUpdateServEventTerminate //this event will only be used for test purpose
       
    42 	};
       
    43 	
       
    44 class CSurfaceUpdateServer;
       
    45 
       
    46 /**
       
    47 The class implements interface(s) required for content update
       
    48 Intended to be used by Surface-update control flow
       
    49 @see MSurfaceUpdateServerProvider
       
    50 */
       
    51 class CSurfaceUpdateServerProvider : public CActive, public MSurfaceUpdateServerProvider
       
    52 	{
       
    53 public:
       
    54 	static CSurfaceUpdateServerProvider* NewL(CActive::TPriority aPriority, CSurfaceUpdateServer* aServer);
       
    55 	~CSurfaceUpdateServerProvider();
       
    56 	//from MSurfaceUpdateServerProvider
       
    57 	IMPORT_C TInt Register(TInt aScreen, CBase* aUpdateReceiver, TInt aPriority);
       
    58 	//the following function is intended to be used for test purpose only, 
       
    59 	//will have no effect in the release build 
       
    60 	IMPORT_C void Terminate();
       
    61 protected:
       
    62 	CSurfaceUpdateServerProvider(CActive::TPriority aPriority, CSurfaceUpdateServer* aServer);
       
    63 	void ConstructL();
       
    64 	void RunL();
       
    65 	void DoCancel();
       
    66 protected:
       
    67 	CSurfaceUpdateServer* iServer;
       
    68 	TThreadId iThreadId;
       
    69 	TInt iRegisterErr;
       
    70 	CBase* iUpdateReceiver;
       
    71 	TInt iScreen;
       
    72 	TInt iPriority;
       
    73 	RSemaphore iSemaphore;
       
    74 	};
       
    75 /**
       
    76 Priority is used to identify the master screen for the surface. 
       
    77 */
       
    78 class TUpdateReceiverPriorityEntry
       
    79 	{
       
    80 public:
       
    81 	TInt iPriority; //Highest number signifies highest priority of the screen.
       
    82 	MCompositionSurfaceUpdate* iUpdateReceiver; //doesn't own
       
    83 	};
       
    84 
       
    85 
       
    86 /**
       
    87 The server maintains session with the clients. 
       
    88 It starts during the initialization of the Compositor thread.  
       
    89 */
       
    90 class CSurfaceUpdateServer : public CServer2
       
    91 	{
       
    92 friend class CSurfaceUpdateSession;
       
    93 public:
       
    94 	static CSurfaceUpdateServer* NewL();
       
    95 	
       
    96 	~CSurfaceUpdateServer();
       
    97 
       
    98 	TInt Register(TInt aScreen, CBase* aUpdateReceiver, TInt aPriority); 
       
    99 	virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
       
   100 	static void PanicServer(TSurfaceUpdateServPanic aPanic);
       
   101 
       
   102 	/**
       
   103 	Provide surface update provider for usage by the content update receiver.
       
   104 	
       
   105 	@return surface update provider
       
   106 	*/
       
   107 	MSurfaceUpdateServerProvider* SurfaceUpdateProvider() const
       
   108 		{
       
   109 		return static_cast <MSurfaceUpdateServerProvider*> (iServerProvider);
       
   110 		}
       
   111 	static TInt ThreadFunction(TAny* aAny);
       
   112 	// for DEF118736: [v9.5] turfaceupdatetestserver unexecuted
       
   113 	// For test purposes, only if iNumberPendingNotification reaches zero, the surface update server can be shut.
       
   114 	// The counter is incremented by one when the CUpdateReceiverNotification AO is set to self-destroyed in surface update session's destructor()
       
   115 	// The counter is decremented by one before its self-destruction in CUpdateReceiverNotification AO's RunL()
       
   116 #ifdef TEST_SURFACE_UPDATE
       
   117 	TInt iNumberPendingNotification;
       
   118 #endif
       
   119 protected:
       
   120 	void ConstructL();
       
   121 	CSurfaceUpdateServer(CActive::TPriority aPriority);
       
   122 	MCompositionSurfaceUpdate* UpdateReceiver(TInt aScreen) const;
       
   123 	/**
       
   124 	 @return content update receiver priority list   
       
   125 	 */
       
   126 	inline const RPointerArray<TUpdateReceiverPriorityEntry>& UpdateReceiverPriority() const;
       
   127 	
       
   128 	inline TInt NumUpdateReceivers() const;
       
   129 	static TInt CompareUpdateReceiverPriority(const TUpdateReceiverPriorityEntry& aEntry1, const TUpdateReceiverPriorityEntry& aEntry2);
       
   130 protected:
       
   131 	RPointerArray<MCompositionSurfaceUpdate> iUpdateReceiver; //Screen number is the index for the access of the receiver entry in the array
       
   132 	RPointerArray<TUpdateReceiverPriorityEntry> iUpdateReceiverPriorityOrder; //stored in priority order, the higher the priority of the receiver the closer to the beginning of the array
       
   133 	CSurfaceUpdateServerProvider* iServerProvider;
       
   134 	};
       
   135 
       
   136 
       
   137 enum TNotificationType
       
   138 	{
       
   139 	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.*/
       
   140 	EUpdateSrvAvailable,
       
   141 	EUpdateSrvDisplayed,
       
   142 	EUpdateSrvDisplayedXTimes,
       
   143 	};
       
   144 
       
   145 class CSurfaceUpdateSession;
       
   146 class CUpdateReceiverNotificationBatch;
       
   147 
       
   148 /**
       
   149 Notification object. Content update receiver signals the server via this object of composition events.
       
   150 */
       
   151 class CUpdateReceiverNotification : public CActive
       
   152 	{
       
   153 public:
       
   154 	CUpdateReceiverNotification(CActive::TPriority aPriority, TInt aReceiverPriority, CUpdateReceiverNotificationBatch *aParentNotificationBatch);
       
   155 	~CUpdateReceiverNotification();
       
   156 	TRequestStatus& Status();
       
   157 	void Activate();
       
   158 protected:
       
   159 	void DoCancel();
       
   160 	virtual void RunL();
       
   161 public:
       
   162 	TUint32	iTimeStamp;
       
   163 	TInt iUpdateReceiverPriority;
       
   164 	TBool iSelfDestructWhenRun;
       
   165 protected:
       
   166 #ifdef TEST_SURFACE_UPDATE
       
   167 	void DecNumberPendingNotifications();
       
   168 #endif	
       
   169 protected:
       
   170 	CUpdateReceiverNotificationBatch *iParentNotificationBatch; //doesn't own
       
   171 #ifdef TEST_SURFACE_UPDATE
       
   172 	CSurfaceUpdateServer* iServer;
       
   173 #endif
       
   174 	};
       
   175 
       
   176 /**
       
   177  The class manages the batch of notification objects with the same type and 
       
   178  initiated by the particular SubmitUpdate request.
       
   179 */
       
   180 class CUpdateReceiverNotificationBatch : public CBase
       
   181 	{
       
   182 public:
       
   183 	CUpdateReceiverNotificationBatch(CSurfaceUpdateSession *aSession, TInt aNumReceivers);
       
   184 	~CUpdateReceiverNotificationBatch();
       
   185 	void ProcessNotificationEvent(CUpdateReceiverNotification* aReceiverNotification);
       
   186 	TBool IsActive() const;
       
   187 	CUpdateReceiverNotification* UpdateReceiverNotification(TInt aReceiverPriority = 0);
       
   188 	void CheckForReuse();
       
   189 #ifdef TEST_SURFACE_UPDATE
       
   190 	CSurfaceUpdateServer* Server();
       
   191 	void IncNumberPendingNotifications();
       
   192 #endif
       
   193 public:
       
   194 	RMessage2 iMsg;
       
   195 	TNotificationType iType;
       
   196 	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
       
   197 protected:
       
   198 	CSurfaceUpdateSession *iSession; //doesn't own
       
   199 	TInt iNumUpdateReceivers;
       
   200 	TBool iCompleteWithSuccess;
       
   201 	TInt iHighestPriority; //attributed to successful notification
       
   202 	TUint32	iTimeStamp; //attributed to successful notification
       
   203 	};
       
   204 
       
   205 /**
       
   206 Maintain the channel between clients and the server. 
       
   207 Functions are provided will respond appropriately to client messages. 
       
   208 */
       
   209 class CSurfaceUpdateSession : public CSession2
       
   210 	{
       
   211 public:
       
   212 	CSurfaceUpdateSession(const RPointerArray<TUpdateReceiverPriorityEntry>& aReceiverEntryList);
       
   213 	~CSurfaceUpdateSession();
       
   214 	void SubmitUpdate(const RMessage2& aMessage);
       
   215 	void NotifyWhenAvailable(const RMessage2& aMessage);
       
   216 	void NotifyWhenDisplayed(const RMessage2& aMessage);
       
   217 	void NotifyWhenDisplayedXTimes(const RMessage2& aMessage);
       
   218 	void CancelAllUpdateNotifications();
       
   219 protected:
       
   220 	void DoSubmitUpdateL(const RMessage2& aMessage);
       
   221 	void StoreNotification(CUpdateReceiverNotificationBatch*& aNotifier, const RMessage2& aMessage, TNotificationType aType);
       
   222 	virtual void ServiceL(const RMessage2& aMessage);
       
   223 	void PanicClient(const RMessage2& aMessage, TInt aPanic) const;
       
   224 	CUpdateReceiverNotificationBatch* UpdateReceiverNotificationBatchL();
       
   225 	void IssueRequestComplete(TInt aErr);
       
   226 	void DispatchUpdate(const TSurfaceId& aSurfaceId, TInt aBuffer, RRegion* aRegion, TInt* aDisplayedXTimes,  MCompositionSurfaceUpdate* aReceiver = NULL );
       
   227 #ifdef TEST_SURFACE_UPDATE
       
   228 	void SetHeapFailure(const RMessage2& aMessage);
       
   229 #endif	
       
   230 private:
       
   231 	RPointerArray<CUpdateReceiverNotificationBatch> iUpdateReceiverNotificationBatches;
       
   232 	CUpdateReceiverNotificationBatch* iAvailable;	
       
   233 	CUpdateReceiverNotificationBatch* iDisplayed;	
       
   234 	CUpdateReceiverNotificationBatch* iDisplayedXTimes;
       
   235 	const RPointerArray<TUpdateReceiverPriorityEntry>& iUpdateReceiverEntryList; //doesn't own
       
   236 	enum 
       
   237 		{
       
   238 		EUpdateMethodNone,
       
   239 		EUpdateMethodPerScreen,
       
   240 		EUpdateMethodGlobal,
       
   241 		} iUpdateMethod;
       
   242 	};
       
   243 
       
   244 inline const RPointerArray<TUpdateReceiverPriorityEntry>& CSurfaceUpdateServer::UpdateReceiverPriority() const
       
   245 	{
       
   246 	return iUpdateReceiverPriorityOrder;
       
   247 	}
       
   248 
       
   249 #endif