openvg/openvgrefimplementation/sfopenvg/sfopenvg/include/eglsync.h
branchEGL_MERGE
changeset 216 b87045f2f5d7
child 217 205d3af68142
equal deleted inserted replaced
212:a8e55d78eb52 216:b87045f2f5d7
       
     1 // Copyright (c) 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 // The API provides functionality which allows waiting on the aSync object 
       
    15 // to become signaled and to change status from signaled to unsignaled or vice
       
    16 // versa.
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology 
       
    21 */
       
    22 
       
    23 #ifndef __EGL_SYNC_H_
       
    24 #define __EGL_SYNC_H_
       
    25 
       
    26 #include <e32hashtab.h>
       
    27 #include <e32base.h>
       
    28 
       
    29 #include "riMiniEGL.h"
       
    30 
       
    31 
       
    32 
       
    33 NONSHARABLE_CLASS(CEglSync): public CBase 
       
    34 {
       
    35 public:
       
    36     /*-------------------------------------------------------------------*//*!
       
    37      * \brief   Factory function used to create a CEglSync instance
       
    38      * \ingroup eglSync
       
    39      * \param   aFrontLock Reference to the lock protecting the sync map
       
    40      *          aHeap Reference to the Heap to be used by EGL Sync extension
       
    41      * \param   aSync the sync id for the new sync to be created
       
    42      * \param   aDisplay the display id of the associated display
       
    43      * \param   aType the sync type
       
    44      * \return  a pointer to the extension instance if successful or NULL otherwise 
       
    45      *//*-------------------------------------------------------------------*/
       
    46     static CEglSync* Create(RFastLock& aFrontLock, 
       
    47                             EGLSyncKHR aSync, 
       
    48                             EGLDisplay aDisplay, 
       
    49                             EGLenum aType);
       
    50     
       
    51     /*-------------------------------------------------------------------*//*!
       
    52      * \brief   Public destructor
       
    53      * \ingroup eglSync
       
    54      *//*-------------------------------------------------------------------*/
       
    55     ~CEglSync();
       
    56     
       
    57 private:
       
    58     /*-------------------------------------------------------------------*//*!
       
    59      * \brief   Private constructor
       
    60      * \ingroup eglSync
       
    61      *//*-------------------------------------------------------------------*/
       
    62     CEglSync(RFastLock& aFrontLock,
       
    63              EGLSyncKHR aSync, 
       
    64              EGLDisplay aDisplay, 
       
    65              EGLenum aType);
       
    66     
       
    67     /*-------------------------------------------------------------------*//*!
       
    68      * \brief   Private initialisation method to be used by the factory method
       
    69      * \ingroup eglSync
       
    70      *//*-------------------------------------------------------------------*/
       
    71     TInt Initialize();
       
    72     
       
    73 public:
       
    74     /*-------------------------------------------------------------------*//*!
       
    75      * \brief   Blocks the calling thread until the specified aSync object 
       
    76      * is signaled, or until <aTimeout> nanoseconds have passed. 
       
    77      * It is supposed that the lock protecting
       
    78      * the sync map is already acquired. The call will release this lock. 
       
    79      * \ingroup eglSync
       
    80      * \param   aFlags   If the EGL_FLUSH_COMMANDS_BIT_KHR bit is set in <aFlags>
       
    81      * and <aSync> is unsignaled when the function is called, then the equivalent
       
    82      * of Flush() will be performed for the current API context.   
       
    83      * \param   aTimeout The thread will be unblocked when <aTimeout> is expired.
       
    84      * If the <aTimeout> is to zero, the function just test the current status 
       
    85      * of the aSync object. If the <aTimeout> is set to EGL_FOREVER_KHR, then the 
       
    86      * function does not time out. For all other values, <aTimeout> is adjusted to 
       
    87      * the closest aValue which may be substantially longer than one nanosecond. 
       
    88      * \return  EGL_CONDITION_SATISFIED if <aSync> was signaled before
       
    89      * the timeout expired, which includes the case when <aSync> was already 
       
    90      * signaled when eglClientWaitSyncKHR was called; EGL_TIMEOUT_EXPIRED_KHR if the 
       
    91      * specified timeout period expired before <aSync> was signaled; 
       
    92      * EGL_FALSE if an error occurs.
       
    93      * \error  EGL_BAD_PARAMETER if <aFlags> does not equal
       
    94      * to 0 or EGL_SYNC_FLUSH_COMMAND_BIT_KHR
       
    95      *//*-------------------------------------------------------------------*/
       
    96     EGLint ClientWaitSync(EGLint aFlags, EGLTimeKHR aTimeout);
       
    97     
       
    98     /*-------------------------------------------------------------------*//*!
       
    99      * \brief   Signals or unsignals the reusable aSync object.  
       
   100      * \ingroup eglSync
       
   101      * \param   aMode    Status of the aSync object. There are two possible states: 
       
   102      *  EGL_SIGNALED_KHR and EGL_UNSIGNALED_KHR. 
       
   103      * \return  EGL_SUCCESS if an operation was successful; 
       
   104      * EGL_BAD_MATCH if the type of <aSync> is not EGL_SYNC_REUSABLE_KHR
       
   105      *//*-------------------------------------------------------------------*/
       
   106     EGLint SignalSync(EGLenum aMode);
       
   107     
       
   108     /*-------------------------------------------------------------------*//*!
       
   109      * \brief   Preapares the sync object for destruction.  
       
   110      * \ingroup eglSync
       
   111      * \return  EGL_TRUE if the object can be destroyed immediately (the sync lock is not released)
       
   112      *          EGL_FALSE if the object cannot be deleted (the sync lock is released) 
       
   113      *//*-------------------------------------------------------------------*/
       
   114     EGLBoolean DestroySyncReady();
       
   115     
       
   116     /*-------------------------------------------------------------------*//*!
       
   117     * \brief   Query an aAttribute of the aSync object  
       
   118      * \ingroup eglSync
       
   119     * \param   aDisplay     Identifier of the display which owns the aSync object
       
   120     * \param   aValue   Pointer to the aValue for the 
       
   121     *           requested aAttribute which will be filled on function return. 
       
   122     * \return  EGL_TRUE if an operation was successful and EGL_FALSE otherwise
       
   123     * \error   EGL_BAD_ATTRIBUTE if <aAttribute>  does not lie within expected range;
       
   124     * EGL_BAD_MATCH if <aAttribute> is not supported 
       
   125     * for the type of aSync object passed in <aSync>
       
   126     *//*-------------------------------------------------------------------*/
       
   127     EGLBoolean GetSyncAttrib(EGLint aAttribute, EGLint *aValue);
       
   128     
       
   129     /*-------------------------------------------------------------------*//*!
       
   130      * \brief   Returns the associated display Id  
       
   131      * \ingroup eglSync
       
   132      *//*-------------------------------------------------------------------*/
       
   133     EGLDisplay Display() const { return iDisplay; }
       
   134     
       
   135     /*-------------------------------------------------------------------*//*!
       
   136     * \brief   Returns the sync type  
       
   137     * \ingroup eglSync
       
   138     *//*-------------------------------------------------------------------*/
       
   139     EGLenum Type() const { return iSyncType; }
       
   140 private:
       
   141     const EGLSyncKHR  iEglSync;
       
   142     const EGLDisplay  iDisplay;
       
   143     const EGLenum     iSyncType;
       
   144     EGLenum     iSyncState;
       
   145     EGLBoolean  iDestroyed;
       
   146     EGLint      iWaiters;
       
   147     RMutex      iSyncMutex;
       
   148     RCondVar    iSyncCondVar;
       
   149     RFastLock&  iFrontLock;
       
   150     
       
   151     static const EGLint KSupportedFlags;
       
   152 };
       
   153 
       
   154 
       
   155 NONSHARABLE_CLASS(CEglSyncExtension): public CBase
       
   156     {
       
   157 public:
       
   158     /*-------------------------------------------------------------------*//*!
       
   159      * \brief   Factory function used to create a CEglSyncExtension instance
       
   160      * \ingroup eglSync
       
   161      * \param   aEglInstance Reference to the Egl Instance implementation object
       
   162      * \return  a pointer to the extension instance if successful or NUL otherwise 
       
   163      *//*-------------------------------------------------------------------*/
       
   164     static CEglSyncExtension* Create(OpenVGRI::EGL& aEglInstance);
       
   165     
       
   166     /*-------------------------------------------------------------------*//*!
       
   167      * \brief   Public destructor
       
   168      * \ingroup eglSync
       
   169      *//*-------------------------------------------------------------------*/
       
   170     ~CEglSyncExtension();
       
   171 private:
       
   172     
       
   173     /*-------------------------------------------------------------------*//*!
       
   174      * \brief   Private initialisation method to be used by the factory method
       
   175      * \ingroup eglSync
       
   176      *//*-------------------------------------------------------------------*/
       
   177     EGLBoolean Construct();
       
   178     
       
   179     /*-------------------------------------------------------------------*//*!
       
   180      * \brief   Private constructor
       
   181      * \ingroup eglSync
       
   182      *//*-------------------------------------------------------------------*/
       
   183     CEglSyncExtension(OpenVGRI::EGL& aEglInstance);
       
   184     
       
   185 public:    
       
   186     /*-------------------------------------------------------------------*//*!
       
   187      * \brief   Create a aSync object for the specified display.
       
   188      * \ingroup api
       
   189      * \param   aDisplay     Identifier of the display which will own the aSync object
       
   190      * \param   type    Type of the aSync object. EGL_SYNC_REUSABLE_KHR is only supported
       
   191      * \param   attrib_list Attribute-aValue list specifying attributes of the aSync 
       
   192      * object, terminated by an aAttribute entry EGL_NONE
       
   193      * \return  Handle for the created aSync object if successful, EGL_NO_SYNC_KHR otherwise
       
   194      * \error   EGL_BAD_DISPLAY if <aDisplay> is not a name of a valid EGLDisplay;
       
   195      * EGL_NOT_INITIALIZED if the display object associated 
       
   196      * with the <aDisplay> has not been initialized;
       
   197      * EGL_BAD_ATTRIBUTE if <attrib_list> is neither NULL nor empty (containing only EGL_NONE) or 
       
   198      * if <type> is not a supported type of aSync object;
       
   199      * EGL_BAD_ALLOC if the memory allocation related to aSync object is not successful
       
   200      * \note    If <type> is EGL_SYNC_REUSABLE_KHR, a reusable aSync object is created. 
       
   201      * In this case <attrib_list> must be NULL or empty (containing only EGL_NONE).
       
   202      *  *//*-------------------------------------------------------------------*/
       
   203     static EGLSyncKHR eglCreateSyncKHR(EGLDisplay aDisplay, 
       
   204                                        EGLenum aType, 
       
   205                                        const EGLint* aAttribList);
       
   206     
       
   207     /*-------------------------------------------------------------------*//*!
       
   208      * \brief   Destroy a aSync object and free memory associated with it
       
   209      * \ingroup api
       
   210      * \param   aDisplay     Identifier of the display which owns the aSync object
       
   211      * \param   aSync    Sync object handle. 
       
   212      * \return  EGL_TRUE if deletion was successful and EGL_FALSE otherwise
       
   213      * \error   EGL_BAD_DISPLAY if <aDisplay> is not a name of a valid EGLDisplay;
       
   214      * EGL_NOT_INITIALIZED if the display object associated 
       
   215      * with the <aDisplay> has not been initialized;
       
   216      * EGL_BAD_PARAMETER if <aSync> is not a valid aSync object for <aDisplay>
       
   217      * \note    If any eglClientWaitSyncKHR commands are blocking on <aSync> when 
       
   218      * eglDestroySyncKHR is called, they will be woken up, as if <aSync> were signaled. 
       
   219      * If no errors are generated, <aSync> will no longer be the handle of a valid aSync object.
       
   220      *//*-------------------------------------------------------------------*/
       
   221     static EGLBoolean eglDestroySyncKHR(EGLDisplay aDisplay, EGLSyncKHR aSync);
       
   222     
       
   223     /*-------------------------------------------------------------------*//*!
       
   224      * \brief   Blocks the calling thread until the specified aSync object 
       
   225      * is signaled, or until <aTimeout> nanoseconds have passed.  
       
   226      * \ingroup api
       
   227      * \param   aDisplay     Identifier of the display which owns the aSync object.
       
   228      * \param   aSync    Sync object handle. 
       
   229      * \param   aFlags   If the EGL_FLUSH_COMMANDS_BIT_KHR bit is set in <aFlags>
       
   230      * and <aSync> is unsignaled when the function is called, then the equivalent
       
   231      * of Flush() will be performed for the current API context.   
       
   232      * \param   aTimeout The thread will be unblocked when <aTimeout> is expired.
       
   233      * If the <aTimeout> is to zero, the function just test the current status 
       
   234      * of the aSync object. If the <aTimeout> is set to EGL_FOREVER_KHR, then the 
       
   235      * function does not time out. For all other values, <aTimeout> is adjusted to 
       
   236      * the closest aValue which may be substantially longer than one nanosecond. 
       
   237      * \return  EGL_CONDITION_SATISFIED if <aSync> was signaled before
       
   238      * the timeout expired, which includes the case when <aSync> was already 
       
   239      * signaled when eglClientWaitSyncKHR was called; EGL_TIMEOUT_EXPIRED_KHR if the 
       
   240      * specified timeout period expired before <aSync> was signaled; 
       
   241      * EGL_FALSE if an error occurs.
       
   242      * \error   EGL_BAD_DISPLAY if <aDisplay> is not a name of a valid EGLDisplay;
       
   243      * EGL_NOT_INITIALIZED if the display object associated w
       
   244      * ith the <aDisplay> has not been initialized;
       
   245      * EGL_BAD_PARAMETER if <aSync> is not a valid aSync object for <aDisplay> or 
       
   246      * if <aFlags> does not equal to 0 or EGL_SYNC_FLUSH_COMMAND_BIT_KHR
       
   247      * Note\    More than one eglClientWaitSyncKHR may 
       
   248      * be outstanding on the same <aSync> at any given time. 
       
   249      * When there are multiple threads blocked on the same <aSync> and the aSync object is signaled, 
       
   250      * all such threads are released, but the order in which they are released is not defined.
       
   251      * If a aSync object is destroyed while an eglClientWaitSyncKHR is blocking on that object, 
       
   252      * eglClientWaitSyncKHR will unblock and return immediately, just as if the aSync object 
       
   253      * had been signaled prior to being destroyed.
       
   254      *//*-------------------------------------------------------------------*/
       
   255     static EGLint eglClientWaitSyncKHR(EGLDisplay aDisplay, 
       
   256                                        EGLSyncKHR aSync, 
       
   257                                        EGLint aFlags, 
       
   258                                        EGLTimeKHR aTimeout);
       
   259     
       
   260     /*-------------------------------------------------------------------*//*!
       
   261      * \brief   Signals or unsignals the reusable aSync object.  
       
   262      * \ingroup api
       
   263      * \param   aDisplay     Identifier of the display which owns the aSync object.
       
   264      * \param   aSync    Sync object handle. 
       
   265      * \param   aMode    Status of the aSync object. There are two possible states: 
       
   266      *  EGL_SIGNALED_KHR and EGL_UNSIGNALED_KHR. 
       
   267      * \return  EGL_TRUE if an operation was successful and EGL_FALSE otherwise.
       
   268      *//*-------------------------------------------------------------------*/
       
   269     static EGLBoolean eglSignalSyncKHR(EGLDisplay aDisplay, 
       
   270                                        EGLSyncKHR aSync, 
       
   271                                        EGLenum aMode);
       
   272     
       
   273     /*-------------------------------------------------------------------*//*!
       
   274      * \brief   Query an aAttribute of the aSync object  
       
   275      * \ingroup api
       
   276      * \param   aDisplay     Identifier of the display which owns the aSync object
       
   277      * \param   aSync    Sync object handle. 
       
   278      * \param   aAttribute   An aAttribute to be retrieved. 
       
   279      * \param   aValue   Pointer to the aValue for the requested aAttribute 
       
   280      *          which will be filled on function return. 
       
   281      * \return  EGL_TRUE if an operation was successful and EGL_FALSE otherwise
       
   282      * \error   EGL_BAD_DISPLAY if <aDisplay> is not a name of a valid EGLDisplay;
       
   283      * EGL_NOT_INITIALIZED if the display object associated 
       
   284      * with the <aDisplay> has not been initialized;
       
   285      * EGL_BAD_PARAMETER if <aSync> is not a valid aSync object for <aDisplay> or if <aValue> is not 
       
   286      * a valid pointer; EGL_BAD_ATTRIBUTE if <aAttribute>  does not lie within expected range;
       
   287      * EGL_BAD_MATCH if <aAttribute> is not supported for the type of aSync object passed in <aSync>
       
   288      *//*-------------------------------------------------------------------*/
       
   289     static EGLBoolean eglGetSyncAttribKHR(EGLDisplay aDisplay, 
       
   290                                           EGLSyncKHR aSync, 
       
   291                                           EGLint aAttribute, 
       
   292                                           EGLint* aValue);
       
   293     
       
   294     /*-------------------------------------------------------------------*//*!
       
   295      * \brief   Signals or unsignals the reusable aSync object.  
       
   296      * \ingroup api
       
   297      * \param   aDisplay     Identifier of the display which owns the aSync object.
       
   298      * \param   aSync    Sync object handle. 
       
   299      * \param   aSync    Status of the aSync object. There are two possible states: 
       
   300      *  EGL_SIGNALED_KHR and EGL_UNSIGNALED_KHR. 
       
   301      * \return  EGL_SUCCESS if an operation was successful; 
       
   302      * EGL_BAD_DISPLAY if <aDisplay> is not a name of a valid EGLDisplay; 
       
   303      * EGL_NOT_INITIALIZED if the display object associated with the <aDisplay> has not 
       
   304      * been initialized; EGL_BAD_PARAMETER if <aSync> is not a valid aSync object for <aDisplay> 
       
   305      * or if <aSync> does not lie within expected range;
       
   306      * EGL_BAD_MATCH if the type of <aSync> is not EGL_SYNC_REUSABLE_KHR
       
   307      * \note    This function does not generate an error.
       
   308      *//*-------------------------------------------------------------------*/
       
   309     static EGLint egl_Private_SignalSyncNOK(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode);
       
   310     
       
   311 public:
       
   312     /*-------------------------------------------------------------------*//*!
       
   313      * \brief   Initialisation request when a new display is created  
       
   314      * \ingroup eglSync
       
   315      * \param  aEglDisplay a display identifier 
       
   316      * \return  EGL_SUCCESS if successful; 
       
   317      *//*-------------------------------------------------------------------*/
       
   318     IMPORT_C TInt EglSyncDisplayCreate(EGLDisplay aDisplay);
       
   319     
       
   320     /*-------------------------------------------------------------------*//*!
       
   321      * \brief   Request to destroy all syncs associated with a display as preamble
       
   322      *          of destroying the specified display  
       
   323      * \ingroup eglSync
       
   324      * \param  aEglDisplay a display identifier 
       
   325      *//*-------------------------------------------------------------------*/
       
   326     void EglSyncDisplayDestroy(EGLDisplay aDisplay);
       
   327     
       
   328 private:
       
   329     /*-------------------------------------------------------------------*//*!
       
   330      * \brief   Query and request to lock a specified display   
       
   331      * \ingroup eglSync
       
   332      * \param   aEglDisplay a display identifier 
       
   333      * \return  EGL_SUCCESS if successful;
       
   334      *          EGL_BAD_DISPLAY is not a name of a valid EGLDisplay
       
   335      *          EGL_NOT_INITIALIZED if the display object associated 
       
   336      *          with the <aEglDisplay> has not been initialized 
       
   337      *//*-------------------------------------------------------------------*/
       
   338     EGLint FindAndLockDisplay(EGLDisplay aDisplay);
       
   339     
       
   340     /*-------------------------------------------------------------------*//*!
       
   341      * \brief   Releases the lock associated with a valid EGLDisplay   
       
   342      * \ingroup eglSync
       
   343      * \param   aEglDisplay a display identifier 
       
   344      *//*-------------------------------------------------------------------*/
       
   345     void ReleaseDisplayLock(EGLDisplay aDisplay);
       
   346     
       
   347 private:
       
   348     /*-------------------------------------------------------------------*//*!
       
   349      * \brief   Private implementation for <eglCreateSyncKHR> public static interface   
       
   350      * \ingroup eglSync
       
   351      *//*-------------------------------------------------------------------*/
       
   352     EGLSyncKHR EglCreateSyncKHR(EGLDisplay aDisplay, EGLenum aType, const EGLint* aAttribList);
       
   353     
       
   354     /*-------------------------------------------------------------------*//*!
       
   355      * \brief   Private implementation for <eglDestroySyncKHR> public static interface   
       
   356      * \ingroup eglSync
       
   357      *//*-------------------------------------------------------------------*/
       
   358     EGLBoolean EglDestroySyncKHR(EGLDisplay aDisplay, EGLSyncKHR aSync);
       
   359     
       
   360     /*-------------------------------------------------------------------*//*!
       
   361      * \brief   Private implementation for <eglClientWaitSyncKHR> public static interface   
       
   362      * \ingroup eglSync
       
   363      *//*-------------------------------------------------------------------*/
       
   364     EGLint EglClientWaitSyncKHR(EGLDisplay aDisplay, 
       
   365                                 EGLSyncKHR aSync, 
       
   366                                 EGLint aFlags, 
       
   367                                 EGLTimeKHR aTimeout);
       
   368     
       
   369     /*-------------------------------------------------------------------*//*!
       
   370      * \brief   Private implementation for <eglSignalSyncKHR> public static interface
       
   371      * \ingroup eglSync
       
   372      *//*-------------------------------------------------------------------*/
       
   373     EGLBoolean EglSignalSyncKHR(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode);
       
   374     
       
   375     /*-------------------------------------------------------------------*//*!
       
   376      * \brief   Private implementation for <eglGetSyncAttribKHR> public static interface
       
   377      * \ingroup eglSync
       
   378      *//*-------------------------------------------------------------------*/
       
   379     EGLBoolean EglGetSyncAttribKHR(EGLDisplay aDisplay, 
       
   380                                    EGLSyncKHR aSync, 
       
   381                                    EGLint aAttribute, 
       
   382                                    EGLint* aValue);
       
   383     
       
   384     /*-------------------------------------------------------------------*//*!
       
   385      * \brief   Private implementation for <egl_Private_SignalSyncNOK> public static interface
       
   386      * \ingroup eglSync
       
   387      *//*-------------------------------------------------------------------*/
       
   388     EGLint Egl_Private_SignalSyncNOK(EGLDisplay aDisplay, EGLSyncKHR aSync, EGLenum aMode);
       
   389     
       
   390 private:
       
   391     /*-------------------------------------------------------------------*//*!
       
   392      * \brief   Creates a sync and inserts it in the sync map   
       
   393      * \ingroup eglSync
       
   394      * \param   aEglDisplay the id of the associated display 
       
   395      * \param   aType The sync type 
       
   396      * \return  the id of the sync created
       
   397      *//*-------------------------------------------------------------------*/
       
   398     EGLSyncKHR CreateSync(EGLDisplay aDisplay, EGLenum aType);
       
   399     
       
   400     /*-------------------------------------------------------------------*//*!
       
   401      * \brief   Destroy a sync associated with a display   
       
   402      * \ingroup eglSync
       
   403      * \param   aEglDisplay the id of the associated display 
       
   404      *//*-------------------------------------------------------------------*/
       
   405     void EglDestroySync(EGLDisplay aDisplay);
       
   406     
       
   407 private:
       
   408     typedef RHashMap<EGLint,CEglSync*> REglSyncHashMap;
       
   409     
       
   410     REglSyncHashMap iEglSyncMap;
       
   411     RFastLock       iEglSyncMapLock;
       
   412     EGLint          iEglSyncId;
       
   413     };
       
   414 
       
   415 #endif /* __EGL_SYNC_H_ */