[REFACTOR] gl probes refactor 48/17148/2
authorVitaliy Cherepanov <v.cherepanov@samsung.com>
Tue, 4 Mar 2014 09:41:00 +0000 (13:41 +0400)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Sat, 29 Mar 2014 05:06:43 +0000 (22:06 -0700)
init lib and dlsym search moved to separate function
to minimize lib size

Change-Id: I895ebceab2ad32ef1155154c1e67a64b6192f58a
Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
helper/common_probe_init.cpp
include/common_probe_init.h
probe_graphics/da_gles20.h
probe_graphics/da_gles20_tizen.cpp

index 0afa7f1..7b4883f 100644 (file)
@@ -37,6 +37,21 @@ void dummy()
 {
        return;
 }
+
+void probe_terminate_with_err(const char *msg, const char *func_name,
+                             ORIGINAL_LIBRARY id)
+{
+       char error_msg[1024];
+
+       sprintf(error_msg, "%s : [%s], %s", msg, func_name, lib_string[id]);
+       perror(error_msg);
+       PRINTERR(error_msg);
+       //wait for flush
+       sleep(1);
+       exit(0);
+
+}
+
 ////////////////////////////////////////////////////////////////////////////
 //egl init probe function
 //  params:
@@ -57,7 +72,6 @@ void init_probe_egl(__attribute__ ((unused))const char *func_name, void **func_p
 void init_probe_egl(const char *func_name, void **func_pointer,
                    ORIGINAL_LIBRARY id)
 {
-       char error_msg[1024];
        void *faddr = 0;
 
        (gProbeBlockCount++);
@@ -65,26 +79,12 @@ void init_probe_egl(const char *func_name, void **func_pointer,
                lib_handle[id] = dlopen(lib_string[id],
                                        RTLD_LAZY | RTLD_GLOBAL);
 
-               if (lib_handle[id] == ((void *)0)) {
-                       sprintf(error_msg, "dlopen failed : [%s],%s",
-                               func_name, lib_string[id]);
-                       perror(error_msg);
-                       PRINTERR(error_msg);
-                       //wait for flush
-                       sleep(1);
-                       exit(0);
-               }
+               if (lib_handle[id] == ((void *)0))
+                       probe_terminate_with_err("dlopen failed", func_name, id);
        };
        faddr = dlsym(lib_handle[id], func_name);
-       if (faddr == __null || dlerror() != __null) {
-               sprintf(error_msg, "dlsym failed : [%s],%s",
-                       func_name, lib_string[id]);
-               perror(error_msg);
-               PRINTERR(error_msg);
-               //wait for flush
-               sleep(1);
-               exit(0);
-       }
+       if (faddr == __null || dlerror() != __null)
+               probe_terminate_with_err("dlsym failed", func_name, id);
        memcpy(func_pointer, &faddr, sizeof(faddr));
        (gProbeBlockCount--);
 }
index 102480d..541f9bb 100644 (file)
@@ -41,4 +41,6 @@
 //    function have no return becouse on error it terminates main application
 void init_probe_egl(const char *func_name, void **func_pointer, ORIGINAL_LIBRARY id);
 
+void probe_terminate_with_err(const char *msg, const char *func_name,
+                             ORIGINAL_LIBRARY id);
 #endif /* __COMMON_PROBE_INIT_H__ */
index f8bc862..0f0010f 100644 (file)
 #define APITYPE_CONTEXT 1
 #define APITYPE_NO_CONTEXT 2
 
+#define FUNC(FUNCNAME) FUNCNAME
+#define FUNCSTR(FUNCNAME) #FUNCNAME
+#define FUNCID(FUNCNAME) API_ID_##FUNCNAME
+
 #define PACK_GL_ADD_COMMON(GL_api_type, GL_elapsed_time)                       \
        do {    /* PACK_GL_ADD_COMMON */                                        \
                BUF_PTR = pack_int64(BUF_PTR, voidp_to_uint64((void *)eglGetCurrentContext()));\
        DECLARE_VARIABLE_STANDARD_NORET;                                \
        GLenum error = GL_NO_ERROR;                                     \
        static methodType FUNCNAME ## p = 0;                            \
-       void* tmpPtr = 0;                                               \
        int32_t vAPI_ID = API_ID_ ## FUNCNAME;                          \
        uint64_t start_nsec = 0;                                        \
        PRE_PROBEBLOCK();                                               \
        if(blockresult != 0)                                            \
                start_nsec = get_current_nsec();                        \
        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);                                \
-                       }                                               \
-                       probeInfo_t tempProbeInfo;                      \
-                       setProbePoint(&tempProbeInfo);                  \
-                       if(blockresult != 0) {                          \
-                               /* get max value */                             \
-                               char maxValString[64];                          \
-                               GLint maxVal[2];                                \
-                               glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVal[0]);               \
-                               glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxVal[1]); \
-                               sprintf(maxValString, "%d,%d", maxVal[0], maxVal[1]);           \
-                               PREPARE_LOCAL_BUF();                    \
-                               PACK_COMMON_BEGIN(MSG_PROBE_GL, vAPI_ID, "", 0);\
-                               PACK_COMMON_END('p', 1, 0, 0);          \
-                               PACK_GL_ADD(APITYPE_INIT, 0, maxValString);     \
-                               FLUSH_LOCAL_BUF();                      \
-                       }                                               \
-               }                                                       \
-                                                                       \
-               tmpPtr = dlsym(lib_handle[LIBGLES20], #FUNCNAME);       \
-               if (tmpPtr == NULL || dlerror() != NULL) {              \
-                       perror("dlsym failed : " #FUNCNAME);            \
-                       exit(0);                                        \
-               }                                                       \
-                                                                       \
-               memcpy(&FUNCNAME##p, &tmpPtr, sizeof(tmpPtr));          \
-               probeBlockEnd();                                        \
+               init_probe_gl(#FUNCNAME, (void **)&FUNCNAME##p,         \
+                             LIBGLES20, blockresult, vAPI_ID);         \
        }
 
 #define INIT_LIB_ID_STR(LIB_ID, LIB_STR, KEYS)                                                 \
        if(!FUNCNAME##p)                                                \
                init_probe_egl(#FUNCNAME, (void **)&FUNCNAME##p, LIBEGL)
 
-#define FUNC(FUNCNAME) FUNCNAME
-#define FUNCSTR(FUNCNAME) #FUNCNAME
-#define FUNCID(FUNCNAME) API_ID_##FUNCNAME
-
 #define BEFORE_EGL_TIZEN(FUNCNAME)                                     \
        DECLARE_VARIABLE_STANDARD_NORET;                                \
        GLenum error = EGL_SUCCESS;                                     \
index 2d3519c..201e26b 100644 (file)
 #include "da_gles20.h"
 #include "daprobe.h"
 #include "binproto.h"
+#include "common_probe_init.h"
 
 static char contextValue[256];
 static enum DaOptions _sopt = OPT_GLES;
 static __thread GLenum gl_error_external = GL_NO_ERROR;
 
+static void init_probe_gl(const char *func_name, void **func_pointer,
+                  ORIGINAL_LIBRARY id, int blockresult, int32_t vAPI_ID)
+{
+       void *faddr;
+
+       probeBlockStart();
+       if (lib_handle[id] == ((void *)0)) {
+               lib_handle[id] = dlopen(lib_string[id], RTLD_LAZY);
+               if (lib_handle[id] == ((void *)0))
+                       probe_terminate_with_err("dlopen failed", func_name, id);
+
+               probeInfo_t tempProbeInfo;
+               setProbePoint(&tempProbeInfo);
+               if (blockresult != 0) {
+                       /* get max value */
+                       char maxValString[64];
+                       GLint maxVal[2];
+                       glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVal[0]);
+                       glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxVal[1]);
+                       sprintf(maxValString, "%d,%d", maxVal[0], maxVal[1]);
+                       PREPARE_LOCAL_BUF();
+                       PACK_COMMON_BEGIN(MSG_PROBE_GL, vAPI_ID, "", 0);
+                       PACK_COMMON_END('p', 1, 0, 0);
+                       PACK_GL_ADD(APITYPE_INIT, 0, maxValString);
+                       FLUSH_LOCAL_BUF();
+               }
+       }
+
+       faddr = dlsym(lib_handle[id], func_name);
+       if (faddr == NULL || dlerror() != NULL)
+               probe_terminate_with_err("dlopen failed", func_name, id);
+
+       memcpy(func_pointer, &faddr, sizeof(faddr));
+       probeBlockEnd();
+}
 // ==================================================================
 // A 2
 // ==================================================================