egl/eglrefimpl/src/session.cpp
branchEGL_MERGE
changeset 58 5b9c23c1a54c
parent 57 2bf8a359aa2f
child 59 0fb7b31791c3
equal deleted inserted replaced
57:2bf8a359aa2f 58:5b9c23c1a54c
    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 	{
    77 	Dll::SetTls( NULL ); //set TLS to NULL Jose
    77 	Dll::SetTls( NULL ); 
    78 	}
    78 	}
    79 
    79 
    80 CEglThreadSession::~CEglThreadSession()
    80 CEglThreadSession::~CEglThreadSession()
    81 	{
    81 	{
    82 	delete iEgl;
    82 	delete iEgl;
    85 
    85 
    86 CEglThreadSession* CEglThreadSession::Static()
    86 CEglThreadSession* CEglThreadSession::Static()
    87 	{
    87 	{
    88 	CEglThreadSession* es = reinterpret_cast<CEglThreadSession*>(Dll::Tls());
    88 	CEglThreadSession* es = reinterpret_cast<CEglThreadSession*>(Dll::Tls());
    89 	
    89 	
    90 	if(es)
       
    91 		{
       
    92 		RDebug::Printf(" &&&&&&&&&&&&&&&&& if CEglThreadSession not null,CEglThreadSession Addr of CEglThreadSession &&&&&&&&&&&= %x\n", es);
       
    93 		}
       
    94 	if (es)
    90 	if (es)
    95 		{
    91 		{
    96 		return es;
    92 		return es;
    97 		}
    93 		}
    98 
    94 
   107 	CEglDriver* drv = CEglDriver::GetDriver();
   103 	CEglDriver* drv = CEglDriver::GetDriver();
   108 	__ASSERT_DEBUG(drv, User::Panic(KEglPanicCategory, EEglPanicDriverNull));
   104 	__ASSERT_DEBUG(drv, User::Panic(KEglPanicCategory, EEglPanicDriverNull));
   109 
   105 
   110 	// create session object on default thread's heap
   106 	// create session object on default thread's heap
   111 	es = new CEglThreadSession(*drv);
   107 	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)
   108 	if (!es || Dll::SetTls(es)!= KErrNone)
   117 		{
   109 		{
   118 		delete es;
   110 		delete es;
   119 		return NULL;
   111 		return NULL;
   120 		}
   112 		}
   181     if (err != KErrNone)
   173     if (err != KErrNone)
   182         {
   174         {
   183         SetError(EGL_NOT_INITIALIZED);
   175         SetError(EGL_NOT_INITIALIZED);
   184         return EGL_FALSE;
   176         return EGL_FALSE;
   185         }
   177         }
       
   178     
   186     EGL* pEgl = NULL;
   179     EGL* pEgl = NULL;
   187     pEgl = new EGL();
   180     
   188     
   181     try
   189     iEgl = pEgl;
   182     {
       
   183 		pEgl = new EGL();
       
   184 		iEgl = pEgl;
       
   185     }
       
   186     catch(std::bad_alloc)
       
   187     {
       
   188     	SetError(EGL_BAD_ALLOC);
       
   189     	return EGL_FALSE;
       
   190     }
   190     
   191     
   191     RIEGLDisplay* Egldisplay = iEgl->getDisplay(aDisplay);
   192     RIEGLDisplay* Egldisplay = iEgl->getDisplay(aDisplay);
   192     //create the current display
   193     //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
   194     
   194 	RIEGLDisplay* newDisplay = NULL;
   195 	RIEGLDisplay* newDisplay = NULL;
   195 	try
   196 	try
   196 	{
   197 	{
   197 		newDisplay = new RIEGLDisplay(aDisplay);	//throws bad_alloc
   198 		newDisplay = new RIEGLDisplay(aDisplay); //throws bad_alloc
   198 		iEgl->addDisplay(newDisplay);	//throws bad_alloc
   199 		iEgl->addDisplay(newDisplay);	//throws bad_alloc
   199 		Egldisplay = newDisplay;
   200 		Egldisplay = newDisplay;
   200 		RI_ASSERT(Egldisplay);
   201 		RI_ASSERT(Egldisplay);
   201 	}
   202 	}
   202 	catch(std::bad_alloc)
   203 	catch(std::bad_alloc)
   203 	{
   204 	{
       
   205 		RI_DELETE(pEgl);
   204 		RI_DELETE(newDisplay);
   206 		RI_DELETE(newDisplay);
   205 	//	EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE); //TODO Need to enable this later. Jose
   207     	SetError(EGL_BAD_DISPLAY);
   206 	}
   208     	return EGL_FALSE;
   207     
   209 	}
   208     //need to think of deleting egl if anything goes wrong.
   210     
   209     if (aMajor)	
   211     if (aMajor)	
   210         {
   212         {
   211         *aMajor = KEglMajorVersion;
   213         *aMajor = KEglMajorVersion;
   212         }
   214         }
   213     if (aMinor)
   215     if (aMinor)