egl/eglrefimpl/src/session.cpp
branchEGL_MERGE
changeset 190 19ce5231ffe4
parent 60 013f1c757b1e
child 74 0f98da52363f
equal deleted inserted replaced
90:bda9a4b12167 190:19ce5231ffe4
    70         return retval; \
    70         return retval; \
    71         }
    71         }
    72                                                                 
    72                                                                 
    73 CEglThreadSession::CEglThreadSession(CEglDriver& aDriver):
    73 CEglThreadSession::CEglThreadSession(CEglDriver& aDriver):
    74 	iDriver(aDriver),
    74 	iDriver(aDriver),
    75 	iError(EGL_SUCCESS)
    75 	iError(EGL_SUCCESS),
    76 	{
    76 	iEgl(NULL)
    77 	Dll::SetTls( NULL ); //set TLS to NULL Jose
    77 	{
       
    78 	Dll::SetTls( NULL ); 
    78 	}
    79 	}
    79 
    80 
    80 CEglThreadSession::~CEglThreadSession()
    81 CEglThreadSession::~CEglThreadSession()
    81 	{
    82 	{
    82 	delete iEgl;
    83 	delete iEgl;
    85 
    86 
    86 CEglThreadSession* CEglThreadSession::Static()
    87 CEglThreadSession* CEglThreadSession::Static()
    87 	{
    88 	{
    88 	CEglThreadSession* es = reinterpret_cast<CEglThreadSession*>(Dll::Tls());
    89 	CEglThreadSession* es = reinterpret_cast<CEglThreadSession*>(Dll::Tls());
    89 	
    90 	
    90 	if(es)
       
    91 		{
       
    92 		RDebug::Printf(" &&&&&&&&&&&&&&&&& if CEglThreadSession not null,CEglThreadSession Addr of CEglThreadSession &&&&&&&&&&&= %x\n", es);
       
    93 		}
       
    94 	if (es)
    91 	if (es)
    95 		{
    92 		{
    96 		return es;
    93 		return es;
    97 		}
    94 		}
    98 
    95 
   107 	CEglDriver* drv = CEglDriver::GetDriver();
   104 	CEglDriver* drv = CEglDriver::GetDriver();
   108 	__ASSERT_DEBUG(drv, User::Panic(KEglPanicCategory, EEglPanicDriverNull));
   105 	__ASSERT_DEBUG(drv, User::Panic(KEglPanicCategory, EEglPanicDriverNull));
   109 
   106 
   110 	// create session object on default thread's heap
   107 	// create session object on default thread's heap
   111 	es = new CEglThreadSession(*drv);
   108 	es = new CEglThreadSession(*drv);
   112 	RDebug::Printf("In CEglThreadSession::Static(),CEglThreadSession Addr of CEglThreadSession Ptr = %x\n", &es);
       
   113 	RDebug::Printf("In CEglThreadSession::Static(),CEglThreadSession Addr of CEglThreadSession= %x\n", es);
       
   114 	//RDebug::Printf("In CEglThreadSession::Static(),Thread Id %Lu",(RThread().Id().Id()));
       
   115 	RDebug::Printf("In CEglThreadSession::Static(),Thread Id %Lu",(RThread().Id()));
       
   116 	if (!es || Dll::SetTls(es)!= KErrNone)
   109 	if (!es || Dll::SetTls(es)!= KErrNone)
   117 		{
   110 		{
   118 		delete es;
   111 		delete es;
   119 		return NULL;
   112 		return NULL;
   120 		}
   113 		}
   181     if (err != KErrNone)
   174     if (err != KErrNone)
   182         {
   175         {
   183         SetError(EGL_NOT_INITIALIZED);
   176         SetError(EGL_NOT_INITIALIZED);
   184         return EGL_FALSE;
   177         return EGL_FALSE;
   185         }
   178         }
       
   179     
   186     EGL* pEgl = NULL;
   180     EGL* pEgl = NULL;
   187     pEgl = new EGL();
   181     
   188     
   182     try
   189     iEgl = pEgl;
   183     {
   190     
   184 		pEgl = new EGL();
   191     RIEGLDisplay* Egldisplay = iEgl->getDisplay(aDisplay);
   185 		iEgl = pEgl;
       
   186     }
       
   187     catch(std::bad_alloc)
       
   188     {
       
   189     	SetError(EGL_BAD_ALLOC);
       
   190     	return EGL_FALSE;
       
   191     }
       
   192     
       
   193     RIEGLDisplay* eglDispaly = iEgl->getDisplay(aDisplay);
       
   194     if(eglDispaly)
       
   195     	return EGL_TRUE;
       
   196    
   192     //create the current display
   197     //create the current display
   193     //if a context and a surface are bound by the time of eglTerminate, they remain bound until eglMakeCurrent is called
   198   	RIEGLDisplay* newDisplay = NULL;
   194 	RIEGLDisplay* newDisplay = NULL;
       
   195 	try
   199 	try
   196 	{
   200 	{
   197 		newDisplay = new RIEGLDisplay(aDisplay);	//throws bad_alloc
   201 		newDisplay = new RIEGLDisplay(aDisplay); //throws bad_alloc
   198 		iEgl->addDisplay(newDisplay);	//throws bad_alloc
   202 		iEgl->addDisplay(newDisplay);	//throws bad_alloc
   199 		Egldisplay = newDisplay;
   203 		eglDispaly = newDisplay;
   200 		RI_ASSERT(Egldisplay);
   204 		RI_ASSERT(eglDispaly);
   201 	}
   205 	}
   202 	catch(std::bad_alloc)
   206 	catch(std::bad_alloc)
   203 	{
   207 	{
       
   208 		RI_DELETE(iEgl);
       
   209 		iEgl = NULL;
   204 		RI_DELETE(newDisplay);
   210 		RI_DELETE(newDisplay);
   205 	//	EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE); //TODO Need to enable this later. Jose
   211     	SetError(EGL_BAD_DISPLAY);
   206 	}
   212     	return EGL_FALSE;
   207     
   213 	}
   208     //need to think of deleting egl if anything goes wrong.
   214     
   209     if (aMajor)	
   215     if (aMajor)	
   210         {
   216         {
   211         *aMajor = KEglMajorVersion;
   217         *aMajor = KEglMajorVersion;
   212         }
   218         }
   213     if (aMinor)
   219     if (aMinor)