[FIX] eglSwapBuffers probe fix
authorNikita Kalyazin <n.kalyazin@samsung.com>
Tue, 17 Sep 2013 13:30:34 +0000 (17:30 +0400)
committerNikita Kalyazin <n.kalyazin@samsung.com>
Wed, 18 Sep 2013 06:51:43 +0000 (10:51 +0400)
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 <n.kalyazin@samsung.com>
include/api_id_mapping.h
probe_graphics/da_gles20.cpp
probe_graphics/da_gles20.h
scripts/api_names.txt

index 3372886..f4ee9bc 100644 (file)
 #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
index dceeabe..362374f 100644 (file)
@@ -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
index f536cf0..de21fa4 100644 (file)
@@ -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, ...) \
index afae75f..2da7172 100644 (file)
@@ -527,3 +527,6 @@ glIsProgram
 glIsRenderbuffer
 glIsShader
 glIsTexture
+
+_SglSwapBuffers
+eglSwapBuffers