os/graphics/graphicscomposition/openwfsupport/src/eglsynchelper.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicscomposition/openwfsupport/src/eglsynchelper.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,202 @@
     1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// eglsynchelper.c
    1.18 +//
    1.19 +
    1.20 +#include "eglsynchelper.h"
    1.21 +#include "EGL/egltypes.h"
    1.22 +
    1.23 +#ifndef EGL_EGLEXT_PROTOTYPES
    1.24 +
    1.25 +#define EGLSYNC_TYPE 0xE5
    1.26 +
    1.27 +/* sync object data type for POSIX thread implementation*/
    1.28 +
    1.29 +typedef struct CondVarSync_* NativeSyncType;
    1.30 +
    1.31 +#ifdef __cplusplus
    1.32 +extern "C" {
    1.33 +#endif
    1.34 +
    1.35 +/*-------------------------------------------------------------------*//*!
    1.36 + * \brief   Create a sync object for the specified display.
    1.37 + * \ingroup api
    1.38 + * \param   dpy     Identifier of the display which will own the sync object
    1.39 + * \param   type    Type of the sync object. EGL_SYNC_REUSABLE_KHR is only supported
    1.40 + * \param   attrib_list Attribute-value list specifying attributes of the sync 
    1.41 + * object, terminated by an attribute entry EGL_NONE
    1.42 + * \return  Handle for the created sync object if successful, EGL_NO_SYNC_KHR otherwise
    1.43 + * \error   EGL_BAD_DISPLAY if <dpy> is not a name of a valid EGLDisplay;
    1.44 + * EGL_NOT_INITIALIZED if the display object associated with the <dpy> has not been initialized;
    1.45 + * EGL_BAD_ATTRIBUTE if <attrib_list> is neither NULL nor empty (containing only EGL_NONE) or 
    1.46 + * if <type> is not a supported type of sync object;
    1.47 + * EGL_BAD_ALLOC if the memory allocation related to sync object is not successful
    1.48 + * \note    If <type> is EGL_SYNC_REUSABLE_KHR, a reusable sync object is created. 
    1.49 + * In this case <attrib_list> must be NULL or empty (containing only EGL_NONE).
    1.50 + *  *//*-------------------------------------------------------------------*/
    1.51 +EGLSyncKHR eglCreateSyncKHR( EGLDisplay dpy,
    1.52 +                       EGLenum condition,
    1.53 +                       const EGLint *attrib_list )
    1.54 +{
    1.55 +    PFNEGLCREATESYNCKHRPROC createPointer = (PFNEGLCREATESYNCKHRPROC) eglGetProcAddress("eglCreateSyncKHR");
    1.56 +
    1.57 +	if (createPointer == NULL)
    1.58 +		{
    1.59 +		return EGL_NO_SYNC_KHR;
    1.60 +		}
    1.61 +	else
    1.62 +		{
    1.63 +		return createPointer(dpy, condition, attrib_list);
    1.64 +		}
    1.65 +}
    1.66 +
    1.67 +
    1.68 +/*-------------------------------------------------------------------*//*!
    1.69 + * \brief   Destroy a sync object and free memory associated with it
    1.70 + * \ingroup api
    1.71 + * \param   dpy     Identifier of the display which owns the sync object
    1.72 + * \param   sync    Sync object handle. 
    1.73 + * \return  EGL_TRUE if deletion was successful and EGL_FALSE otherwise
    1.74 + * \error   EGL_BAD_DISPLAY if <dpy> is not a name of a valid EGLDisplay;
    1.75 + * EGL_NOT_INITIALIZED if the display object associated with the <dpy> has not been initialized;
    1.76 + * EGL_BAD_PARAMETER if <sync> is not a valid sync object for <dpy>
    1.77 + * \note    If any eglClientWaitSyncKHR commands are blocking on <sync> when 
    1.78 + * eglDestroySyncKHR is called, they will be woken up, as if <sync> were signaled. 
    1.79 + * If no errors are generated, <sync> will no longer be the handle of a valid sync object.
    1.80 + *//*-------------------------------------------------------------------*/
    1.81 +EGLBoolean eglDestroySyncKHR( EGLDisplay dpy, EGLSyncKHR sync )
    1.82 +{
    1.83 +    PFNEGLDESTROYSYNCKHRPROC destroyPointer = (PFNEGLDESTROYSYNCKHRPROC) eglGetProcAddress("eglDestroySyncKHR");
    1.84 +
    1.85 +	if (destroyPointer == NULL)
    1.86 +		{
    1.87 +		return EGL_FALSE;
    1.88 +		}
    1.89 +	else
    1.90 +		{
    1.91 +		return destroyPointer(dpy, sync);
    1.92 +		}
    1.93 +}
    1.94 +
    1.95 +/*-------------------------------------------------------------------*//*!
    1.96 + * \brief   Blocks the calling thread until the specified sync object 
    1.97 + * is signaled, or until <timeout> nanoseconds have passed.  
    1.98 + * \ingroup api
    1.99 + * \param   dpy     Identifier of the display which owns the sync object.
   1.100 + * \param   sync    Sync object handle. 
   1.101 + * \param   flags   If the EGL_FLUSH_COMMANDS_BIT_KHR bit is set in <flags>
   1.102 + * and <sync> is unsignaled when the function is called, then the equivalent
   1.103 + * of Flush() will be performed for the current API context.   
   1.104 + * \param   timeout The thread will be unblocked when <timeout> is expired.
   1.105 + * If the <timeout> is to zero, the function just test the current status 
   1.106 + * of the sync object. If the <timeout> is set to EGL_FOREVER_KHR, then the 
   1.107 + * function does not time out. For all other values, <timeout> is adjusted to 
   1.108 + * the closest value which may be substantially longer than one nanosecond. 
   1.109 + * \return  EGL_CONDITION_SATISFIED if <sync> was signaled before
   1.110 + * the timeout expired, which includes the case when <sync> was already 
   1.111 + * signaled when eglClientWaitSyncKHR was called; EGL_TIMEOUT_EXPIRED_KHR if the 
   1.112 + * specified timeout period expired before <sync> was signaled; 
   1.113 + * EGL_FALSE if an error occurs.
   1.114 + * \error   EGL_BAD_DISPLAY if <dpy> is not a name of a valid EGLDisplay;
   1.115 + * EGL_NOT_INITIALIZED if the display object associated with the <dpy> has not been initialized;
   1.116 + * EGL_BAD_PARAMETER if <sync> is not a valid sync object for <dpy> or 
   1.117 + * if <flags> does not equal to 0 or EGL_SYNC_FLUSH_COMMAND_BIT_KHR
   1.118 + * Note\    More than one eglClientWaitSyncKHR may be outstanding on the same <sync> at any given time. 
   1.119 + * When there are multiple threads blocked on the same <sync> and the sync object is signaled, 
   1.120 + * all such threads are released, but the order in which they are released is not defined.
   1.121 + * If a sync object is destroyed while an eglClientWaitSyncKHR is blocking on that object, 
   1.122 + * eglClientWaitSyncKHR will unblock and return immediately, just as if the sync object 
   1.123 + * had been signaled prior to being destroyed.
   1.124 + *//*-------------------------------------------------------------------*/
   1.125 +EGLint eglClientWaitSyncKHR( EGLDisplay dpy,
   1.126 +                             EGLSyncKHR sync,
   1.127 +                             EGLint flags,
   1.128 +                             EGLTimeKHR timeout )
   1.129 +{
   1.130 +    PFNEGLCLIENTWAITSYNCKHRPROC clientWaitPointer = (PFNEGLCLIENTWAITSYNCKHRPROC) eglGetProcAddress("eglClientWaitSyncKHR");
   1.131 +
   1.132 +	if (clientWaitPointer == NULL)
   1.133 +		{
   1.134 +		return EGL_FALSE;
   1.135 +		}
   1.136 +	else
   1.137 +		{
   1.138 +		return clientWaitPointer(dpy, sync, flags, timeout);
   1.139 +		}
   1.140 +}
   1.141 +
   1.142 +/*-------------------------------------------------------------------*//*!
   1.143 + * \brief   Signals or unsignals the reusable sync object.  
   1.144 + * \ingroup api
   1.145 + * \param   dpy     Identifier of the display which owns the sync object.
   1.146 + * \param   sync    Sync object handle. 
   1.147 + * \param   mode    Status of the sync object. There are two possible states: 
   1.148 + *  EGL_SIGNALED_KHR and EGL_UNSIGNALED_KHR. 
   1.149 + * \return  EGL_TRUE if an operation was successful and EGL_FALSE otherwise.
   1.150 + * \note    The error code returned from eglSignalSyncImpl() will be generated
   1.151 + *//*-------------------------------------------------------------------*/
   1.152 +EGLBoolean eglSignalSyncKHR( EGLDisplay dpy,
   1.153 +                             EGLSyncKHR sync,
   1.154 +                             EGLenum mode )
   1.155 +{
   1.156 +    PFNEGLSIGNALSYNCKHRPROC signalPointer = (PFNEGLSIGNALSYNCKHRPROC) eglGetProcAddress("eglSignalSyncKHR");
   1.157 +	
   1.158 +   if (signalPointer == NULL)
   1.159 +	   {
   1.160 +	   return EGL_FALSE;
   1.161 +       }
   1.162 +   else
   1.163 +	   {
   1.164 +	   return signalPointer(dpy, sync, mode);
   1.165 +	   }
   1.166 +}
   1.167 +
   1.168 +
   1.169 +/*-------------------------------------------------------------------*//*!
   1.170 + * \brief   Query an attribute of the sync object  
   1.171 + * \ingroup api
   1.172 + * \param   dpy     Identifier of the display which owns the sync object
   1.173 + * \param   sync    Sync object handle. 
   1.174 + * \param   attribute   An attribute to be retrieved. 
   1.175 + * \param   value   Pointer to the value for the requested attribute which will be filled on function return. 
   1.176 + * \return  EGL_TRUE if an operation was successful and EGL_FALSE otherwise
   1.177 + * \error   EGL_BAD_DISPLAY if <dpy> is not a name of a valid EGLDisplay;
   1.178 + * EGL_NOT_INITIALIZED if the display object associated with the <dpy> has not been initialized;
   1.179 + * EGL_BAD_PARAMETER if <sync> is not a valid sync object for <dpy> or if <value> is not 
   1.180 + * a valid pointer; EGL_BAD_ATTRIBUTE if <attribute>  does not lie within expected range;
   1.181 + * EGL_BAD_MATCH if <attribute> is not supported for the type of sync object passed in <sync>
   1.182 + *//*-------------------------------------------------------------------*/
   1.183 +EGLBoolean eglGetSyncAttribKHR( EGLDisplay dpy,
   1.184 +                                EGLSyncKHR sync,
   1.185 +                                EGLint attribute,
   1.186 +                                EGLint *value )
   1.187 +{
   1.188 +    PFNEGLGETSYNCATTRIBKHRPROC getAttribPointer = (PFNEGLGETSYNCATTRIBKHRPROC) eglGetProcAddress("eglGetSyncAttribKHR");
   1.189 +
   1.190 +	if (getAttribPointer == NULL)
   1.191 +		{
   1.192 +		return EGL_FALSE;
   1.193 +		}
   1.194 +	else
   1.195 +		{
   1.196 +		return getAttribPointer(dpy, sync, attribute, value);
   1.197 +		}
   1.198 +}
   1.199 +
   1.200 +
   1.201 +
   1.202 +#ifdef __cplusplus
   1.203 +}
   1.204 +#endif
   1.205 +#endif