HostConnection *HostConnection::get() { /* TODO: Make this configurable with a system property */ const int useQemuPipe = USE_QEMU_PIPE; // Get thread info EGLThreadInfo *tinfo = getEGLThreadInfo(); if (!tinfo) { return NULL; } if (tinfo->hostConn == NULL) { HostConnection *con = new HostConnection(); if (NULL == con) { return NULL; } if (useQemuPipe) { QemuPipeStream *stream = new QemuPipeStream(STREAM_BUFFER_SIZE); if (!stream) { LOGE("Failed to create QemuPipeStream for host connection!!!\n"); delete con; return NULL; } if (stream->connect() < 0) { LOGE("Failed to connect to host (QemuPipeStream)!!!\n"); delete con; return NULL; } con->m_stream = stream; } else /* !useQemuPipe */ { TcpStream *stream = new TcpStream(STREAM_BUFFER_SIZE); if (!stream) { LOGE("Failed to create TcpStream for host connection!!!\n"); delete con; return NULL; } if (stream->connect("10.0.2.2", STREAM_PORT_NUM) < 0) { LOGE("Failed to connect to host (TcpStream)!!!\n"); delete con; return NULL; } con->m_stream = stream; } // send zero 'clientFlags' to the host. unsigned int *pClientFlags = (unsigned int *)con->m_stream->allocBuffer(sizeof(unsigned int)); *pClientFlags = 0; con->m_stream->commitBuffer(sizeof(unsigned int)); LOGD("HostConnection::get() New Host Connection established %p, tid %d\n", con, gettid()); tinfo->hostConn = con; } return tinfo->hostConn; }
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; }
gl2_client_context_t *HostConnection::s_getGL2Context() { EGLThreadInfo *ti = getEGLThreadInfo(); if (ti->hostConn) { return ti->hostConn->m_gl2Enc; } return NULL; }
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; }
static const char *getGLString(int glEnum) { EGLThreadInfo *tInfo = getEGLThreadInfo(); if (!tInfo || !tInfo->currentContext) { return NULL; } const char** strPtr = NULL; #define GL_VENDOR 0x1F00 #define GL_RENDERER 0x1F01 #define GL_VERSION 0x1F02 #define GL_EXTENSIONS 0x1F03 switch(glEnum) { case GL_VERSION: strPtr = &tInfo->currentContext->versionString; break; case GL_VENDOR: strPtr = &tInfo->currentContext->vendorString; break; case GL_RENDERER: strPtr = &tInfo->currentContext->rendererString; break; case GL_EXTENSIONS: strPtr = &tInfo->currentContext->extensionString; break; } if (!strPtr) { return NULL; } if (*strPtr != NULL) { // // string is already cached // return *strPtr; } // // first query of that string - need to query host // DEFINE_AND_VALIDATE_HOST_CONNECTION(NULL); char *hostStr = NULL; int n = rcEnc->rcGetGLString(rcEnc, glEnum, NULL, 0); if (n < 0) { hostStr = new char[-n+1]; n = rcEnc->rcGetGLString(rcEnc, glEnum, hostStr, -n); if (n <= 0) { delete [] hostStr; hostStr = NULL; } } // // keep the string in the context and return its value // *strPtr = hostStr; return hostStr; }
static T setErrorFunc(GLint error, T returnValue) { getEGLThreadInfo()->eglError = error; return returnValue; }
EGLContext eglGetCurrentContext() { EGLThreadInfo *ti = getEGLThreadInfo(); return (ti->currentContext ? ti->currentContext : EGL_NO_CONTEXT); }