Additional support for EGL Sync Extension EGL_MERGE
authorMartin Jakl <jakl.martin@cell-telecom.com>
Fri, 26 Nov 2010 17:41:06 +0000
branchEGL_MERGE
changeset 217 205d3af68142
parent 216 b87045f2f5d7
Additional support for EGL Sync Extension
openvg/openvgrefimplementation/sfopenvg/sfopenvg/extensions/eglsync.cpp
openvg/openvgrefimplementation/sfopenvg/sfopenvg/include/eglsync.h
openvg/openvgrefimplementation/sfopenvg/sfopenvg/riMiniEGL.cpp
openvg/openvgrefimplementation/sfopenvg/sfopenvg/riMiniEGL.h
--- a/openvg/openvgrefimplementation/sfopenvg/sfopenvg/extensions/eglsync.cpp	Thu Nov 18 23:28:27 2010 +0000
+++ b/openvg/openvgrefimplementation/sfopenvg/sfopenvg/extensions/eglsync.cpp	Fri Nov 26 17:41:06 2010 +0000
@@ -153,9 +153,15 @@
     EGLint ret = (EGLint) EGL_FALSE;
     if (iSyncState == EGL_UNSIGNALED_KHR)
         {
-        if (aTimeout && (aFlags & EGL_SYNC_FLUSH_COMMANDS_BIT_KHR) && (eglGetCurrentContext() != EGL_NO_CONTEXT))
+#ifdef BUILD_WITH_PRIVATE_EGL
+			if (aTimeout && (aFlags & EGL_SYNC_FLUSH_COMMANDS_BIT_KHR) && (do_eglGetCurrentContext() != EGL_NO_CONTEXT))
             {
-            switch(eglQueryAPI())
+				switch(do_eglQueryAPI())
+#else
+			if (aTimeout && (aFlags & EGL_SYNC_FLUSH_COMMANDS_BIT_KHR) && (eglGetCurrentContext() != EGL_NO_CONTEXT))
+			{
+				switch(eglQueryAPI())
+#endif
                 {
                 case EGL_OPENGL_ES_API:
                     //ToDo: make sure these cases are covered
@@ -311,8 +317,8 @@
 
 CEglSyncExtension::CEglSyncExtension(OpenVGRI::EGL& aEglInstance):
 iEglSyncMap(),
-iEglSyncId(0)/*,
-iEglInstance(aEglInstance)*/
+iEglSyncId(0),
+iEglInstance(aEglInstance)
     {
 
     }
--- a/openvg/openvgrefimplementation/sfopenvg/sfopenvg/include/eglsync.h	Thu Nov 18 23:28:27 2010 +0000
+++ b/openvg/openvgrefimplementation/sfopenvg/sfopenvg/include/eglsync.h	Fri Nov 26 17:41:06 2010 +0000
@@ -410,6 +410,8 @@
     REglSyncHashMap iEglSyncMap;
     RFastLock       iEglSyncMapLock;
     EGLint          iEglSyncId;
+    
+    OpenVGRI::EGL&    iEglInstance;
     };
 
 #endif /* __EGL_SYNC_H_ */
--- a/openvg/openvgrefimplementation/sfopenvg/sfopenvg/riMiniEGL.cpp	Thu Nov 18 23:28:27 2010 +0000
+++ b/openvg/openvgrefimplementation/sfopenvg/sfopenvg/riMiniEGL.cpp	Fri Nov 26 17:41:06 2010 +0000
@@ -88,6 +88,29 @@
 	//currentThreads contain just pointers to threads we just deleted
 }
 
+// -----------------------------------------------------------------------------
+// 2nd phase constructor
+// ported from guestEGL
+//-----------------------------------------------------------------------------
+//
+void EGL::Create()
+{
+	EGL_TRACE("  EGL::Create ");
+    //OpenSgResources();
+    TInt err;
+	err = iDisplayMapLock.CreateLocal();
+	EGLPANIC_ASSERT(err == KErrNone, EEglPanicDisplayMapLockCreateLocalFailed);
+
+	//err = iEglImageLock.CreateLocal();
+	//EGLPANIC_ASSERT(err == KErrNone, EEglPanicEglImageLockCreateLocalFailed);	
+
+	InitialiseExtensions();
+
+	//const char* initExtensionList = EglInternalFunction_QueryExtensionList();
+	//EGL_TRACE("  CGuestEGL::Create  initExtensionList=0x%x (\"%s\") <--",
+	//		initExtensionList, initExtensionList ? initExtensionList : "");
+}
+
 /*-------------------------------------------------------------------*//*!
 * \brief	
 * \param	
@@ -106,6 +129,7 @@
 		{
 		//create TLS instance
 		pEgl = RI_NEW(EGL, ());
+		pEgl->Create();
 		Dll::SetTls(pEgl);
 		}
 	return pEgl;
@@ -173,6 +197,21 @@
 	return NULL;		//error: the display hasn't been eglInitialized
 }
 
+/*-------------------------------------------------------------------*//*!
+* \brief	Creates a display given a display ID, including Display info
+* \param	
+* \return	
+* \note		if egl has been initialized for this display, the display ID can
+*			be found from egl->m_displays
+*//*-------------------------------------------------------------------*/
+void EGL::addDisplay(RIEGLDisplay* display)
+{
+	RI_ASSERT(display); 
+	m_displays.push_back(display); //throws bad alloc
+	CreateDisplayInfo(display->getID());
+}  
+
+
 /*
   Create an information object for an opened Display.
  */
@@ -213,6 +252,8 @@
 
 		if (err == KErrNone)
 		{
+			// mark as initialized here??
+			dispInfo->iInitialized = ETrue;
 			result = ETrue;
 		}
 	}
@@ -1231,8 +1272,10 @@
 	EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
 
 	int renderBuffer = EGL_BACK_BUFFER;
-	int colorSpace = EGL_VG_COLORSPACE_sRGB;
-	int alphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE;
+	int colorSpace = EGL_COLORSPACE_sRGB;
+	int alphaFormat = EGL_ALPHA_FORMAT_NONPRE;
+   
+
 	if(attrib_list)
 	{
 		for(int i=0;attrib_list[i] != EGL_NONE;i+=2)
@@ -1320,6 +1363,7 @@
 			RWindow* window = (RWindow*)(win);				
 			RWsSession& session = *window->Session();
 			session.RegisterSurface(surfaceInfo.iScreenNumber, surfaceInfo.iSurfaceId);
+			surfaceConfig.SetFlip(ETrue); // don't ask :o
 			window->SetBackgroundSurface(surfaceConfig, ETrue);
 		}
 		else
@@ -2605,20 +2649,183 @@
 * \return	
 * \note		
 *//*-------------------------------------------------------------------*/
+/**
+	Obtain extension function pointer.
 
+	Provide support for the Symbian Graphics SHAI for EGL Extensions
+	@param aName	Name of extension
+	@return			Function pointer, or NULL if not available.
+
+	@note  Known extensions and their directly associated functions:
+	   1. EGL_KHR_image 
+			None
+	   2. EGL_KHR_image_base 
+			eglCreateImageKHR,
+			eglDestroyImageKHR
+	   3. EGL_KHR_image_pixmap
+			None
+	   4. EGL_KHR_vg_parent_image
+			None
+	   5. EGL_KHR_gl_texture_2D_image
+			None
+	   6. EGL_KHR_gl_texture_cubemap_image
+			EGLImageTargetTexture2DOES,
+			EGLImageTargetRenderbufferStorageOES
+	   7. EGL_KHR_lock_surface2
+			eglLockSurfaceKHR,
+			eglUnlockSurfaceKHR
+	   8. EGL_NOK_resource_profiling2
+			eglQueryProfilingDataNOK
+	   9. EGL_SYMBIAN_composition
+			None
+	  10. EGL_NOK_image_endpoint
+			eglCreateEndpointNOK,
+			eglDestroyEndpointNOK,
+			eglGetEndpointAttribNOK,
+			eglSetEndpointAttribNOK,
+			eglEndpointBeginStreamingNOK,
+			eglEndpointEndStreamingNOK,
+			eglAcquireImageNOK,
+			eglReleaseImageNOK,
+			eglGetEndpointDirtyAreaNOK,
+			eglEndpointRequestNotificationNOK,
+			eglEndpointCancelNotificationNOK,
+			eglCreateEndpointNOK
+	  11. NOK_pixmap_type_rsgimage
+			None
+	  12. EGL_NOK_swap_region
+			eglSwapBuffersRegionNOK
+
+	@see Khronos EGL 1.4 Specification, eglGetProcAddress()
+	@author Faisal Memon Community EGL project
+	ported to Merge EGL
+	*/
 typedef void RI_Proc();
 
 //EGLAPI void (* EGLAPIENTRY      eglGetProcAddress(const char *procname))(void);
 
 #ifdef BUILD_WITH_PRIVATE_EGL
-RI_APIENTRY void (*do_eglGetProcAddress(const char *procname))(...)
+RI_APIENTRY void (*do_eglGetProcAddress(const char *aName))(...)
 #else
-void (*eglGetProcAddress(const char *procname))(...)
+void (*eglGetProcAddress(const char *aName))(...)
 #endif
 {
+	/*
 	if(!procname)
 		return NULL;
 	return NULL;
+	*/
+	
+/*ProcPointer CGuestEGL::eglGetProcAddress(const char* aName)*/
+	if (strncmp("eglCreateImageKHR", aName, strlen("eglCreateImageKHR")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglDestroyImageKHR", aName, strlen("eglDestroyImageKHR")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("EGLImageTargetTexture2DOES", aName, strlen("EGLImageTargetTexture2DOES")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("EGLImageTargetRenderbufferStorageOES", aName, strlen("EGLImageTargetRenderbufferStorageOES")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglLockSurfaceKHR", aName, strlen("eglLockSurfaceKHR")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglUnlockSurfaceKHR", aName, strlen("eglUnlockSurfaceKHR")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("EGL_KHR_lock_surface", aName, strlen("EGL_KHR_lock_surface")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglQueryProfilingDataNOK", aName, strlen("eglQueryProfilingDataNOK")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglCreateEndpointNOK", aName, strlen("eglCreateEndpointNOK")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglDestroyEndpointNOK", aName, strlen("eglDestroyEndpointNOK")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglGetEndpointAttribNOK", aName, strlen("eglGetEndpointAttribNOK")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglEndpointBeginStreamingNOK", aName, strlen("eglEndpointBeginStreamingNOK")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglEndpointEndStreamingNOK", aName, strlen("eglEndpointEndStreamingNOK")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglAcquireImageNOK", aName, strlen("eglAcquireImageNOK")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglReleaseImageNOK", aName, strlen("eglReleaseImageNOK")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglGetEndpointDirtyAreaNOK", aName, strlen("eglGetEndpointDirtyAreaNOK")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglEndpointRequestNotificationNOK", aName, strlen("eglEndpointRequestNotificationNOK")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglEndpointCancelNotificationNOK", aName, strlen("eglEndpointCancelNotificationNOK")) == 0)
+	{
+		return NULL;
+	}
+	else if (strncmp("eglCreateEndpointNOK", aName, strlen("eglCreateEndpointNOK")) == 0)
+	{
+	    return NULL;
+	}
+	else if (strncmp("eglSwapBuffersRegionNOK", aName, strlen("eglSwapBuffersRegionNOK")) == 0)
+	{
+	    return NULL;
+	}
+	else if (strncmp("egl_Private_SignalSyncNOK", aName, strlen("egl_Private_SignalSyncNOK")) == 0)
+	{
+		return (ProcPointer)CEglSyncExtension::egl_Private_SignalSyncNOK;
+	}
+	else if (strncmp("eglCreateSyncKHR", aName, strlen("eglCreateSyncKHR")) == 0)
+	{
+		return (ProcPointer)CEglSyncExtension::eglCreateSyncKHR;
+	}
+	else if (strncmp("eglDestroySyncKHR", aName, strlen("eglDestroySyncKHR")) == 0)
+	{
+		return (ProcPointer)CEglSyncExtension::eglDestroySyncKHR;
+	}
+	else if (strncmp("eglClientWaitSyncKHR", aName, strlen("eglClientWaitSyncKHR")) == 0)
+	{
+		return (ProcPointer)CEglSyncExtension::eglClientWaitSyncKHR;
+	}
+	else if (strncmp("eglSignalSyncKHR", aName, strlen("eglSignalSyncKHR")) == 0)
+	{
+		return (ProcPointer)CEglSyncExtension::eglSignalSyncKHR;
+	}
+	else if (strncmp("eglGetSyncAttribKHR", aName, strlen("eglGetSyncAttribKHR")) == 0)
+	{
+		return (ProcPointer)CEglSyncExtension::eglGetSyncAttribKHR;
+	}
+	else
+	{
+		return NULL;
+	}
+		
 }
 
 
--- a/openvg/openvgrefimplementation/sfopenvg/sfopenvg/riMiniEGL.h	Thu Nov 18 23:28:27 2010 +0000
+++ b/openvg/openvgrefimplementation/sfopenvg/sfopenvg/riMiniEGL.h	Fri Nov 26 17:41:06 2010 +0000
@@ -77,7 +77,6 @@
 	ESurfaceTypePixmapSgImage = 3,
 	} TEglSurfaceType;
 
-#define KDefaultScreenNumber 0
 	
 class CEglContext;
 
@@ -126,6 +125,9 @@
 //	RMutex                             iContextMapLock;
     RHashMap<EGLContext, CEglContext*> iContextMap;
     };
+
+// prototype to help eglGetProcAddress() API 
+typedef void (*ProcPointer)(...);
 //==============================================================================================
 
 namespace OpenVGRI
@@ -276,6 +278,9 @@
     Drawable*       getDrawable() const        { return m_drawable; }
     bool            isLargestPbuffer() const   { return m_largestPbuffer; }
     int             getRenderBuffer() const    { return m_renderBuffer; }
+    
+    void 			Lock()						{iSurfaceLock.ReadLock();}
+    void 			Unlock()					{iSurfaceLock.Unlock();}
 
 private:
 	RIEGLSurface(const RIEGLSurface&);
@@ -286,6 +291,8 @@
 	bool			 m_largestPbuffer;
 	int				 m_renderBuffer;		//EGL_BACK_BUFFER or EGL_SINGLE_BUFFER
 	int				 m_referenceCount;
+	
+	RReadWriteLock	 iSurfaceLock; 			// protects the surface for multi-threaded clients
 };
 
 RIEGLSurface* CastToRIEGLSurface(EGLSurface aSurfaceId);
@@ -434,9 +441,11 @@
     TSurfaceInfo* EglInternalFunction_GetPlatformSurface( EGLDisplay display, EGLSurface surface );
     EGLBoolean EglInternalFunction_SurfaceResized(TSurfaceInfo&, int, int);
 private:
+    friend EGL* getEGL();
 	EGL(const EGL&);						// Not allowed.
 	const EGL& operator=(const EGL&);		// Not allowed.
-
+	void Create();
+	
 	Array<RIEGLThread*>		m_threads;			//threads that have called EGL
 	Array<RIEGLThread*>		m_currentThreads;	//threads that have a bound context
 	Array<RIEGLDisplay*>	m_displays;