guestrendering/guestegl/src/guestegl.cpp
branchbug235_bringup_0
changeset 39 c8311e991ee3
parent 28 9464ab1666a0
child 40 eaa1315a8556
equal deleted inserted replaced
38:2688aad49bab 39:c8311e991ee3
   197         {
   197         {
   198         return NULL;
   198         return NULL;
   199         }
   199         }
   200 	}
   200 	}
   201 
   201 
   202 EGLSurface CGuestEGL::eglCreateWindowSurface(TEglThreadState&, int, int, void*, const int*)
   202 EGLSurface CGuestEGL::eglCreateWindowSurface(TEglThreadState& aThreadState, EGLDisplay aDisplay, EGLConfig aConfig, 
   203 	{
   203 		EGLNativeWindowType aNativeWindow, const EGLint *aAttribList)
   204 	return 0; // stub code
   204 	{
   205 	}
   205 
       
   206 	// FAISALMEMON NEW
       
   207 	/**
       
   208 	 * pseudo code:
       
   209 	 * 
       
   210 	 * surfacemamanger.
       
   211 	 * 	open()
       
   212 	 *   createsurface(2 buffers, width, height, pixel format,...)
       
   213 	 *   map surface -> get chunk
       
   214 	 * serialization.eglCreateWindowSurface(..)
       
   215 	 * eglinternalfunctioncreatesurface(chunk, width, height, ..)
       
   216 	 * egl.... setwindowsurfacebuffers(...)
       
   217 	 * surfaceupdatesession.connect()
       
   218 	 * wnd.setbackgroundsurface()
       
   219 	 */
       
   220 	EGL_TRACE( "CGuestEGL::eglCreateWindowSurface");
       
   221 	EGL_TRACE_ATTRIB_LIST(aAttribList);
       
   222 
       
   223 	RWindow* window;
       
   224 	window = (RWindow*) aNativeWindow;
       
   225 	TSize size = window->Size();
       
   226 	
       
   227 	EGLSurface newSurfaceId = EGL_NO_SURFACE;
       
   228 	TSurfaceInfo* surfaceInfo = NULL;
       
   229 	EGLint error = EGL_BAD_DISPLAY;
       
   230 	TSurfaceId surfaceId;
       
   231 
       
   232     RSurfaceManager::TSurfaceCreationAttributesBuf buf;
       
   233     RSurfaceManager::TSurfaceCreationAttributes& attributes = buf();
       
   234 
       
   235     attributes.iSize = size;
       
   236     attributes.iBuffers = 2;           // REQUIREMENT because host side assumes exactly two buffers
       
   237     attributes.iPixelFormat = EUidPixelFormatARGB_8888;  // this is a guess; either query or hardcode to match syborg
       
   238     attributes.iStride = 4 * size.iWidth;          // Number of bytes between start of one line and start of next
       
   239     attributes.iOffsetToFirstBuffer = 0;
       
   240     attributes.iAlignment = EPageAligned;                      // alignment, 1,2,4,8,16,32,64 byte aligned or EPageAligned
       
   241     attributes.iHintCount=0;  
       
   242     attributes.iSurfaceHints = NULL;
       
   243     attributes.iOffsetBetweenBuffers = 0;
       
   244     attributes.iContiguous = ETrue;
       
   245     attributes.iCacheAttrib = RSurfaceManager::ENotCached;      // Cache attributes
       
   246 
       
   247 	iDisplayMapLock.WriteLock();
       
   248 	CEglDisplayInfo** pDispInfo;
       
   249 	pDispInfo = iDisplayMap.Find(aDisplay);
       
   250 	
       
   251 	if (pDispInfo && *pDispInfo)
       
   252 			{
       
   253 			RHeap* threadHeap = CVghwUtils::SwitchToVghwHeap();
       
   254 	
       
   255 			surfaceInfo = new TSurfaceInfo();
       
   256 			if (surfaceInfo)
       
   257 				{
       
   258 				surfaceInfo->iConfigId = aConfig;
       
   259 				surfaceInfo->iSurfaceManager.Open();
       
   260 				surfaceInfo->iSurfaceManager.CreateSurface(buf, surfaceId);
       
   261 				(*pDispInfo)->iSurfaceMap.Insert(surfaceId, surfaceInfo);
       
   262 				(void) surfaceInfo->iSurfaceManager.MapSurface(surfaceId, surfaceInfo->iChunk);
       
   263 				RemoteFunctionCallData rfcdata;
       
   264 				EglRFC eglApiData( rfcdata );
       
   265 				eglApiData.Init( EglRFC::EeglCreateWindowSurface);
       
   266 				eglApiData.AppendEGLDisplay(aDisplay);
       
   267 				eglApiData.AppendEGLConfig(aConfig);
       
   268 				eglApiData.AppendEGLNativeWindowType(aNativeWindow);				
       
   269 				eglApiData.AppendEGLintVector(aAttribList, TAttribUtils::AttribListLength(aAttribList) );
       
   270 				eglApiData.AppendEGLint(size.iWidth);
       
   271 				eglApiData.AppendEGLint(size.iHeight);
       
   272 				eglApiData.AppendEGLint(1000); // horizontalPitch arbitrary
       
   273 				eglApiData.AppendEGLint(1000); // verticalPitch arbitrary
       
   274 				surfaceInfo->iHostSurfaceId = aThreadState.ExecEglSurfaceCmd(eglApiData); // todo check if is valid
       
   275 				EglInternalFunction_CreateSurface(aThreadState, aDisplay, surfaceInfo->iHostSurfaceId, aConfig, window, *surfaceInfo);
       
   276 				surfaceInfo->iSurfaceUpdateSession.Connect();
       
   277 				TSurfaceConfiguration surfaceConfig;
       
   278 				surfaceConfig.SetSurfaceId(surfaceId);
       
   279 				window->SetBackgroundSurface(surfaceConfig, ETrue);
       
   280 				}
       
   281 			CVghwUtils::SwitchFromVghwHeap(threadHeap);
       
   282 			}
       
   283 	
       
   284 		iDisplayMapLock.Unlock();
       
   285 		
       
   286 	aThreadState.SetEglError(EGL_SUCCESS);
       
   287 
       
   288 	return surfaceInfo->iHostSurfaceId;
       
   289 	
       
   290 	// FAISALMEMON END OF NEW
       
   291 	
       
   292 	}
       
   293 
   206 const char* CGuestEGL::eglQueryString(EGLDisplay aDisplay, EGLint aName)
   294 const char* CGuestEGL::eglQueryString(EGLDisplay aDisplay, EGLint aName)
   207 	{
   295 	{
   208 	return NULL; // stub code
   296 	return NULL; // stub code
   209 	}
   297 	}
   210 // FAISALMEMON END OF STUB CODE
   298 // FAISALMEMON END OF STUB CODE
   900 	return result;
   988 	return result;
   901 	}
   989 	}
   902 
   990 
   903 EGLBoolean CGuestEGL::eglSwapBuffers(TEglThreadState& aThreadState, EGLDisplay aDisplay, EGLSurface aSurface)
   991 EGLBoolean CGuestEGL::eglSwapBuffers(TEglThreadState& aThreadState, EGLDisplay aDisplay, EGLSurface aSurface)
   904     {
   992     {
       
   993 	/**
       
   994 	 * PSEUDO CODE
       
   995 	 * serialization.eglSwapBuffers
       
   996 	 * (maybe finish currently bound api)
       
   997 	 * surfaceupdatesession.notifywhenavailable
       
   998 	 *   .whendisplayed()  (alternative choice from above)
       
   999 	 * surfaceupdatesession.submitupdated()
       
  1000 	 * user:waitforrequestl
       
  1001 	 */
   905     EglInternalFunction_SwapWindowSurface(aThreadState, aDisplay, aSurface);
  1002     EglInternalFunction_SwapWindowSurface(aThreadState, aDisplay, aSurface);
   906 
  1003 
   907     // ToDo when all surfaces are recorded in client validate BEFORE sending cmd to host
  1004     // ToDo when all surfaces are recorded in client validate BEFORE sending cmd to host
   908     TSurfaceInfo* surfaceInfo = EglInternalFunction_GetPlatformSurface( aDisplay, aSurface );
  1005     TSurfaceInfo* surfaceInfo = EglInternalFunction_GetPlatformSurface( aDisplay, aSurface );
   909     EGL_CHECK_ERROR( surfaceInfo, EGL_BAD_SURFACE, EGL_FALSE );
  1006     EGL_CHECK_ERROR( surfaceInfo, EGL_BAD_SURFACE, EGL_FALSE );
  1078     TUint8 offsetToFirstBuffer = 0; // This is wrong; just stub code
  1175     TUint8 offsetToFirstBuffer = 0; // This is wrong; just stub code
  1079     TUint8 offsetToSecondBuffer = 0; // This is wrong; just stub code
  1176     TUint8 offsetToSecondBuffer = 0; // This is wrong; just stub code
  1080     // FAISALMEMON END OF STUB CODE
  1177     // FAISALMEMON END OF STUB CODE
  1081     
  1178     
  1082     TUint32 chunkHWBase = 0;
  1179     TUint32 chunkHWBase = 0;
  1083     (void)CVghwUtils::MapToHWAddress(aSurfaceInfo.iChunk->Handle(), chunkHWBase);
  1180     (void)CVghwUtils::MapToHWAddress(aSurfaceInfo.iChunk.Handle(), chunkHWBase);
  1084     // FAISALMEMON write code to handle errors in the above function
  1181     // FAISALMEMON write code to handle errors in the above function
  1085     EGL_TRACE("CGuestEGL::EglInternalFunction_CreateSurface AFTER VGHWUtils::MapToHWAddress");
  1182     EGL_TRACE("CGuestEGL::EglInternalFunction_CreateSurface AFTER VGHWUtils::MapToHWAddress");
  1086 
  1183 
  1087 	TUint32 frameBufferBaseAddress(0);
  1184 	TUint32 frameBufferBaseAddress(0);
  1088 	(void)CVghwUtils::GetFrameBufferBaseAddress(frameBufferBaseAddress);
  1185 	(void)CVghwUtils::GetFrameBufferBaseAddress(frameBufferBaseAddress);
  1089 	EGL_TRACE("CPlatsimEGL::egliCreateSurface AFTER VGHWUtils::MapToHWAddress");
  1186 	EGL_TRACE("CPlatsimEGL::egliCreateSurface AFTER VGHWUtils::MapToHWAddress");
  1090 
  1187 
  1091     /* Store the pointer to the pixel data */
  1188     /* Store the pointer to the pixel data */
  1092     aSurfaceInfo.iBuffer0 = aSurfaceInfo.iChunk->Base() + offsetToFirstBuffer;
  1189     aSurfaceInfo.iBuffer0 = aSurfaceInfo.iChunk.Base() + offsetToFirstBuffer;
  1093     aSurfaceInfo.iBuffer1 = aSurfaceInfo.iChunk->Base() + offsetToSecondBuffer;
  1190     aSurfaceInfo.iBuffer1 = aSurfaceInfo.iChunk.Base() + offsetToSecondBuffer;
  1094 
  1191 
  1095     aSurfaceInfo.iBuffer0Index = (chunkHWBase + offsetToFirstBuffer) -  frameBufferBaseAddress;
  1192     aSurfaceInfo.iBuffer0Index = (chunkHWBase + offsetToFirstBuffer) -  frameBufferBaseAddress;
  1096     aSurfaceInfo.iBuffer1Index = (chunkHWBase + offsetToSecondBuffer) - frameBufferBaseAddress;
  1193     aSurfaceInfo.iBuffer1Index = (chunkHWBase + offsetToSecondBuffer) - frameBufferBaseAddress;
  1097     EGL_TRACE("CGuestEGL::EglInternalFunction_CreateSurface %u %x %x %x %x",chunkHWBase, offsetToFirstBuffer, offsetToSecondBuffer,
  1194     EGL_TRACE("CGuestEGL::EglInternalFunction_CreateSurface %u %x %x %x %x",chunkHWBase, offsetToFirstBuffer, offsetToSecondBuffer,
  1098     		aSurfaceInfo.iBuffer0Index,
  1195     		aSurfaceInfo.iBuffer0Index,