egl/sfopenvg/riMiniEGL.cpp
branchEGL_MERGE
changeset 190 19ce5231ffe4
parent 72 360f71440b77
child 74 0f98da52363f
equal deleted inserted replaced
90:bda9a4b12167 190:19ce5231ffe4
    26  *
    26  *
    27  *//**
    27  *//**
    28  * \file
    28  * \file
    29  * \brief	Simple implementation of EGL 1.3
    29  * \brief	Simple implementation of EGL 1.3
    30  * \note	caveats:
    30  * \note	caveats:
    31  - always renders into the backbuffer and blits it to window (no single buffered rendering)
    31 			- always renders into the backbuffer and blits it to window (no single buffered rendering)
    32  - no native Windows or Mac OS X pixmap support
    32 			- no native Windows or Mac OS X pixmap support
    33  - no power management events
    33 			- no power management events
    34  - no support for swap interval
    34 			- no support for swap interval
    35  * \todo	what happens in egl functions when eglTerminate has been called but the context and surface are still in use?
    35  * \todo	what happens in egl functions when eglTerminate has been called but the context and surface are still in use?
    36  * \todo	OSDeinitMutex should be called in case getEGL fails.
    36  * \todo	OSDeinitMutex should be called in case getEGL fails.
    37  *//*-------------------------------------------------------------------*/
    37  *//*-------------------------------------------------------------------*/
    38 
    38 
    39 #include "riMiniEGL.h"
    39 #include "riMiniEGL.h"
    40 #include "eglprivate.h"
    40 #include "eglprivate.h"
       
    41 #include "riMath.h"
    41 #include <e32debug.h>
    42 #include <e32debug.h>
       
    43 
       
    44 //==============================================================================================
       
    45 
    42 namespace OpenVGRI
    46 namespace OpenVGRI
    43 {
    47 {
    44 //using namespace OpenVGRI;
    48 void* OSGetCurrentThreadID(void);
       
    49 void OSAcquireMutex(void);
       
    50 void OSReleaseMutex(void);
       
    51 void OSDeinitMutex(void);
       
    52 
       
    53 EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id);
       
    54 void* OSCreateWindowContext(EGLNativeWindowType window);
       
    55 void OSDestroyWindowContext(void* context);
       
    56 bool OSIsWindow(const void* context);
       
    57 void OSGetWindowSize(const void* context, int& width, int& height);
       
    58 void OSBlitToWindow(void* context, const Drawable* drawable);
       
    59 EGLBoolean OSGetNativePixmapInfo(NativePixmapType pixmap, int* width, int* height, int* stride, VGImageFormat* format, int** data);
       
    60 
       
    61 
       
    62 
       
    63 /*-------------------------------------------------------------------*//*!
       
    64 * \brief	
       
    65 * \param	
       
    66 * \return	
       
    67 * \note		
       
    68 *//*-------------------------------------------------------------------*/
       
    69 
       
    70 class RIEGLContext
       
    71 {
       
    72 public:
       
    73 	RIEGLContext(OpenVGRI::VGContext* vgctx, const EGLConfig config);
       
    74 	~RIEGLContext();
       
    75 	void	addReference()				{ m_referenceCount++; }
       
    76 	int		removeReference()			{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
       
    77 
       
    78     VGContext*      getVGContext() const      { return m_vgContext; }
       
    79     EGLConfig getConfig() const         { return m_config; }
       
    80 private:
       
    81 	RIEGLContext(const RIEGLContext&);
       
    82 	RIEGLContext& operator=(const RIEGLContext&);
       
    83 	VGContext*		m_vgContext;
       
    84 	const EGLConfig	m_config;
       
    85 	int				m_referenceCount;
       
    86 };
       
    87 
       
    88 RIEGLContext* CastToRIEGLContext(EGLContext aCtxId);
       
    89 EGLContext CastFromRIEGLContext(RIEGLContext* aCtx);
    45 
    90 
    46 RIEGLContext::RIEGLContext(OpenVGRI::VGContext* vgctx, const EGLConfig config) :
    91 RIEGLContext::RIEGLContext(OpenVGRI::VGContext* vgctx, const EGLConfig config) :
    47 	m_vgContext(vgctx), m_config(config), m_referenceCount(0)
    92 	m_vgContext(vgctx),
    48 	{
    93 	m_config(config),
    49 	}
    94 	m_referenceCount(0)
       
    95 {
       
    96 }
    50 RIEGLContext::~RIEGLContext()
    97 RIEGLContext::~RIEGLContext()
    51 	{
    98 {
    52 	RI_ASSERT(m_referenceCount == 0);
    99 	RI_ASSERT(m_referenceCount == 0);
    53 	RI_DELETE(m_vgContext);
   100 	RI_DELETE(m_vgContext);
    54 	}
   101 }
    55 
   102 
    56 /*-------------------------------------------------------------------*//*!
   103 /*-------------------------------------------------------------------*//*!
    57  * \brief	
   104 * \brief	
    58  * \param	
   105 * \param	
    59  * \return	
   106 * \return	
    60  * \note		
   107 * \note		
    61  *//*-------------------------------------------------------------------*/
   108 *//*-------------------------------------------------------------------*/
    62 
   109 
    63 RIEGLSurface::RIEGLSurface(void* OSWindowContext, const EGLConfig config,
   110 class RIEGLSurface
    64 		Drawable* drawable, bool largestPbuffer, int renderBuffer) :
   111 {
    65 	m_OSWindowContext(OSWindowContext), m_config(config), m_drawable(drawable),
   112 public:
    66 			m_largestPbuffer(largestPbuffer), m_renderBuffer(renderBuffer),
   113     RIEGLSurface(void* OSWindowContext, const EGLConfig config, Drawable* drawable, bool largestPbuffer, int renderBuffer);
    67 			m_referenceCount(0)
   114 	~RIEGLSurface();
    68 	{
   115 	void	addReference()				{ m_referenceCount++; }
    69 	RI_ASSERT(m_renderBuffer == EGL_BACK_BUFFER); //only back buffer rendering is supported
   116 	int		removeReference()			{ m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
    70 	m_drawable->addReference();
   117 
    71 	}
   118     void*           getOSWindowContext() const { return m_OSWindowContext; }
       
   119     EGLConfig       getConfig() const          { return m_config; }
       
   120     Drawable*       getDrawable() const        { return m_drawable; }
       
   121     bool            isLargestPbuffer() const   { return m_largestPbuffer; }
       
   122     int             getRenderBuffer() const    { return m_renderBuffer; }
       
   123 
       
   124 private:
       
   125 	RIEGLSurface(const RIEGLSurface&);
       
   126 	RIEGLSurface& operator=(const RIEGLSurface&);
       
   127     void*            m_OSWindowContext;
       
   128 	const EGLConfig	 m_config;
       
   129 	Drawable*        m_drawable;
       
   130 	bool			 m_largestPbuffer;
       
   131 	int				 m_renderBuffer;		//EGL_BACK_BUFFER or EGL_SINGLE_BUFFER
       
   132 	int				 m_referenceCount;
       
   133 };
       
   134 
       
   135 RIEGLSurface* CastToRIEGLSurface(EGLSurface aSurfaceId);
       
   136 EGLSurface CastFromRIEGLSurface(RIEGLSurface* aSurface);
       
   137 
       
   138 RIEGLSurface::RIEGLSurface(void* OSWindowContext, const EGLConfig config, Drawable* drawable, bool largestPbuffer, int renderBuffer) :
       
   139     m_OSWindowContext(OSWindowContext),
       
   140 	m_config(config),
       
   141 	m_drawable(drawable),
       
   142 	m_largestPbuffer(largestPbuffer),
       
   143 	m_renderBuffer(renderBuffer),
       
   144 	m_referenceCount(0)
       
   145 {
       
   146     RI_ASSERT(m_renderBuffer == EGL_BACK_BUFFER);   //only back buffer rendering is supported
       
   147     m_drawable->addReference();
       
   148 }
    72 
   149 
    73 RIEGLSurface::~RIEGLSurface()
   150 RIEGLSurface::~RIEGLSurface()
    74 	{
   151 {
    75 	RI_ASSERT(m_referenceCount == 0);
   152 	RI_ASSERT(m_referenceCount == 0);
    76 	OSDestroyWindowContext(m_OSWindowContext);
   153     OSDestroyWindowContext(m_OSWindowContext);
    77 	if (m_drawable)
   154 	if(m_drawable)
    78 		{
   155 	{
    79 		if (!m_drawable->removeReference())
   156 		if(!m_drawable->removeReference())
    80 			RI_DELETE(m_drawable);
   157 			RI_DELETE(m_drawable);
    81 		}
   158 	}
    82 	}
   159 }
    83 
   160 
    84 RIEGLDisplay::RIEGLDisplay(EGLDisplay id) :
   161 RIEGLDisplay::RIEGLDisplay(EGLDisplay id) :
    85 	m_id(id), m_contexts(), m_surfaces()
   162 	m_id(id),
    86 	{
   163 	m_contexts(),
       
   164 	m_surfaces()
       
   165 {
    87 	RI_ASSERT(EGL_NUMCONFIGS == 60);
   166 	RI_ASSERT(EGL_NUMCONFIGS == 60);
    88 
   167 
    89 	//sorted by RGB/LUMINANCE (exact), larger total number of color bits (at least), buffer size (at least), config ID (exact)
   168 	//sorted by RGB/LUMINANCE (exact), larger total number of color bits (at least), buffer size (at least), config ID (exact)
    90 	//NOTE: 16 bit configs need to be sorted on the fly if the request ignores some channels
   169 	//NOTE: 16 bit configs need to be sorted on the fly if the request ignores some channels
    91 	//NOTE: config IDs start from 1
   170 	//NOTE: config IDs start from 1
    92 	//               R  B  G  A  L  bpp samples maskBits ID
   171 	//               R  B  G  A  L  bpp samples maskBits ID
    93 	m_configs[0].set(8, 8, 8, 8, 0, 32, 1, 8, 1); //EGL_RGB_BUFFER, buffer size = 32
   172 	m_configs[0].set(8, 8, 8, 8, 0, 32, 1, 8, 1);	//EGL_RGB_BUFFER, buffer size = 32
    94 	m_configs[1].set(8, 8, 8, 0, 0, 32, 1, 8, 2); //EGL_RGB_BUFFER, buffer size = 24
   173 	m_configs[1].set(8, 8, 8, 0, 0, 32, 1, 8, 2);	//EGL_RGB_BUFFER, buffer size = 24
    95 	m_configs[2].set(5, 5, 5, 1, 0, 16, 1, 4, 3); //EGL_RGB_BUFFER, buffer size = 16
   174 	m_configs[2].set(5, 5, 5, 1, 0, 16, 1, 4, 3);	//EGL_RGB_BUFFER, buffer size = 16
    96 	m_configs[3].set(5, 6, 5, 0, 0, 16, 1, 4, 4); //EGL_RGB_BUFFER, buffer size = 16
   175 	m_configs[3].set(5, 6, 5, 0, 0, 16, 1, 4, 4);	//EGL_RGB_BUFFER, buffer size = 16
    97 	m_configs[4].set(4, 4, 4, 4, 0, 16, 1, 4, 5); //EGL_RGB_BUFFER, buffer size = 16
   176 	m_configs[4].set(4, 4, 4, 4, 0, 16, 1, 4, 5);	//EGL_RGB_BUFFER, buffer size = 16
    98 	m_configs[5].set(0, 0, 0, 8, 0, 8, 1, 8, 6); //EGL_RGB_BUFFER, buffer size = 8
   177 	m_configs[5].set(0, 0, 0, 8, 0, 8,  1, 8, 6);	//EGL_RGB_BUFFER, buffer size = 8
    99 	m_configs[6].set(0, 0, 0, 4, 0, 4, 1, 4, 7); //EGL_RGB_BUFFER, buffer size = 8
   178 	m_configs[6].set(0, 0, 0, 4, 0, 4,  1, 4, 7);	//EGL_RGB_BUFFER, buffer size = 8
   100 	m_configs[7].set(0, 0, 0, 1, 0, 1, 1, 1, 8); //EGL_RGB_BUFFER, buffer size = 8
   179 	m_configs[7].set(0, 0, 0, 1, 0, 1,  1, 1, 8);	//EGL_RGB_BUFFER, buffer size = 8
   101 	m_configs[8].set(0, 0, 0, 0, 8, 8, 1, 8, 9); //EGL_LUMINANCE_BUFFER, buffer size = 8
   180 	m_configs[8].set(0, 0, 0, 0, 8, 8,  1, 8, 9);	//EGL_LUMINANCE_BUFFER, buffer size = 8
   102 	m_configs[9].set(0, 0, 0, 0, 1, 1, 1, 1, 10); //EGL_LUMINANCE_BUFFER, buffer size = 1
   181 	m_configs[9].set(0, 0, 0, 0, 1, 1,  1, 1, 10);	//EGL_LUMINANCE_BUFFER, buffer size = 1
   103 
   182 
   104 	m_configs[10].set(8, 8, 8, 8, 0, 32, 4, 1, 11); //EGL_RGB_BUFFER, buffer size = 32
   183 	m_configs[10].set(8, 8, 8, 8, 0, 32, 4, 1, 11);	//EGL_RGB_BUFFER, buffer size = 32
   105 	m_configs[11].set(8, 8, 8, 0, 0, 32, 4, 1, 12); //EGL_RGB_BUFFER, buffer size = 24
   184 	m_configs[11].set(8, 8, 8, 0, 0, 32, 4, 1, 12);	//EGL_RGB_BUFFER, buffer size = 24
   106 	m_configs[12].set(5, 5, 5, 1, 0, 16, 4, 1, 13); //EGL_RGB_BUFFER, buffer size = 16
   185 	m_configs[12].set(5, 5, 5, 1, 0, 16, 4, 1, 13);	//EGL_RGB_BUFFER, buffer size = 16
   107 	m_configs[13].set(5, 6, 5, 0, 0, 16, 4, 1, 14); //EGL_RGB_BUFFER, buffer size = 16
   186 	m_configs[13].set(5, 6, 5, 0, 0, 16, 4, 1, 14);	//EGL_RGB_BUFFER, buffer size = 16
   108 	m_configs[14].set(4, 4, 4, 4, 0, 16, 4, 1, 15); //EGL_RGB_BUFFER, buffer size = 16
   187 	m_configs[14].set(4, 4, 4, 4, 0, 16, 4, 1, 15);	//EGL_RGB_BUFFER, buffer size = 16
   109 	m_configs[15].set(0, 0, 0, 8, 0, 8, 4, 1, 16); //EGL_RGB_BUFFER, buffer size = 8
   188 	m_configs[15].set(0, 0, 0, 8, 0, 8,  4, 1, 16);	//EGL_RGB_BUFFER, buffer size = 8
   110 	m_configs[16].set(0, 0, 0, 4, 0, 4, 4, 1, 17); //EGL_RGB_BUFFER, buffer size = 8
   189 	m_configs[16].set(0, 0, 0, 4, 0, 4,  4, 1, 17);	//EGL_RGB_BUFFER, buffer size = 8
   111 	m_configs[17].set(0, 0, 0, 1, 0, 1, 4, 1, 18); //EGL_RGB_BUFFER, buffer size = 8
   190 	m_configs[17].set(0, 0, 0, 1, 0, 1,  4, 1, 18);	//EGL_RGB_BUFFER, buffer size = 8
   112 	m_configs[18].set(0, 0, 0, 0, 8, 8, 4, 1, 19); //EGL_LUMINANCE_BUFFER, buffer size = 8
   191 	m_configs[18].set(0, 0, 0, 0, 8, 8,  4, 1, 19);	//EGL_LUMINANCE_BUFFER, buffer size = 8
   113 	m_configs[19].set(0, 0, 0, 0, 1, 1, 4, 1, 20); //EGL_LUMINANCE_BUFFER, buffer size = 1
   192 	m_configs[19].set(0, 0, 0, 0, 1, 1,  4, 1, 20);	//EGL_LUMINANCE_BUFFER, buffer size = 1
   114 
   193 
   115 	m_configs[20].set(8, 8, 8, 8, 0, 32, 32, 1, 21); //EGL_RGB_BUFFER, buffer size = 32
   194 	m_configs[20].set(8, 8, 8, 8, 0, 32, 32, 1, 21);	//EGL_RGB_BUFFER, buffer size = 32
   116 	m_configs[21].set(8, 8, 8, 0, 0, 32, 32, 1, 22); //EGL_RGB_BUFFER, buffer size = 24
   195 	m_configs[21].set(8, 8, 8, 0, 0, 32, 32, 1, 22);	//EGL_RGB_BUFFER, buffer size = 24
   117 	m_configs[22].set(5, 5, 5, 1, 0, 16, 32, 1, 23); //EGL_RGB_BUFFER, buffer size = 16
   196 	m_configs[22].set(5, 5, 5, 1, 0, 16, 32, 1, 23);	//EGL_RGB_BUFFER, buffer size = 16
   118 	m_configs[23].set(5, 6, 5, 0, 0, 16, 32, 1, 24); //EGL_RGB_BUFFER, buffer size = 16
   197 	m_configs[23].set(5, 6, 5, 0, 0, 16, 32, 1, 24);	//EGL_RGB_BUFFER, buffer size = 16
   119 	m_configs[24].set(4, 4, 4, 4, 0, 16, 32, 1, 25); //EGL_RGB_BUFFER, buffer size = 16
   198 	m_configs[24].set(4, 4, 4, 4, 0, 16, 32, 1, 25);	//EGL_RGB_BUFFER, buffer size = 16
   120 	m_configs[25].set(0, 0, 0, 8, 0, 8, 32, 1, 26); //EGL_RGB_BUFFER, buffer size = 8
   199 	m_configs[25].set(0, 0, 0, 8, 0, 8,  32, 1, 26);	//EGL_RGB_BUFFER, buffer size = 8
   121 	m_configs[26].set(0, 0, 0, 4, 0, 4, 32, 1, 27); //EGL_RGB_BUFFER, buffer size = 8
   200 	m_configs[26].set(0, 0, 0, 4, 0, 4,  32, 1, 27);	//EGL_RGB_BUFFER, buffer size = 8
   122 	m_configs[27].set(0, 0, 0, 1, 0, 1, 32, 1, 28); //EGL_RGB_BUFFER, buffer size = 8
   201 	m_configs[27].set(0, 0, 0, 1, 0, 1,  32, 1, 28);	//EGL_RGB_BUFFER, buffer size = 8
   123 	m_configs[28].set(0, 0, 0, 0, 8, 8, 32, 1, 29); //EGL_LUMINANCE_BUFFER, buffer size = 8
   202 	m_configs[28].set(0, 0, 0, 0, 8, 8,  32, 1, 29);	//EGL_LUMINANCE_BUFFER, buffer size = 8
   124 	m_configs[29].set(0, 0, 0, 0, 1, 1, 32, 1, 30); //EGL_LUMINANCE_BUFFER, buffer size = 1
   203 	m_configs[29].set(0, 0, 0, 0, 1, 1,  32, 1, 30);	//EGL_LUMINANCE_BUFFER, buffer size = 1
   125 
   204 
   126 	//configs without mask
   205     //configs without mask
   127 	m_configs[30].set(8, 8, 8, 8, 0, 32, 1, 0, 31); //EGL_RGB_BUFFER, buffer size = 32
   206 	m_configs[30].set(8, 8, 8, 8, 0, 32, 1, 0, 31);	//EGL_RGB_BUFFER, buffer size = 32
   128 	m_configs[31].set(8, 8, 8, 0, 0, 32, 1, 0, 32); //EGL_RGB_BUFFER, buffer size = 24
   207 	m_configs[31].set(8, 8, 8, 0, 0, 32, 1, 0, 32);	//EGL_RGB_BUFFER, buffer size = 24
   129 	m_configs[32].set(5, 5, 5, 1, 0, 16, 1, 0, 33); //EGL_RGB_BUFFER, buffer size = 16
   208 	m_configs[32].set(5, 5, 5, 1, 0, 16, 1, 0, 33);	//EGL_RGB_BUFFER, buffer size = 16
   130 	m_configs[33].set(5, 6, 5, 0, 0, 16, 1, 0, 34); //EGL_RGB_BUFFER, buffer size = 16
   209 	m_configs[33].set(5, 6, 5, 0, 0, 16, 1, 0, 34);	//EGL_RGB_BUFFER, buffer size = 16
   131 	m_configs[34].set(4, 4, 4, 4, 0, 16, 1, 0, 35); //EGL_RGB_BUFFER, buffer size = 16
   210 	m_configs[34].set(4, 4, 4, 4, 0, 16, 1, 0, 35);	//EGL_RGB_BUFFER, buffer size = 16
   132 	m_configs[35].set(0, 0, 0, 8, 0, 8, 1, 0, 36); //EGL_RGB_BUFFER, buffer size = 8
   211 	m_configs[35].set(0, 0, 0, 8, 0, 8,  1, 0, 36);	//EGL_RGB_BUFFER, buffer size = 8
   133 	m_configs[36].set(0, 0, 0, 4, 0, 4, 1, 0, 37); //EGL_RGB_BUFFER, buffer size = 8
   212 	m_configs[36].set(0, 0, 0, 4, 0, 4,  1, 0, 37);	//EGL_RGB_BUFFER, buffer size = 8
   134 	m_configs[37].set(0, 0, 0, 1, 0, 1, 1, 0, 38); //EGL_RGB_BUFFER, buffer size = 8
   213 	m_configs[37].set(0, 0, 0, 1, 0, 1,  1, 0, 38);	//EGL_RGB_BUFFER, buffer size = 8
   135 	m_configs[38].set(0, 0, 0, 0, 8, 8, 1, 0, 39); //EGL_LUMINANCE_BUFFER, buffer size = 8
   214 	m_configs[38].set(0, 0, 0, 0, 8, 8,  1, 0, 39);	//EGL_LUMINANCE_BUFFER, buffer size = 8
   136 	m_configs[39].set(0, 0, 0, 0, 1, 1, 1, 0, 40); //EGL_LUMINANCE_BUFFER, buffer size = 1
   215 	m_configs[39].set(0, 0, 0, 0, 1, 1,  1, 0, 40);	//EGL_LUMINANCE_BUFFER, buffer size = 1
   137 
   216 
   138 	m_configs[40].set(8, 8, 8, 8, 0, 32, 4, 0, 41); //EGL_RGB_BUFFER, buffer size = 32
   217 	m_configs[40].set(8, 8, 8, 8, 0, 32, 4, 0, 41);	//EGL_RGB_BUFFER, buffer size = 32
   139 	m_configs[41].set(8, 8, 8, 0, 0, 32, 4, 0, 42); //EGL_RGB_BUFFER, buffer size = 24
   218 	m_configs[41].set(8, 8, 8, 0, 0, 32, 4, 0, 42);	//EGL_RGB_BUFFER, buffer size = 24
   140 	m_configs[42].set(5, 5, 5, 1, 0, 16, 4, 0, 43); //EGL_RGB_BUFFER, buffer size = 16
   219 	m_configs[42].set(5, 5, 5, 1, 0, 16, 4, 0, 43);	//EGL_RGB_BUFFER, buffer size = 16
   141 	m_configs[43].set(5, 6, 5, 0, 0, 16, 4, 0, 44); //EGL_RGB_BUFFER, buffer size = 16
   220 	m_configs[43].set(5, 6, 5, 0, 0, 16, 4, 0, 44);	//EGL_RGB_BUFFER, buffer size = 16
   142 	m_configs[44].set(4, 4, 4, 4, 0, 16, 4, 0, 45); //EGL_RGB_BUFFER, buffer size = 16
   221 	m_configs[44].set(4, 4, 4, 4, 0, 16, 4, 0, 45);	//EGL_RGB_BUFFER, buffer size = 16
   143 	m_configs[45].set(0, 0, 0, 8, 0, 8, 4, 0, 46); //EGL_RGB_BUFFER, buffer size = 8
   222 	m_configs[45].set(0, 0, 0, 8, 0, 8,  4, 0, 46);	//EGL_RGB_BUFFER, buffer size = 8
   144 	m_configs[46].set(0, 0, 0, 4, 0, 4, 4, 0, 47); //EGL_RGB_BUFFER, buffer size = 8
   223 	m_configs[46].set(0, 0, 0, 4, 0, 4,  4, 0, 47);	//EGL_RGB_BUFFER, buffer size = 8
   145 	m_configs[47].set(0, 0, 0, 1, 0, 1, 4, 0, 48); //EGL_RGB_BUFFER, buffer size = 8
   224 	m_configs[47].set(0, 0, 0, 1, 0, 1,  4, 0, 48);	//EGL_RGB_BUFFER, buffer size = 8
   146 	m_configs[48].set(0, 0, 0, 0, 8, 8, 4, 0, 49); //EGL_LUMINANCE_BUFFER, buffer size = 8
   225 	m_configs[48].set(0, 0, 0, 0, 8, 8,  4, 0, 49);	//EGL_LUMINANCE_BUFFER, buffer size = 8
   147 	m_configs[49].set(0, 0, 0, 0, 1, 1, 4, 0, 50); //EGL_LUMINANCE_BUFFER, buffer size = 1
   226 	m_configs[49].set(0, 0, 0, 0, 1, 1,  4, 0, 50);	//EGL_LUMINANCE_BUFFER, buffer size = 1
   148 
   227 
   149 	m_configs[50].set(8, 8, 8, 8, 0, 32, 32, 0, 51); //EGL_RGB_BUFFER, buffer size = 32
   228 	m_configs[50].set(8, 8, 8, 8, 0, 32, 32, 0, 51);	//EGL_RGB_BUFFER, buffer size = 32
   150 	m_configs[51].set(8, 8, 8, 0, 0, 32, 32, 0, 52); //EGL_RGB_BUFFER, buffer size = 24
   229 	m_configs[51].set(8, 8, 8, 0, 0, 32, 32, 0, 52);	//EGL_RGB_BUFFER, buffer size = 24
   151 	m_configs[52].set(5, 5, 5, 1, 0, 16, 32, 0, 53); //EGL_RGB_BUFFER, buffer size = 16
   230 	m_configs[52].set(5, 5, 5, 1, 0, 16, 32, 0, 53);	//EGL_RGB_BUFFER, buffer size = 16
   152 	m_configs[53].set(5, 6, 5, 0, 0, 16, 32, 0, 54); //EGL_RGB_BUFFER, buffer size = 16
   231 	m_configs[53].set(5, 6, 5, 0, 0, 16, 32, 0, 54);	//EGL_RGB_BUFFER, buffer size = 16
   153 	m_configs[54].set(4, 4, 4, 4, 0, 16, 32, 0, 55); //EGL_RGB_BUFFER, buffer size = 16
   232 	m_configs[54].set(4, 4, 4, 4, 0, 16, 32, 0, 55);	//EGL_RGB_BUFFER, buffer size = 16
   154 	m_configs[55].set(0, 0, 0, 8, 0, 8, 32, 0, 56); //EGL_RGB_BUFFER, buffer size = 8
   233 	m_configs[55].set(0, 0, 0, 8, 0, 8,  32, 0, 56);	//EGL_RGB_BUFFER, buffer size = 8
   155 	m_configs[56].set(0, 0, 0, 4, 0, 4, 32, 0, 57); //EGL_RGB_BUFFER, buffer size = 8
   234 	m_configs[56].set(0, 0, 0, 4, 0, 4,  32, 0, 57);	//EGL_RGB_BUFFER, buffer size = 8
   156 	m_configs[57].set(0, 0, 0, 1, 0, 1, 32, 0, 58); //EGL_RGB_BUFFER, buffer size = 8
   235 	m_configs[57].set(0, 0, 0, 1, 0, 1,  32, 0, 58);	//EGL_RGB_BUFFER, buffer size = 8
   157 	m_configs[58].set(0, 0, 0, 0, 8, 8, 32, 0, 59); //EGL_LUMINANCE_BUFFER, buffer size = 8
   236 	m_configs[58].set(0, 0, 0, 0, 8, 8,  32, 0, 59);	//EGL_LUMINANCE_BUFFER, buffer size = 8
   158 	m_configs[59].set(0, 0, 0, 0, 1, 1, 32, 0, 60); //EGL_LUMINANCE_BUFFER, buffer size = 1
   237 	m_configs[59].set(0, 0, 0, 0, 1, 1,  32, 0, 60);	//EGL_LUMINANCE_BUFFER, buffer size = 1
   159 	/*
   238 /*
   160 	 attrib                default        criteria order   priority
   239 attrib                default        criteria order   priority
   161 	 --------------------------------------------------------------
   240 --------------------------------------------------------------
   162 	 EGL_COLOR_BUFFER_TYPE EGL_RGB_BUFFER Exact    None    2 
   241 EGL_COLOR_BUFFER_TYPE EGL_RGB_BUFFER Exact    None    2 
   163 	 EGL_RED_SIZE          0              AtLeast  Special 3 
   242 EGL_RED_SIZE          0              AtLeast  Special 3 
   164 	 EGL_GREEN_SIZE        0              AtLeast  Special 3 
   243 EGL_GREEN_SIZE        0              AtLeast  Special 3 
   165 	 EGL_BLUE_SIZE         0              AtLeast  Special 3 
   244 EGL_BLUE_SIZE         0              AtLeast  Special 3 
   166 	 EGL_LUMINANCE_SIZE    0              AtLeast  Special 3 
   245 EGL_LUMINANCE_SIZE    0              AtLeast  Special 3 
   167 	 EGL_ALPHA_SIZE        0              AtLeast  Special 3 
   246 EGL_ALPHA_SIZE        0              AtLeast  Special 3 
   168 	 EGL_BUFFER_SIZE       0              AtLeast  Smaller 4 
   247 EGL_BUFFER_SIZE       0              AtLeast  Smaller 4 
   169 	 EGL_CONFIG_ID         EGL_DONT_CARE  Exact    Smaller 11
   248 EGL_CONFIG_ID         EGL_DONT_CARE  Exact    Smaller 11
   170 	 */
   249 */
   171 	}
   250 }
   172 
   251 
   173 RIEGLDisplay::~RIEGLDisplay()
   252 RIEGLDisplay::~RIEGLDisplay()
   174 	{
   253 {
   175 	//mark everything for deletion, but don't delete the current context and surface
   254 	//mark everything for deletion, but don't delete the current context and surface
   176 	for (int i = 0; i < m_contexts.size(); i++)
   255 	for(int i=0;i<m_contexts.size();i++)
   177 		{
   256 	{
   178 		if (!m_contexts[i]->removeReference())
   257 		if(!m_contexts[i]->removeReference())
   179 			RI_DELETE(m_contexts[i]);
   258 			RI_DELETE(m_contexts[i]);
   180 		}
   259 	}
   181 	m_contexts.clear(); //remove all contexts from the list (makes further references to the current contexts invalid)
   260 	m_contexts.clear();	//remove all contexts from the list (makes further references to the current contexts invalid)
   182 
   261 
   183 	for (int i = 0; i < m_surfaces.size(); i++)
   262 	for(int i=0;i<m_surfaces.size();i++)
   184 		{
   263 	{
   185 		if (!m_surfaces[i]->removeReference())
   264 		if(!m_surfaces[i]->removeReference())
   186 			RI_DELETE(m_surfaces[i]);
   265 			RI_DELETE(m_surfaces[i]);
   187 		}
   266 	}
   188 	m_surfaces.clear(); //remove all surfaces from the list (makes further references to the current surfaces invalid)
   267 	m_surfaces.clear();	//remove all surfaces from the list (makes further references to the current surfaces invalid)
   189 	}
   268 }
   190 
   269 
   191 EGLBoolean RIEGLDisplay::contextExists(const EGLContext ctx) const
   270 EGLBoolean RIEGLDisplay::contextExists(const EGLContext ctx) const
   192 	{
   271 {
   193 	for (int i = 0; i < m_contexts.size(); i++)
   272 	for(int i=0;i<m_contexts.size();i++)
   194 		{
   273 	{
   195 		if (m_contexts[i] == CastToRIEGLContext(ctx))
   274 		if(m_contexts[i] == CastToRIEGLContext(ctx))
   196 			return EGL_TRUE;
   275 			return EGL_TRUE;
   197 		}
   276 	}
   198 	return EGL_FALSE;
   277 	return EGL_FALSE;
   199 	}
   278 }
   200 
   279 
   201 EGLBoolean RIEGLDisplay::surfaceExists(const EGLSurface surf) const
   280 EGLBoolean RIEGLDisplay::surfaceExists(const EGLSurface surf) const
   202 	{
   281 {
   203 	for (int i = 0; i < m_surfaces.size(); i++)
   282 	for(int i=0;i<m_surfaces.size();i++)
   204 		{
   283 	{
   205 		if (m_surfaces[i] == CastToRIEGLSurface(surf))
   284 		if(m_surfaces[i] == CastToRIEGLSurface(surf))
   206 			return EGL_TRUE;
   285 			return EGL_TRUE;
   207 		}
   286 	}
   208 	return EGL_FALSE;
   287 	return EGL_FALSE;
   209 	}
   288 }
   210 
   289 
   211 EGLBoolean RIEGLDisplay::configExists(const EGLConfig config) const
   290 EGLBoolean RIEGLDisplay::configExists(const EGLConfig config) const
   212 	{
   291 {
   213 	for (int i = 0; i < EGL_NUMCONFIGS; i++)
   292     for(int i=0;i<EGL_NUMCONFIGS;i++)
   214 		{
   293     {
   215 		if (m_configs[i].m_config == config)
   294         if(m_configs[i].m_config == config)
   216 			return EGL_TRUE;
   295 		return EGL_TRUE;
   217 		}
   296     }
   218 	return EGL_FALSE;
   297 	return EGL_FALSE;
   219 	}
   298 }
       
   299 
       
   300 /*-------------------------------------------------------------------*//*!
       
   301 * \brief	
       
   302 * \param	
       
   303 * \return	
       
   304 * \note		
       
   305 *//*-------------------------------------------------------------------*/
       
   306 
       
   307 class RIEGLThread
       
   308 {
       
   309 public:
       
   310 	RIEGLThread(void* currentThreadID);
       
   311 	~RIEGLThread();
       
   312 
       
   313     void*           getThreadID() const       { return m_threadID; }
       
   314 
       
   315     void            makeCurrent(RIEGLContext* c, RIEGLSurface* s)       { m_context = c; m_surface = s; }
       
   316 	RIEGLContext*	getCurrentContext() const   { return m_context; }
       
   317 	RIEGLSurface*	getCurrentSurface() const   { return m_surface; }
       
   318 
       
   319     void            setError(EGLint error)      { m_error = error; }
       
   320     EGLint          getError() const            { return m_error; }
       
   321 
       
   322     void            bindAPI(EGLint api)         { m_boundAPI = api; }
       
   323     EGLint          getBoundAPI() const         { return m_boundAPI; }
       
   324 
       
   325 private:
       
   326 	RIEGLThread(const RIEGLThread&);
       
   327 	RIEGLThread operator=(const RIEGLThread&);
       
   328 
       
   329 	RIEGLContext*		m_context;
       
   330 	RIEGLSurface*		m_surface;
       
   331 	EGLint              m_error;
       
   332 	void*               m_threadID;
       
   333 	EGLint              m_boundAPI;
       
   334 };
   220 
   335 
   221 RIEGLThread::RIEGLThread(void* currentThreadID) :
   336 RIEGLThread::RIEGLThread(void* currentThreadID) :
   222 	m_context(NULL), m_surface(NULL), m_error(EGL_SUCCESS), m_threadID(
   337 	m_context(NULL),
   223 			currentThreadID), m_boundAPI(EGL_NONE)
   338 	m_surface(NULL),
   224 	{
   339 	m_error(EGL_SUCCESS),
   225 	}
   340 	m_threadID(currentThreadID),
       
   341 	m_boundAPI(EGL_NONE)
       
   342 {
       
   343 }
   226 
   344 
   227 RIEGLThread::~RIEGLThread()
   345 RIEGLThread::~RIEGLThread()
   228 	{
   346 {
   229 	}
   347 }
       
   348 
       
   349 
       
   350 
       
   351 
       
   352 
       
   353 Image* CastToImage(EGLClientBuffer aBufferId);
       
   354 EGLClientBuffer CastFromImage(Image* aBUffer);
       
   355 
       
   356 
   230 
   357 
   231 EGL::EGL() :
   358 EGL::EGL() :
   232 	m_threads(), m_currentThreads(), m_displays(), m_referenceCount(0)
   359 	m_threads(),
   233 	{
   360 	m_currentThreads(),
   234 	}
   361 	m_displays(),
       
   362 	m_referenceCount(0)
       
   363 {
       
   364 }
   235 EGL::~EGL()
   365 EGL::~EGL()
   236 	{
   366 {
   237 	for (int i = 0; i < m_displays.size(); i++)
   367 	for(int i=0;i<m_displays.size();i++)
   238 		{
   368 	{
   239 		RI_DELETE(m_displays[i]);
   369 		RI_DELETE(m_displays[i]);
   240 		}
   370 	}
   241 	for (int i = 0; i < m_threads.size(); i++)
   371 	for(int i=0;i<m_threads.size();i++)
   242 		{
   372 	{
   243 		RI_DELETE(m_threads[i]);
   373 		RI_DELETE(m_threads[i]);
   244 		}
   374 	}
   245 	//currentThreads contain just pointers to threads we just deleted
   375 	//currentThreads contain just pointers to threads we just deleted
   246 	}
   376 }
   247 
   377 
   248 /*-------------------------------------------------------------------*//*!
   378 /*-------------------------------------------------------------------*//*!
   249  * \brief	
   379 * \brief	
   250  * \param	
   380 * \param	
   251  * \return	
   381 * \return	
   252  * \note		
   382 * \note		
   253  *//*-------------------------------------------------------------------*/
   383 *//*-------------------------------------------------------------------*/
   254 
   384 
   255 //static EGL* g_egl = NULL;	//never use this directly
   385 //static EGL* g_egl = NULL;	//never use this directly
   256 EGL* getEGL()
   386 EGL* getEGL()
   257 	{
   387 {
   258 	/*if(!g_egl)
   388 	/*if(!g_egl)
   259 	 {
   389 	{
   260 	 try
   390 		try
   261 	 {
   391 		{
   262 	 g_egl = RI_NEW(EGL, ());				//throws bad_alloc
   392 			g_egl = RI_NEW(EGL, ());				//throws bad_alloc
   263 	 g_egl->addReference();
   393 			g_egl->addReference();
   264 	 }
   394 		}
   265 	 catch(std::bad_alloc)
   395 		catch(std::bad_alloc)
   266 	 {
   396 		{
   267 	 g_egl = NULL;
   397 			g_egl = NULL;
   268 	 }
   398 		}
   269 	 }
   399 	}
   270 	 return g_egl;
   400 	return g_egl;
   271 	 */
   401 	*/
       
   402 
   272 
   403 
   273 	//use TLS to store static global g_egl
   404 	//use TLS to store static global g_egl
   274 	EGL* pEgl = NULL;
   405 	EGL* pEgl = NULL;
   275 	
   406 	
   276 	CEglThreadSession* es = reinterpret_cast<CEglThreadSession*>(Dll::Tls());
   407 	CEglThreadSession* es = reinterpret_cast<CEglThreadSession*>(Dll::Tls());
   277 	if (es)
   408 	if (es)
   278 		{
   409 		{
   279 	    return es->getEgl();
   410 		return es->getEgl();
   280 		}
   411 		}
   281 	
   412 	
   282 	const TInt err = CEglDriver::Open();
   413 	const TInt err = CEglDriver::Open();
   283 	if (err != KErrNone)
   414 	if (err != KErrNone)
   284 		{
   415 		{
   296 	if (!es || Dll::SetTls(es)!= KErrNone)
   427 	if (!es || Dll::SetTls(es)!= KErrNone)
   297 		{
   428 		{
   298 		delete es;
   429 		delete es;
   299 		return NULL;
   430 		return NULL;
   300 		}
   431 		}
       
   432 	return es->getEgl();
       
   433 
   301 	
   434 	
   302 	return es->getEgl();
   435 }
   303 	
   436 static void releaseEGL()
   304 	//TODO do we need to associate EGL with session here Jose
   437 {
   305 /*	if ((pEgl = static_cast<EGL*> (Dll::Tls())) == NULL)
   438 /*
       
   439 	if(g_egl)
       
   440 	{
       
   441 		if(!g_egl->removeReference())
   306 		{
   442 		{
   307 		//create TLS instance
   443 			RI_DELETE(g_egl);
   308 		pEgl = RI_NEW(EGL, ());
   444 			g_egl = NULL;
   309 		RDebug::Printf("---------- In getEGL()::Static(),Addr of pEgl Ptr = %x\n", &pEgl);
   445 		}
   310 		RDebug::Printf("---------- In getEGL()::Static(),Addr of pEgl= %x\n", pEgl);
   446 	}
   311 		//RDebug::Printf("In CEglThreadSession::Static(),Thread Id %Lu",(RThread().Id().Id()));
   447 	*/
   312 		RDebug::Printf("---------- In getEGL()::Static(),Thread Id %Lu",(RThread().Id()));
   448 	EGL* pEgl = static_cast<EGL*>(Dll::Tls());
   313 		Dll::SetTls(pEgl);
       
   314 		}*/
       
   315 	//return pEgl;
       
   316 
       
   317 	}
       
   318 
       
   319 
       
   320 static void releaseEGL()
       
   321 	{
       
   322 	/*
       
   323 	 if(g_egl)
       
   324 	 {
       
   325 	 if(!g_egl->removeReference())
       
   326 	 {
       
   327 	 RI_DELETE(g_egl);
       
   328 	 g_egl = NULL;
       
   329 	 }
       
   330 	 }
       
   331 	 */
       
   332 	EGL* pEgl = static_cast<EGL*> (Dll::Tls());
       
   333 	if (pEgl)
   449 	if (pEgl)
   334 		delete pEgl;
   450 		delete pEgl; 
   335 	Dll::SetTls(NULL);
   451 	Dll::SetTls(NULL);
   336 
   452 
   337 	}
   453 }
   338 
   454 
   339 /*-------------------------------------------------------------------*//*!
   455 /*-------------------------------------------------------------------*//*!
   340  * \brief	Given a display ID, return the corresponding object, or NULL
   456 * \brief	Given a display ID, return the corresponding object, or NULL
   341  *			if the ID hasn't been initialized.
   457 *			if the ID hasn't been initialized.
   342  * \param	
   458 * \param	
   343  * \return	
   459 * \return	
   344  * \note		if egl has been initialized for this display, the display ID can
   460 * \note		if egl has been initialized for this display, the display ID can
   345  *			be found from egl->m_displays
   461 *			be found from egl->m_displays
   346  *//*-------------------------------------------------------------------*/
   462 *//*-------------------------------------------------------------------*/
   347 
   463 
   348 RIEGLDisplay* EGL::getDisplay(EGLDisplay displayID) const
   464 RIEGLDisplay* EGL::getDisplay(EGLDisplay displayID) const
   349 	{
   465 {
   350 	for (int i = 0; i < m_displays.size(); i++)
   466 	for(int i=0;i<m_displays.size();i++)
   351 		{
   467 	{
   352 		if (displayID == m_displays[i]->getID())
   468 		if(displayID == m_displays[i]->getID())
   353 			return m_displays[i];
   469 			return m_displays[i];
   354 		}
   470 	}
   355 	return NULL; //error: the display hasn't been eglInitialized
   471 	return NULL;		//error: the display hasn't been eglInitialized
   356 	}
   472 }
   357 
   473 
   358 /*-------------------------------------------------------------------*//*!
   474 /*-------------------------------------------------------------------*//*!
   359  * \brief	return EGLDisplay for the current context
   475 * \brief	return EGLDisplay for the current context
   360  * \param	
   476 * \param	
   361  * \return	
   477 * \return	
   362  * \note		
   478 * \note		
   363  *//*-------------------------------------------------------------------*/
   479 *//*-------------------------------------------------------------------*/
   364 
   480 
   365 EGLDisplay EGL::findDisplay(EGLContext ctx) const
   481 EGLDisplay EGL::findDisplay(EGLContext ctx) const
   366 	{
   482 {
   367 	for (int i = 0; i < m_displays.size(); i++)
   483 	for(int i=0;i<m_displays.size();i++)
   368 		{
   484 	{
   369 		if (m_displays[i]->contextExists(ctx))
   485         if(m_displays[i]->contextExists(ctx))
   370 			return m_displays[i]->getID();
   486             return m_displays[i]->getID();
   371 		}
   487 	}
   372 	return EGL_NO_DISPLAY;
   488     return EGL_NO_DISPLAY;
   373 	}
   489 }
   374 
   490 
   375 /*-------------------------------------------------------------------*//*!
   491 /*-------------------------------------------------------------------*//*!
   376  * \brief	return an EGL thread struct for the thread made current, or
   492 * \brief	return an EGL thread struct for the thread made current, or
   377  *            NULL if there's no current context.
   493 *            NULL if there's no current context.
   378  * \param	
   494 * \param	
   379  * \return	
   495 * \return	
   380  * \note		
   496 * \note		
   381  *//*-------------------------------------------------------------------*/
   497 *//*-------------------------------------------------------------------*/
   382 
   498 
   383 RIEGLThread* EGL::getCurrentThread() const
   499 RIEGLThread* EGL::getCurrentThread() const
   384 	{
   500 {
   385 	void* currentThreadID = OSGetCurrentThreadID();
   501 	void* currentThreadID = OSGetCurrentThreadID();
   386 	for (int i = 0; i < m_currentThreads.size(); i++)
   502 	for(int i=0;i<m_currentThreads.size();i++)
   387 		{
   503 	{
   388 		if (currentThreadID == m_currentThreads[i]->getThreadID())
   504 		if(currentThreadID == m_currentThreads[i]->getThreadID())
   389 			return m_currentThreads[i];
   505 			return m_currentThreads[i];
   390 		}
   506 	}
   391 	return NULL; //thread is not current
   507 	return NULL;		//thread is not current
   392 	}
   508 }
   393 
   509 
   394 /*-------------------------------------------------------------------*//*!
   510 /*-------------------------------------------------------------------*//*!
   395  * \brief	return an EGL thread struct corresponding to current OS thread.
   511 * \brief	return an EGL thread struct corresponding to current OS thread.
   396  * \param	
   512 * \param	
   397  * \return	
   513 * \return	
   398  * \note		
   514 * \note		
   399  *//*-------------------------------------------------------------------*/
   515 *//*-------------------------------------------------------------------*/
   400 
   516 
   401 RIEGLThread* EGL::getThread()
   517 RIEGLThread* EGL::getThread()
   402 	{
   518 {
   403 	void* currentThreadID = OSGetCurrentThreadID();
   519 	void* currentThreadID = OSGetCurrentThreadID();
   404 	for (int i = 0; i < m_threads.size(); i++)
   520 	for(int i=0;i<m_threads.size();i++)
   405 		{
   521 	{
   406 		if (currentThreadID == m_threads[i]->getThreadID())
   522 		if(currentThreadID == m_threads[i]->getThreadID())
   407 			return m_threads[i];
   523 			return m_threads[i];
   408 		}
   524 	}
   409 
   525 
   410 	//EGL doesn't have a struct for the thread yet, add it to EGL's list
   526 	//EGL doesn't have a struct for the thread yet, add it to EGL's list
   411 	RIEGLThread* newThread = NULL;
   527 	RIEGLThread* newThread = NULL;
   412 	try
   528 	try
   413 		{
   529 	{
   414 		newThread = RI_NEW(RIEGLThread, (OSGetCurrentThreadID())); //throws bad_alloc
   530 		newThread = RI_NEW(RIEGLThread, (OSGetCurrentThreadID()));	//throws bad_alloc
   415 		m_threads.push_back(newThread); //throws bad_alloc
   531 		m_threads.push_back(newThread);	//throws bad_alloc
   416 		return newThread;
   532 		return newThread;
   417 		}
   533 	}
   418 	catch (std::bad_alloc)
   534 	catch(std::bad_alloc)
   419 		{
   535 	{
   420 		RI_DELETE(newThread);
   536 		RI_DELETE(newThread);
   421 		return NULL;
   537 		return NULL;
   422 		}
   538 	}
   423 	}
   539 }
   424 
   540 
   425 /*-------------------------------------------------------------------*//*!
   541 /*-------------------------------------------------------------------*//*!
   426  * \brief	destroy an EGL thread struct
   542 * \brief	destroy an EGL thread struct
   427  * \param	
   543 * \param	
   428  * \return	
   544 * \return	
   429  * \note		
   545 * \note		
   430  *//*-------------------------------------------------------------------*/
   546 *//*-------------------------------------------------------------------*/
   431 
   547 
   432 void EGL::destroyThread()
   548 void EGL::destroyThread()
   433 	{
   549 {
   434 	void* currentThreadID = OSGetCurrentThreadID();
   550 	void* currentThreadID = OSGetCurrentThreadID();
   435 	for (int i = 0; i < m_threads.size(); i++)
   551 	for(int i=0;i<m_threads.size();i++)
   436 		{
   552 	{
   437 		if (currentThreadID == m_threads[i]->getThreadID())
   553 		if(currentThreadID == m_threads[i]->getThreadID())
   438 			{
   554         {
   439 			RIEGLThread* thread = m_threads[i];
   555             RIEGLThread* thread = m_threads[i];
   440 			bool res = m_threads.remove(thread);
   556             bool res = m_threads.remove(thread);
   441 			RI_ASSERT(res);
   557             RI_ASSERT(res);
   442 			RI_UNREF(res);
   558             RI_UNREF(res);
   443 			RI_DELETE(thread);
   559             RI_DELETE(thread);
   444 			break;
   560             break;
   445 			}
   561         }
   446 		}
   562 	}
   447 	}
   563 }
   448 
   564 
   449 /*-------------------------------------------------------------------*//*!
   565 /*-------------------------------------------------------------------*//*!
   450  * \brief	
   566 * \brief	
   451  * \param	
   567 * \param	
   452  * \return	
   568 * \return	
   453  * \note		
   569 * \note		
   454  *//*-------------------------------------------------------------------*/
   570 *//*-------------------------------------------------------------------*/
   455 
   571 
   456 bool EGL::isInUse(const void* image) const
   572 bool EGL::isInUse(const void* image) const
   457 	{
   573 {
   458 	for (int i = 0; i < m_currentThreads.size(); i++)
   574     for(int i=0;i<m_currentThreads.size();i++)
   459 		{
   575     {
   460 		RIEGLSurface* s = m_currentThreads[i]->getCurrentSurface();
   576         RIEGLSurface* s = m_currentThreads[i]->getCurrentSurface();
   461 		if (s && s->getDrawable() && s->getDrawable()->isInUse((Image*) image))
   577         if(s && s->getDrawable() && s->getDrawable()->isInUse((Image*)image))
   462 			return true;
   578             return true;
   463 		}
   579     }
   464 	return false;
   580     return false;
       
   581 }
       
   582 
       
   583 /*-------------------------------------------------------------------*//*!
       
   584 * \brief	
       
   585 * \param	
       
   586 * \return	
       
   587 * \note		
       
   588 *//*-------------------------------------------------------------------*/
       
   589 
       
   590 #define EGL_GET_DISPLAY(DISPLAY, RETVAL) \
       
   591 	OSAcquireMutex(); \
       
   592 	EGL* egl = getEGL(); \
       
   593     if(!egl) \
       
   594     { \
       
   595 		OSReleaseMutex(); \
       
   596 		return RETVAL; \
       
   597     } \
       
   598 	RIEGLDisplay* display = egl->getDisplay(DISPLAY); \
       
   599 
       
   600 #define EGL_GET_EGL(RETVAL) \
       
   601 	OSAcquireMutex(); \
       
   602 	EGL* egl = getEGL(); \
       
   603     if(!egl) \
       
   604     { \
       
   605 		OSReleaseMutex(); \
       
   606 		return RETVAL; \
       
   607     } \
       
   608 
       
   609 #define EGL_IF_ERROR(COND, ERRORCODE, RETVAL) \
       
   610 	if(COND) { eglSetError(egl, ERRORCODE); OSReleaseMutex(); return RETVAL; } \
       
   611 
       
   612 #define EGL_RETURN(ERRORCODE, RETVAL) \
       
   613 	{ \
       
   614 		eglSetError(egl, ERRORCODE); \
       
   615 		OSReleaseMutex(); \
       
   616 		return RETVAL; \
   465 	}
   617 	}
   466 
   618 
   467 // Note: egl error handling model differs from OpenVG. The latest error is stored instead of the oldest one.
   619 // Note: egl error handling model differs from OpenVG. The latest error is stored instead of the oldest one.
   468 static void eglSetError(EGL* egl, EGLint error)
   620 static void eglSetError(EGL* egl, EGLint error)
   469 	{
   621 {
   470 	RIEGLThread* thread = egl->getThread();
   622 	RIEGLThread* thread = egl->getThread();
   471 	if (thread)
   623 	if(thread)
   472 		thread->setError(error);
   624 		thread->setError(error);
   473 	}
   625 }
   474 
   626 
   475 /*-------------------------------------------------------------------*//*!
   627 /*-------------------------------------------------------------------*//*!
   476  * \brief	Returns the OpenVG context current to the calling thread.
   628 * \brief	Returns the OpenVG context current to the calling thread.
   477  * \param	
   629 * \param	
   478  * \return	
   630 * \return	
   479  * \note		This function is always called from a mutexed API function
   631 * \note		This function is always called from a mutexed API function
   480  *//*-------------------------------------------------------------------*/
   632 *//*-------------------------------------------------------------------*/
   481 
   633 
   482 void* eglvgGetCurrentVGContext(void)
   634 void* eglvgGetCurrentVGContext(void)
   483 	{
   635 {
   484 	EGL* egl = getEGL();
   636 	EGL* egl = getEGL();
   485 /*	RDebug::Printf(" \n");
   637     if(egl)
   486 	RDebug::Printf(" \n");
   638     {
   487 	RDebug::Printf(" \n");
   639         RIEGLThread* thread = egl->getCurrentThread();
   488 	
   640         if(thread)
   489 	
   641         {
   490 	RDebug::Printf(" $$$$$$$$$$$$$ I am in function eglvgGetCurrentVGContext $$$$$$$$$$$$$$$$$\n");
   642             RI_ASSERT(thread->getCurrentContext() && thread->getCurrentSurface());
   491 	RDebug::Printf(" $$$$$$$$$$$$$ In eglvgGetCurrentVGContext,Thread Id %Lu  $$$$$$$$$$$$$ ",(RThread().Id()));*/
   643             return thread->getCurrentContext()->getVGContext();
   492 	
   644         }
   493 			
   645     }
   494 	if (egl)
   646 	return NULL;	//not initialized or made current
   495 		{
   647 }
   496 		RIEGLThread* thread = egl->getCurrentThread();
   648 
   497 		//RDebug::Printf(" $$$$$$$$$$$$$ I am in function eglvgGetCurrentVGContext.EGL addr is %x = \n",egl);
   649 /*-------------------------------------------------------------------*//*!
   498 		if (thread)
   650 * \brief	Check if the image is current in any of the displays
   499 			{
   651 * \param	
   500 			RI_ASSERT(thread->getCurrentContext() && thread->getCurrentSurface());
   652 * \return	
   501 			return thread->getCurrentContext()->getVGContext();
   653 * \note		This function is always called from a mutexed API function
   502 			}
   654 *//*-------------------------------------------------------------------*/
   503 		}
       
   504 	return NULL; //not initialized or made current
       
   505 	}
       
   506 
       
   507 /*-------------------------------------------------------------------*//*!
       
   508  * \brief	Check if the image is current in any of the displays
       
   509  * \param	
       
   510  * \return	
       
   511  * \note		This function is always called from a mutexed API function
       
   512  *//*-------------------------------------------------------------------*/
       
   513 
   655 
   514 bool eglvgIsInUse(void* image)
   656 bool eglvgIsInUse(void* image)
   515 	{
   657 {
   516 	EGL* egl = getEGL();
   658 	EGL* egl = getEGL();
   517 	if (egl)
   659     if(egl)
   518 		{
   660     {
   519 		return egl->isInUse(image);
   661         return egl->isInUse(image);
   520 		}
   662     }
   521 	return false;
   663 	return false;
   522 	}
   664 }
   523 
   665 
   524  //helper functions
   666 //helper functions
   525  RIEGLContext* CastToRIEGLContext(EGLContext aCtxId)
   667 RIEGLContext* CastToRIEGLContext(EGLContext aCtxId)
   526  {
   668   {
   527  return (RIEGLContext*)(aCtxId);
   669   return (RIEGLContext*)(aCtxId);
   528  }
   670   }
   529  EGLContext CastFromRIEGLContext(RIEGLContext* aCtx)
   671 EGLContext CastFromRIEGLContext(RIEGLContext* aCtx)
   530  {
   672   {
   531  return (EGLContext)(aCtx);
   673   return (EGLContext)(aCtx);
   532  }
   674   }
   533 
   675 
   534  RIEGLSurface* CastToRIEGLSurface(EGLSurface aSurfaceId)
   676 RIEGLSurface* CastToRIEGLSurface(EGLSurface aSurfaceId)
   535  {
   677   {
   536  return (RIEGLSurface*)(aSurfaceId);
   678   return (RIEGLSurface*)(aSurfaceId);
   537  }
   679   }
   538  EGLSurface CastFromRIEGLSurface(RIEGLSurface* aSurface)
   680 EGLSurface CastFromRIEGLSurface(RIEGLSurface* aSurface)
   539  {
   681   {
   540  return (EGLSurface)(aSurface);
   682   return (EGLSurface)(aSurface);
   541  }
   683   }
   542 
   684 
   543  Image* CastToImage(EGLClientBuffer aBufferId)
   685 Image* CastToImage(EGLClientBuffer aBufferId)
   544  {
   686   {
   545  return (Image*)(aBufferId);
   687   return (Image*)(aBufferId);
   546  }
   688   }
   547 
   689 
   548  EGLClientBuffer CastFromImage(Image* aBUffer)
   690 EGLClientBuffer CastFromImage(Image* aBUffer)
   549  {
   691   {
   550  return (EGLClientBuffer)(aBUffer);
   692   return (EGLClientBuffer)(aBUffer);
   551  }
   693   }
   552 }// namespace OpenVGRI
       
   553 
   694 
   554 //==============================================================================================
   695 //==============================================================================================
   555 
   696 
       
   697 }	//namespace OpenVGRI
       
   698 
   556 using namespace OpenVGRI;
   699 using namespace OpenVGRI;
   557 /*-------------------------------------------------------------------*//*!
   700 
   558  * \brief	
   701 
   559  * \param	
   702 
   560  * \return	
   703 
   561  * \note		
   704 
   562  *//*-------------------------------------------------------------------*/
   705 /*-------------------------------------------------------------------*//*!
       
   706 * \brief	
       
   707 * \param	
       
   708 * \return	
       
   709 * \note		
       
   710 *//*-------------------------------------------------------------------*/
   563 
   711 
   564 #ifdef BUILD_WITH_PRIVATE_EGL
   712 #ifdef BUILD_WITH_PRIVATE_EGL
   565 RI_APIENTRY EGLint do_eglGetError()
   713 RI_APIENTRY EGLint do_eglGetError()
   566 #else
   714 #else
   567 EGLint eglGetError()
   715 EGLint eglGetError()
   568 #endif
   716 #endif
   569 	{
   717 {
   570 	OSAcquireMutex();
   718     OSAcquireMutex();
   571 	EGLint ret = EGL_SUCCESS;
   719     EGLint ret = EGL_SUCCESS;
   572 	EGL* egl = getEGL();
   720 	EGL* egl = getEGL();
   573 	if (egl)
   721     if(egl)
   574 		{
   722     {
   575 		RIEGLThread* thread = egl->getThread();
   723         RIEGLThread* thread = egl->getThread();
   576 		if (thread)
   724         if(thread)
   577 			ret = thread->getError(); //initialized, return error code
   725             ret = thread->getError();	//initialized, return error code
   578 		}
   726     }
   579 	else
   727     else ret = EGL_NOT_INITIALIZED;
   580 		ret = EGL_NOT_INITIALIZED;
   728     OSReleaseMutex();
   581 	OSReleaseMutex();
   729     return ret;
   582 	return ret;
   730 }
   583 	}
   731 
   584 
   732 /*-------------------------------------------------------------------*//*!
   585 /*-------------------------------------------------------------------*//*!
   733 * \brief	
   586  * \brief	
   734 * \param	
   587  * \param	
   735 * \return	
   588  * \return	
   736 * \note		
   589  * \note		
   737 *//*-------------------------------------------------------------------*/
   590  *//*-------------------------------------------------------------------*/
       
   591 
   738 
   592 #ifdef BUILD_WITH_PRIVATE_EGL
   739 #ifdef BUILD_WITH_PRIVATE_EGL
   593 RI_APIENTRY EGLDisplay do_eglGetDisplay(EGLNativeDisplayType display_id)
   740 RI_APIENTRY EGLDisplay do_eglGetDisplay(EGLNativeDisplayType display_id)
   594 #else
   741 #else
   595 EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id)
   742 EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id)
   596 #endif
   743 #endif
   597 	{
   744 {
   598 	return OSGetDisplay(display_id);
   745     return OSGetDisplay(display_id);
   599 	}
   746 }
   600 
   747 
   601 /*-------------------------------------------------------------------*//*!
   748 /*-------------------------------------------------------------------*//*!
   602  * \brief	
   749 * \brief	
   603  * \param	
   750 * \param	
   604  * \return	
   751 * \return	
   605  * \note		
   752 * \note		
   606  *//*-------------------------------------------------------------------*/
   753 *//*-------------------------------------------------------------------*/
   607 
   754 
   608 #ifdef BUILD_WITH_PRIVATE_EGL
   755 #ifdef BUILD_WITH_PRIVATE_EGL
   609 RI_APIENTRY EGLBoolean do_eglInitialize(EGLDisplay dpy, EGLint *major,
   756 RI_APIENTRY EGLBoolean do_eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
   610 		EGLint *minor)
       
   611 #else
   757 #else
   612 EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
   758 EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
   613 #endif
   759 #endif
   614 	{
   760 {
   615 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
   761 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
   616 	EGL_IF_ERROR(display, EGL_SUCCESS, EGL_TRUE); //already initialized
   762 	EGL_IF_ERROR(display, EGL_SUCCESS, EGL_TRUE);	//already initialized
   617 
   763 
   618 	//create the current display
   764 	//create the current display
   619 	//if a context and a surface are bound by the time of eglTerminate, they remain bound until eglMakeCurrent is called
   765 	//if a context and a surface are bound by the time of eglTerminate, they remain bound until eglMakeCurrent is called
   620 	RIEGLDisplay* newDisplay = NULL;
   766 	RIEGLDisplay* newDisplay = NULL;
   621 	try
   767 	try
   622 		{
   768 	{
   623 		newDisplay = RI_NEW(RIEGLDisplay, (dpy)); //throws bad_alloc
   769 		newDisplay = RI_NEW(RIEGLDisplay, (dpy));	//throws bad_alloc
   624 		egl->addDisplay(newDisplay); //throws bad_alloc
   770 		egl->addDisplay(newDisplay);	//throws bad_alloc
   625 		display = newDisplay;
   771 		display = newDisplay;
   626 		RI_ASSERT(display);
   772 		RI_ASSERT(display);
   627 		}
   773 	}
   628 	catch (std::bad_alloc)
   774 	catch(std::bad_alloc)
   629 		{
   775 	{
   630 		RI_DELETE(newDisplay);
   776 		RI_DELETE(newDisplay);
   631 		EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
   777 		EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
   632 		}
   778 	}
   633 
   779 
   634 	if (major)
   780 	if(major) *major = 1;
   635 		*major = 1;
   781 	if(minor) *minor = 2;
   636 	if (minor)
       
   637 		*minor = 2;
       
   638 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   782 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   639 	}
   783 }
   640 
   784 
   641 /*-------------------------------------------------------------------*//*!
   785 /*-------------------------------------------------------------------*//*!
   642  * \brief	
   786 * \brief	
   643  * \param	
   787 * \param	
   644  * \return	
   788 * \return	
   645  * \note		
   789 * \note		
   646  *//*-------------------------------------------------------------------*/
   790 *//*-------------------------------------------------------------------*/
   647 
   791 
   648 #ifdef BUILD_WITH_PRIVATE_EGL
   792 #ifdef BUILD_WITH_PRIVATE_EGL
   649 RI_APIENTRY EGLBoolean do_eglTerminate(EGLDisplay dpy)
   793 RI_APIENTRY EGLBoolean do_eglTerminate(EGLDisplay dpy)
   650 #else
   794 #else
   651 EGLBoolean eglTerminate(EGLDisplay dpy)
   795 EGLBoolean eglTerminate(EGLDisplay dpy)
   652 #endif
   796 #endif
   653 	{
   797 {
   654 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
   798 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
   655 	EGL_IF_ERROR(!display, EGL_SUCCESS, EGL_TRUE);
   799 	EGL_IF_ERROR(!display, EGL_SUCCESS, EGL_TRUE);
   656 	egl->removeDisplay(display);
   800     egl->removeDisplay(display);
   657 	RI_DELETE(display);
   801     RI_DELETE(display);
   658 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   802 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   659 	}
   803 }
   660 
   804 
   661 /*-------------------------------------------------------------------*//*!
   805 /*-------------------------------------------------------------------*//*!
   662  * \brief	
   806 * \brief	
   663  * \param	
   807 * \param	
   664  * \return	
   808 * \return	
   665  * \note		
   809 * \note		
   666  *//*-------------------------------------------------------------------*/
   810 *//*-------------------------------------------------------------------*/
   667 
   811 
   668 #ifdef BUILD_WITH_PRIVATE_EGL
   812 #ifdef BUILD_WITH_PRIVATE_EGL
   669 RI_APIENTRY const char *do_eglQueryString(EGLDisplay dpy, EGLint name)
   813 RI_APIENTRY const char *do_eglQueryString(EGLDisplay dpy, EGLint name)
   670 #else
   814 #else
   671 const char *eglQueryString(EGLDisplay dpy, EGLint name)
   815 const char *eglQueryString(EGLDisplay dpy, EGLint name)
   672 #endif
   816 #endif
   673 { EGL_GET_DISPLAY(dpy, NULL);
   817 {
   674 EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, NULL);
   818 	EGL_GET_DISPLAY(dpy, NULL);
   675 
   819 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, NULL);
   676 static const char apis[] = "OpenVG";
   820 
   677 static const char extensions[] = "";
   821 	static const char apis[] = "OpenVG";
   678 static const char vendor[] = "Khronos Group";
   822 	static const char extensions[] = "";
   679 static const char version[] = "1.3";
   823 	static const char vendor[] = "Khronos Group";
   680 
   824 	static const char version[] = "1.3";
   681 const char* ret = NULL;
   825 
   682 switch(name)
   826 	const char* ret = NULL;
       
   827 	switch(name)
   683 	{
   828 	{
   684 	case EGL_CLIENT_APIS:
   829 	case EGL_CLIENT_APIS:
   685 	ret = apis;
   830 		ret = apis;
   686 	break;
   831 		break;
   687 
   832 
   688 	case EGL_EXTENSIONS:
   833 	case EGL_EXTENSIONS:
   689 	ret = extensions;
   834 		ret = extensions;
   690 	break;
   835 		break;
   691 
   836 
   692 	case EGL_VENDOR:
   837 	case EGL_VENDOR:
   693 	ret = vendor;
   838 		ret = vendor;
   694 	break;
   839 		break;
   695 
   840 
   696 	case EGL_VERSION:
   841 	case EGL_VERSION:
   697 	ret = version;
   842 		ret = version;
   698 	break;
   843 		break;
   699 
   844 
   700 	default:
   845 	default:
   701 	EGL_RETURN(EGL_BAD_PARAMETER, NULL);
   846 		EGL_RETURN(EGL_BAD_PARAMETER, NULL);
   702 	}
   847 	}
   703 EGL_RETURN(EGL_SUCCESS, ret);
   848 	EGL_RETURN(EGL_SUCCESS, ret);
   704 }
   849 }
   705 
   850 
   706 /*-------------------------------------------------------------------*//*!
   851 /*-------------------------------------------------------------------*//*!
   707  * \brief	
   852 * \brief	
   708  * \param	
   853 * \param	
   709  * \return	
   854 * \return	
   710  * \note		
   855 * \note		
   711  *//*-------------------------------------------------------------------*/
   856 *//*-------------------------------------------------------------------*/
   712 
   857 
   713 #ifdef BUILD_WITH_PRIVATE_EGL
   858 #ifdef BUILD_WITH_PRIVATE_EGL
   714 RI_APIENTRY EGLBoolean do_eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
   859 RI_APIENTRY EGLBoolean do_eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
   715 		EGLint config_size, EGLint *num_config)
       
   716 #else
   860 #else
   717 EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
   861 EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
   718 #endif
   862 #endif
   719 	{
   863 {
   720 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
   864 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
   721 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
   865 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
   722 	EGL_IF_ERROR(!num_config, EGL_BAD_PARAMETER, EGL_FALSE);
   866 	EGL_IF_ERROR(!num_config, EGL_BAD_PARAMETER, EGL_FALSE);
   723 	if (!configs)
   867 	if(!configs)
   724 		{
   868 	{
   725 		*num_config = display->getNumConfigs();
   869 		*num_config = display->getNumConfigs();
   726 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   870 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   727 		}
   871 	}
   728 	*num_config = RI_INT_MIN(config_size, display->getNumConfigs());
   872 	*num_config = RI_INT_MIN(config_size, display->getNumConfigs());
   729 	for (int i = 0; i < *num_config; i++)
   873 	for(int i=0;i<*num_config;i++)
   730 		configs[i] = display->getConfigByIdx(i).m_config;
   874 		configs[i] = display->getConfigByIdx(i).m_config;
   731 
   875 
   732 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   876 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   733 	}
   877 }
   734 
   878 
   735 /*-------------------------------------------------------------------*//*!
   879 /*-------------------------------------------------------------------*//*!
   736  * \brief	
   880 * \brief	
   737  * \param	
   881 * \param	
   738  * \return	
   882 * \return	
   739  * \note		
   883 * \note		
   740  *//*-------------------------------------------------------------------*/
   884 *//*-------------------------------------------------------------------*/
   741 
   885 
   742 static bool smaller(EGLint c, EGLint filter)
   886 static bool smaller(EGLint c, EGLint filter)
   743 	{
   887 {
   744 	return (filter != EGL_DONT_CARE) && (c < filter);
   888 	return (filter != EGL_DONT_CARE) && (c < filter);
   745 	}
   889 }
   746 
   890 
   747 #ifdef BUILD_WITH_PRIVATE_EGL
   891 #ifdef BUILD_WITH_PRIVATE_EGL
   748 RI_APIENTRY EGLBoolean do_eglChooseConfig(EGLDisplay dpy,
   892 RI_APIENTRY EGLBoolean do_eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
   749 		const EGLint *attrib_list, EGLConfig *configs, EGLint config_size,
       
   750 		EGLint *num_config)
       
   751 #else
   893 #else
   752 EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
   894 EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
   753 #endif
   895 #endif
   754 	{
   896 {
   755 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
   897 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
   756 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
   898 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
   757 	EGL_IF_ERROR(!num_config, EGL_BAD_PARAMETER, EGL_FALSE);
   899 	EGL_IF_ERROR(!num_config, EGL_BAD_PARAMETER, EGL_FALSE);
   758 
   900 
   759 	if (!configs)
   901 	if(!configs)
   760 		{
   902 	{
   761 		*num_config = display->getNumConfigs();
   903 		*num_config = display->getNumConfigs();
   762 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   904 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   763 		}
   905 	}
   764 	*num_config = 0;
   906 	*num_config = 0;
   765 	if (!config_size)
   907 	if(!config_size)
   766 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   908 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   767 
   909 
   768 	int bufferSize = 0;
   910 	int bufferSize = 0;
   769 	int redSize = 0;
   911 	int redSize = 0;
   770 	int greenSize = 0;
   912 	int greenSize = 0;
   773 	int alphaSize = 0;
   915 	int alphaSize = 0;
   774 	int colorBufferType = EGL_RGB_BUFFER;
   916 	int colorBufferType = EGL_RGB_BUFFER;
   775 	int configID = EGL_DONT_CARE;
   917 	int configID = EGL_DONT_CARE;
   776 	int sampleBuffers = 0;
   918 	int sampleBuffers = 0;
   777 	int samples = 0;
   919 	int samples = 0;
   778 	if (attrib_list)
   920 	if(attrib_list)
       
   921 	{
       
   922 		for(int i=0;attrib_list[i] != EGL_NONE;i+=2)
   779 		{
   923 		{
   780 		for (int i = 0; attrib_list[i] != EGL_NONE; i += 2)
   924 			switch(attrib_list[i])
   781 			{
   925 			{
   782 			switch (attrib_list[i])
   926 			case EGL_BUFFER_SIZE:				//depth of the color buffer
   783 				{
   927 				bufferSize = attrib_list[i+1];
   784 				case EGL_BUFFER_SIZE: //depth of the color buffer
   928 				break;
   785 					bufferSize = attrib_list[i + 1];
   929 			case EGL_RED_SIZE:					//bits of Red in the color buffer
   786 					break;
   930 				redSize = attrib_list[i+1];
   787 				case EGL_RED_SIZE: //bits of Red in the color buffer
   931 				break;
   788 					redSize = attrib_list[i + 1];
   932 			case EGL_GREEN_SIZE:				//bits of Green in the color buffer
   789 					break;
   933 				greenSize = attrib_list[i+1];
   790 				case EGL_GREEN_SIZE: //bits of Green in the color buffer
   934 				break;
   791 					greenSize = attrib_list[i + 1];
   935 			case EGL_BLUE_SIZE:					//bits of Blue in the color buffer
   792 					break;
   936 				blueSize = attrib_list[i+1];
   793 				case EGL_BLUE_SIZE: //bits of Blue in the color buffer
   937 				break;
   794 					blueSize = attrib_list[i + 1];
   938 			case EGL_LUMINANCE_SIZE:			//bits of Luminance in the color buffer
   795 					break;
   939 				luminanceSize = attrib_list[i+1];
   796 				case EGL_LUMINANCE_SIZE: //bits of Luminance in the color buffer
   940 				break;
   797 					luminanceSize = attrib_list[i + 1];
   941 			case EGL_ALPHA_SIZE:				//bits of Alpha in the color buffer
   798 					break;
   942 				alphaSize = attrib_list[i+1];
   799 				case EGL_ALPHA_SIZE: //bits of Alpha in the color buffer
   943 				break;
   800 					alphaSize = attrib_list[i + 1];
   944 			case EGL_ALPHA_MASK_SIZE:			//bits of Alpha in the alpha mask buffer
   801 					break;
   945 				if(attrib_list[i+1] > 8)
   802 				case EGL_ALPHA_MASK_SIZE: //bits of Alpha in the alpha mask buffer
   946 					EGL_RETURN(EGL_SUCCESS, EGL_TRUE);	//not supported
   803 					if (attrib_list[i + 1] > 8)
   947 				break;
   804 						EGL_RETURN(EGL_SUCCESS, EGL_TRUE)
   948 			case EGL_COLOR_BUFFER_TYPE:			//enum color buffer type (EGL_RGB_BUFFER, EGL_LUMINANCE_BUFFER)
   805 					; //not supported
   949 				EGL_IF_ERROR(attrib_list[i+1] != EGL_RGB_BUFFER && attrib_list[i+1] != EGL_LUMINANCE_BUFFER && attrib_list[i+1] != EGL_DONT_CARE, EGL_BAD_ATTRIBUTE, EGL_FALSE);
   806 					break;
   950 				colorBufferType = attrib_list[i+1];
   807 				case EGL_COLOR_BUFFER_TYPE: //enum color buffer type (EGL_RGB_BUFFER, EGL_LUMINANCE_BUFFER)
   951 				break;
   808 					EGL_IF_ERROR(attrib_list[i+1] != EGL_RGB_BUFFER && attrib_list[i+1] != EGL_LUMINANCE_BUFFER && attrib_list[i+1] != EGL_DONT_CARE, EGL_BAD_ATTRIBUTE, EGL_FALSE)
   952 			case EGL_CONFIG_ID:					//unique EGLConfig identifier
   809 					;
   953 				configID = attrib_list[i+1];
   810 					colorBufferType = attrib_list[i + 1];
   954 				break;
   811 					break;
   955 
   812 				case EGL_CONFIG_ID: //unique EGLConfig identifier
   956 			case EGL_SAMPLE_BUFFERS:			//integer number of multisample buffers
   813 					configID = attrib_list[i + 1];
   957 				sampleBuffers = attrib_list[i+1];
   814 					break;
   958 				break;
   815 
   959 			case EGL_SAMPLES:					//integer number of samples per pixel
   816 				case EGL_SAMPLE_BUFFERS: //integer number of multisample buffers
   960 				samples = attrib_list[i+1];
   817 					sampleBuffers = attrib_list[i + 1];
   961 				break;
   818 					break;
   962 
   819 				case EGL_SAMPLES: //integer number of samples per pixel
   963 			case EGL_BIND_TO_TEXTURE_RGB:		//boolean True if bindable to RGB textures. (always EGL_FALSE)
   820 					samples = attrib_list[i + 1];
   964 			case EGL_BIND_TO_TEXTURE_RGBA:		//boolean True if bindable to RGBA textures. (always EGL_FALSE)
   821 					break;
   965 			case EGL_DEPTH_SIZE:				//integer bits of Z in the depth buffer (always 0)
   822 
   966 			case EGL_LEVEL:						//integer frame buffer level (always 0)
   823 				case EGL_BIND_TO_TEXTURE_RGB: //boolean True if bindable to RGB textures. (always EGL_FALSE)
   967 			case EGL_NATIVE_RENDERABLE:			//boolean EGL TRUE if native rendering APIs can render to surface (always EGL_FALSE)
   824 				case EGL_BIND_TO_TEXTURE_RGBA: //boolean True if bindable to RGBA textures. (always EGL_FALSE)
   968 			case EGL_STENCIL_SIZE:				//integer bits of Stencil in the stencil buffer (always 0)
   825 				case EGL_DEPTH_SIZE: //integer bits of Z in the depth buffer (always 0)
   969 				if(attrib_list[i+1])
   826 				case EGL_LEVEL: //integer frame buffer level (always 0)
   970 					EGL_RETURN(EGL_SUCCESS, EGL_TRUE);	//not supported
   827 				case EGL_NATIVE_RENDERABLE: //boolean EGL TRUE if native rendering APIs can render to surface (always EGL_FALSE)
   971 				break;
   828 				case EGL_STENCIL_SIZE: //integer bits of Stencil in the stencil buffer (always 0)
   972 
   829 					if (attrib_list[i + 1])
   973 			case EGL_CONFIG_CAVEAT:				//enum any caveats for the configuration (always EGL_NONE)
   830 						EGL_RETURN(EGL_SUCCESS, EGL_TRUE)
   974 			case EGL_NATIVE_VISUAL_TYPE:		//integer native visual type of the associated visual (always EGL_NONE)
   831 					; //not supported
   975 				if(attrib_list[i+1] != EGL_NONE)
   832 					break;
   976 					EGL_RETURN(EGL_SUCCESS, EGL_TRUE);	//not supported
   833 
   977 				break;
   834 				case EGL_CONFIG_CAVEAT: //enum any caveats for the configuration (always EGL_NONE)
   978 
   835 				case EGL_NATIVE_VISUAL_TYPE: //integer native visual type of the associated visual (always EGL_NONE)
   979 			case EGL_MAX_SWAP_INTERVAL:			//integer maximum swap interval (always 1)
   836 					if (attrib_list[i + 1] != EGL_NONE)
   980 			case EGL_MIN_SWAP_INTERVAL:			//integer minimum swap interval (always 1)
   837 						EGL_RETURN(EGL_SUCCESS, EGL_TRUE)
   981 				if(attrib_list[i+1] != 1)
   838 					; //not supported
   982 					EGL_RETURN(EGL_SUCCESS, EGL_TRUE);	//not supported
   839 					break;
   983 				break;
   840 
   984 
   841 				case EGL_MAX_SWAP_INTERVAL: //integer maximum swap interval (always 1)
   985 			case EGL_RENDERABLE_TYPE:			//bitmask which client rendering APIs are supported. (always EGL_OPENVG_BIT)
   842 				case EGL_MIN_SWAP_INTERVAL: //integer minimum swap interval (always 1)
   986 				if(!(attrib_list[i+1] & EGL_OPENVG_BIT))
   843 					if (attrib_list[i + 1] != 1)
   987 					EGL_RETURN(EGL_SUCCESS, EGL_TRUE);	//not supported
   844 						EGL_RETURN(EGL_SUCCESS, EGL_TRUE)
   988 				break;
   845 					; //not supported
   989 
   846 					break;
   990 			case EGL_SURFACE_TYPE:				//bitmask which types of EGL surfaces are supported. (always EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | EGL_VG_COLORSPACE_LINEAR_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT)
   847 
   991 				break;	//all types are always supported
   848 				case EGL_RENDERABLE_TYPE: //bitmask which client rendering APIs are supported. (always EGL_OPENVG_BIT)
   992 
   849 					if (!(attrib_list[i + 1] & EGL_OPENVG_BIT))
   993 			case EGL_TRANSPARENT_TYPE:			//enum type of transparency supported (always EGL_NONE)
   850 						EGL_RETURN(EGL_SUCCESS, EGL_TRUE)
   994 			case EGL_NATIVE_VISUAL_ID:			//integer handle of corresponding native visual (always 0)
   851 					; //not supported
   995 			case EGL_MAX_PBUFFER_WIDTH:			//integer maximum width of pbuffer (always INT_MAX)
   852 					break;
   996 			case EGL_MAX_PBUFFER_HEIGHT:		//integer maximum height of pbuffer (always INT_MAX)
   853 
   997 			case EGL_MAX_PBUFFER_PIXELS:		//integer maximum size of pbuffer (always INT_MAX)
   854 				case EGL_SURFACE_TYPE: //bitmask which types of EGL surfaces are supported. (always EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | EGL_VG_COLORSPACE_LINEAR_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT)
   998 			case EGL_TRANSPARENT_RED_VALUE:		//integer transparent red value (undefined)
   855 					break; //all types are always supported
   999 			case EGL_TRANSPARENT_GREEN_VALUE:	//integer transparent green value (undefined)
   856 
  1000 			case EGL_TRANSPARENT_BLUE_VALUE:	//integer transparent blue value (undefined)
   857 				case EGL_TRANSPARENT_TYPE: //enum type of transparency supported (always EGL_NONE)
  1001 				break;	//ignored
   858 				case EGL_NATIVE_VISUAL_ID: //integer handle of corresponding native visual (always 0)
  1002 
   859 				case EGL_MAX_PBUFFER_WIDTH: //integer maximum width of pbuffer (always INT_MAX)
  1003 			default:
   860 				case EGL_MAX_PBUFFER_HEIGHT: //integer maximum height of pbuffer (always INT_MAX)
  1004 				EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE);	//unknown attribute
   861 				case EGL_MAX_PBUFFER_PIXELS: //integer maximum size of pbuffer (always INT_MAX)
       
   862 				case EGL_TRANSPARENT_RED_VALUE: //integer transparent red value (undefined)
       
   863 				case EGL_TRANSPARENT_GREEN_VALUE: //integer transparent green value (undefined)
       
   864 				case EGL_TRANSPARENT_BLUE_VALUE: //integer transparent blue value (undefined)
       
   865 					break; //ignored
       
   866 
       
   867 				default:
       
   868 					EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE)
       
   869 					; //unknown attribute
       
   870 				}
       
   871 			}
  1005 			}
   872 		}
  1006 		}
   873 
  1007 	}
   874 	if (configID && configID != EGL_DONT_CARE)
  1008 
   875 		{ //if CONFIG_ID is defined, ignore the rest of the attribs
  1009 	if(configID && configID != EGL_DONT_CARE)
   876 		for (int i = 0; i < EGL_NUMCONFIGS; i++)
  1010 	{	//if CONFIG_ID is defined, ignore the rest of the attribs
   877 			{
  1011         for(int i=0;i<EGL_NUMCONFIGS;i++)
   878 			if (display->getConfigByIdx(i).m_configID == configID)
  1012         {
   879 				{
  1013             if(display->getConfigByIdx(i).m_configID == configID)
   880 				*num_config = 1;
  1014             {
   881 				*configs = display->getConfigByIdx(i).m_config;
  1015                 *num_config = 1;
   882 				}
  1016                 *configs = display->getConfigByIdx(i).m_config;
   883 			}
  1017             }
       
  1018         }
   884 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1019 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   885 		}
  1020 	}
   886 
  1021 
   887 	//go through all configs, add passed configs to return list
  1022 	//go through all configs, add passed configs to return list
   888 	//TODO take alpha mask size into account
  1023     //TODO take alpha mask size into account
   889 	EGLConfig found[EGL_NUMCONFIGS];
  1024 	EGLConfig found[EGL_NUMCONFIGS];
   890 	int keys[EGL_NUMCONFIGS];
  1025     int keys[EGL_NUMCONFIGS];
   891 	int numFound = 0;
  1026 	int numFound = 0;
   892 	for (int i = 0; i < display->getNumConfigs(); i++)
  1027 	for(int i=0;i<display->getNumConfigs();i++)
   893 		{
  1028 	{
   894 		const RIEGLConfig& c = display->getConfigByIdx(i);
  1029 		const RIEGLConfig& c = display->getConfigByIdx(i);
   895 
  1030 
   896 		int colorBits = c.m_desc.redBits + c.m_desc.greenBits
  1031 		int colorBits = c.m_desc.redBits + c.m_desc.greenBits + c.m_desc.blueBits;
   897 				+ c.m_desc.blueBits;
       
   898 		int luminanceBits = c.m_desc.luminanceBits;
  1032 		int luminanceBits = c.m_desc.luminanceBits;
   899 		int configBufferSize;
  1033 		int configBufferSize;
   900 		if (colorBits)
  1034 		if(colorBits)
   901 			{
  1035 		{
   902 			RI_ASSERT(!luminanceBits);
  1036 			RI_ASSERT(!luminanceBits);
   903 			colorBits += c.m_desc.alphaBits;
  1037 			colorBits += c.m_desc.alphaBits;
   904 			configBufferSize = colorBits;
  1038 			configBufferSize = colorBits;
   905 			}
  1039 		}
   906 		else if (luminanceBits)
  1040 		else if(luminanceBits)
   907 			{
  1041 		{
   908 			luminanceBits += c.m_desc.alphaBits;
  1042 			luminanceBits += c.m_desc.alphaBits;
   909 			configBufferSize = luminanceBits;
  1043 			configBufferSize = luminanceBits;
   910 			}
  1044 		}
   911 		else
  1045 		else
   912 			{ //alpha only surface
  1046 		{	//alpha only surface
   913 			colorBits = c.m_desc.alphaBits;
  1047 			colorBits = c.m_desc.alphaBits;
   914 			luminanceBits = c.m_desc.alphaBits;
  1048 			luminanceBits = c.m_desc.alphaBits;
   915 			configBufferSize = colorBits;
  1049 			configBufferSize = colorBits;
   916 			}
  1050 		}
   917 
  1051 
   918 		if (smaller(configBufferSize, bufferSize))
  1052 		if (smaller(configBufferSize, bufferSize))
   919 			continue;
  1053 			continue;
   920 
  1054 
   921 		int configSampleBuffers = c.m_samples == 1 ? 0 : 1;
  1055 		int configSampleBuffers = c.m_samples == 1 ? 0 : 1;
   922 		if (smaller(configSampleBuffers, sampleBuffers))
  1056 		if (smaller(configSampleBuffers, sampleBuffers))
   923 			continue;
  1057 			continue;
   924 		if (smaller(c.m_samples, samples))
  1058 		if (smaller(c.m_samples, samples))
   925 			continue;
  1059 			continue;
   926 
  1060 
   927 		if (smaller(c.m_desc.redBits, redSize) || smaller(c.m_desc.greenBits,
  1061 		if (smaller(c.m_desc.redBits, redSize)
   928 				greenSize) || smaller(c.m_desc.blueBits, blueSize) || smaller(
  1062 			|| smaller(c.m_desc.greenBits, greenSize)
   929 				c.m_desc.alphaBits, alphaSize))
  1063 			|| smaller(c.m_desc.blueBits, blueSize) 
       
  1064 			|| smaller(c.m_desc.alphaBits, alphaSize) )
   930 			continue;
  1065 			continue;
   931 
  1066 
   932 		if (smaller(c.m_desc.luminanceBits, luminanceSize))
  1067 		if (smaller(c.m_desc.luminanceBits, luminanceSize))
   933 			continue;
  1068 			continue;
   934 
  1069 
   935 		if ((colorBufferType == EGL_RGB_BUFFER && !colorBits)
  1070 		if ((colorBufferType == EGL_RGB_BUFFER && !colorBits) ||
   936 				|| (colorBufferType == EGL_LUMINANCE_BUFFER && !luminanceBits))
  1071 			(colorBufferType == EGL_LUMINANCE_BUFFER && !luminanceBits))
   937 			continue;
  1072 			continue;
   938 
  1073 
   939 		int sortKey = c.m_configID; //sort from smaller to larger
  1074 		int sortKey = c.m_configID;	//sort from smaller to larger
   940 		int sortBits = 0;
  1075 		int sortBits = 0;
   941 		if (redSize != 0 && redSize != EGL_DONT_CARE)
  1076 		if(redSize != 0 && redSize != EGL_DONT_CARE)
   942 			sortBits += c.m_desc.redBits;
  1077 			sortBits += c.m_desc.redBits;
   943 		if (greenSize != 0 && greenSize != EGL_DONT_CARE)
  1078 		if(greenSize != 0 && greenSize != EGL_DONT_CARE)
   944 			sortBits += c.m_desc.greenBits;
  1079 			sortBits += c.m_desc.greenBits;
   945 		if (blueSize != 0 && blueSize != EGL_DONT_CARE)
  1080 		if(blueSize != 0 && blueSize != EGL_DONT_CARE)
   946 			sortBits += c.m_desc.blueBits;
  1081 			sortBits += c.m_desc.blueBits;
   947 		if (alphaSize != 0 && alphaSize != EGL_DONT_CARE)
  1082 		if(alphaSize != 0 && alphaSize != EGL_DONT_CARE)
   948 			sortBits += c.m_desc.alphaBits;
  1083 			sortBits += c.m_desc.alphaBits;
   949 		if (luminanceSize != 0 && luminanceSize != EGL_DONT_CARE)
  1084 		if(luminanceSize != 0 && luminanceSize != EGL_DONT_CARE)
   950 			sortBits += c.m_desc.luminanceBits;
  1085 			sortBits += c.m_desc.luminanceBits;
   951 		RI_ASSERT(c.m_configID <= EGL_NUMCONFIGS); //if there are more configs, increase the shift value
  1086 		RI_ASSERT(c.m_configID <= EGL_NUMCONFIGS);	//if there are more configs, increase the shift value
   952 		RI_ASSERT(sortBits <= 32);
  1087 		RI_ASSERT(sortBits <= 32);
   953 		sortKey += (32 - sortBits) << 4; //sort from larger to smaller
  1088 		sortKey += (32-sortBits) << 4;	//sort from larger to smaller
   954 
  1089 
   955 		found[numFound] = c.m_config;
  1090 		found[numFound] = c.m_config;
   956 		keys[numFound++] = sortKey;
  1091 		keys[numFound++] = sortKey;
   957 		}
  1092 	}
   958 	if (!numFound)
  1093 	if(!numFound)
   959 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1094 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   960 
  1095 
   961 	//sort return list into increasing order
  1096 	//sort return list into increasing order
   962 	for (int e = 0; e < numFound - 1; e++)
  1097 	for(int e=0;e<numFound-1;e++)
       
  1098 	{
       
  1099 		for(int f=e+1;f<numFound;f++)
   963 		{
  1100 		{
   964 		for (int f = e + 1; f < numFound; f++)
  1101 			if(keys[e] > keys[f])
   965 			{
  1102 			{
   966 			if (keys[e] > keys[f])
  1103                 EGLConfig tmp = found[e];
   967 				{
  1104                 found[e] = found[f];
   968 				EGLConfig tmp = found[e];
  1105                 found[f] = tmp;
   969 				found[e] = found[f];
       
   970 				found[f] = tmp;
       
   971 				RI_INT_SWAP(keys[e], keys[f]);
  1106 				RI_INT_SWAP(keys[e], keys[f]);
   972 				}
       
   973 			}
  1107 			}
   974 		}
  1108 		}
       
  1109 	}
   975 
  1110 
   976 	//write configs into return array
  1111 	//write configs into return array
   977 	numFound = RI_INT_MIN(numFound, config_size);
  1112 	numFound = RI_INT_MIN(numFound, config_size);
   978 	for (int i = 0; i < numFound; i++)
  1113 	for(int i=0;i<numFound;i++)
   979 		{
  1114 	{
   980 		configs[i] = found[i];
  1115 		configs[i] = found[i];
   981 		}
  1116 	}
   982 	*num_config = numFound;
  1117 	*num_config = numFound;
   983 
  1118 
   984 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1119 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
   985 	}
  1120 }
   986 
  1121 
   987 /*-------------------------------------------------------------------*//*!
  1122 /*-------------------------------------------------------------------*//*!
   988  * \brief	
  1123 * \brief	
   989  * \param	
  1124 * \param	
   990  * \return	
  1125 * \return	
   991  * \note		
  1126 * \note		
   992  *//*-------------------------------------------------------------------*/
  1127 *//*-------------------------------------------------------------------*/
   993 
  1128 
   994 #ifdef BUILD_WITH_PRIVATE_EGL
  1129 #ifdef BUILD_WITH_PRIVATE_EGL
   995 RI_APIENTRY EGLBoolean do_eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
  1130 RI_APIENTRY EGLBoolean do_eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
   996 		EGLint attribute, EGLint *value)
       
   997 #else
  1131 #else
   998 EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
  1132 EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
   999 #endif
  1133 #endif
  1000 	{
  1134 {
  1001 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1135 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1002 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1136 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1003 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_FALSE);
  1137 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_FALSE);
  1004 	const RIEGLConfig& c = display->getConfig(config);
  1138 	const RIEGLConfig& c = display->getConfig(config);
  1005 	switch (attribute)
  1139 	switch(attribute)
  1006 		{
  1140 	{
  1007 		case EGL_BUFFER_SIZE:
  1141 	case EGL_BUFFER_SIZE:
  1008 			*value = RI_INT_MAX(c.m_desc.redBits + c.m_desc.greenBits
  1142 		*value = RI_INT_MAX(c.m_desc.redBits + c.m_desc.greenBits + c.m_desc.blueBits + c.m_desc.alphaBits, c.m_desc.luminanceBits + c.m_desc.alphaBits);
  1009 					+ c.m_desc.blueBits + c.m_desc.alphaBits,
  1143 		break;
  1010 					c.m_desc.luminanceBits + c.m_desc.alphaBits);
  1144 
  1011 			break;
  1145 	case EGL_RED_SIZE:
  1012 
  1146 		*value = c.m_desc.redBits;
  1013 		case EGL_RED_SIZE:
  1147 		break;
  1014 			*value = c.m_desc.redBits;
  1148 
  1015 			break;
  1149 	case EGL_GREEN_SIZE:
  1016 
  1150 		*value = c.m_desc.greenBits;
  1017 		case EGL_GREEN_SIZE:
  1151 		break;
  1018 			*value = c.m_desc.greenBits;
  1152 
  1019 			break;
  1153 	case EGL_BLUE_SIZE:
  1020 
  1154 		*value = c.m_desc.blueBits;
  1021 		case EGL_BLUE_SIZE:
  1155 		break;
  1022 			*value = c.m_desc.blueBits;
  1156 
  1023 			break;
  1157 	case EGL_LUMINANCE_SIZE:
  1024 
  1158 		*value = c.m_desc.luminanceBits;
  1025 		case EGL_LUMINANCE_SIZE:
  1159 		break;
  1026 			*value = c.m_desc.luminanceBits;
  1160 
  1027 			break;
  1161 	case EGL_ALPHA_SIZE:
  1028 
  1162 		*value = c.m_desc.alphaBits;
  1029 		case EGL_ALPHA_SIZE:
  1163 		break;
  1030 			*value = c.m_desc.alphaBits;
  1164 
  1031 			break;
  1165 	case EGL_ALPHA_MASK_SIZE:
  1032 
  1166 		*value = c.m_maskBits;
  1033 		case EGL_ALPHA_MASK_SIZE:
  1167 		break;
  1034 			*value = c.m_maskBits;
  1168 
  1035 			break;
  1169 	case EGL_BIND_TO_TEXTURE_RGB:
  1036 
  1170 	case EGL_BIND_TO_TEXTURE_RGBA:
  1037 		case EGL_BIND_TO_TEXTURE_RGB:
  1171 		*value = EGL_FALSE;
  1038 		case EGL_BIND_TO_TEXTURE_RGBA:
  1172 		break;
  1039 			*value = EGL_FALSE;
  1173 
  1040 			break;
  1174 	case EGL_COLOR_BUFFER_TYPE:
  1041 
  1175 		if(c.m_desc.redBits)
  1042 		case EGL_COLOR_BUFFER_TYPE:
  1176 			*value = EGL_RGB_BUFFER;
  1043 			if (c.m_desc.redBits)
  1177 		else
  1044 				*value = EGL_RGB_BUFFER;
  1178 			*value = EGL_LUMINANCE_BUFFER;
  1045 			else
  1179 		break;
  1046 				*value = EGL_LUMINANCE_BUFFER;
  1180 
  1047 			break;
  1181 	case EGL_CONFIG_CAVEAT:
  1048 
  1182 		*value = EGL_NONE;
  1049 		case EGL_CONFIG_CAVEAT:
  1183 		break;
  1050 			*value = EGL_NONE;
  1184 
  1051 			break;
  1185 	case EGL_CONFIG_ID:
  1052 
  1186 		*value = c.m_configID;
  1053 		case EGL_CONFIG_ID:
  1187 		break;
  1054 			*value = c.m_configID;
  1188 
  1055 			break;
  1189 	case EGL_DEPTH_SIZE:
  1056 
  1190 		*value = 0;
  1057 		case EGL_DEPTH_SIZE:
  1191 		break;
  1058 			*value = 0;
  1192 
  1059 			break;
  1193 	case EGL_LEVEL:
  1060 
  1194 		*value = 0;
  1061 		case EGL_LEVEL:
  1195 		break;
  1062 			*value = 0;
  1196 
  1063 			break;
  1197 	case EGL_MAX_PBUFFER_WIDTH:
  1064 
  1198 	case EGL_MAX_PBUFFER_HEIGHT:
  1065 		case EGL_MAX_PBUFFER_WIDTH:
  1199 		*value = 16384;			//NOTE arbitrary maximum
  1066 		case EGL_MAX_PBUFFER_HEIGHT:
  1200 		break;
  1067 			*value = 16384; //NOTE arbitrary maximum
  1201 		
  1068 			break;
  1202 	case EGL_MAX_PBUFFER_PIXELS:
  1069 
  1203 		*value = 16384*16384;	//NOTE arbitrary maximum
  1070 		case EGL_MAX_PBUFFER_PIXELS:
  1204 		break;
  1071 			*value = 16384 * 16384; //NOTE arbitrary maximum
  1205 
  1072 			break;
  1206 	case EGL_MAX_SWAP_INTERVAL:
  1073 
  1207 	case EGL_MIN_SWAP_INTERVAL:
  1074 		case EGL_MAX_SWAP_INTERVAL:
  1208 		*value = 1;
  1075 		case EGL_MIN_SWAP_INTERVAL:
  1209 		break;
  1076 			*value = 1;
  1210 
  1077 			break;
  1211 	case EGL_NATIVE_RENDERABLE:
  1078 
  1212 		*value = EGL_FALSE;
  1079 		case EGL_NATIVE_RENDERABLE:
  1213 		break;
  1080 			*value = EGL_FALSE;
  1214 
  1081 			break;
  1215 	case EGL_NATIVE_VISUAL_ID:
  1082 
  1216 		*value = 0;
  1083 		case EGL_NATIVE_VISUAL_ID:
  1217 		break;
  1084 			*value = 0;
  1218 
  1085 			break;
  1219 	case EGL_NATIVE_VISUAL_TYPE:
  1086 
  1220 		*value = EGL_NONE;
  1087 		case EGL_NATIVE_VISUAL_TYPE:
  1221 		break;
  1088 			*value = EGL_NONE;
  1222 
  1089 			break;
  1223 	case EGL_RENDERABLE_TYPE:
  1090 
  1224 		*value = EGL_OPENVG_BIT;
  1091 		case EGL_RENDERABLE_TYPE:
  1225 		break;
  1092 			*value = EGL_OPENVG_BIT;
  1226 
  1093 			break;
  1227 	case EGL_SAMPLE_BUFFERS:
  1094 
  1228 		*value = c.m_samples > 1 ? 1 : 0;
  1095 		case EGL_SAMPLE_BUFFERS:
  1229 		break;
  1096 			*value = c.m_samples > 1 ? 1 : 0;
  1230 
  1097 			break;
  1231 	case EGL_SAMPLES:
  1098 
  1232 		*value = c.m_samples > 1 ? c.m_samples : 0;
  1099 		case EGL_SAMPLES:
  1233 		break;
  1100 			*value = c.m_samples > 1 ? c.m_samples : 0;
  1234 
  1101 			break;
  1235 	case EGL_STENCIL_SIZE:
  1102 
  1236 		*value = 0;
  1103 		case EGL_STENCIL_SIZE:
  1237 		break;
  1104 			*value = 0;
  1238 
  1105 			break;
  1239 	case EGL_SURFACE_TYPE:
  1106 
  1240 		*value = EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | EGL_VG_COLORSPACE_LINEAR_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT;
  1107 		case EGL_SURFACE_TYPE:
  1241 		break;
  1108 			*value = EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT
  1242 
  1109 					| EGL_VG_COLORSPACE_LINEAR_BIT
  1243 	case EGL_TRANSPARENT_TYPE:
  1110 					| EGL_VG_ALPHA_FORMAT_PRE_BIT;
  1244 		*value = EGL_NONE;
  1111 			break;
  1245 		break;
  1112 
  1246 
  1113 		case EGL_TRANSPARENT_TYPE:
  1247 	case EGL_TRANSPARENT_RED_VALUE:
  1114 			*value = EGL_NONE;
  1248 	case EGL_TRANSPARENT_GREEN_VALUE:
  1115 			break;
  1249 	case EGL_TRANSPARENT_BLUE_VALUE:
  1116 
  1250 		*value = 0;
  1117 		case EGL_TRANSPARENT_RED_VALUE:
  1251 		break;
  1118 		case EGL_TRANSPARENT_GREEN_VALUE:
  1252 
  1119 		case EGL_TRANSPARENT_BLUE_VALUE:
  1253     case EGL_CONFORMANT:
  1120 			*value = 0;
  1254         *value = EGL_OPENVG_BIT;  //TODO return proper value
  1121 			break;
  1255         break;
  1122 
  1256 
  1123 		case EGL_CONFORMANT:
  1257 	default:
  1124 			*value = EGL_OPENVG_BIT; //TODO return proper value
  1258 		EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE);
  1125 			break;
  1259 	}
  1126 
       
  1127 		default:
       
  1128 			EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE)
       
  1129 			;
       
  1130 		}
       
  1131 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1260 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1132 	}
  1261 }
  1133 
  1262 
  1134 /*-------------------------------------------------------------------*//*!
  1263 /*-------------------------------------------------------------------*//*!
  1135  * \brief	
  1264 * \brief	
  1136  * \param	
  1265 * \param	
  1137  * \return	
  1266 * \return	
  1138  * \note		
  1267 * \note		
  1139  *//*-------------------------------------------------------------------*/
  1268 *//*-------------------------------------------------------------------*/
  1140 
  1269 
  1141 #ifdef BUILD_WITH_PRIVATE_EGL
  1270 #ifdef BUILD_WITH_PRIVATE_EGL
  1142 RI_APIENTRY EGLSurface do_eglCreateWindowSurface(EGLDisplay dpy,
  1271 RI_APIENTRY EGLSurface do_eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
  1143 		EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
       
  1144 #else
  1272 #else
  1145 EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
  1273 EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
  1146 #endif
  1274 #endif
  1147 	{
  1275 {
  1148 	EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
  1276 	EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
  1149 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
  1277 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
  1150 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
  1278 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
  1151 
  1279 
  1152 	int renderBuffer = EGL_BACK_BUFFER;
  1280 	int renderBuffer = EGL_BACK_BUFFER;
  1153 	int colorSpace = EGL_VG_COLORSPACE_sRGB;
  1281 	int colorSpace = EGL_VG_COLORSPACE_sRGB;
  1154 	int alphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE;
  1282 	int alphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE;
  1155 	if (attrib_list)
  1283 	if(attrib_list)
       
  1284 	{
       
  1285 		for(int i=0;attrib_list[i] != EGL_NONE;i+=2)
  1156 		{
  1286 		{
  1157 		for (int i = 0; attrib_list[i] != EGL_NONE; i += 2)
  1287 			switch(attrib_list[i])
  1158 			{
  1288 			{
  1159 			switch (attrib_list[i])
  1289 			case EGL_RENDER_BUFFER:
  1160 				{
  1290 				renderBuffer = attrib_list[i+1];
  1161 				case EGL_RENDER_BUFFER:
  1291 				break;
  1162 					renderBuffer = attrib_list[i + 1];
  1292 
  1163 					break;
  1293 			case EGL_VG_COLORSPACE:
  1164 
  1294 				colorSpace = attrib_list[i+1];
  1165 				case EGL_VG_COLORSPACE:
  1295 				break;
  1166 					colorSpace = attrib_list[i + 1];
  1296 
  1167 					break;
  1297 			case EGL_VG_ALPHA_FORMAT:
  1168 
  1298 				alphaFormat = attrib_list[i+1];
  1169 				case EGL_VG_ALPHA_FORMAT:
  1299 				break;
  1170 					alphaFormat = attrib_list[i + 1];
  1300 
  1171 					break;
  1301 			default:
  1172 
  1302 				EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
  1173 				default:
       
  1174 					EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE)
       
  1175 					;
       
  1176 				}
       
  1177 			}
  1303 			}
  1178 		}
  1304 		}
       
  1305 	}
  1179 	//we ignore the renderBuffer parameter since we can only render to double buffered surfaces
  1306 	//we ignore the renderBuffer parameter since we can only render to double buffered surfaces
  1180 
  1307 
  1181 	//TODO If the attributes of win do not correspond to config, then an EGL BAD MATCH error is generated.
  1308 	//TODO If the attributes of win do not correspond to config, then an EGL BAD MATCH error is generated.
  1182 	//TODO If there is already an EGLConfig associated with win (as a result of a previous eglCreateWindowSurface call), then an EGL BAD ALLOC error is generated
  1309 	//TODO If there is already an EGLConfig associated with win (as a result of a previous eglCreateWindowSurface call), then an EGL BAD ALLOC error is generated
  1183 
  1310 
  1184 	void* wc = NULL;
  1311     void* wc = NULL;
  1185 	Drawable* d = NULL;
  1312     Drawable* d = NULL;
  1186 	RIEGLSurface* s = NULL;
  1313 	RIEGLSurface* s = NULL;
  1187 	try
  1314 	try
  1188 		{
  1315 	{
  1189 		wc = OSCreateWindowContext(win);
  1316         wc = OSCreateWindowContext(win);
  1190 		RI_ASSERT(wc);
  1317 		RI_ASSERT(wc);
  1191 		//TODO what should happen if window width or height is zero?
  1318 		//TODO what should happen if window width or height is zero?
  1192 		int windowWidth = 0, windowHeight = 0;
  1319 		int windowWidth = 0, windowHeight = 0;
  1193 		OSGetWindowSize(wc, windowWidth, windowHeight);
  1320 		OSGetWindowSize(wc, windowWidth, windowHeight);
  1194 		bool isWindow = OSIsWindow(wc);
  1321         bool isWindow = OSIsWindow(wc);
  1195 		if (windowWidth <= 0 || windowHeight <= 0 || !isWindow)
  1322 		if(windowWidth <= 0 || windowHeight <= 0 || !isWindow)
  1196 			{
  1323 		{
  1197 			OSDestroyWindowContext(wc);
  1324             OSDestroyWindowContext(wc);
  1198 			EGL_IF_ERROR(!isWindow, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
  1325             EGL_IF_ERROR(!isWindow, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
  1199 			EGL_IF_ERROR(windowWidth <= 0 || windowHeight <= 0, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
  1326 			EGL_IF_ERROR(windowWidth <= 0 || windowHeight <= 0, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
  1200 			}
  1327 		}
  1201 		d
  1328 		d = RI_NEW(Drawable, (display->getConfig(config).configToDescriptor((colorSpace == EGL_VG_COLORSPACE_LINEAR) ? false : true, (alphaFormat == EGL_VG_ALPHA_FORMAT_PRE) ? true : false), windowWidth, windowHeight, display->getConfig(config).m_samples, display->getConfig(config).m_maskBits));	//throws bad_alloc
  1202 				= RI_NEW(Drawable, (display->getConfig(config).configToDescriptor((colorSpace == EGL_VG_COLORSPACE_LINEAR) ? false : true, (alphaFormat == EGL_VG_ALPHA_FORMAT_PRE) ? true : false), windowWidth, windowHeight, display->getConfig(config).m_samples, display->getConfig(config).m_maskBits)); //throws bad_alloc
       
  1203 		RI_ASSERT(d);
  1329 		RI_ASSERT(d);
  1204 		s = RI_NEW(RIEGLSurface,(wc, config, d, false, renderBuffer)); //throws bad_alloc
  1330 		s = RI_NEW(RIEGLSurface,(wc, config, d, false, renderBuffer));	//throws bad_alloc
  1205 		RI_ASSERT(s);
  1331 		RI_ASSERT(s);
  1206 		s->addReference();
  1332 		s->addReference();
  1207 		display->addSurface(s); //throws bad_alloc
  1333 		display->addSurface(s);	//throws bad_alloc
  1208 		}
  1334 	}
  1209 	catch (std::bad_alloc)
  1335 	catch(std::bad_alloc)
  1210 		{
  1336 	{
  1211 		OSDestroyWindowContext(wc);
  1337         OSDestroyWindowContext(wc);
  1212 		RI_DELETE(d);
  1338         RI_DELETE(d);
  1213 		RI_DELETE(s);
  1339         RI_DELETE(s);
  1214 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
  1340 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
  1215 		}
  1341 	}
  1216 	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
  1342 	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
  1217 	}
  1343 }
  1218 
  1344 
  1219 /*-------------------------------------------------------------------*//*!
  1345 /*-------------------------------------------------------------------*//*!
  1220  * \brief	
  1346 * \brief	
  1221  * \param	
  1347 * \param	
  1222  * \return	
  1348 * \return	
  1223  * \note		
  1349 * \note		
  1224  *//*-------------------------------------------------------------------*/
  1350 *//*-------------------------------------------------------------------*/
  1225 
  1351 
  1226 #ifdef BUILD_WITH_PRIVATE_EGL
  1352 #ifdef BUILD_WITH_PRIVATE_EGL
  1227 RI_APIENTRY EGLSurface do_eglCreatePbufferSurface(EGLDisplay dpy,
  1353 RI_APIENTRY EGLSurface do_eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
  1228 		EGLConfig config, const EGLint *attrib_list)
       
  1229 #else
  1354 #else
  1230 EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
  1355 EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
  1231 #endif
  1356 #endif
  1232 	{
  1357 {
  1233 	EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
  1358 	EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
  1234 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
  1359 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
  1235 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
  1360 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
  1236 
  1361 
  1237 	int width = 0, height = 0;
  1362 	int width = 0, height = 0;
  1238 	bool largestPbuffer = false;
  1363 	bool largestPbuffer = false;
  1239 	int colorSpace = EGL_VG_COLORSPACE_sRGB;
  1364 	int colorSpace = EGL_VG_COLORSPACE_sRGB;
  1240 	int alphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE;
  1365 	int alphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE;
  1241 	if (attrib_list)
  1366 	if(attrib_list)
       
  1367 	{
       
  1368 		for(int i=0;attrib_list[i] != EGL_NONE;i+=2)
  1242 		{
  1369 		{
  1243 		for (int i = 0; attrib_list[i] != EGL_NONE; i += 2)
  1370 			switch(attrib_list[i])
  1244 			{
  1371 			{
  1245 			switch (attrib_list[i])
  1372 			case EGL_WIDTH:
  1246 				{
  1373 				width = attrib_list[i+1];
  1247 				case EGL_WIDTH:
  1374 				break;
  1248 					width = attrib_list[i + 1];
  1375 
  1249 					break;
  1376 			case EGL_HEIGHT:
  1250 
  1377 				height = attrib_list[i+1];
  1251 				case EGL_HEIGHT:
  1378 				break;
  1252 					height = attrib_list[i + 1];
  1379 
  1253 					break;
  1380 			case EGL_LARGEST_PBUFFER:
  1254 
  1381 				largestPbuffer = attrib_list[i+1] ? true : false;
  1255 				case EGL_LARGEST_PBUFFER:
  1382 				break;
  1256 					largestPbuffer = attrib_list[i + 1] ? true : false;
  1383 
  1257 					break;
  1384 			case EGL_VG_COLORSPACE:
  1258 
  1385 				colorSpace = attrib_list[i+1];
  1259 				case EGL_VG_COLORSPACE:
  1386 				break;
  1260 					colorSpace = attrib_list[i + 1];
  1387 
  1261 					break;
  1388 			case EGL_VG_ALPHA_FORMAT:
  1262 
  1389 				alphaFormat = attrib_list[i+1];
  1263 				case EGL_VG_ALPHA_FORMAT:
  1390 				break;
  1264 					alphaFormat = attrib_list[i + 1];
  1391 
  1265 					break;
  1392 			case EGL_TEXTURE_FORMAT:	//config doesn't support OpenGL ES
  1266 
  1393 			case EGL_TEXTURE_TARGET:	//config doesn't support OpenGL ES
  1267 				case EGL_TEXTURE_FORMAT: //config doesn't support OpenGL ES
  1394 			case EGL_MIPMAP_TEXTURE:	//config doesn't support OpenGL ES
  1268 				case EGL_TEXTURE_TARGET: //config doesn't support OpenGL ES
  1395 			default:
  1269 				case EGL_MIPMAP_TEXTURE: //config doesn't support OpenGL ES
  1396 				EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
  1270 				default:
       
  1271 					EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE)
       
  1272 					;
       
  1273 				}
       
  1274 			}
  1397 			}
  1275 		}
  1398 		}
       
  1399 	}
  1276 	EGL_IF_ERROR(width <= 0 || height <= 0, EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
  1400 	EGL_IF_ERROR(width <= 0 || height <= 0, EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
  1277 
  1401 
  1278 	Drawable* d = NULL;
  1402     Drawable* d = NULL;
  1279 	RIEGLSurface* s = NULL;
  1403 	RIEGLSurface* s = NULL;
  1280 	try
  1404 	try
  1281 		{
  1405 	{
  1282 		d
  1406 		d = RI_NEW(Drawable, (display->getConfig(config).configToDescriptor((colorSpace == EGL_VG_COLORSPACE_LINEAR) ? false : true, (alphaFormat == EGL_VG_ALPHA_FORMAT_PRE) ? true : false), width, height, display->getConfig(config).m_samples, display->getConfig(config).m_maskBits));	//throws bad_alloc
  1283 				= RI_NEW(Drawable, (display->getConfig(config).configToDescriptor((colorSpace == EGL_VG_COLORSPACE_LINEAR) ? false : true, (alphaFormat == EGL_VG_ALPHA_FORMAT_PRE) ? true : false), width, height, display->getConfig(config).m_samples, display->getConfig(config).m_maskBits)); //throws bad_alloc
       
  1284 		RI_ASSERT(d);
  1407 		RI_ASSERT(d);
  1285 		s
  1408 		s = RI_NEW(RIEGLSurface,(NULL, config, d, largestPbuffer, EGL_BACK_BUFFER));	//throws bad_alloc
  1286 				= RI_NEW(RIEGLSurface,(NULL, config, d, largestPbuffer, EGL_BACK_BUFFER)); //throws bad_alloc
       
  1287 		RI_ASSERT(s);
  1409 		RI_ASSERT(s);
  1288 		s->addReference();
  1410 		s->addReference();
  1289 		display->addSurface(s); //throws bad_alloc
  1411 		display->addSurface(s);	//throws bad_alloc
  1290 		}
  1412 	}
  1291 	catch (std::bad_alloc)
  1413 	catch(std::bad_alloc)
  1292 		{
  1414 	{
  1293 		RI_DELETE(d);
  1415         RI_DELETE(d);
  1294 		RI_DELETE(s);
  1416         RI_DELETE(s);
  1295 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
  1417 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
  1296 		}
  1418 	}
  1297 	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
  1419 	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
  1298 	}
  1420 }
  1299 
  1421 
  1300 /*-------------------------------------------------------------------*//*!
  1422 /*-------------------------------------------------------------------*//*!
  1301  * \brief	
  1423 * \brief	
  1302  * \param	
  1424 * \param	
  1303  * \return	
  1425 * \return	
  1304  * \note		
  1426 * \note		
  1305  *//*-------------------------------------------------------------------*/
  1427 *//*-------------------------------------------------------------------*/
  1306 
  1428 
  1307 #ifdef BUILD_WITH_PRIVATE_EGL
  1429 #ifdef BUILD_WITH_PRIVATE_EGL
  1308 RI_APIENTRY EGLSurface do_eglCreatePbufferFromClientBuffer(EGLDisplay dpy,
  1430 RI_APIENTRY EGLSurface do_eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
  1309 		EGLenum buftype, EGLClientBuffer buffer, EGLConfig config,
       
  1310 		const EGLint *attrib_list)
       
  1311 #else
  1431 #else
  1312 EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
  1432 EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
  1313 #endif
  1433 #endif
  1314 	{
  1434 {
  1315 	EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
  1435 	EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
  1316 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
  1436 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
  1317 	EGL_IF_ERROR(buftype != EGL_OPENVG_IMAGE, EGL_BAD_PARAMETER, EGL_NO_SURFACE);
  1437 	EGL_IF_ERROR(buftype != EGL_OPENVG_IMAGE, EGL_BAD_PARAMETER, EGL_NO_SURFACE);
  1318 	EGL_IF_ERROR(!buffer, EGL_BAD_PARAMETER, EGL_NO_SURFACE); //TODO should also check if buffer really is a valid VGImage object (needs VG context for that)
  1438 	EGL_IF_ERROR(!buffer, EGL_BAD_PARAMETER, EGL_NO_SURFACE);	//TODO should also check if buffer really is a valid VGImage object (needs VG context for that)
  1319 	Image* image = (Image*) buffer;
  1439     Image* image = (Image*)buffer;
  1320 	EGL_IF_ERROR(image->isInUse(), EGL_BAD_ACCESS, EGL_NO_SURFACE); //buffer is in use by OpenVG
  1440 	EGL_IF_ERROR(image->isInUse(), EGL_BAD_ACCESS, EGL_NO_SURFACE);	//buffer is in use by OpenVG
  1321 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
  1441 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
  1322 	EGL_IF_ERROR(attrib_list && attrib_list[0] != EGL_NONE, EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); //there are no valid attribs for OpenVG
  1442 	EGL_IF_ERROR(attrib_list && attrib_list[0] != EGL_NONE, EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);	//there are no valid attribs for OpenVG
  1323 	const Color::Descriptor& bc = ((Image*) buffer)->getDescriptor();
  1443 	const Color::Descriptor& bc = ((Image*)buffer)->getDescriptor();
  1324 	const Color::Descriptor& cc = display->getConfig(config).m_desc;
  1444 	const Color::Descriptor& cc = display->getConfig(config).m_desc;
  1325 	EGL_IF_ERROR(bc.redBits != cc.redBits || bc.greenBits != cc.greenBits || bc.blueBits != cc.blueBits ||
  1445 	EGL_IF_ERROR(bc.redBits != cc.redBits || bc.greenBits != cc.greenBits || bc.blueBits != cc.blueBits ||
  1326 			bc.alphaBits != cc.alphaBits || bc.luminanceBits != cc.luminanceBits, EGL_BAD_MATCH, EGL_NO_SURFACE);
  1446 				 bc.alphaBits != cc.alphaBits || bc.luminanceBits != cc.luminanceBits, EGL_BAD_MATCH, EGL_NO_SURFACE);
  1327 
  1447 
  1328 	//TODO If buffer is already bound to another pbuffer, an EGL BAD ACCESS error is generated.
  1448 	//TODO If buffer is already bound to another pbuffer, an EGL BAD ACCESS error is generated.
  1329 
  1449 
  1330 	Drawable* d = NULL;
  1450     Drawable* d = NULL;
  1331 	RIEGLSurface* s = NULL;
  1451 	RIEGLSurface* s = NULL;
  1332 	try
  1452 	try
  1333 		{
  1453 	{
  1334 		d = RI_NEW(Drawable, (image, display->getConfig(config).m_maskBits));
  1454 		d = RI_NEW(Drawable, (image, display->getConfig(config).m_maskBits));
  1335 		RI_ASSERT(d);
  1455 		RI_ASSERT(d);
  1336 		s = RI_NEW(RIEGLSurface,(NULL, config, d, false, EGL_BACK_BUFFER)); //throws bad_alloc
  1456 		s = RI_NEW(RIEGLSurface,(NULL, config, d, false, EGL_BACK_BUFFER));	//throws bad_alloc
  1337 		RI_ASSERT(s);
  1457 		RI_ASSERT(s);
  1338 		s->addReference();
  1458 		s->addReference();
  1339 		display->addSurface(s); //throws bad_alloc
  1459 		display->addSurface(s);	//throws bad_alloc
  1340 		}
  1460 	}
  1341 	catch (std::bad_alloc)
  1461 	catch(std::bad_alloc)
  1342 		{
  1462 	{
  1343 		RI_DELETE(d);
  1463         RI_DELETE(d);
  1344 		RI_DELETE(s);
  1464         RI_DELETE(s);
  1345 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
  1465 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
  1346 		}
  1466 	}
  1347 	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
  1467 	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
  1348 	}
  1468 }
  1349 
  1469 
  1350 /*-------------------------------------------------------------------*//*!
  1470 /*-------------------------------------------------------------------*//*!
  1351  * \brief	
  1471 * \brief	
  1352  * \param	
  1472 * \param	
  1353  * \return	
  1473 * \return	
  1354  * \note		
  1474 * \note		
  1355  *//*-------------------------------------------------------------------*/
  1475 *//*-------------------------------------------------------------------*/
  1356 
  1476 
  1357 #ifdef BUILD_WITH_PRIVATE_EGL
  1477 #ifdef BUILD_WITH_PRIVATE_EGL
  1358 RI_APIENTRY EGLSurface do_eglCreatePixmapSurface(EGLDisplay dpy,
  1478 RI_APIENTRY EGLSurface do_eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
  1359 		EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
       
  1360 #else
  1479 #else
  1361 EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
  1480 EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
  1362 #endif
  1481 #endif
  1363 	{
  1482 {
  1364 	EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
  1483     EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
  1365 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
  1484 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
  1366 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
  1485 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
  1367 	//EGL_IF_ERROR(!pixmap || !isValidImageFormat(pixmap->format) || !pixmap->data || pixmap->width <= 0 || pixmap->height <= 0, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
  1486 	//EGL_IF_ERROR(!pixmap || !isValidImageFormat(pixmap->format) || !pixmap->data || pixmap->width <= 0 || pixmap->height <= 0, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
  1368 
  1487 
  1369 	RI_UNREF(attrib_list);
  1488 	RI_UNREF(attrib_list);
  1370 	EGL_IF_ERROR(display->getConfig(config).m_samples != 1, EGL_BAD_MATCH, EGL_NO_SURFACE);
  1489 	EGL_IF_ERROR(display->getConfig(config).m_samples != 1, EGL_BAD_MATCH, EGL_NO_SURFACE);
  1371 
  1490 
  1372 	//TODO If there is already an EGLSurface associated with pixmap (as a result of a previous eglCreatePixmapSurface call), then a EGL BAD ALLOC error is generated.
  1491 	//TODO If there is already an EGLSurface associated with pixmap (as a result of a previous eglCreatePixmapSurface call), then a EGL BAD ALLOC error is generated.
  1373 
  1492 	
  1374 
  1493 	
  1375 	EGLint width = -1;
  1494 	EGLint  width  = -1;
  1376 	EGLint height = -1;
  1495 	EGLint  height = -1;
  1377 	EGLint stride = -1;
  1496 	EGLint  stride = -1;
  1378 	VGImageFormat format;
  1497 	VGImageFormat format;
  1379 	int* data = NULL;
  1498 	int* data = NULL;
  1380 	EGLBoolean err = OSGetNativePixmapInfo(pixmap, &width, &height, &stride,
  1499 	EGLBoolean err = OSGetNativePixmapInfo(pixmap, &width, &height, &stride,&format, &data);
  1381 			&format, &data);
  1500 	
  1382 
  1501     Drawable* d = NULL;
  1383 	Drawable* d = NULL;
       
  1384 	RIEGLSurface* s = NULL;
  1502 	RIEGLSurface* s = NULL;
  1385 	try
  1503 	try
  1386 		{
  1504 	{
  1387 		d
  1505 		d = RI_NEW(Drawable, (Color::formatToDescriptor(format), width, height, stride, (RIuint8*)data, display->getConfig(config).m_maskBits));	//throws bad_alloc
  1388 				= RI_NEW(Drawable, (Color::formatToDescriptor(format), width, height, stride, (RIuint8*)data, display->getConfig(config).m_maskBits)); //throws bad_alloc
       
  1389 		RI_ASSERT(d);
  1506 		RI_ASSERT(d);
  1390 		s = RI_NEW(RIEGLSurface,(NULL, config, d, false, EGL_BACK_BUFFER)); //throws bad_alloc
  1507 		s = RI_NEW(RIEGLSurface,(NULL, config, d, false, EGL_BACK_BUFFER));	//throws bad_alloc
  1391 		RI_ASSERT(s);
  1508 		RI_ASSERT(s);
  1392 		s->addReference();
  1509 		s->addReference();
  1393 		display->addSurface(s); //throws bad_alloc
  1510 		display->addSurface(s);	//throws bad_alloc
  1394 		}
  1511 	}
  1395 	catch (std::bad_alloc)
  1512 	catch(std::bad_alloc)
  1396 		{
  1513 	{
  1397 		RI_DELETE(d);
  1514         RI_DELETE(d);
  1398 		RI_DELETE(s);
  1515         RI_DELETE(s);
  1399 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
  1516 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
  1400 		}
  1517 	}
  1401 	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
  1518 	EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
  1402 
  1519 	
  1403 	}
  1520 }
  1404 
  1521 
  1405 /*-------------------------------------------------------------------*//*!
  1522 /*-------------------------------------------------------------------*//*!
  1406  * \brief	
  1523 * \brief	
  1407  * \param	
  1524 * \param	
  1408  * \return	
  1525 * \return	
  1409  * \note		
  1526 * \note		
  1410  *//*-------------------------------------------------------------------*/
  1527 *//*-------------------------------------------------------------------*/
  1411 
  1528 
  1412 #ifdef BUILD_WITH_PRIVATE_EGL
  1529 #ifdef BUILD_WITH_PRIVATE_EGL
  1413 RI_APIENTRY EGLBoolean do_eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
  1530 RI_APIENTRY EGLBoolean do_eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
  1414 #else
  1531 #else
  1415 EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
  1532 EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
  1416 #endif
  1533 #endif
  1417 	{
  1534 {
  1418 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1535 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1419 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1536 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1420 	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
  1537 	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
  1421 
  1538 
  1422 	display->removeSurface((RIEGLSurface*) surface);
  1539     display->removeSurface((RIEGLSurface*)surface);
  1423 	if (!((RIEGLSurface*) surface)->removeReference())
  1540 	if(!((RIEGLSurface*)surface)->removeReference())
  1424 		RI_DELETE((RIEGLSurface*)surface);
  1541 		RI_DELETE((RIEGLSurface*)surface);
  1425 
  1542 
  1426 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1543 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1427 	}
  1544 }
  1428 
  1545 
  1429 /*-------------------------------------------------------------------*//*!
  1546 /*-------------------------------------------------------------------*//*!
  1430  * \brief	
  1547 * \brief	
  1431  * \param	
  1548 * \param	
  1432  * \return	
  1549 * \return	
  1433  * \note		
  1550 * \note		
  1434  *//*-------------------------------------------------------------------*/
  1551 *//*-------------------------------------------------------------------*/
  1435 
  1552 
  1436 #ifdef BUILD_WITH_PRIVATE_EGL
  1553 #ifdef BUILD_WITH_PRIVATE_EGL
  1437 RI_APIENTRY EGLBoolean do_eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
  1554 RI_APIENTRY EGLBoolean do_eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
  1438 		EGLint attribute, EGLint value)
       
  1439 #else
  1555 #else
  1440 EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
  1556 EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
  1441 #endif
  1557 #endif
  1442 	{
  1558 {
  1443 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1559 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1444 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1560 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1445 	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
  1561 	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
  1446 	RI_UNREF(attribute);
  1562 	RI_UNREF(attribute);
  1447 	RI_UNREF(value);
  1563 	RI_UNREF(value);
  1448 	//do nothing
  1564 	//do nothing
  1449 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1565 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1450 	}
  1566 }
  1451 
  1567 
  1452 /*-------------------------------------------------------------------*//*!
  1568 /*-------------------------------------------------------------------*//*!
  1453  * \brief	
  1569 * \brief	
  1454  * \param	
  1570 * \param	
  1455  * \return	
  1571 * \return	
  1456  * \note		
  1572 * \note		
  1457  *//*-------------------------------------------------------------------*/
  1573 *//*-------------------------------------------------------------------*/
  1458 
  1574 
  1459 #ifdef BUILD_WITH_PRIVATE_EGL
  1575 #ifdef BUILD_WITH_PRIVATE_EGL
  1460 RI_APIENTRY EGLBoolean do_eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
  1576 RI_APIENTRY EGLBoolean do_eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
  1461 		EGLint attribute, EGLint *value)
       
  1462 #else
  1577 #else
  1463 EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
  1578 EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
  1464 #endif
  1579 #endif
  1465 	{
  1580 {
  1466 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1581 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1467 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1582 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1468 	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
  1583 	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
  1469 	//TODO give an error if value is NULL?
  1584 	//TODO give an error if value is NULL?
  1470 
  1585 
  1471 	RIEGLSurface* s = (RIEGLSurface*) surface;
  1586 	RIEGLSurface* s = (RIEGLSurface*)surface;
  1472 	switch (attribute)
  1587 	switch(attribute)
  1473 		{
  1588 	{
  1474 		case EGL_VG_ALPHA_FORMAT:
  1589 	case EGL_VG_ALPHA_FORMAT:
  1475 			*value
  1590 		*value = (s->getDrawable()->getDescriptor().isPremultiplied()) ? EGL_VG_ALPHA_FORMAT_PRE : EGL_VG_ALPHA_FORMAT_NONPRE;
  1476 					= (s->getDrawable()->getDescriptor().isPremultiplied()) ? EGL_VG_ALPHA_FORMAT_PRE
  1591 		break;
  1477 							: EGL_VG_ALPHA_FORMAT_NONPRE;
  1592 
  1478 			break;
  1593 	case EGL_VG_COLORSPACE:
  1479 
  1594 		*value = (s->getDrawable()->getDescriptor().isNonlinear()) ? EGL_VG_COLORSPACE_sRGB : EGL_VG_COLORSPACE_LINEAR;
  1480 		case EGL_VG_COLORSPACE:
  1595 		break;
  1481 			*value
  1596 
  1482 					= (s->getDrawable()->getDescriptor().isNonlinear()) ? EGL_VG_COLORSPACE_sRGB
  1597 	case EGL_CONFIG_ID:
  1483 							: EGL_VG_COLORSPACE_LINEAR;
  1598 		*value = display->getConfig(s->getConfig()).m_configID;
  1484 			break;
  1599 		break;
  1485 
  1600 
  1486 		case EGL_CONFIG_ID:
  1601 	case EGL_HEIGHT:
  1487 			*value = display->getConfig(s->getConfig()).m_configID;
  1602 		*value = s->getDrawable()->getHeight();
  1488 			break;
  1603 		break;
  1489 
  1604 
  1490 		case EGL_HEIGHT:
  1605 	case EGL_HORIZONTAL_RESOLUTION:
  1491 			*value = s->getDrawable()->getHeight();
  1606 		*value = EGL_UNKNOWN;			//TODO Horizontal dot pitch
  1492 			break;
  1607 		break;
  1493 
  1608 
  1494 		case EGL_HORIZONTAL_RESOLUTION:
  1609 	case EGL_LARGEST_PBUFFER:
  1495 			*value = EGL_UNKNOWN; //TODO Horizontal dot pitch
  1610 		if(!s->getOSWindowContext())
  1496 			break;
  1611 			*value = s->isLargestPbuffer() ? EGL_TRUE : EGL_FALSE;
  1497 
  1612 		break;
  1498 		case EGL_LARGEST_PBUFFER:
  1613 
  1499 			if (!s->getOSWindowContext())
  1614 	case EGL_MIPMAP_TEXTURE:
  1500 				*value = s->isLargestPbuffer() ? EGL_TRUE : EGL_FALSE;
  1615 		if(!s->getOSWindowContext())
  1501 			break;
  1616 			*value = EGL_FALSE;
  1502 
  1617 		break;
  1503 		case EGL_MIPMAP_TEXTURE:
  1618 
  1504 			if (!s->getOSWindowContext())
  1619 	case EGL_MIPMAP_LEVEL:
  1505 				*value = EGL_FALSE;
  1620 		if(!s->getOSWindowContext())
  1506 			break;
  1621 			*value = 0;
  1507 
  1622 		break;
  1508 		case EGL_MIPMAP_LEVEL:
  1623 
  1509 			if (!s->getOSWindowContext())
  1624 	case EGL_PIXEL_ASPECT_RATIO:
  1510 				*value = 0;
  1625 		*value = EGL_UNKNOWN;			//TODO Display aspect ratio
  1511 			break;
  1626 		break;
  1512 
  1627 
  1513 		case EGL_PIXEL_ASPECT_RATIO:
  1628 	case EGL_RENDER_BUFFER:
  1514 			*value = EGL_UNKNOWN; //TODO Display aspect ratio
  1629 		*value = s->getRenderBuffer();
  1515 			break;
  1630 		break;
  1516 
  1631 
  1517 		case EGL_RENDER_BUFFER:
  1632 	case EGL_SWAP_BEHAVIOR:
  1518 			*value = s->getRenderBuffer();
  1633 		*value = EGL_BUFFER_PRESERVED;
  1519 			break;
  1634 		break;
  1520 
  1635 
  1521 		case EGL_SWAP_BEHAVIOR:
  1636 	case EGL_TEXTURE_FORMAT:
  1522 			*value = EGL_BUFFER_PRESERVED;
  1637 		if(!s->getOSWindowContext())
  1523 			break;
  1638 			*value = EGL_NO_TEXTURE;
  1524 
  1639 		break;
  1525 		case EGL_TEXTURE_FORMAT:
  1640 
  1526 			if (!s->getOSWindowContext())
  1641 	case EGL_TEXTURE_TARGET:
  1527 				*value = EGL_NO_TEXTURE;
  1642 		if(!s->getOSWindowContext())
  1528 			break;
  1643 			*value = EGL_NO_TEXTURE;
  1529 
  1644 		break;
  1530 		case EGL_TEXTURE_TARGET:
  1645 
  1531 			if (!s->getOSWindowContext())
  1646 	case EGL_VERTICAL_RESOLUTION:
  1532 				*value = EGL_NO_TEXTURE;
  1647 		*value = EGL_UNKNOWN;			//TODO Vertical dot pitch
  1533 			break;
  1648 		break;
  1534 
  1649 
  1535 		case EGL_VERTICAL_RESOLUTION:
  1650 	case EGL_WIDTH:
  1536 			*value = EGL_UNKNOWN; //TODO Vertical dot pitch
  1651 		*value = s->getDrawable()->getWidth();
  1537 			break;
  1652 		break;
  1538 
  1653 
  1539 		case EGL_WIDTH:
  1654 	default:
  1540 			*value = s->getDrawable()->getWidth();
  1655 		EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE);
  1541 			break;
  1656 	}
  1542 
       
  1543 		default:
       
  1544 			EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE)
       
  1545 			;
       
  1546 		}
       
  1547 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1657 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1548 	}
  1658 }
  1549 
  1659 
  1550 /*-------------------------------------------------------------------*//*!
  1660 /*-------------------------------------------------------------------*//*!
  1551  * \brief	
  1661 * \brief	
  1552  * \param	
  1662 * \param	
  1553  * \return	
  1663 * \return	
  1554  * \note		
  1664 * \note		
  1555  *//*-------------------------------------------------------------------*/
  1665 *//*-------------------------------------------------------------------*/
  1556 
  1666 
  1557 #ifdef BUILD_WITH_PRIVATE_EGL
  1667 #ifdef BUILD_WITH_PRIVATE_EGL
  1558 RI_APIENTRY EGLContext do_eglCreateContext(EGLDisplay dpy, EGLConfig config,
  1668 RI_APIENTRY EGLContext do_eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
  1559 		EGLContext share_context, const EGLint *attrib_list)
       
  1560 #else
  1669 #else
  1561 EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
  1670 EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
  1562 #endif
  1671 #endif
  1563 	{
  1672 {
  1564 	EGL_GET_DISPLAY(dpy, EGL_NO_CONTEXT);
  1673 	EGL_GET_DISPLAY(dpy, EGL_NO_CONTEXT);
  1565 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_CONTEXT);
  1674 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_CONTEXT);
  1566 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_CONTEXT);
  1675 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_CONTEXT);
  1567 	RI_UNREF(attrib_list);
  1676 	RI_UNREF(attrib_list);
  1568 
  1677 
  1569 	RIEGLThread* thread = egl->getThread();
  1678 	RIEGLThread* thread = egl->getThread();
  1570 	if (!thread)
  1679 	if(!thread)
  1571 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
  1680 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
  1572 
  1681 
  1573 	//creation of OpenGL ES contexts is not allowed in this implementation
  1682 	//creation of OpenGL ES contexts is not allowed in this implementation
  1574 	if (thread->getBoundAPI() != EGL_OPENVG_API)
  1683 	if(thread->getBoundAPI() != EGL_OPENVG_API)
  1575 		EGL_RETURN(EGL_BAD_MATCH, EGL_NO_CONTEXT);
  1684 		EGL_RETURN(EGL_BAD_MATCH, EGL_NO_CONTEXT);
  1576 
  1685 
  1577 	OpenVGRI::VGContext* vgctx = NULL;
  1686     OpenVGRI::VGContext* vgctx = NULL;
  1578 	RIEGLContext* c = NULL;
  1687 	RIEGLContext* c = NULL;
  1579 	try
  1688 	try
  1580 		{
  1689 	{
  1581 		vgctx
  1690 		vgctx = RI_NEW(OpenVGRI::VGContext, (share_context ? ((RIEGLContext*)share_context)->getVGContext() : NULL));	//throws bad_alloc
  1582 				= RI_NEW(OpenVGRI::VGContext, (share_context ? ((RIEGLContext*)share_context)->getVGContext() : NULL)); //throws bad_alloc
  1691 		c = RI_NEW(RIEGLContext, (vgctx, config));	//throws bad_alloc
  1583 		c = RI_NEW(RIEGLContext, (vgctx, config)); //throws bad_alloc
       
  1584 		
       
  1585 		RDebug::Printf(" ---------------------------- In eglCreateContext,VGContext addr is %x  $$$$$$$$$$$$$ ",vgctx);
       
  1586 		RDebug::Printf(" ---------------------------- In eglCreateContext,RIEGLContext addr is %x  $$$$$$$$$$$$$ ",c);
       
  1587 		c->addReference();
  1692 		c->addReference();
  1588 		display->addContext(c); //throws bad_alloc
  1693 		display->addContext(c);	//throws bad_alloc
  1589 		}
  1694 	}
  1590 	catch (std::bad_alloc)
  1695 	catch(std::bad_alloc)
  1591 		{
  1696 	{
  1592 		RI_DELETE(vgctx);
  1697         RI_DELETE(vgctx);
  1593 		RI_DELETE(c);
  1698         RI_DELETE(c);
  1594 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
  1699 		EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
  1595 		}
  1700 	}
  1596 
  1701 
  1597 	EGL_RETURN(EGL_SUCCESS, (EGLContext)c);
  1702 	EGL_RETURN(EGL_SUCCESS, (EGLContext)c);
  1598 	}
  1703 }
  1599 
  1704 
  1600 /*-------------------------------------------------------------------*//*!
  1705 /*-------------------------------------------------------------------*//*!
  1601  * \brief	
  1706 * \brief	
  1602  * \param	
  1707 * \param	
  1603  * \return	
  1708 * \return	
  1604  * \note		
  1709 * \note		
  1605  *//*-------------------------------------------------------------------*/
  1710 *//*-------------------------------------------------------------------*/
  1606 
  1711 
  1607 #ifdef BUILD_WITH_PRIVATE_EGL
  1712 #ifdef BUILD_WITH_PRIVATE_EGL
  1608 RI_APIENTRY EGLBoolean do_eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
  1713 RI_APIENTRY EGLBoolean do_eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
  1609 #else
  1714 #else
  1610 EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
  1715 EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
  1611 #endif
  1716 #endif
  1612 	{
  1717 {
  1613 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1718 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1614 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1719 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1615 	EGL_IF_ERROR(!display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
  1720 	EGL_IF_ERROR(!display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
  1616 
  1721 
  1617 	RIEGLContext* context = (RIEGLContext*) ctx;
  1722 	RIEGLContext* context = (RIEGLContext*)ctx;
  1618 	display->removeContext(context);
  1723     display->removeContext(context);
  1619 	if (!context->removeReference())
  1724 	if(!context->removeReference() )
  1620 		RI_DELETE(context);
  1725 		RI_DELETE(context);
  1621 
  1726 
  1622 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1727 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1623 	}
  1728 }
  1624 
  1729 
  1625 /*-------------------------------------------------------------------*//*!
  1730 /*-------------------------------------------------------------------*//*!
  1626  * \brief	
  1731 * \brief	
  1627  * \param	
  1732 * \param	
  1628  * \return	
  1733 * \return	
  1629  * \note		
  1734 * \note		
  1630  *//*-------------------------------------------------------------------*/
  1735 *//*-------------------------------------------------------------------*/
  1631 
  1736 
  1632 #ifdef BUILD_WITH_PRIVATE_EGL
  1737 #ifdef BUILD_WITH_PRIVATE_EGL
  1633 RI_APIENTRY EGLBoolean do_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw,
  1738 RI_APIENTRY EGLBoolean do_eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
  1634 		EGLSurface read, EGLContext ctx)
       
  1635 #else
  1739 #else
  1636 EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
  1740 EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
  1637 #endif
  1741 #endif
  1638 	{
  1742 {
  1639 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1743 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1640 	EGL_IF_ERROR(ctx != EGL_NO_CONTEXT && !display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
  1744 	EGL_IF_ERROR(ctx != EGL_NO_CONTEXT && !display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
  1641 	EGL_IF_ERROR(draw != EGL_NO_SURFACE && !display->surfaceExists(draw), EGL_BAD_SURFACE, EGL_FALSE);
  1745 	EGL_IF_ERROR(draw != EGL_NO_SURFACE && !display->surfaceExists(draw), EGL_BAD_SURFACE, EGL_FALSE);
  1642 	EGL_IF_ERROR(read != EGL_NO_SURFACE && !display->surfaceExists(read), EGL_BAD_SURFACE, EGL_FALSE);
  1746 	EGL_IF_ERROR(read != EGL_NO_SURFACE && !display->surfaceExists(read), EGL_BAD_SURFACE, EGL_FALSE);
  1643 	EGL_IF_ERROR(draw != read, EGL_BAD_MATCH, EGL_FALSE); //TODO what's the proper error code?
  1747 	EGL_IF_ERROR(draw != read, EGL_BAD_MATCH, EGL_FALSE);	//TODO what's the proper error code?
  1644 	EGL_IF_ERROR((draw != EGL_NO_SURFACE && ctx == EGL_NO_CONTEXT) || (draw == EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT), EGL_BAD_MATCH, EGL_FALSE);
  1748 	EGL_IF_ERROR((draw != EGL_NO_SURFACE && ctx == EGL_NO_CONTEXT) || (draw == EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT), EGL_BAD_MATCH, EGL_FALSE);
  1645 
  1749 
  1646 	RIEGLSurface* s = NULL;
  1750 	RIEGLSurface* s = NULL;
  1647 	RIEGLContext* c = NULL;
  1751 	RIEGLContext* c = NULL;
  1648 	if (draw != EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT)
  1752 	if(draw != EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT)
  1649 		{
  1753 	{
  1650 		EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1754 		EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1651 
  1755 
  1652 		s = (RIEGLSurface*) draw;
  1756 		s = (RIEGLSurface*)draw;
  1653 		c = (RIEGLContext*) ctx;
  1757 		c = (RIEGLContext*)ctx;
  1654 
  1758 
  1655 		//If either draw or read are pbuffers created with eglCreatePbufferFromClientBuffer, and the underlying bound client API buffers
  1759         //If either draw or read are pbuffers created with eglCreatePbufferFromClientBuffer, and the underlying bound client API buffers
  1656 		//are in use by the client API that created them, an EGL BAD ACCESS error is generated.
  1760         //are in use by the client API that created them, an EGL BAD ACCESS error is generated.
  1657 		EGL_IF_ERROR(s->getDrawable()->isInUse(), EGL_BAD_ACCESS, EGL_FALSE);
  1761 		EGL_IF_ERROR(s->getDrawable()->isInUse(), EGL_BAD_ACCESS, EGL_FALSE);
       
  1762 
  1658 
  1763 
  1659 		//TODO properly check compatibility of surface and context:
  1764 		//TODO properly check compatibility of surface and context:
  1660 		//-both have RGB or LUMINANCE configs
  1765 		//-both have RGB or LUMINANCE configs
  1661 		//-buffer bit depths match
  1766 		//-buffer bit depths match
  1662 		//-configs support OpenVG
  1767 		//-configs support OpenVG
  1663 		//-both have the same display
  1768 		//-both have the same display
  1664 		EGL_IF_ERROR(s->getConfig() != c->getConfig(), EGL_BAD_MATCH, EGL_FALSE);
  1769 		EGL_IF_ERROR(s->getConfig() != c->getConfig(), EGL_BAD_MATCH, EGL_FALSE);
  1665 		//TODO check if context or surfaces are already bound to another thread
  1770 		//TODO check if context or surfaces are already bound to another thread
  1666 
  1771 
  1667 		//If a native window underlying either draw or read is no longer valid, an EGL BAD NATIVE WINDOW error is generated.
  1772 		//If a native window underlying either draw or read is no longer valid, an EGL BAD NATIVE WINDOW error is generated.
  1668 		EGL_IF_ERROR(s->getOSWindowContext() && !OSIsWindow(s->getOSWindowContext()), EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
  1773         EGL_IF_ERROR(s->getOSWindowContext() && !OSIsWindow(s->getOSWindowContext()), EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
  1669 
  1774 
  1670 		//TODO If the previous context of the calling display has unflushed commands, and the previous surface is no longer valid, an EGL BAD CURRENT SURFACE error is generated. (can this happen?)
  1775 		//TODO If the previous context of the calling display has unflushed commands, and the previous surface is no longer valid, an EGL BAD CURRENT SURFACE error is generated. (can this happen?)
  1671 		//TODO If the ancillary buffers for draw and read cannot be allocated, an EGL BAD ALLOC error is generated. (mask buffer?)
  1776 		//TODO If the ancillary buffers for draw and read cannot be allocated, an EGL BAD ALLOC error is generated. (mask buffer?)
  1672 		}
  1777 	}
  1673 
  1778 
  1674 	//check if the thread is current
  1779 	//check if the thread is current
  1675 	RIEGLThread* thread = egl->getCurrentThread();
  1780 	RIEGLThread* thread = egl->getCurrentThread();
  1676 	if (thread)
  1781 	if(thread)
  1677 		{ //thread is current, release the old bindinds and remove the thread from the current thread list
  1782 	{	//thread is current, release the old bindinds and remove the thread from the current thread list
  1678 		RIEGLContext* pc = thread->getCurrentContext();
  1783 		RIEGLContext* pc = thread->getCurrentContext();
  1679 		RIEGLSurface* ps = thread->getCurrentSurface();
  1784 		RIEGLSurface* ps = thread->getCurrentSurface();
  1680 		if (pc)
  1785 		if(pc)
  1681 			{
  1786 		{
  1682 #ifdef BUILD_WITH_PRIVATE_OPENVG
  1787 #ifdef BUILD_WITH_PRIVATE_OPENVG
  1683 			do_vgFlush();
  1788 			do_vgFlush();
  1684 #else
  1789 #else
  1685 			vgFlush();
  1790 			vgFlush();
  1686 #endif
  1791 #endif
  1687 			pc->getVGContext()->setDefaultDrawable(NULL);
  1792 			pc->getVGContext()->setDefaultDrawable(NULL);
  1688 			if (!pc->removeReference())
  1793 			if(!pc->removeReference())
  1689 				RI_DELETE(pc);
  1794 				RI_DELETE(pc);
  1690 			}
  1795 		}
  1691 		if (ps)
  1796 		if(ps)
  1692 			{
  1797 		{
  1693 			if (!ps->removeReference())
  1798 			if(!ps->removeReference())
  1694 				RI_DELETE(ps);
  1799 				RI_DELETE(ps);
  1695 			}
       
  1696 
       
  1697 		egl->removeCurrentThread(thread);
       
  1698 		}
  1800 		}
  1699 
  1801 
  1700 	if (c && s)
  1802         egl->removeCurrentThread(thread);
  1701 		{
  1803 	}
       
  1804 
       
  1805 	if( c && s )
       
  1806 	{
  1702 		//bind context and surface to the current display
  1807 		//bind context and surface to the current display
  1703 		RIEGLThread* newThread = egl->getThread();
  1808 		RIEGLThread* newThread = egl->getThread();
  1704 		if (!newThread)
  1809 		if(!newThread)
  1705 			EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
  1810 			EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
  1706 		newThread->makeCurrent(c, s);
  1811         newThread->makeCurrent(c, s);
  1707 		Drawable* temp = s->getDrawable();
       
  1708 		RDebug::Printf(" ------------------------------ In Drawable* temp,Drawable addr is %x  $$$$$$$$$$$$$ ",temp);
       
  1709 		c->getVGContext()->setDefaultDrawable(s->getDrawable());
  1812 		c->getVGContext()->setDefaultDrawable(s->getDrawable());
  1710 
  1813 
  1711 		try
  1814 		try
  1712 			{
  1815 		{
  1713 			egl->addCurrentThread(newThread); //throws bad_alloc
  1816 			egl->addCurrentThread(newThread);	//throws bad_alloc
  1714 			}
  1817 		}
  1715 		catch (std::bad_alloc)
  1818 		catch(std::bad_alloc)
  1716 			{
  1819 		{
  1717 			EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
  1820 			EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
  1718 			}
  1821 		}
  1719 
  1822 
  1720 		c->addReference();
  1823 		c->addReference();
  1721 		s->addReference();
  1824 		s->addReference();
  1722 		}
  1825 	}
  1723 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1826 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1724 	}
  1827 }
  1725 
  1828 
  1726 /*-------------------------------------------------------------------*//*!
  1829 /*-------------------------------------------------------------------*//*!
  1727  * \brief	
  1830 * \brief	
  1728  * \param	
  1831 * \param	
  1729  * \return	
  1832 * \return	
  1730  * \note		
  1833 * \note		
  1731  *//*-------------------------------------------------------------------*/
  1834 *//*-------------------------------------------------------------------*/
  1732 
  1835 
  1733 #ifdef BUILD_WITH_PRIVATE_EGL
  1836 #ifdef BUILD_WITH_PRIVATE_EGL
  1734 RI_APIENTRY EGLContext do_eglGetCurrentContext()
  1837 RI_APIENTRY EGLContext do_eglGetCurrentContext()
  1735 #else
  1838 #else
  1736 EGLContext eglGetCurrentContext()
  1839 EGLContext eglGetCurrentContext()
  1737 #endif
  1840 #endif
  1738 	{
  1841 {
  1739 	EGL_GET_EGL(EGL_NO_CONTEXT);
  1842     EGL_GET_EGL(EGL_NO_CONTEXT);
  1740 	EGLContext ret = EGL_NO_CONTEXT;
  1843 	EGLContext ret = EGL_NO_CONTEXT;
  1741 	RIEGLThread* thread = egl->getCurrentThread();
  1844 	RIEGLThread* thread = egl->getCurrentThread();
  1742 	if (thread && thread->getBoundAPI() == EGL_OPENVG_API)
  1845 	if(thread && thread->getBoundAPI() == EGL_OPENVG_API)
  1743 		{
  1846     {
  1744 		ret = CastFromRIEGLContext(thread->getCurrentContext());
  1847         ret = CastFromRIEGLContext(thread->getCurrentContext());
  1745 		RI_ASSERT(ret);
  1848         RI_ASSERT(ret);
  1746 		}
  1849     }
  1747 	EGL_RETURN(EGL_SUCCESS, ret);
  1850 	EGL_RETURN(EGL_SUCCESS, ret);
  1748 	}
  1851 }
  1749 
  1852 
  1750 /*-------------------------------------------------------------------*//*!
  1853 /*-------------------------------------------------------------------*//*!
  1751  * \brief	
  1854 * \brief	
  1752  * \param	
  1855 * \param	
  1753  * \return	
  1856 * \return	
  1754  * \note		
  1857 * \note		
  1755  *//*-------------------------------------------------------------------*/
  1858 *//*-------------------------------------------------------------------*/
  1756 
  1859 
  1757 #ifdef BUILD_WITH_PRIVATE_EGL
  1860 #ifdef BUILD_WITH_PRIVATE_EGL
  1758 RI_APIENTRY EGLSurface do_eglGetCurrentSurface(EGLint readdraw)
  1861 RI_APIENTRY EGLSurface do_eglGetCurrentSurface(EGLint readdraw)
  1759 #else
  1862 #else
  1760 EGLSurface eglGetCurrentSurface(EGLint readdraw)
  1863 EGLSurface eglGetCurrentSurface(EGLint readdraw)
  1761 #endif
  1864 #endif
  1762 	{
  1865 {
  1763 	EGL_GET_EGL(EGL_NO_SURFACE);
  1866     EGL_GET_EGL(EGL_NO_SURFACE);
  1764 	EGL_IF_ERROR(readdraw != EGL_READ && readdraw != EGL_DRAW, EGL_BAD_PARAMETER, EGL_NO_SURFACE);
  1867 	EGL_IF_ERROR(readdraw != EGL_READ && readdraw != EGL_DRAW, EGL_BAD_PARAMETER, EGL_NO_SURFACE);
  1765 	EGLContext ret = EGL_NO_SURFACE;
  1868 	EGLContext ret = EGL_NO_SURFACE;
  1766 	RIEGLThread* thread = egl->getCurrentThread();
  1869 	RIEGLThread* thread = egl->getCurrentThread();
  1767 	if (thread && thread->getBoundAPI() == EGL_OPENVG_API)
  1870 	if(thread && thread->getBoundAPI() == EGL_OPENVG_API)
  1768 		{
  1871     {
  1769 		ret = OpenVGRI::CastFromRIEGLSurface(thread->getCurrentSurface());
  1872         ret = CastFromRIEGLSurface(thread->getCurrentSurface());
  1770 		RI_ASSERT(ret);
  1873         RI_ASSERT(ret);
  1771 		}
  1874     }
  1772 	EGL_RETURN(EGL_SUCCESS, ret);
  1875 	EGL_RETURN(EGL_SUCCESS, ret);
  1773 	}
  1876 }
  1774 
  1877 
  1775 /*-------------------------------------------------------------------*//*!
  1878 /*-------------------------------------------------------------------*//*!
  1776  * \brief	Returns the current display
  1879 * \brief	Returns the current display
  1777  * \param	
  1880 * \param	
  1778  * \return	
  1881 * \return	
  1779  * \note		
  1882 * \note		
  1780  *//*-------------------------------------------------------------------*/
  1883 *//*-------------------------------------------------------------------*/
  1781 
  1884 
  1782 #ifdef BUILD_WITH_PRIVATE_EGL
  1885 #ifdef BUILD_WITH_PRIVATE_EGL
  1783 RI_APIENTRY EGLDisplay do_eglGetCurrentDisplay(void)
  1886 RI_APIENTRY EGLDisplay do_eglGetCurrentDisplay(void)
  1784 #else
  1887 #else
  1785 EGLDisplay eglGetCurrentDisplay(void)
  1888 EGLDisplay eglGetCurrentDisplay(void)
  1786 #endif
  1889 #endif
  1787 	{
  1890 {
  1788 	EGL_GET_EGL(EGL_NO_DISPLAY);
  1891     EGL_GET_EGL(EGL_NO_DISPLAY);
  1789 
  1892 
  1790 	RIEGLThread* thread = egl->getCurrentThread();
  1893 	RIEGLThread* thread = egl->getCurrentThread();
  1791 	if (!thread || thread->getBoundAPI() != EGL_OPENVG_API)
  1894 	if(!thread || thread->getBoundAPI() != EGL_OPENVG_API)
  1792 		EGL_RETURN(EGL_SUCCESS, EGL_NO_DISPLAY);
  1895 		EGL_RETURN(EGL_SUCCESS, EGL_NO_DISPLAY);
  1793 
  1896 
  1794 	RIEGLContext* ctx = thread->getCurrentContext();
  1897 	RIEGLContext* ctx = thread->getCurrentContext();
  1795 	RI_ASSERT(ctx);
  1898     RI_ASSERT(ctx);
  1796 	EGLDisplay ret = egl->findDisplay(OpenVGRI::CastFromRIEGLContext(ctx));
  1899     EGLDisplay ret = egl->findDisplay(CastFromRIEGLContext(ctx));
  1797 	EGL_RETURN(EGL_SUCCESS, ret);
  1900 	EGL_RETURN(EGL_SUCCESS, ret);
  1798 	}
  1901 }
  1799 
  1902 
  1800 /*-------------------------------------------------------------------*//*!
  1903 /*-------------------------------------------------------------------*//*!
  1801  * \brief	
  1904 * \brief	
  1802  * \param	
  1905 * \param	
  1803  * \return	
  1906 * \return	
  1804  * \note		
  1907 * \note		
  1805  *//*-------------------------------------------------------------------*/
  1908 *//*-------------------------------------------------------------------*/
  1806 
  1909 
  1807 #ifdef BUILD_WITH_PRIVATE_EGL
  1910 #ifdef BUILD_WITH_PRIVATE_EGL
  1808 RI_APIENTRY EGLBoolean do_eglQueryContext(EGLDisplay dpy, EGLContext ctx,
  1911 RI_APIENTRY EGLBoolean do_eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value)
  1809 		EGLint attribute, EGLint* value)
       
  1810 #else
  1912 #else
  1811 EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value)
  1913 EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value)
  1812 #endif
  1914 #endif
  1813 	{
  1915 {
  1814 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1916 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1815 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1917 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1816 	EGL_IF_ERROR(!display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
  1918 	EGL_IF_ERROR(!display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
  1817 	EGL_IF_ERROR(attribute != EGL_CONFIG_ID && attribute != EGL_CONTEXT_CLIENT_TYPE, EGL_BAD_ATTRIBUTE, EGL_FALSE);
  1919 	EGL_IF_ERROR(attribute != EGL_CONFIG_ID && attribute != EGL_CONTEXT_CLIENT_TYPE, EGL_BAD_ATTRIBUTE, EGL_FALSE);
  1818 	if (attribute == EGL_CONFIG_ID)
  1920 	if(attribute == EGL_CONFIG_ID)
  1819 		*value
  1921 		*value = display->getConfig(((RIEGLContext*)ctx)->getConfig()).m_configID;
  1820 				= display->getConfig(((RIEGLContext*) ctx)->getConfig()).m_configID;
  1922 	if(attribute == EGL_CONTEXT_CLIENT_TYPE)
  1821 	if (attribute == EGL_CONTEXT_CLIENT_TYPE)
       
  1822 		*value = EGL_OPENVG_API;
  1923 		*value = EGL_OPENVG_API;
  1823 	// \todo [kalle 05/Jul/05] Handling of EGL_RENDER_BUFFER attribute is missing.
  1924 	// \todo [kalle 05/Jul/05] Handling of EGL_RENDER_BUFFER attribute is missing.
  1824 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1925 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1825 	}
  1926 }
  1826 
  1927 
  1827 /*-------------------------------------------------------------------*//*!
  1928 /*-------------------------------------------------------------------*//*!
  1828  * \brief	
  1929 * \brief	
  1829  * \param	
  1930 * \param	
  1830  * \return	
  1931 * \return	
  1831  * \note		
  1932 * \note		
  1832  *//*-------------------------------------------------------------------*/
  1933 *//*-------------------------------------------------------------------*/
  1833 
  1934 
  1834 #ifdef BUILD_WITH_PRIVATE_EGL
  1935 #ifdef BUILD_WITH_PRIVATE_EGL
  1835 RI_APIENTRY EGLBoolean do_eglBindAPI(EGLenum api)
  1936 RI_APIENTRY EGLBoolean do_eglBindAPI(EGLenum api)
  1836 #else
  1937 #else
  1837 EGLBoolean eglBindAPI(EGLenum api)
  1938 EGLBoolean eglBindAPI(EGLenum api)
  1838 #endif
  1939 #endif
  1839 	{
  1940 {
  1840 	EGL_GET_EGL(EGL_FALSE);
  1941     EGL_GET_EGL(EGL_FALSE);
  1841 	EGL_IF_ERROR(api != EGL_OPENVG_API && api != EGL_OPENGL_ES_API, EGL_BAD_PARAMETER, EGL_FALSE);
  1942 	EGL_IF_ERROR(api != EGL_OPENVG_API && api != EGL_OPENGL_ES_API, EGL_BAD_PARAMETER, EGL_FALSE);
  1842 	RIEGLThread* thread = egl->getThread();
  1943 	RIEGLThread* thread = egl->getThread();
  1843 	if (thread)
  1944 	if(thread)
  1844 		thread->bindAPI(api);
  1945 		thread->bindAPI(api);
  1845 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1946 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1846 	}
  1947 }
  1847 
  1948 
  1848 /*-------------------------------------------------------------------*//*!
  1949 /*-------------------------------------------------------------------*//*!
  1849  * \brief	
  1950 * \brief	
  1850  * \param	
  1951 * \param	
  1851  * \return	
  1952 * \return	
  1852  * \note		
  1953 * \note		
  1853  *//*-------------------------------------------------------------------*/
  1954 *//*-------------------------------------------------------------------*/
  1854 
  1955 
  1855 #ifdef BUILD_WITH_PRIVATE_EGL
  1956 #ifdef BUILD_WITH_PRIVATE_EGL
  1856 RI_APIENTRY EGLenum do_eglQueryAPI(void)
  1957 RI_APIENTRY EGLenum do_eglQueryAPI(void)
  1857 #else
  1958 #else
  1858 EGLenum eglQueryAPI(void)
  1959 EGLenum eglQueryAPI(void)
  1859 #endif
  1960 #endif
  1860 	{
  1961 {
  1861 	EGL_GET_EGL(EGL_NONE);
  1962     EGL_GET_EGL(EGL_NONE);
  1862 	RIEGLThread* thread = egl->getThread();
  1963 	RIEGLThread* thread = egl->getThread();
  1863 	if (thread)
  1964 	if(thread)
  1864 		EGL_RETURN(EGL_SUCCESS, thread->getBoundAPI());
  1965 		EGL_RETURN(EGL_SUCCESS, thread->getBoundAPI());
  1865 	EGL_RETURN(EGL_SUCCESS, EGL_NONE);
  1966 	EGL_RETURN(EGL_SUCCESS, EGL_NONE);
  1866 	}
  1967 }
  1867 
  1968 
  1868 /*-------------------------------------------------------------------*//*!
  1969 /*-------------------------------------------------------------------*//*!
  1869  * \brief	
  1970 * \brief	
  1870  * \param	
  1971 * \param	
  1871  * \return	
  1972 * \return	
  1872  * \note		
  1973 * \note		
  1873  *//*-------------------------------------------------------------------*/
  1974 *//*-------------------------------------------------------------------*/
  1874 
  1975 
  1875 #ifdef BUILD_WITH_PRIVATE_EGL
  1976 #ifdef BUILD_WITH_PRIVATE_EGL
  1876 RI_APIENTRY EGLBoolean do_eglWaitClient()
  1977 RI_APIENTRY EGLBoolean do_eglWaitClient()
  1877 #else
  1978 #else
  1878 EGLBoolean eglWaitClient()
  1979 EGLBoolean eglWaitClient()
  1879 #endif
  1980 #endif
  1880 	{
  1981 {
  1881 	EGL_GET_EGL(EGL_FALSE);
  1982     EGL_GET_EGL(EGL_FALSE);
  1882 	RIEGLThread* thread = egl->getCurrentThread();
  1983 	RIEGLThread* thread = egl->getCurrentThread();
  1883 	if (thread && thread->getBoundAPI() == EGL_OPENVG_API)
  1984 	if(thread && thread->getBoundAPI() == EGL_OPENVG_API)
  1884 #ifdef BUILD_WITH_PRIVATE_OPENVG
  1985 #ifdef BUILD_WITH_PRIVATE_OPENVG
  1885 		do_vgFinish();
  1986 		do_vgFlush();
  1886 #else
  1987 #else
  1887 		vgFinish();
  1988 		vgFinish();
  1888 #endif
  1989 #endif
  1889 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1990 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1890 	}
  1991 }
  1891 
  1992 
  1892 /*-------------------------------------------------------------------*//*!
  1993 /*-------------------------------------------------------------------*//*!
  1893  * \brief	Waits for OpenGL ES
  1994 * \brief	Waits for OpenGL ES
  1894  * \param	
  1995 * \param	
  1895  * \return	
  1996 * \return	
  1896  * \note		
  1997 * \note		
  1897  *//*-------------------------------------------------------------------*/
  1998 *//*-------------------------------------------------------------------*/
  1898 
  1999 
  1899 #ifdef BUILD_WITH_PRIVATE_EGL
  2000 #ifdef BUILD_WITH_PRIVATE_EGL
  1900 RI_APIENTRY EGLBoolean do_eglWaitGL(void)
  2001 RI_APIENTRY EGLBoolean do_eglWaitGL(void)
  1901 #else
  2002 #else
  1902 EGLBoolean eglWaitGL(void)
  2003 EGLBoolean eglWaitGL(void)
  1903 #endif
  2004 #endif
  1904 	{
  2005 {
  1905 	return EGL_TRUE;
  2006 	return EGL_TRUE;
  1906 	}
  2007 }
  1907 
  2008 
  1908 /*-------------------------------------------------------------------*//*!
  2009 /*-------------------------------------------------------------------*//*!
  1909  * \brief	
  2010 * \brief	
  1910  * \param	
  2011 * \param	
  1911  * \return	
  2012 * \return	
  1912  * \note		We don't support native rendering
  2013 * \note		We don't support native rendering
  1913  *//*-------------------------------------------------------------------*/
  2014 *//*-------------------------------------------------------------------*/
  1914 
  2015 
  1915 #ifdef BUILD_WITH_PRIVATE_EGL
  2016 #ifdef BUILD_WITH_PRIVATE_EGL
  1916 RI_APIENTRY EGLBoolean do_eglWaitNative(EGLint engine)
  2017 RI_APIENTRY EGLBoolean do_eglWaitNative(EGLint engine)
  1917 #else
  2018 #else
  1918 EGLBoolean eglWaitNative(EGLint engine)
  2019 EGLBoolean eglWaitNative(EGLint engine)
  1919 #endif
  2020 #endif
  1920 	{
  2021 {
  1921 	RI_UNREF(engine);
  2022 	RI_UNREF(engine);
  1922 	return EGL_TRUE;
  2023 	return EGL_TRUE;
  1923 	}
  2024 }
  1924 
  2025 
  1925 /*-------------------------------------------------------------------*//*!
  2026 /*-------------------------------------------------------------------*//*!
  1926  * \brief	
  2027 * \brief	
  1927  * \param	
  2028 * \param	
  1928  * \return	
  2029 * \return	
  1929  * \note		
  2030 * \note		
  1930  *//*-------------------------------------------------------------------*/
  2031 *//*-------------------------------------------------------------------*/
  1931 
  2032 
  1932 #ifdef BUILD_WITH_PRIVATE_EGL
  2033 #ifdef BUILD_WITH_PRIVATE_EGL
  1933 RI_APIENTRY EGLBoolean do_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
  2034 RI_APIENTRY EGLBoolean do_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
  1934 #else
  2035 #else
  1935 EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
  2036 EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
  1936 #endif
  2037 #endif
  1937 	{
  2038 {
  1938 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  2039 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1939 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  2040 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1940 	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
  2041 	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
  1941 
  2042 
  1942 	RIEGLSurface* s = (RIEGLSurface*) surface;
  2043 	RIEGLSurface* s = (RIEGLSurface*)surface;
  1943 
  2044 
  1944 	RIEGLThread* currentThread = egl->getCurrentThread();
  2045 	RIEGLThread* currentThread = egl->getCurrentThread();
  1945 	EGL_IF_ERROR(!currentThread || currentThread->getCurrentSurface() != s, EGL_BAD_SURFACE, EGL_FALSE);
  2046 	EGL_IF_ERROR(!currentThread || currentThread->getCurrentSurface() != s, EGL_BAD_SURFACE, EGL_FALSE);
  1946 	EGL_IF_ERROR(!OSIsWindow(s->getOSWindowContext()), EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
  2047 	EGL_IF_ERROR(!OSIsWindow(s->getOSWindowContext()), EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
  1947 
  2048 
  1949 	do_vgFlush();
  2050 	do_vgFlush();
  1950 #else
  2051 #else
  1951 	vgFlush();
  2052 	vgFlush();
  1952 #endif
  2053 #endif
  1953 
  2054 
  1954 	if (!s->getOSWindowContext())
  2055 	if(!s->getOSWindowContext())
  1955 		{ //do nothing for other than window surfaces (NOTE: single-buffered window surfaces should return immediately as well)
  2056 	{	//do nothing for other than window surfaces (NOTE: single-buffered window surfaces should return immediately as well)
  1956 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  2057 		EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1957 		}
  2058 	}
  1958 
  2059 
  1959 	int windowWidth = 0, windowHeight = 0;
  2060 	int windowWidth = 0, windowHeight = 0;
  1960 	OSGetWindowSize(s->getOSWindowContext(), windowWidth, windowHeight);
  2061     OSGetWindowSize(s->getOSWindowContext(), windowWidth, windowHeight);
  1961 
  2062 
  1962 	if (windowWidth != s->getDrawable()->getWidth() || windowHeight
  2063 	if(windowWidth != s->getDrawable()->getWidth() || windowHeight != s->getDrawable()->getHeight())
  1963 			!= s->getDrawable()->getHeight())
  2064 	{	//resize the back buffer
  1964 		{ //resize the back buffer
       
  1965 		RIEGLContext* c = currentThread->getCurrentContext();
  2065 		RIEGLContext* c = currentThread->getCurrentContext();
  1966 		RI_ASSERT(c);
  2066 		RI_ASSERT(c);
  1967 		try
  2067 		try
  1968 			{
  2068 		{
  1969 			s->getDrawable()->resize(windowWidth, windowHeight); //throws bad_alloc
  2069 			s->getDrawable()->resize(windowWidth, windowHeight);	//throws bad_alloc
  1970 			}
  2070 		}
  1971 		catch (std::bad_alloc)
  2071 		catch(std::bad_alloc)
  1972 			{
  2072 		{
  1973 			c->getVGContext()->setDefaultDrawable(NULL);
  2073 			c->getVGContext()->setDefaultDrawable(NULL);
  1974 			EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
  2074 			EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
  1975 			}
       
  1976 		}
  2075 		}
  1977 
  2076 	}
  1978 	OSBlitToWindow(s->getOSWindowContext(), s->getDrawable());
  2077 
       
  2078     OSBlitToWindow(s->getOSWindowContext(), s->getDrawable());
  1979 
  2079 
  1980 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  2080 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  1981 	}
  2081 }
  1982 
  2082 
  1983 /*-------------------------------------------------------------------*//*!
  2083 /*-------------------------------------------------------------------*//*!
  1984  * \brief	
  2084 * \brief	
  1985  * \param	
  2085 * \param	
  1986  * \return	
  2086 * \return	
  1987  * \note		
  2087 * \note		
  1988  *//*-------------------------------------------------------------------*/
  2088 *//*-------------------------------------------------------------------*/
  1989 
  2089 
  1990 #ifdef BUILD_WITH_PRIVATE_EGL
  2090 #ifdef BUILD_WITH_PRIVATE_EGL
  1991 RI_APIENTRY EGLBoolean do_eglCopyBuffers(EGLDisplay dpy, EGLSurface surface,
  2091 RI_APIENTRY EGLBoolean do_eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
  1992 		EGLNativePixmapType target)
       
  1993 #else
  2092 #else
  1994 EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
  2093 EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
  1995 #endif
  2094 #endif
  1996 	{
  2095 {
  1997 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  2096 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  1998 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  2097 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  1999 	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
  2098 	EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
  2000 	//EGL_IF_ERROR(!target || !isValidImageFormat(target->format) || !target->data || target->width <= 0 || target->height <= 0, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE);
  2099 	//EGL_IF_ERROR(!target || !isValidImageFormat(target->format) || !target->data || target->width <= 0 || target->height <= 0, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE);
  2001 	EGLint width = -1;
  2100 	EGLint  width  = -1;
  2002 	EGLint height = -1;
  2101 	EGLint  height = -1;
  2003 	EGLint stride = -1;
  2102 	EGLint  stride = -1;
  2004 	VGImageFormat format;
  2103 	VGImageFormat format;
  2005 	int* data = NULL;
  2104 	int* data = NULL;
  2006 	EGLBoolean err = OSGetNativePixmapInfo(target, &width, &height, &stride,
  2105 	EGLBoolean err = OSGetNativePixmapInfo(target, &width, &height, &stride,&format, &data);
  2007 			&format, &data);
  2106 	
  2008 
  2107 	TUint* fdata = (TUint*)((TUint)data + ( stride * ( height - 1  ) ) );	
  2009 	TUint* fdata = (TUint*) ((TUint) data + (stride * (height - 1)));
       
  2010 	try
  2108 	try
  2011 		{
  2109 	{
  2012 		Image output(Color::formatToDescriptor(format), width, height, -stride,
  2110 		Image output(Color::formatToDescriptor(format), width, height, -stride, (RIuint8*)fdata);
  2013 				(RIuint8*) fdata);
  2111         output.addReference();
  2014 		output.addReference();
  2112 		output.blit(((RIEGLSurface*)surface)->getDrawable()->getColorBuffer(), 0, 0, 0, 0, width, height);	//throws bad_alloc
  2015 		output.blit(((RIEGLSurface*) surface)->getDrawable()->getColorBuffer(),
  2113         output.removeReference();
  2016 				0, 0, 0, 0, width, height); //throws bad_alloc
  2114 	}
  2017 		output.removeReference();
  2115 	catch(std::bad_alloc)
  2018 		}
  2116 	{
  2019 	catch (std::bad_alloc)
  2117 	}
  2020 		{
       
  2021 		}
       
  2022 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  2118 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  2023 
  2119 	
  2024 	}
  2120 }
  2025 
  2121 
  2026 /*-------------------------------------------------------------------*//*!
  2122 /*-------------------------------------------------------------------*//*!
  2027  * \brief	
  2123 * \brief	
  2028  * \param	
  2124 * \param	
  2029  * \return	
  2125 * \return	
  2030  * \note		We support only swap interval one
  2126 * \note		We support only swap interval one
  2031  *//*-------------------------------------------------------------------*/
  2127 *//*-------------------------------------------------------------------*/
  2032 
  2128 
  2033 #ifdef BUILD_WITH_PRIVATE_EGL
  2129 #ifdef BUILD_WITH_PRIVATE_EGL
  2034 RI_APIENTRY EGLBoolean do_eglSwapInterval(EGLDisplay dpy, EGLint interval)
  2130 RI_APIENTRY EGLBoolean do_eglSwapInterval(EGLDisplay dpy, EGLint interval)
  2035 #else
  2131 #else
  2036 EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
  2132 EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
  2037 #endif
  2133 #endif
  2038 	{
  2134 {
  2039 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  2135 	EGL_GET_DISPLAY(dpy, EGL_FALSE);
  2040 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  2136 	EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
  2041 	RI_UNREF(interval);
  2137 	RI_UNREF(interval);
  2042 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  2138 	EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
  2043 	}
  2139 }
  2044 
  2140 
  2045 /*-------------------------------------------------------------------*//*!
  2141 /*-------------------------------------------------------------------*//*!
  2046  * \brief	
  2142 * \brief	
  2047  * \param	
  2143 * \param	
  2048  * \return	
  2144 * \return	
  2049  * \note		
  2145 * \note		
  2050  *//*-------------------------------------------------------------------*/
  2146 *//*-------------------------------------------------------------------*/
  2051 
  2147 
  2052 typedef void RI_Proc();
  2148 typedef void RI_Proc();
  2053 
  2149 
  2054 //EGLAPI void (* EGLAPIENTRY      eglGetProcAddress(const char *procname))(void);
  2150 //EGLAPI void (* EGLAPIENTRY      eglGetProcAddress(const char *procname))(void);
  2055 
  2151 
  2056 #ifdef BUILD_WITH_PRIVATE_EGL
  2152 #ifdef BUILD_WITH_PRIVATE_EGL
  2057 RI_APIENTRY void (*do_eglGetProcAddress(const char *procname))(...)
  2153 RI_APIENTRY void (*do_eglGetProcAddress(const char *procname))(...)
  2058 #else
  2154 #else
  2059 		void (*eglGetProcAddress(const char *procname))(...)
  2155 void (*eglGetProcAddress(const char *procname))(...)
  2060 #endif
  2156 #endif
  2061 			{
  2157 {
  2062 			if (!procname)
  2158 	if(!procname)
  2063 				return NULL;
  2159 		return NULL;
  2064 			return NULL;
  2160 	return NULL;
  2065 			}
  2161 }
  2066 
  2162 
  2067 		/*-------------------------------------------------------------------*//*!
  2163 
  2068 		 * \brief	
  2164 
  2069 		 * \param	
  2165 /*-------------------------------------------------------------------*//*!
  2070 		 * \return	
  2166 * \brief	
  2071 		 * \note		
  2167 * \param	
  2072 		 *//*-------------------------------------------------------------------*/
  2168 * \return	
  2073 
  2169 * \note		
  2074 #ifdef BUILD_WITH_PRIVATE_EGL
  2170 *//*-------------------------------------------------------------------*/
  2075 		RI_APIENTRY EGLBoolean do_eglReleaseThread(void)
  2171 
  2076 #else
  2172 #ifdef BUILD_WITH_PRIVATE_EGL
  2077 		EGLBoolean eglReleaseThread(void)
  2173 RI_APIENTRY EGLBoolean do_eglReleaseThread(void)
  2078 #endif
  2174 #else
  2079 			{
  2175 EGLBoolean eglReleaseThread(void)
  2080 			EGL_GET_EGL(EGL_FALSE);
  2176 #endif
  2081 
  2177 {
  2082 			//check if the thread is current
  2178     EGL_GET_EGL(EGL_FALSE);
  2083 			RIEGLThread* thread = egl->getCurrentThread();
  2179 
  2084 			if (thread)
  2180 	//check if the thread is current
  2085 				{ //thread is current, release the old bindings and remove the thread from the current thread list
  2181 	RIEGLThread* thread = egl->getCurrentThread();
  2086 				RIEGLContext* pc = thread->getCurrentContext();
  2182 	if(thread)
  2087 				RIEGLSurface* ps = thread->getCurrentSurface();
  2183 	{	//thread is current, release the old bindings and remove the thread from the current thread list
  2088 				if (pc)
  2184 		RIEGLContext* pc = thread->getCurrentContext();
  2089 					{
  2185 		RIEGLSurface* ps = thread->getCurrentSurface();
       
  2186 		if(pc)
       
  2187 		{
  2090 #ifdef BUILD_WITH_PRIVATE_OPENVG
  2188 #ifdef BUILD_WITH_PRIVATE_OPENVG
  2091 					do_vgFlush();
  2189 			do_vgFlush();
  2092 #else
  2190 #else
  2093 					vgFlush();
  2191 			vgFlush();
  2094 #endif
  2192 #endif
  2095 					pc->getVGContext()->setDefaultDrawable(NULL);
  2193 			pc->getVGContext()->setDefaultDrawable(NULL);
  2096 					if (!pc->removeReference())
  2194 			if(!pc->removeReference())
  2097 						RI_DELETE(pc);
  2195 				RI_DELETE(pc);
  2098 					}
  2196 		}
  2099 				if (ps)
  2197 		if(ps)
  2100 					{
  2198 		{
  2101 					if (!ps->removeReference())
  2199 			if(!ps->removeReference())
  2102 						RI_DELETE(ps);
  2200 				RI_DELETE(ps);
  2103 					}
  2201 		}
  2104 
  2202 
  2105 				egl->removeCurrentThread(thread);
  2203         egl->removeCurrentThread(thread);
  2106 				}
  2204 	}
  2107 
  2205 
  2108 			//destroy EGL's thread struct
  2206     //destroy EGL's thread struct
  2109 			egl->destroyThread();
  2207     egl->destroyThread();
  2110 
  2208 
  2111 			//destroy the EGL instance
  2209 	//destroy the EGL instance
  2112 			releaseEGL();
  2210 	releaseEGL();
  2113 
  2211 
  2114 			OSReleaseMutex();
  2212 	OSReleaseMutex();
  2115 			OSDeinitMutex();
  2213     OSDeinitMutex();
  2116 
  2214 
  2117 			return EGL_SUCCESS;
  2215 	return EGL_SUCCESS;
  2118 			}
  2216 }
  2119 
  2217 
  2120 #ifdef BUILD_WITH_PRIVATE_EGL
  2218 #ifdef BUILD_WITH_PRIVATE_EGL
  2121 		RI_APIENTRY EGLBoolean do_eglBindTexImage(EGLDisplay dpy,
  2219 RI_APIENTRY EGLBoolean do_eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
  2122 				EGLSurface surface, EGLint buffer)
  2220 #else
  2123 #else
  2221 EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
  2124 		EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
  2222 #endif
  2125 #endif
  2223 	{
  2126 			{
  2224 	//not implemented
  2127 			//not implemented
  2225 	RI_ASSERT(0);
  2128 			RI_ASSERT(0);
  2226 	return false;
  2129 			return false;
  2227 	}
  2130 			}
  2228 
  2131 
  2229 #ifdef BUILD_WITH_PRIVATE_EGL
  2132 #ifdef BUILD_WITH_PRIVATE_EGL
  2230 RI_APIENTRY EGLBoolean do_eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
  2133 		RI_APIENTRY EGLBoolean do_eglReleaseTexImage(EGLDisplay dpy,
       
  2134 				EGLSurface surface, EGLint buffer)
       
  2135 #else 
  2231 #else 
  2136 		EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
  2232 EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
  2137 #endif
  2233 #endif
  2138 			{
  2234 	{
  2139 			//not implemented
  2235 	//not implemented
  2140 			RI_ASSERT(0);
  2236 	RI_ASSERT(0);
  2141 			return false;
  2237 	return false;
  2142 			}
  2238 	}
  2143 #undef EGL_NUMCONFIGS
  2239 #undef EGL_NUMCONFIGS
  2144