From 99e3dcb6d0ab7657b5ce01170d31453e6a3d0360 Mon Sep 17 00:00:00 2001 From: Nikita Kalyazin Date: Tue, 17 Sep 2013 17:30:34 +0400 Subject: [PATCH] [FIX] eglSwapBuffers probe fix Probing this function caused black screen for OpenGL applications before. The matter of the problem: - eglSwapBuffers is just a macro in inc/egl_macro.h (framework/osp/uifw): #define eglSwapBuffers _SglSwapBuffers - _SglSwapBuffers is a wrapper that calls true eglSwapBuffers inside; - we used to call eglSwapBuffers where _SglSwapBuffers must be called. This caused an error (EGL_BAD_SURFACE). In order to probe eglSwapBuffers function we need to undef the macro first. Moreover, eglSwapBuffers is not called at Emulator (GlesShader sample application). So I added _SglSwapBuffers function itself as well. Minor fix: for EGL functions eglGetError (insted of glGetError) should be called. Change-Id: I6a99c67a8f28fc2cca3ea0ea78de7afb252cb9c1 Signed-off-by: Nikita Kalyazin --- include/api_id_mapping.h | 3 ++ probe_graphics/da_gles20.cpp | 30 +++++++++---- probe_graphics/da_gles20.h | 104 ++++++++++++++++++++++++++++++++++++++----- scripts/api_names.txt | 3 ++ 4 files changed, 121 insertions(+), 19 deletions(-) diff --git a/include/api_id_mapping.h b/include/api_id_mapping.h index 3372886..f4ee9bc 100644 --- a/include/api_id_mapping.h +++ b/include/api_id_mapping.h @@ -527,3 +527,6 @@ #define API_ID_glIsRenderbuffer 504 // glIsRenderbuffer #define API_ID_glIsShader 505 // glIsShader #define API_ID_glIsTexture 506 // glIsTexture + +#define API_ID__SglSwapBuffers 507 // _SglSwapBuffers +#define API_ID_eglSwapBuffers 508 // eglSwapBuffers diff --git a/probe_graphics/da_gles20.cpp b/probe_graphics/da_gles20.cpp index dceeabe..362374f 100644 --- a/probe_graphics/da_gles20.cpp +++ b/probe_graphics/da_gles20.cpp @@ -473,15 +473,27 @@ void glEnableVertexAttribArray(GLuint index) { AFTER(NO_RETURN_VALUE, APITYPE_CONTEXT, "", "d", index); } -//EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { -// typedef EGLBoolean (*methodType)(EGLDisplay, EGLSurface); -// BEFORE_EGL(eglSwapBuffers); -// EGLBoolean ret = eglSwapBuffersp(dpy, surface); -// error = glGetError(); -//AFTER_NO_PARAM(ret, APITYPE_CONTEXT, ""); -// -// return ret; -//} +#undef eglSwapBuffers +extern "C" EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { + typedef EGLBoolean (*methodType)(EGLDisplay, EGLSurface); + BEFORE_EGL(eglSwapBuffers); + EGLBoolean ret = eglSwapBuffersp(dpy, surface); + error = eglGetError(); + AFTER_NO_PARAM(ret, APITYPE_CONTEXT, ""); + + return ret; +} +#define eglSwapBuffers _SglSwapBuffers + +EGLBoolean _SglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { + typedef EGLBoolean (*methodType)(EGLDisplay, EGLSurface); + BEFORE_OSP_UIFW(_SglSwapBuffers); + EGLBoolean ret = _SglSwapBuffersp(dpy, surface); + error = eglGetError(); + AFTER_NO_PARAM(ret, APITYPE_CONTEXT, ""); + + return ret; +} // ================================================================== // F 5 diff --git a/probe_graphics/da_gles20.h b/probe_graphics/da_gles20.h index f536cf0..de21fa4 100644 --- a/probe_graphics/da_gles20.h +++ b/probe_graphics/da_gles20.h @@ -55,16 +55,100 @@ char contextValue[256]; } while (0) -#define BEFORE(FUNCNAME) \ - DECLARE_VARIABLE_STANDARD_NORET; \ - GLenum error = GL_NO_ERROR; \ - static methodType FUNCNAME ## p = 0; \ - void* tmpPtr = 0; \ - int32_t vAPI_ID = API_ID_ ## FUNCNAME; \ - long startTime = getCurrentTime(); \ - PREPARE_LOCAL_BUF(); \ - GET_REAL_FUNCP_STR(#FUNCNAME, LIBGLES20, tmpPtr); \ - memcpy(& FUNCNAME ## p, &tmpPtr, sizeof(tmpPtr)); \ +#define BEFORE(FUNCNAME) \ + DECLARE_VARIABLE_STANDARD_NORET; \ + GLenum error = GL_NO_ERROR; \ + static methodType FUNCNAME ## p = 0; \ + void* tmpPtr = 0; \ + int32_t vAPI_ID = API_ID_ ## FUNCNAME; \ + long startTime = getCurrentTime(); \ + if(!FUNCNAME##p) { \ + probeBlockStart(); \ + if (lib_handle[LIBGLES20] == ((void *) 0)) { \ + lib_handle[LIBGLES20] = dlopen(lib_string[LIBGLES20], RTLD_LAZY); \ + if (lib_handle[LIBGLES20] == ((void *) 0)) { \ + char perror_msg[128]; \ + sprintf(perror_msg, "dlopen failed : %s", \ + lib_string[LIBGLES20]); \ + perror(perror_msg); \ + exit(0); \ + } \ + } \ + \ + /* TODO: add library init event here */ \ + \ + tmpPtr = dlsym(lib_handle[LIBGLES20], #FUNCNAME); \ + if (tmpPtr == NULL || dlerror() != NULL) { \ + perror("dlsym failed : " #FUNCNAME); \ + exit(0); \ + } \ + \ + memcpy(&FUNCNAME##p, &tmpPtr, sizeof(tmpPtr)); \ + probeBlockEnd(); \ + } \ + PRE_PROBEBLOCK() + +#define BEFORE_EGL(FUNCNAME) \ + DECLARE_VARIABLE_STANDARD_NORET; \ + GLenum error = GL_NO_ERROR; \ + static methodType FUNCNAME ## p = 0; \ + void* tmpPtr = 0; \ + int32_t vAPI_ID = API_ID_ ## FUNCNAME; \ + long startTime = getCurrentTime(); \ + if(!FUNCNAME##p) { \ + probeBlockStart(); \ + if (lib_handle[LIBEGL] == ((void *) 0)) { \ + lib_handle[LIBEGL] = dlopen(lib_string[LIBEGL], RTLD_LAZY | RTLD_GLOBAL); \ + if (lib_handle[LIBEGL] == ((void *) 0)) { \ + char perror_msg[128]; \ + sprintf(perror_msg, "dlopen failed : %s", \ + lib_string[LIBEGL]); \ + perror(perror_msg); \ + exit(0); \ + } \ + } \ + \ + tmpPtr = dlsym(lib_handle[LIBEGL], #FUNCNAME); \ + if (tmpPtr == NULL || dlerror() != NULL) { \ + perror("dlsym failed : " #FUNCNAME); \ + exit(0); \ + } \ + \ + memcpy(&FUNCNAME##p, &tmpPtr, sizeof(tmpPtr)); \ + probeBlockEnd(); \ + } \ + PRE_PROBEBLOCK() + +#define BEFORE_OSP_UIFW(FUNCNAME) \ + DECLARE_VARIABLE_STANDARD_NORET; \ + GLenum error = GL_NO_ERROR; \ + static methodType FUNCNAME ## p = 0; \ + void* tmpPtr = 0; \ + int32_t vAPI_ID = API_ID_ ## FUNCNAME; \ + long startTime = getCurrentTime(); \ + PREPARE_LOCAL_BUF(); \ + if(!FUNCNAME##p) { \ + probeBlockStart(); \ + if (lib_handle[LIBOSP_UIFW] == ((void *) 0)) { \ + lib_handle[LIBOSP_UIFW] = dlopen(lib_string[LIBOSP_UIFW], RTLD_LAZY); \ + if (lib_handle[LIBOSP_UIFW] == ((void *) 0)) { \ + char perror_msg[128]; \ + sprintf(perror_msg, "dlopen failed : %s", \ + lib_string[LIBOSP_UIFW]); \ + perror(perror_msg); \ + exit(0); \ + } \ + } \ + \ + tmpPtr = dlsym(lib_handle[LIBOSP_UIFW], #FUNCNAME); \ + if (tmpPtr == NULL || dlerror() != NULL) { \ + perror("dlsym failed : " #FUNCNAME); \ + exit(0); \ + } \ + \ + memcpy(&FUNCNAME##p, &tmpPtr, sizeof(tmpPtr)); \ + probeBlockEnd(); \ + } \ PRE_PROBEBLOCK() #define AFTER(RET_VAL, APITYPE, CONTEXT_VAL, INPUTFORMAT, ...) \ diff --git a/scripts/api_names.txt b/scripts/api_names.txt index afae75f..2da7172 100644 --- a/scripts/api_names.txt +++ b/scripts/api_names.txt @@ -527,3 +527,6 @@ glIsProgram glIsRenderbuffer glIsShader glIsTexture + +_SglSwapBuffers +eglSwapBuffers -- 2.7.4