[FEATURE] add evas_gl_ probes
[platform/core/system/swap-probe.git] / helper / common_probe_init.c
similarity index 63%
rename from helper/common_probe_init.cpp
rename to helper/common_probe_init.c
index 7b4883f..4ecabd7 100644 (file)
  */
 
 #include <unistd.h>
+#include "da_gles20.h"
+#include "binproto.h"
 #include "common_probe_init.h"
 
-
-
 //#define EGL_TEST
 
-void dummy()
-{
-       return;
-}
-
 void probe_terminate_with_err(const char *msg, const char *func_name,
                              ORIGINAL_LIBRARY id)
 {
        char error_msg[1024];
+       const char *lib_name = "unknown";
 
-       sprintf(error_msg, "%s : [%s], %s", msg, func_name, lib_string[id]);
+       if (id < NUM_ORIGINAL_LIBRARY)
+               lib_name = lib_string[id];
+       sprintf(error_msg, "%s : [%s], %s", msg, func_name, lib_name);
        perror(error_msg);
        PRINTERR(error_msg);
        //wait for flush
@@ -62,6 +60,12 @@ void probe_terminate_with_err(const char *msg, const char *func_name,
 //    search original function by name
 //    function have no return becouse on error it terminates main application
 #ifdef EGL_TEST
+
+void dummy()
+{
+       return;
+}
+
 void init_probe_egl(__attribute__ ((unused))const char *func_name, void **func_pointer,
                    __attribute__ ((unused))ORIGINAL_LIBRARY id)
 {
@@ -83,9 +87,47 @@ void init_probe_egl(const char *func_name, void **func_pointer,
                        probe_terminate_with_err("dlopen failed", func_name, id);
        };
        faddr = dlsym(lib_handle[id], func_name);
-       if (faddr == __null || dlerror() != __null)
+       if (faddr == NULL || dlerror() != NULL)
                probe_terminate_with_err("dlsym failed", func_name, id);
        memcpy(func_pointer, &faddr, sizeof(faddr));
        (gProbeBlockCount--);
 }
 #endif
+
+
+void init_probe_gl(const char *func_name, void **func_pointer,
+                  ORIGINAL_LIBRARY id, int blockresult, int32_t vAPI_ID)
+{
+       void *faddr;
+       probeInfo_t tempProbeInfo;
+
+       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);
+
+               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("function not found in lib", func_name,
+                                        id);
+
+       memcpy(func_pointer, &faddr, sizeof(faddr));
+       probeBlockEnd();
+}