[FEATURE] add evas_gl_ probes
[platform/core/system/swap-probe.git] / helper / common_probe_init.c
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Vitaliy Cherepanov <v.cherepanov@samsung.com>
9  *
10  * This library is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU Lesser General Public License as published by the
12  * Free Software Foundation; either version 2.1 of the License, or (at your option)
13  * any later version.
14  *
15  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
16  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this library; if not, write to the Free Software Foundation, Inc., 51
22  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  * Contributors:
25  * - S-Core Co., Ltd
26  *
27  */
28
29 #include <unistd.h>
30 #include "da_gles20.h"
31 #include "binproto.h"
32 #include "common_probe_init.h"
33
34 //#define EGL_TEST
35
36 void probe_terminate_with_err(const char *msg, const char *func_name,
37                               ORIGINAL_LIBRARY id)
38 {
39         char error_msg[1024];
40         const char *lib_name = "unknown";
41
42         if (id < NUM_ORIGINAL_LIBRARY)
43                 lib_name = lib_string[id];
44         sprintf(error_msg, "%s : [%s], %s", msg, func_name, lib_name);
45         perror(error_msg);
46         PRINTERR(error_msg);
47         //wait for flush
48         sleep(1);
49         exit(0);
50
51 }
52
53 ////////////////////////////////////////////////////////////////////////////
54 //egl init probe function
55 //  params:
56 //    func_name    - original function name for dlsym search
57 //    func_pointer - original function pointer (return)
58 //
59 //  info
60 //    search original function by name
61 //    function have no return becouse on error it terminates main application
62 #ifdef EGL_TEST
63
64 void dummy()
65 {
66         return;
67 }
68
69 void init_probe_egl(__attribute__ ((unused))const char *func_name, void **func_pointer,
70                     __attribute__ ((unused))ORIGINAL_LIBRARY id)
71 {
72         PRINTMSG(func_name);
73         *func_pointer = (void *)dummy;
74 }
75 #else
76 void init_probe_egl(const char *func_name, void **func_pointer,
77                     ORIGINAL_LIBRARY id)
78 {
79         void *faddr = 0;
80
81         (gProbeBlockCount++);
82         if (lib_handle[id] == ((void *)0)) {
83                 lib_handle[id] = dlopen(lib_string[id],
84                                         RTLD_LAZY | RTLD_GLOBAL);
85
86                 if (lib_handle[id] == ((void *)0))
87                         probe_terminate_with_err("dlopen failed", func_name, id);
88         };
89         faddr = dlsym(lib_handle[id], func_name);
90         if (faddr == NULL || dlerror() != NULL)
91                 probe_terminate_with_err("dlsym failed", func_name, id);
92         memcpy(func_pointer, &faddr, sizeof(faddr));
93         (gProbeBlockCount--);
94 }
95 #endif
96
97
98 void init_probe_gl(const char *func_name, void **func_pointer,
99                    ORIGINAL_LIBRARY id, int blockresult, int32_t vAPI_ID)
100 {
101         void *faddr;
102         probeInfo_t tempProbeInfo;
103
104         probeBlockStart();
105         if (lib_handle[id] == ((void *)0)) {
106                 lib_handle[id] = dlopen(lib_string[id], RTLD_LAZY);
107                 if (lib_handle[id] == ((void *)0))
108                         probe_terminate_with_err("dlopen failed", func_name, id);
109
110                 setProbePoint(&tempProbeInfo);
111                 if (blockresult != 0) {
112                         /* get max value */
113                         char maxValString[64];
114                         GLint maxVal[2];
115                         glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVal[0]);
116                         glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxVal[1]);
117                         sprintf(maxValString, "%d,%d", maxVal[0], maxVal[1]);
118                         PREPARE_LOCAL_BUF();
119                         PACK_COMMON_BEGIN(MSG_PROBE_GL, vAPI_ID, "", 0);
120                         PACK_COMMON_END('p', 1, 0, 0);
121                         PACK_GL_ADD(APITYPE_INIT, 0, maxValString);
122                         FLUSH_LOCAL_BUF();
123                 }
124         }
125
126         faddr = dlsym(lib_handle[id], func_name);
127         if (faddr == NULL || dlerror() != NULL)
128                 probe_terminate_with_err("function not found in lib", func_name,
129                                          id);
130
131         memcpy(func_pointer, &faddr, sizeof(faddr));
132         probeBlockEnd();
133 }