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