EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) { EGLWrapperContext *wctx = (EGLWrapperContext *)ctx; EGLContext aglContext = (ctx == EGL_NO_CONTEXT ? EGL_NO_CONTEXT : wctx->aglContext); EGLThreadInfo *ti = getEGLThreadInfo(); EGLBoolean res = getDispatch()->eglMakeCurrent(dpy, draw, read, aglContext); if (res ) { // NOTE - we do get a pointer to the server connection, (rather then using ti->serverConn) // for cases that this is the first egl call of the current thread. ServerConnection *server; if (s_needEncode && (server = ServerConnection::s_getServerConnection())) { server->utEnc()->makeCurrentContext(server->utEnc(), getpid(), (uint32_t) (draw == EGL_NO_SURFACE ? 0 : draw), (uint32_t) (read == EGL_NO_SURFACE ? 0 : read), (uint32_t) (ctx == EGL_NO_CONTEXT ? 0 : ctx)); server->glEncoder()->setClientState( wctx ? wctx->clientState : NULL ); server->gl2Encoder()->setClientState( wctx ? wctx->clientState : NULL ); } // set current context in our thread info ti->currentContext = wctx; } return res; }
EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { ServerConnection *server; if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { server->utEnc()->swapBuffers(server->utEnc(), getpid(), (uint32_t)surface); server->glEncoder()->flush(); server->gl2Encoder()->flush(); return 1; } return getDispatch()->eglSwapBuffers(dpy, surface); }
EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) { EGLBoolean res = getDispatch()->eglDestroySurface(dpy, surface); if (res && surface != EGL_NO_SURFACE) { ServerConnection *server; if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { server->utEnc()->destroySurface(server->utEnc(), getpid(), (uint32_t)surface); } } return res; }
EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list) { EGLSurface surface = getDispatch()->eglCreatePixmapSurface(dpy, config, pixmap, attrib_list); if (surface != EGL_NO_SURFACE) { ServerConnection *server; if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { server->utEnc()->createSurface(server->utEnc(), getpid(), (uint32_t)surface); } } return surface; }
EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) { EGLContext share = share_context; if (share) share = ((EGLWrapperContext *)share_context)->aglContext; // check if are ES2, and convert it to ES1. int nAttribs = 0; if (attrib_list != NULL) { while(attrib_list[nAttribs] != EGL_NONE) { nAttribs++; } nAttribs++; } EGLint *attrib = NULL; if (nAttribs > 0) { attrib = new EGLint[nAttribs]; memcpy(attrib, attrib_list, nAttribs * sizeof(EGLint)); } int version = 1; for (int i = 0; i < nAttribs; i++) { if (attrib[i] == EGL_CONTEXT_CLIENT_VERSION && attrib[i + 1] == 2) { version = 2; attrib[i + 1] = 1; // replace to version 1 } } EGLContext ctx = getDispatch()->eglCreateContext(dpy, config, share, attrib); delete attrib; EGLWrapperContext *wctx = new EGLWrapperContext(ctx, version); if (ctx != EGL_NO_CONTEXT) { ServerConnection *server; if (s_needEncode && (server = ServerConnection::s_getServerConnection()) != NULL) { wctx->clientState = new GLClientState(); server->utEnc()->createContext(server->utEnc(), getpid(), (uint32_t)wctx, (uint32_t)(share_context == EGL_NO_CONTEXT ? 0 : share_context), wctx->version); } } return (EGLContext)wctx; }
EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) { EGLWrapperContext *wctx = (EGLWrapperContext *)ctx; EGLBoolean res = EGL_FALSE; if (ctx && ctx != EGL_NO_CONTEXT) { res = getDispatch()->eglDestroyContext(dpy, wctx->aglContext); if (res) { EGLThreadInfo *ti = getEGLThreadInfo(); ServerConnection *server; if (s_needEncode && (server = ServerConnection::s_getServerConnection())) { server->utEnc()->destroyContext(ti->serverConn->utEnc(), getpid(), (uint32_t)ctx); } if (ti->currentContext == wctx) ti->currentContext = NULL; delete wctx; } } return res; }