os/graphics/graphicscomposition/openwftest/src/eglsynchelper.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 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 // eglsynchelper.c
    15 //
    16 
    17 #include "eglsynchelper.h"
    18 #include "EGL/egltypes.h"
    19 
    20 #ifndef EGL_EGLEXT_PROTOTYPES
    21 
    22 #define EGLSYNC_TYPE 0xE5
    23 
    24 /* sync object data type for POSIX thread implementation*/
    25 
    26 typedef struct CondVarSync_* NativeSyncType;
    27 
    28 #ifdef __cplusplus
    29 extern "C" {
    30 #endif
    31 
    32 /*-------------------------------------------------------------------*//*!
    33  * \brief   Create a sync object for the specified display.
    34  * \ingroup api
    35  * \param   dpy     Identifier of the display which will own the sync object
    36  * \param   type    Type of the sync object. EGL_SYNC_REUSABLE_KHR is only supported
    37  * \param   attrib_list Attribute-value list specifying attributes of the sync 
    38  * object, terminated by an attribute entry EGL_NONE
    39  * \return  Handle for the created sync object if successful, EGL_NO_SYNC_KHR otherwise
    40  * \error   EGL_BAD_DISPLAY if <dpy> is not a name of a valid EGLDisplay;
    41  * EGL_NOT_INITIALIZED if the display object associated with the <dpy> has not been initialized;
    42  * EGL_BAD_ATTRIBUTE if <attrib_list> is neither NULL nor empty (containing only EGL_NONE) or 
    43  * if <type> is not a supported type of sync object;
    44  * EGL_BAD_ALLOC if the memory allocation related to sync object is not successful
    45  * \note    If <type> is EGL_SYNC_REUSABLE_KHR, a reusable sync object is created. 
    46  * In this case <attrib_list> must be NULL or empty (containing only EGL_NONE).
    47  *  *//*-------------------------------------------------------------------*/
    48 EGLSyncKHR eglCreateSyncKHR( EGLDisplay dpy,
    49                        EGLenum condition,
    50                        const EGLint *attrib_list )
    51 {
    52     PFNEGLCREATESYNCKHRPROC createPointer = (PFNEGLCREATESYNCKHRPROC) eglGetProcAddress("eglCreateSyncKHR");
    53 
    54 	if (createPointer == NULL)
    55 		{
    56 		return EGL_NO_SYNC_KHR;
    57 		}
    58 	else
    59 		{
    60 		return createPointer(dpy, condition, attrib_list);
    61 		}
    62 }
    63 
    64 
    65 /*-------------------------------------------------------------------*//*!
    66  * \brief   Destroy a sync object and free memory associated with it
    67  * \ingroup api
    68  * \param   dpy     Identifier of the display which owns the sync object
    69  * \param   sync    Sync object handle. 
    70  * \return  EGL_TRUE if deletion was successful and EGL_FALSE otherwise
    71  * \error   EGL_BAD_DISPLAY if <dpy> is not a name of a valid EGLDisplay;
    72  * EGL_NOT_INITIALIZED if the display object associated with the <dpy> has not been initialized;
    73  * EGL_BAD_PARAMETER if <sync> is not a valid sync object for <dpy>
    74  * \note    If any eglClientWaitSyncKHR commands are blocking on <sync> when 
    75  * eglDestroySyncKHR is called, they will be woken up, as if <sync> were signaled. 
    76  * If no errors are generated, <sync> will no longer be the handle of a valid sync object.
    77  *//*-------------------------------------------------------------------*/
    78 EGLBoolean eglDestroySyncKHR( EGLDisplay dpy, EGLSyncKHR sync )
    79 {
    80     PFNEGLDESTROYSYNCKHRPROC destroyPointer = (PFNEGLDESTROYSYNCKHRPROC) eglGetProcAddress("eglDestroySyncKHR");
    81 
    82 	if (destroyPointer == NULL)
    83 		{
    84 		return EGL_FALSE;
    85 		}
    86 	else
    87 		{
    88 		return destroyPointer(dpy, sync);
    89 		}
    90 }
    91 
    92 /*-------------------------------------------------------------------*//*!
    93  * \brief   Blocks the calling thread until the specified sync object 
    94  * is signaled, or until <timeout> nanoseconds have passed.  
    95  * \ingroup api
    96  * \param   dpy     Identifier of the display which owns the sync object.
    97  * \param   sync    Sync object handle. 
    98  * \param   flags   If the EGL_FLUSH_COMMANDS_BIT_KHR bit is set in <flags>
    99  * and <sync> is unsignaled when the function is called, then the equivalent
   100  * of Flush() will be performed for the current API context.   
   101  * \param   timeout The thread will be unblocked when <timeout> is expired.
   102  * If the <timeout> is to zero, the function just test the current status 
   103  * of the sync object. If the <timeout> is set to EGL_FOREVER_KHR, then the 
   104  * function does not time out. For all other values, <timeout> is adjusted to 
   105  * the closest value which may be substantially longer than one nanosecond. 
   106  * \return  EGL_CONDITION_SATISFIED if <sync> was signaled before
   107  * the timeout expired, which includes the case when <sync> was already 
   108  * signaled when eglClientWaitSyncKHR was called; EGL_TIMEOUT_EXPIRED_KHR if the 
   109  * specified timeout period expired before <sync> was signaled; 
   110  * EGL_FALSE if an error occurs.
   111  * \error   EGL_BAD_DISPLAY if <dpy> is not a name of a valid EGLDisplay;
   112  * EGL_NOT_INITIALIZED if the display object associated with the <dpy> has not been initialized;
   113  * EGL_BAD_PARAMETER if <sync> is not a valid sync object for <dpy> or 
   114  * if <flags> does not equal to 0 or EGL_SYNC_FLUSH_COMMAND_BIT_KHR
   115  * Note\    More than one eglClientWaitSyncKHR may be outstanding on the same <sync> at any given time. 
   116  * When there are multiple threads blocked on the same <sync> and the sync object is signaled, 
   117  * all such threads are released, but the order in which they are released is not defined.
   118  * If a sync object is destroyed while an eglClientWaitSyncKHR is blocking on that object, 
   119  * eglClientWaitSyncKHR will unblock and return immediately, just as if the sync object 
   120  * had been signaled prior to being destroyed.
   121  *//*-------------------------------------------------------------------*/
   122 EGLint eglClientWaitSyncKHR( EGLDisplay dpy,
   123                              EGLSyncKHR sync,
   124                              EGLint flags,
   125                              EGLTimeKHR timeout )
   126 {
   127     PFNEGLCLIENTWAITSYNCKHRPROC clientWaitPointer = (PFNEGLCLIENTWAITSYNCKHRPROC) eglGetProcAddress("eglClientWaitSyncKHR");
   128 
   129 	if (clientWaitPointer == NULL)
   130 		{
   131 		return EGL_FALSE;
   132 		}
   133 	else
   134 		{
   135 		return clientWaitPointer(dpy, sync, flags, timeout);
   136 		}
   137 }
   138 
   139 /*-------------------------------------------------------------------*//*!
   140  * \brief   Signals or unsignals the reusable sync object.  
   141  * \ingroup api
   142  * \param   dpy     Identifier of the display which owns the sync object.
   143  * \param   sync    Sync object handle. 
   144  * \param   mode    Status of the sync object. There are two possible states: 
   145  *  EGL_SIGNALED_KHR and EGL_UNSIGNALED_KHR. 
   146  * \return  EGL_TRUE if an operation was successful and EGL_FALSE otherwise.
   147  * \note    The error code returned from eglSignalSyncImpl() will be generated
   148  *//*-------------------------------------------------------------------*/
   149 EGLBoolean eglSignalSyncKHR( EGLDisplay dpy,
   150                              EGLSyncKHR sync,
   151                              EGLenum mode )
   152 {
   153     PFNEGLSIGNALSYNCKHRPROC signalPointer = (PFNEGLSIGNALSYNCKHRPROC) eglGetProcAddress("eglSignalSyncKHR");
   154 	
   155    if (signalPointer == NULL)
   156 	   {
   157 	   return EGL_FALSE;
   158        }
   159    else
   160 	   {
   161 	   return signalPointer(dpy, sync, mode);
   162 	   }
   163 }
   164 
   165 
   166 /*-------------------------------------------------------------------*//*!
   167  * \brief   Query an attribute of the sync object  
   168  * \ingroup api
   169  * \param   dpy     Identifier of the display which owns the sync object
   170  * \param   sync    Sync object handle. 
   171  * \param   attribute   An attribute to be retrieved. 
   172  * \param   value   Pointer to the value for the requested attribute which will be filled on function return. 
   173  * \return  EGL_TRUE if an operation was successful and EGL_FALSE otherwise
   174  * \error   EGL_BAD_DISPLAY if <dpy> is not a name of a valid EGLDisplay;
   175  * EGL_NOT_INITIALIZED if the display object associated with the <dpy> has not been initialized;
   176  * EGL_BAD_PARAMETER if <sync> is not a valid sync object for <dpy> or if <value> is not 
   177  * a valid pointer; EGL_BAD_ATTRIBUTE if <attribute>  does not lie within expected range;
   178  * EGL_BAD_MATCH if <attribute> is not supported for the type of sync object passed in <sync>
   179  *//*-------------------------------------------------------------------*/
   180 EGLBoolean eglGetSyncAttribKHR( EGLDisplay dpy,
   181                                 EGLSyncKHR sync,
   182                                 EGLint attribute,
   183                                 EGLint *value )
   184 {
   185     PFNEGLGETSYNCATTRIBKHRPROC getAttribPointer = (PFNEGLGETSYNCATTRIBKHRPROC) eglGetProcAddress("eglGetSyncAttribKHR");
   186 
   187 	if (getAttribPointer == NULL)
   188 		{
   189 		return EGL_FALSE;
   190 		}
   191 	else
   192 		{
   193 		return getAttribPointer(dpy, sync, attribute, value);
   194 		}
   195 }
   196 
   197 
   198 
   199 #ifdef __cplusplus
   200 }
   201 #endif
   202 #endif