EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR(EGLDisplay display, EGLContext context, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) { VALIDATE_DISPLAY(display); VALIDATE_CONTEXT(context); // We only support EGL_GL_TEXTURE_2D images if (target != EGL_GL_TEXTURE_2D_KHR) { RETURN_ERROR(EGL_NO_IMAGE_KHR,EGL_BAD_PARAMETER); } ThreadInfo* thread = getThreadInfo(); ShareGroupPtr sg = thread->shareGroup; if (sg.Ptr() != NULL) { unsigned int globalTexName = sg->getGlobalName(TEXTURE, SafeUIntFromPointer(buffer)); if (!globalTexName) return EGL_NO_IMAGE_KHR; ImagePtr img( new EglImage() ); if (img.Ptr() != NULL) { ObjectDataPtr objData = sg->getObjectData(TEXTURE, SafeUIntFromPointer(buffer)); if (!objData.Ptr()) return EGL_NO_IMAGE_KHR; TextureData *texData = (TextureData *)objData.Ptr(); if(!texData->width || !texData->height) return EGL_NO_IMAGE_KHR; img->width = texData->width; img->height = texData->height; img->border = texData->border; img->internalFormat = texData->internalFormat; img->globalTexName = globalTexName; return dpy->addImageKHR(img); } } return EGL_NO_IMAGE_KHR; }
EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw) { if (!EglValidate::surfaceTarget(readdraw)) { return EGL_NO_SURFACE; } ThreadInfo* thread = getThreadInfo(); EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); ContextPtr ctx = thread->eglContext; if(dpy && ctx.Ptr()) { SurfacePtr surface = readdraw == EGL_READ ? ctx->read() : ctx->draw(); if(surface.Ptr()) { // This double check is required because a surface might still be // current after it is destroyed - in which case its handle should // be invalid, that is EGL_NO_SURFACE should be returned even // though the surface is current. EGLSurface s = (EGLSurface)SafePointerFromUInt(surface->getHndl()); surface = dpy->getSurface(s); if(surface.Ptr()) { return s; } } } return EGL_NO_SURFACE; }
void detachEGLImage(unsigned int imageId) { ThreadInfo* thread = getThreadInfo(); ContextPtr ctx = thread->eglContext; if (ctx.Ptr()) { ctx->detachImage(imageId); } }
/* * myGetThreadContext - get a thread's context */ static void myGetThreadContext( DWORD id, CONTEXT *pc ) { thread_info *ti; pc->ContextFlags = CONTEXT_TO_USE; ti = getThreadInfo( id ); if( ti != NULL ) { GetThreadContext( ti->th, pc ); } } /* myGetThreadContext */
/* * deadThread - a thread is dead */ static void deadThread( DWORD id ) { thread_info *ti; ti = getThreadInfo( id ); if( ti != NULL ) { ti->live = FALSE; } } /* deadThread */
//----------------------------------------------------------------------------- /// Push a new marker that starts now void Profiler::pushCpuMarker(const char* name, const video::SColor& color) { // Don't do anything when frozen if(m_freeze_state == FROZEN || m_freeze_state == WAITING_FOR_UNFREEZE) return; ThreadInfo& ti = getThreadInfo(); MarkerStack& markers_stack = ti.markers_stack[m_write_id]; double start = getTimeMilliseconds() - m_time_last_sync; size_t layer = markers_stack.size(); // Add to the stack of current markers markers_stack.push(Marker(start, -1.0, name, color, layer)); }
/************************** KHR IMAGE *************************************************************/ EglImage *attachEGLImage(unsigned int imageId) { ThreadInfo* thread = getThreadInfo(); EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); ContextPtr ctx = thread->eglContext; if (ctx.Ptr()) { ImagePtr img = dpy->getImage(reinterpret_cast<EGLImageKHR>(imageId)); if(img.Ptr()) { ctx->attachImage(imageId,img); return img.Ptr(); } } return NULL; }
EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void) { ThreadInfo* thread = getThreadInfo(); EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); ContextPtr ctx = thread->eglContext; if(dpy && ctx.Ptr()){ // This double check is required because a context might still be current after it is destroyed - in which case // its handle should be invalid, that is EGL_NO_CONTEXT should be returned even though the context is current EGLContext c = (EGLContext)SafePointerFromUInt(ctx->getHndl()); if(dpy->getContext(c).Ptr()) { return c; } } return EGL_NO_CONTEXT; }
/* * RecordSample - record a sample in a specific thread */ void RecordSample( unsigned offset, unsigned short segment, DWORD real_tid ) { samp_block *old_samples; unsigned old_sample_index; unsigned old_sample_count; thread_info *ti; DWORD tid; ti = getThreadInfo( real_tid ); if( ti == NULL ) { return; } tid = ti->index; LastSampleIndex = ti->SampleIndex; if( ti->SampleIndex == 0 ) { ti->Samples->pref.tick = CurrTick; if( CallGraphMode ) { ti->CallGraph->pref.tick = CurrTick; } } ++CurrTick; ti->Samples->d.sample.sample[ti->SampleIndex].offset = offset; ti->Samples->d.sample.sample[ti->SampleIndex].segment = segment; ti->SampleIndex++; if( CallGraphMode ) { ti->SampleCount++; } if( CallGraphMode && tid == 0 ) { old_sample_count = SampleCount; old_samples = Samples; /* since RecordCGraph isn't */ old_sample_index = SampleIndex; /* used to threads, we fool */ Samples = ti->Samples; /* it into storing the info */ SampleIndex = ti->SampleIndex; /* in the right place by */ SampleCount = ti->SampleCount; RecordCGraph(); /* changing its pointers */ ti->Samples = Samples; /* and restoring them later */ ti->SampleIndex = SampleIndex; ti->SampleCount = SampleCount; Samples = old_samples; SampleIndex = old_sample_index; SampleCount = old_sample_count; } if( ti->SampleIndex >= Margin ) { StopAndSave(); } } /* RecordSample */
//----------------------------------------------------------------------------- /// Stop the last pushed marker void Profiler::popCpuMarker() { // Don't do anything when frozen if(m_freeze_state == FROZEN || m_freeze_state == WAITING_FOR_UNFREEZE) return; ThreadInfo& ti = getThreadInfo(); assert(ti.markers_stack[m_write_id].size() > 0); MarkerStack& markers_stack = ti.markers_stack[m_write_id]; MarkerList& markers_done = ti.markers_done[m_write_id]; // Update the date of end of the marker Marker& marker = markers_stack.top(); marker.end = getTimeMilliseconds() - m_time_last_sync; // Remove the marker from the stack and add it to the list of markers done markers_done.push_front(marker); markers_stack.pop(); }
EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay display, EGLSurface surface) { VALIDATE_DISPLAY(display); VALIDATE_SURFACE(surface,Srfc); ThreadInfo* thread = getThreadInfo(); ContextPtr currentCtx = thread->eglContext; //if surface not window return if(Srfc->type() != EglSurface::WINDOW){ RETURN_ERROR(EGL_TRUE,EGL_SUCCESS); } if(!currentCtx.Ptr() || !currentCtx->usingSurface(Srfc) || !dpy->nativeType()->isValidNativeWin(Srfc.Ptr()->native())) { RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); } dpy->nativeType()->swapBuffers(Srfc->native()); return EGL_TRUE; }
int main(int argc, char *argv[]) { //Variable declarations FILE *fileptr = NULL; char tmpstring[MAXLEN+1]; time_t rawtime; struct tm * timeinfo; char namegen[1024]; int k=0; int status = 0; yyin = fopen(argv[1], "r"); struct config_params params; struct storage_record record_temp; struct bigstring str; int max_keys = 10; char keynames[10][100]; yyparse(¶ms, &record_temp, &str, &max_keys, keynames, &status); printf("port number: %d\n", params.server_port); printf("status1: %d\n", status); if (status == -1) { printf("Error in configration files\n"); errno = ERR_INVALID_PARAM; exit(EXIT_FAILURE); } printf("status2: %d\n", status); status = check_column(¶ms); printf("status3: %d\n", status); if (status == -1) { printf("Error in configration files\n"); errno = ERR_INVALID_PARAM; exit(EXIT_FAILURE); } struct city **headlist=(struct city**)malloc(sizeof(struct city*) * MAX_TABLES); for(k=0;k<100;k++){ headlist[k]=(struct city*)malloc(sizeof(struct city)); } //End of variable declarations if(flag!=1&&LOGGING==2){ time ( &rawtime ); timeinfo = localtime ( &rawtime ); sprintf(namegen,"Server-%.4d-%.2d-%.2d-%.2d-%.2d-%.2d.log",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); fileptr=fopen(namegen,"w"); flag=1; } // Process command line arguments. //This program expects exactly one argument: the config file name. assert(argc > 0); if (argc != 2){ if(LOGGING==2){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); sprintf(tmpstring,"Usage %s <config_file>\n",argv[0]); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp } printf("Usage %s <config_file>\n", argv[0]); exit(EXIT_FAILURE); } if (status != 0) { if(LOGGING==2){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); sprintf(tmpstring,"Error processing config file.\n"); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp } printf("Error processing config file.\n"); exit(EXIT_FAILURE); } if(LOGGING==2){ sprintf(tmpstring,"Server on %s:%d\n",params.server_host, params.server_port); time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp printf("Server on %s:%d\n",params.server_host,params.server_port); } // Create a socket. int listensock = socket(PF_INET, SOCK_STREAM, 0); if (listensock < 0) { if(LOGGING==2){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); sprintf(tmpstring,"Error creating socket.\n"); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp } printf("Error creating socket.\n"); exit(EXIT_FAILURE); } // Allow listening port to be reused if defunct. int yes = 1; status = setsockopt(listensock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes); if (status != 0) { if(LOGGING==2){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); sprintf(tmpstring,"Error configuring socket.\n"); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp } printf("Error configuring socket.\n"); exit(EXIT_FAILURE); } // Bind it to the listening port. struct sockaddr_in listenaddr; memset(&listenaddr, 0, sizeof listenaddr); listenaddr.sin_family = AF_INET; listenaddr.sin_port = htons(params.server_port); inet_pton(AF_INET, params.server_host, &(listenaddr.sin_addr)); // bind to local IP address status = bind(listensock, (struct sockaddr*) &listenaddr, sizeof listenaddr); if (status != 0) { if(LOGGING==2){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); sprintf(tmpstring,"Error binding socket.\n"); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp } printf("Error binding socket.\n"); exit(EXIT_FAILURE); } // Listen for connections. status = listen(listensock, MAX_LISTENQUEUELEN); if (status != 0) { if(LOGGING==2){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); sprintf(tmpstring,"Error listening on socket.\n"); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp } printf("Error listening on socket.\n"); exit(EXIT_FAILURE); } if (params.option == 0) { // Listen loop. int wait_for_connections = 1; while (wait_for_connections) { // Wait for a connection. struct sockaddr_in clientaddr; socklen_t clientaddrlen = sizeof clientaddr; int clientsock = accept(listensock, (struct sockaddr*)&clientaddr, &clientaddrlen); if (clientsock < 0) { if(LOGGING==2){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); sprintf(tmpstring,"Error accepting a connection.\n"); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp } printf("Error accepting a connection.\n"); exit(EXIT_FAILURE); } if(LOGGING==2){ sprintf(tmpstring,"Got a connection from %s:%d\n",inet_ntoa(clientaddr.sin_addr), clientaddr.sin_port); time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp printf("Got a connection from %s:%d\n",inet_ntoa(clientaddr.sin_addr), clientaddr.sin_port); } int auth_success = 0; // Get commands from client. int wait_for_commands = 1; do { // Read a line from the client. char cmd[MAX_CMD_LEN]; int status = recvline(clientsock, cmd, MAX_CMD_LEN); if (status != 0) { // Either an error occurred or the client closed the connection. wait_for_commands = 0; } else { // Handle the command from the client. //printf("OUTSIDE %p", headlist); int status = handle_command(clientsock, cmd, fileptr, ¶ms, headlist, &auth_success); if (status != 0) wait_for_commands = 0; // Oops. An error occured. } } while (wait_for_commands); // Close the connection with the client. close(clientsock); //LOG(("Closed connection from %s:%d.\n", inet_ntoa(clientaddr.sin_addr), clientaddr.sin_port)); if(LOGGING==2){ sprintf(tmpstring, "Closed connection from %s:%d\n",inet_ntoa(clientaddr.sin_addr),clientaddr.sin_port); time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp printf("Closed connection from %s:%d\n",inet_ntoa(clientaddr.sin_addr),clientaddr.sin_port); } auth_success = 0; } // Stop listening for connections. close(listensock); //free(tmpstring); return EXIT_SUCCESS; } else if (params.option == 1) { // Allocate threads pool int i; for (i = 0; i!=MAX_CONNECTIONS; ++i) { runtimeThreads[i] = malloc( sizeof( struct _ThreadInfo ) ); } // Listen loop. int wait_for_connections = 1; while (wait_for_connections) { // Wait for a connection. ThreadInfo tiInfo = getThreadInfo(); tiInfo->clientaddrlen = sizeof(struct sockaddr_in); tiInfo->clientsock = accept(listensock, (struct sockaddr*)&tiInfo->clientaddr, &tiInfo->clientaddrlen); tiInfo->fileptr = fileptr; tiInfo->params = ¶ms; tiInfo->headlist = headlist; tiInfo->auth_success = 0; if (tiInfo->clientsock < 0) { if(LOGGING==2){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); sprintf(tmpstring,"Error accepting a connection.\n"); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp } printf("Error accepting a connection.\n"); exit(EXIT_FAILURE); } else { if(LOGGING==2){ sprintf(tmpstring,"Got a connection from %s:%d\n",inet_ntoa(tiInfo->clientaddr.sin_addr), tiInfo->clientaddr.sin_port); time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); logger(fileptr,namegen);//Timestamp logger(fileptr,tmpstring); } else if(LOGGING==1){ time(&rawtime); timeinfo=localtime(&rawtime); sprintf(namegen,"%.4d-%.2d-%.2d-%.2d-%.2d-%.2d: ",timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); printf("%s",namegen);//Timestamp printf("Got a connection from %s:%d\n",inet_ntoa(tiInfo->clientaddr.sin_addr), tiInfo->clientaddr.sin_port); } pthread_create( &tiInfo->theThread, NULL, threadCallFunction, tiInfo ); } } /* At the end, wait until all connections close */ for (i=topRT; i!=botRT; i = (i+1)%MAX_CONNECTIONS) pthread_join(runtimeThreads[i]->theThread, 0 ); /* Deallocate all the resources */ for (i=0; i!=MAX_CONNECTIONS; i++) free( runtimeThreads[i] ); close(listensock); return EXIT_SUCCESS; } return EXIT_SUCCESS; }
EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void) { ThreadInfo* thread = getThreadInfo(); EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); return eglMakeCurrent(dpy,EGL_NO_SURFACE,EGL_NO_SURFACE,EGL_NO_CONTEXT); }
EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void) { ThreadInfo* thread = getThreadInfo(); return (thread->eglContext.Ptr()) ? thread->eglDisplay : EGL_NO_DISPLAY; }
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context) { VALIDATE_DISPLAY(display); bool releaseContext = EglValidate::releaseContext(context, read, draw); if(!releaseContext && EglValidate::badContextMatch(context, read, draw)) { RETURN_ERROR(EGL_FALSE, EGL_BAD_MATCH); } ThreadInfo* thread = getThreadInfo(); ContextPtr prevCtx = thread->eglContext; if(releaseContext) { //releasing current context if(prevCtx.Ptr()) { g_eglInfo->getIface(prevCtx->version())->flush(); if(!dpy->nativeType()->makeCurrent(NULL,NULL,NULL)) { RETURN_ERROR(EGL_FALSE,EGL_BAD_ACCESS); } thread->updateInfo(ContextPtr(NULL),dpy,NULL,ShareGroupPtr(NULL),dpy->getManager(prevCtx->version())); } } else { //assining new context VALIDATE_CONTEXT(context); VALIDATE_SURFACE(draw,newDrawSrfc); VALIDATE_SURFACE(read,newReadSrfc); EglSurface* newDrawPtr = newDrawSrfc.Ptr(); EglSurface* newReadPtr = newReadSrfc.Ptr(); ContextPtr newCtx = ctx; if (newCtx.Ptr() && prevCtx.Ptr()) { if (newCtx.Ptr() == prevCtx.Ptr()) { if (newDrawPtr == prevCtx->draw().Ptr() && newReadPtr == prevCtx->read().Ptr()) { // nothing to do return EGL_TRUE; } } else { // Make sure previous context is detached from surfaces releaseContext = true; } } //surfaces compatibility check if(!((*ctx->getConfig()).compatibleWith((*newDrawPtr->getConfig()))) || !((*ctx->getConfig()).compatibleWith((*newReadPtr->getConfig())))) { RETURN_ERROR(EGL_FALSE,EGL_BAD_MATCH); } EglOS::Display* nativeDisplay = dpy->nativeType(); EglOS::Surface* nativeRead = newReadPtr->native(); EglOS::Surface* nativeDraw = newDrawPtr->native(); //checking native window validity if(newReadPtr->type() == EglSurface::WINDOW && !nativeDisplay->isValidNativeWin(nativeRead)) { RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW); } if(newDrawPtr->type() == EglSurface::WINDOW && !nativeDisplay->isValidNativeWin(nativeDraw)) { RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW); } if(prevCtx.Ptr()) { g_eglInfo->getIface(prevCtx->version())->flush(); } if (!dpy->nativeType()->makeCurrent( newReadPtr->native(), newDrawPtr->native(), newCtx->nativeType())) { RETURN_ERROR(EGL_FALSE,EGL_BAD_ACCESS); } //TODO: handle the following errors // EGL_BAD_CURRENT_SURFACE , EGL_CONTEXT_LOST , EGL_BAD_ACCESS thread->updateInfo(newCtx,dpy,newCtx->getGlesContext(),newCtx->getShareGroup(),dpy->getManager(newCtx->version())); newCtx->setSurfaces(newReadSrfc,newDrawSrfc); g_eglInfo->getIface(newCtx->version())->initContext(newCtx->getGlesContext(),newCtx->getShareGroup()); // Initialize the GLES extension function table used in // eglGetProcAddress for the context's GLES version if not // yet initialized. We initialize it here to make sure we call the // GLES getProcAddress after when a context is bound. g_eglInfo->initClientExtFuncTable(newCtx->version()); } // release previous context surface binding if(prevCtx.Ptr() && releaseContext) { prevCtx->setSurfaces(SurfacePtr(NULL),SurfacePtr(NULL)); } return EGL_TRUE; }
GLEScontext* getGLESContext() { ThreadInfo* thread = getThreadInfo(); return thread->glesContext; }