EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx, EGLint *attrib_list) { const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; ContextRef _c(dp.get(), ctx); if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { // ctx is not valid return setError(EGL_BAD_CONTEXT, EGL_FALSE); } egl_context_t * c = NULL; c = get_context(ctx); EGLint result = EGL_FALSE; egl_connection_t* const cnx = &gEGLImpl; if (cnx->dso && cnx->egl.eglGpuPerfHintQCOM) { result = cnx->egl.eglGpuPerfHintQCOM( dp->disp.dpy, c->context, attrib_list); } return result; }
EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list, const EGLint *attrib_list) { clearError(); egl_connection_t* cnx = NULL; const egl_display_ptr dp = validate_display_connection(dpy, cnx); if (dp) { if (share_list != EGL_NO_CONTEXT) { if (!ContextRef(dp.get(), share_list).get()) { return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT); } egl_context_t* const c = get_context(share_list); share_list = c->context; } EGLContext context = cnx->egl.eglCreateContext( dp->disp.dpy, config, share_list, attrib_list); if (context != EGL_NO_CONTEXT) { // figure out if it's a GLESv1 or GLESv2 int version = 0; if (attrib_list) { while (*attrib_list != EGL_NONE) { GLint attr = *attrib_list++; GLint value = *attrib_list++; if (attr == EGL_CONTEXT_CLIENT_VERSION) { if (value == 1) { version = egl_connection_t::GLESv1_INDEX; } else if (value == 2 || value == 3) { version = egl_connection_t::GLESv2_INDEX; } } }; } egl_context_t* c = new egl_context_t(dpy, context, config, cnx, version); #if EGL_TRACE if (getEGLDebugLevel() > 0) GLTrace_eglCreateContext(version, c); #endif return c; } else { EGLint error = eglGetError(); ALOGE_IF(error == EGL_SUCCESS, "eglCreateContext(%p, %p, %p, %p) returned EGL_NO_CONTEXT " "but no EGL error!", dpy, config, share_list, attrib_list); } } return EGL_NO_CONTEXT; }
void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) { ATRACE_CALL(); clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) { return; } SurfaceRef _s(dp.get(), surface); if (!_s.get()) { setError(EGL_BAD_SURFACE, EGL_FALSE); return; } }
EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, NativePixmapType target) { clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; SurfaceRef _s(dp.get(), surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); egl_surface_t const * const s = get_surface(surface); return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target); }
EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value) { clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; ContextRef _c(dp.get(), ctx); if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); egl_context_t * const c = get_context(ctx); return c->cnx->egl.eglQueryContext( dp->disp.dpy, c->context, attribute, value); }
EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value) { clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; SurfaceRef _s(dp.get(), surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); egl_surface_t const * const s = get_surface(surface); return s->cnx->egl.eglQuerySurface( dp->disp.dpy, s->surface, attribute, value); }
EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) { clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; SurfaceRef _s(dp.get(), surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); egl_surface_t const * const s = get_surface(surface); if (s->cnx->egl.eglUnlockSurfaceKHR) { return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface); } return setError(EGL_BAD_DISPLAY, EGL_FALSE); }
EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) { clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; SurfaceRef _s(dp.get(), surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); egl_surface_t * const s = get_surface(surface); EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface); if (result == EGL_TRUE) { _s.terminate(); } return result; }
EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) { clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; ContextRef _c(dp.get(), ctx); if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); egl_context_t * const c = get_context(ctx); EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context); if (result == EGL_TRUE) { _c.terminate(); } return result; }
EGLBoolean eglReleaseTexImage( EGLDisplay dpy, EGLSurface surface, EGLint buffer) { clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; SurfaceRef _s(dp.get(), surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); egl_surface_t const * const s = get_surface(surface); if (s->cnx->egl.eglReleaseTexImage) { return s->cnx->egl.eglReleaseTexImage( dp->disp.dpy, s->surface, buffer); } return setError(EGL_BAD_SURFACE, EGL_FALSE); }
EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) { ATRACE_CALL(); clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; SurfaceRef _s(dp.get(), draw); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); #if EGL_TRACE if (gEGLDebugLevel > 0) GLTrace_eglSwapBuffers(dpy, draw); #endif egl_surface_t const * const s = get_surface(draw); if (CC_UNLIKELY(dp->finishOnSwap)) { uint32_t pixel; egl_context_t * const c = get_context( egl_tls_t::getContext() ); if (c) { // glReadPixels() ensures that the frame is complete s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1, GL_RGBA,GL_UNSIGNED_BYTE,&pixel); } } EGLBoolean result = s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); if (CC_UNLIKELY(dp->traceGpuCompletion)) { EGLSyncKHR sync = EGL_NO_SYNC_KHR; { sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL); } if (sync != EGL_NO_SYNC_KHR) { FrameCompletionThread::queueSync(sync); } } return result; }
void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) { ATRACE_CALL(); clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) { return; } SurfaceRef _s(dp.get(), surface); if (!_s.get()) { setError(EGL_BAD_SURFACE, EGL_FALSE); return; } int64_t timestamp = systemTime(SYSTEM_TIME_MONOTONIC); egl_surface_t const * const s = get_surface(surface); native_window_set_buffers_timestamp(s->win.get(), timestamp); }
EGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface, EGLnsecsANDROID time) { clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) { return EGL_FALSE; } SurfaceRef _s(dp.get(), surface); if (!_s.get()) { setError(EGL_BAD_SURFACE, EGL_FALSE); return EGL_FALSE; } egl_surface_t const * const s = get_surface(surface); native_window_set_buffers_timestamp(s->win.get(), time); return EGL_TRUE; }
EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) { clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_NO_IMAGE_KHR; ContextRef _c(dp.get(), ctx); egl_context_t * const c = _c.get(); EGLImageKHR result = EGL_NO_IMAGE_KHR; egl_connection_t* const cnx = &gEGLImpl; if (cnx->dso && cnx->egl.eglCreateImageKHR) { result = cnx->egl.eglCreateImageKHR( dp->disp.dpy, c ? c->context : EGL_NO_CONTEXT, target, buffer, attrib_list); } return result; }
EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) { ATRACE_CALL(); clearError(); const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; SurfaceRef _s(dp.get(), draw); if (!_s.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); #if EGL_TRACE gl_hooks_t const *trace_hooks = getGLTraceThreadSpecific(); if (getEGLDebugLevel() > 0) { if (trace_hooks == NULL) { if (GLTrace_start() < 0) { ALOGE("Disabling Tracer for OpenGL ES"); setEGLDebugLevel(0); } else { // switch over to the trace version of hooks EGLContext ctx = egl_tls_t::getContext(); egl_context_t * const c = get_context(ctx); if (c) { setGLHooksThreadSpecific(c->cnx->hooks[c->version]); GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); } } } GLTrace_eglSwapBuffers(dpy, draw); } else if (trace_hooks != NULL) { // tracing is now disabled, so switch back to the non trace version EGLContext ctx = egl_tls_t::getContext(); egl_context_t * const c = get_context(ctx); if (c) setGLHooksThreadSpecific(c->cnx->hooks[c->version]); GLTrace_stop(); } #endif egl_surface_t const * const s = get_surface(draw); if (CC_UNLIKELY(dp->traceGpuCompletion)) { EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL); if (sync != EGL_NO_SYNC_KHR) { FrameCompletionThread::queueSync(sync); } } if (CC_UNLIKELY(dp->finishOnSwap)) { uint32_t pixel; egl_context_t * const c = get_context( egl_tls_t::getContext() ); if (c) { // glReadPixels() ensures that the frame is complete s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1, GL_RGBA,GL_UNSIGNED_BYTE,&pixel); } } return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); }