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