egl/eglrefimpl/src/session.cpp
branchEGL_MERGE
changeset 190 19ce5231ffe4
parent 60 013f1c757b1e
child 74 0f98da52363f
--- a/egl/eglrefimpl/src/session.cpp	Wed May 19 10:19:21 2010 +0100
+++ b/egl/eglrefimpl/src/session.cpp	Fri Sep 24 16:48:05 2010 +0100
@@ -72,9 +72,10 @@
                                                                 
 CEglThreadSession::CEglThreadSession(CEglDriver& aDriver):
 	iDriver(aDriver),
-	iError(EGL_SUCCESS)
+	iError(EGL_SUCCESS),
+	iEgl(NULL)
 	{
-	Dll::SetTls( NULL ); //set TLS to NULL Jose
+	Dll::SetTls( NULL ); 
 	}
 
 CEglThreadSession::~CEglThreadSession()
@@ -87,10 +88,6 @@
 	{
 	CEglThreadSession* es = reinterpret_cast<CEglThreadSession*>(Dll::Tls());
 	
-	if(es)
-		{
-		RDebug::Printf(" &&&&&&&&&&&&&&&&& if CEglThreadSession not null,CEglThreadSession Addr of CEglThreadSession &&&&&&&&&&&= %x\n", es);
-		}
 	if (es)
 		{
 		return es;
@@ -109,10 +106,6 @@
 
 	// create session object on default thread's heap
 	es = new CEglThreadSession(*drv);
-	RDebug::Printf("In CEglThreadSession::Static(),CEglThreadSession Addr of CEglThreadSession Ptr = %x\n", &es);
-	RDebug::Printf("In CEglThreadSession::Static(),CEglThreadSession Addr of CEglThreadSession= %x\n", es);
-	//RDebug::Printf("In CEglThreadSession::Static(),Thread Id %Lu",(RThread().Id().Id()));
-	RDebug::Printf("In CEglThreadSession::Static(),Thread Id %Lu",(RThread().Id()));
 	if (!es || Dll::SetTls(es)!= KErrNone)
 		{
 		delete es;
@@ -183,29 +176,42 @@
         SetError(EGL_NOT_INITIALIZED);
         return EGL_FALSE;
         }
+    
     EGL* pEgl = NULL;
-    pEgl = new EGL();
-    
-    iEgl = pEgl;
     
-    RIEGLDisplay* Egldisplay = iEgl->getDisplay(aDisplay);
+    try
+    {
+		pEgl = new EGL();
+		iEgl = pEgl;
+    }
+    catch(std::bad_alloc)
+    {
+    	SetError(EGL_BAD_ALLOC);
+    	return EGL_FALSE;
+    }
+    
+    RIEGLDisplay* eglDispaly = iEgl->getDisplay(aDisplay);
+    if(eglDispaly)
+    	return EGL_TRUE;
+   
     //create the current display
-    //if a context and a surface are bound by the time of eglTerminate, they remain bound until eglMakeCurrent is called
-	RIEGLDisplay* newDisplay = NULL;
+  	RIEGLDisplay* newDisplay = NULL;
 	try
 	{
-		newDisplay = new RIEGLDisplay(aDisplay);	//throws bad_alloc
+		newDisplay = new RIEGLDisplay(aDisplay); //throws bad_alloc
 		iEgl->addDisplay(newDisplay);	//throws bad_alloc
-		Egldisplay = newDisplay;
-		RI_ASSERT(Egldisplay);
+		eglDispaly = newDisplay;
+		RI_ASSERT(eglDispaly);
 	}
 	catch(std::bad_alloc)
 	{
+		RI_DELETE(iEgl);
+		iEgl = NULL;
 		RI_DELETE(newDisplay);
-	//	EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE); //TODO Need to enable this later. Jose
+    	SetError(EGL_BAD_DISPLAY);
+    	return EGL_FALSE;
 	}
     
-    //need to think of deleting egl if anything goes wrong.
     if (aMajor)	
         {
         *aMajor = KEglMajorVersion;