uiacceltk/hitchcock/plugins/openwfcrs/inc/openwfcjobmanager.h
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 // Copyright (c) 1995-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 OPENWFCJOBMANAGER_H_
       
    17 #define OPENWFCJOBMANAGER_H_
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <e32base.h>
       
    21 #include <e32debug.h>
       
    22 
       
    23 #include <EGL/egl.h>
       
    24 #include <graphics/eglsynchelper.h>
       
    25 #include <WF/wfc.h>
       
    26 
       
    27 class COpenWfcWrapper;
       
    28 class COpenWfcMonitorThread;
       
    29 class TOpenWfcJob;
       
    30 
       
    31 #if defined(ENABLE_JQ_LOGGING)
       
    32 #define JQLOG(X)  RDebug::Printf X
       
    33 #else
       
    34 #define JQLOG(X)
       
    35 #endif
       
    36 
       
    37 /**
       
    38  * Controls the OpenWF composition
       
    39  */
       
    40 class COpenWfcJobManger : public CBase
       
    41 	{
       
    42 private:
       
    43 
       
    44     enum EOpenWfcJobId
       
    45         {
       
    46             EOpenWfcInvalidJobId = 0,
       
    47             EOpenWfcComposeJobId,
       
    48             EOpenWfcPauseCompositionJobId,
       
    49             EOpenWfcResumeCompositionJobId,
       
    50         };
       
    51     
       
    52 	/**
       
    53 	 * Stores the parameters associated with a composition
       
    54 	 */
       
    55 	struct TComposeRequestDetails
       
    56 		{
       
    57 		TComposeRequestDetails();
       
    58 		void Set(TRequestStatus* aCommitRequest, TThreadId aCallingThread);
       
    59 		void Reset();
       
    60 		TRequestStatus* iCommitRequest;
       
    61 		TThreadId iCallingThread;
       
    62 		TDblQueLink iDlink;
       
    63 		};
       
    64 	
       
    65 	/**
       
    66 	 * Auxilliary class to insure the release of a lock
       
    67 	 */
       
    68 	class Guard
       
    69 		{
       
    70 		public:
       
    71 		Guard(RMutex& aLock);
       
    72 		~Guard();
       
    73 		private:
       
    74 		    RMutex& iLock;
       
    75 		};
       
    76 	
       
    77 public:
       
    78 	/**
       
    79 	 * Two-phased constructor.
       
    80 	 */
       
    81 	static COpenWfcJobManger* NewL(COpenWfcWrapper& aOpenWfcWrapper, 
       
    82                                     WFCDevice aDevice, 
       
    83                                     WFCContext aContext,
       
    84                                     TInt aManagerId);
       
    85 	
       
    86 	/**
       
    87 	 * Two-phased constructor.
       
    88 	 */
       
    89 	static COpenWfcJobManger* NewLC(COpenWfcWrapper& aOpenWfcWrapper, 
       
    90                                     WFCDevice aDevice, 
       
    91                                     WFCContext aContext,
       
    92                                     TInt aManagerId);
       
    93 	/**
       
    94 	 * Destructor.
       
    95 	 */
       
    96 	virtual ~COpenWfcJobManger();
       
    97 	
       
    98 	/**
       
    99 	 * Request to compose the specified scene 
       
   100 	 * 
       
   101 	 * @param aCompleted The notification to be returned when the composition completes
       
   102 	 * @param aUpdatePolicy Update policy to be used
       
   103 	 * @param the Pointer to the first element from the element list containing the scene to be used by the next commit
       
   104 	 * 
       
   105 	 */
       
   106 	void ComposeRequest(TRequestStatus* aCompleted);
       
   107 	
       
   108 	/**
       
   109 	 * Request to pause the composition
       
   110 	 */
       
   111 	void CompositionPauseRequest();
       
   112 	/**
       
   113 	 * Request to resume the composition
       
   114 	 */
       
   115 	void CompositionResumeRequest();
       
   116 	
       
   117     /**
       
   118      * Appends to the compose details list the first detail object from the compose detail list
       
   119      * 
       
   120      * @return NULL if the compose detail pool is empty or a pointer to the appended detail object
       
   121      */
       
   122 	TComposeRequestDetails* AppendDetailsFromPool();
       
   123 
       
   124     /**
       
   125      * Executes an outstanding command, if any.
       
   126      * 
       
   127      */
       
   128     void DoExecuteJob();
       
   129     
       
   130 private:
       
   131     /**
       
   132      * Executes a compose request.
       
   133      * Intended to be invoked by a job
       
   134      * 
       
   135      * @param Reference to the invoking job
       
   136      */
       
   137     void DoComposeJob();
       
   138     
       
   139     /**
       
   140      * Executes a pause composition request
       
   141      * Intended to be invoked by a job
       
   142      * 
       
   143      * @param Reference to the invoking job
       
   144      */
       
   145     void DoPauseCompositionJob();
       
   146     
       
   147     /**
       
   148      * Executes a resume composition request.
       
   149      * Intended to be invoked by a job
       
   150      * 
       
   151      * @param Reference to the invoking job
       
   152      */
       
   153     void DoResumeCompositionJob();
       
   154         
       
   155 	/**
       
   156 	 * Private constructor
       
   157 	 */
       
   158 	COpenWfcJobManger(COpenWfcWrapper& aOpenWfcWrapper, 
       
   159 						 WFCDevice aDevice, 
       
   160 						 WFCContext aContext,
       
   161 						 TInt aManagerId);
       
   162 	
       
   163 	/**
       
   164 	 * Symbian constructor used with the two stage construction pattern
       
   165 	 */
       
   166 	void ConstructL();
       
   167 	
       
   168 	/**
       
   169 	 * Implements a fence operation
       
   170 	 */
       
   171 	void Fence();
       
   172 	
       
   173 	/**
       
   174 	 * Waits until the sync is signalled
       
   175 	 */
       
   176 	void WaitForSync();
       
   177 	
       
   178 	/**
       
   179 	 * Activates the composition on the current context
       
   180 	 */
       
   181 	void Activate();
       
   182 	
       
   183 	/**
       
   184 	 * Deactivates the composition on the current context
       
   185 	 */
       
   186 	void Deactivate();
       
   187 	
       
   188 	/**
       
   189 	 * Execute a composition on the current context
       
   190 	 */
       
   191 	void Compose();
       
   192 	
       
   193 	/**
       
   194 	 * Execute a commit on the current context
       
   195 	 */
       
   196 	void Commit();
       
   197 	
       
   198 	/**
       
   199 	 * Completes all the outstanding requests stored locally
       
   200 	 */
       
   201 	void CompleteComposeRequests(TInt aResult);
       
   202 	
       
   203     /**
       
   204      * Completes all the outstanding pause/resumerequests requests
       
   205      */
       
   206     void CompletePauseResumeRequest(TInt aResult);
       
   207     
       
   208 private:
       
   209 	// 
       
   210 	TDblQue<TComposeRequestDetails> iComposeDetailsPool;
       
   211 	TDblQueIter<TComposeRequestDetails> iComposeDetailsPoolIter;
       
   212 	TDblQue<TComposeRequestDetails> iComposeDetailsList;
       
   213 	TDblQueIter<TComposeRequestDetails> iComposeDetailsListIter;
       
   214     RMutex iJobLock;
       
   215     RMutex iCommandLock;
       
   216     COpenWfcWrapper& iOpenWfcWrapper;
       
   217 	WFCDevice iDevice;
       
   218 	WFCContext iContext;
       
   219 	volatile TBool iCompositionPaused;
       
   220 	volatile TBool iPausedComposePending;
       
   221 	COpenWfcMonitorThread*	iThreadManager;
       
   222 	TInt iManagerId;
       
   223 	EGLSyncKHR iSync;
       
   224 	EGLDisplay iEglDisplay;
       
   225     TRequestStatus iPauseResumeRequestStatus;
       
   226     TThreadId iPauseResumeThread;
       
   227     EOpenWfcJobId iOutstandingJob;
       
   228     static const TInt KComposeDetailsPoolSize = 16;
       
   229 	};
       
   230 
       
   231 inline void COpenWfcJobManger::Fence()
       
   232 	{
       
   233     wfcFence(iDevice, iContext, iEglDisplay, iSync);
       
   234 	}
       
   235 
       
   236 inline void COpenWfcJobManger::WaitForSync()
       
   237 	{
       
   238 	EGLTimeKHR timeout = (EGLTimeKHR) EGL_FOREVER_KHR;
       
   239 	eglClientWaitSyncKHR(iEglDisplay, iSync, 0, timeout);
       
   240 	}
       
   241 
       
   242 inline void COpenWfcJobManger::Activate()
       
   243 	{
       
   244 	wfcActivate(iDevice, iContext);
       
   245 	}
       
   246 
       
   247 inline void COpenWfcJobManger::Deactivate()
       
   248 	{
       
   249 	wfcDeactivate(iDevice, iContext);
       
   250 	}
       
   251 
       
   252 inline void COpenWfcJobManger::Compose()
       
   253 	{
       
   254 	wfcCompose(iDevice, iContext, WFC_TRUE);
       
   255 	}
       
   256 
       
   257 inline void COpenWfcJobManger::Commit()
       
   258 	{
       
   259 	wfcCommit(iDevice, iContext, WFC_TRUE);
       
   260 	}
       
   261 
       
   262 #endif /* OPENWFCJOBMANAGER_H_ */