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