[PROTO] GL: add library init event packing
[platform/core/system/swap-probe.git] / probe_graphics / da_gles20.h
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Sanghyun Lee <sanghyunnim.lee@samsung.com>
9  * Juyoung Kim <j0.kim@samsung.com>
10  * Vitaliy Cherepanov <v.cherepanov@samsung.com>
11  *
12  * This library is free software; you can redistribute it and/or modify it under
13  * the terms of the GNU Lesser General Public License as published by the
14  * Free Software Foundation; either version 2.1 of the License, or (at your option)
15  * any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  * License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this library; if not, write to the Free Software Foundation, Inc., 51
24  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  *
29  */
30
31 #ifndef DA_GLES20_H_
32 #define DA_GLES20_H_
33
34 #include <egl.h>
35 #include <eglext.h>
36 #include <gl2.h>
37 #include <gl2ext.h>
38 #include <errno.h>
39 #include "daprobe.h"
40 #include "dahelper.h"
41
42 #define NO_RETURN_FORMAT "%s"
43 #define NO_RETURN_VALUE 0
44 #define APITYPE_INIT 0
45 #define APITYPE_CONTEXT 1
46 #define APITYPE_NO_CONTEXT 2
47
48 char contextValue[256];
49
50 #define PACK_GL_ADD(GL_api_type, GL_elapsed_time, GL_context_value)             \
51         do {                                                    \
52                 BUF_PTR = pack_int32(BUF_PTR, (uint32_t)GL_api_type);   \
53                 BUF_PTR = pack_int64(BUF_PTR, (uint64_t)GL_elapsed_time); \
54                 BUF_PTR = pack_string(BUF_PTR, GL_context_value);       \
55         } while (0)
56
57
58 #define BEFORE(FUNCNAME)                                                \
59         DECLARE_VARIABLE_STANDARD_NORET;                                \
60         GLenum error = GL_NO_ERROR;                                     \
61         static methodType FUNCNAME ## p = 0;                            \
62         void* tmpPtr = 0;                                               \
63         int32_t vAPI_ID = API_ID_ ## FUNCNAME;                          \
64         uint64_t start_nsec = get_current_nsec();                       \
65         if(!FUNCNAME##p) {                                              \
66                 probeBlockStart();                                      \
67                 if (lib_handle[LIBGLES20] == ((void *) 0)) {            \
68                         lib_handle[LIBGLES20] = dlopen(lib_string[LIBGLES20], RTLD_LAZY); \
69                         if (lib_handle[LIBGLES20] == ((void *) 0)) {    \
70                                 char perror_msg[128];                   \
71                                 sprintf(perror_msg, "dlopen failed : %s", \
72                                         lib_string[LIBGLES20]);         \
73                                 perror(perror_msg);                     \
74                                 exit(0);                                \
75                         }                                               \
76                         probeInfo_t tempProbeInfo;                      \
77                         setProbePoint(&tempProbeInfo);                  \
78                         /* get max value */                             \
79                         char maxValString[64];                          \
80                         GLint maxVal[2];                                \
81                         glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVal[0]);               \
82                         glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxVal[1]); \
83                         sprintf(maxValString, "%d,%d", maxVal[0], maxVal[1]);           \
84                         PREPARE_LOCAL_BUF();                                            \
85                         PACK_COMMON_BEGIN(MSG_PROBE_GL, vAPI_ID, "", 0);                \
86                         PACK_COMMON_END(1, 0, 0);                                       \
87                         PACK_GL_ADD(APITYPE_INIT, 0, maxValString);                     \
88                         FLUSH_LOCAL_BUF();                                              \
89                 }                                                       \
90                                                                         \
91                 tmpPtr = dlsym(lib_handle[LIBGLES20], #FUNCNAME);       \
92                 if (tmpPtr == NULL || dlerror() != NULL) {              \
93                         perror("dlsym failed : " #FUNCNAME);            \
94                         exit(0);                                        \
95                 }                                                       \
96                                                                         \
97                 memcpy(&FUNCNAME##p, &tmpPtr, sizeof(tmpPtr));          \
98                 probeBlockEnd();                                        \
99         }                                                               \
100         PRE_PROBEBLOCK()
101
102 #define BEFORE_EGL(FUNCNAME)                                    \
103         DECLARE_VARIABLE_STANDARD_NORET;                        \
104         GLenum error = GL_NO_ERROR;                             \
105         static methodType FUNCNAME ## p = 0;                    \
106         void* tmpPtr = 0;                                       \
107         int32_t vAPI_ID = API_ID_ ## FUNCNAME;                  \
108         uint64_t start_nsec = get_current_nsec();                       \
109         if(!FUNCNAME##p) {                                              \
110                 probeBlockStart();                                      \
111                 if (lib_handle[LIBEGL] == ((void *) 0)) {               \
112                         lib_handle[LIBEGL] = dlopen(lib_string[LIBEGL], RTLD_LAZY | RTLD_GLOBAL); \
113                         if (lib_handle[LIBEGL] == ((void *) 0)) {       \
114                                 char perror_msg[128];                   \
115                                 sprintf(perror_msg, "dlopen failed : %s", \
116                                         lib_string[LIBEGL]);            \
117                                 perror(perror_msg);                     \
118                                 exit(0);                                \
119                         }                                               \
120                 }                                                       \
121                                                                         \
122                 tmpPtr = dlsym(lib_handle[LIBEGL], #FUNCNAME);     \
123                 if (tmpPtr == NULL || dlerror() != NULL) {              \
124                         perror("dlsym failed : " #FUNCNAME);       \
125                         exit(0);                                        \
126                 }                                                       \
127                                                                         \
128                 memcpy(&FUNCNAME##p, &tmpPtr, sizeof(tmpPtr));     \
129                 probeBlockEnd();                                        \
130         }                                                               \
131         PRE_PROBEBLOCK()
132
133 #define BEFORE_OSP_UIFW(FUNCNAME)                                       \
134         DECLARE_VARIABLE_STANDARD_NORET;                        \
135         GLenum error = GL_NO_ERROR;                             \
136         static methodType FUNCNAME ## p = 0;                    \
137         void* tmpPtr = 0;                                       \
138         int32_t vAPI_ID = API_ID_ ## FUNCNAME;                  \
139         uint64_t start_nsec = get_current_nsec();                               \
140         if(!FUNCNAME##p) {                                              \
141                 probeBlockStart();                                      \
142                 if (lib_handle[LIBOSP_UIFW] == ((void *) 0)) {          \
143                         lib_handle[LIBOSP_UIFW] = dlopen(lib_string[LIBOSP_UIFW], RTLD_LAZY); \
144                         if (lib_handle[LIBOSP_UIFW] == ((void *) 0)) {       \
145                                 char perror_msg[128];                   \
146                                 sprintf(perror_msg, "dlopen failed : %s", \
147                                         lib_string[LIBOSP_UIFW]);               \
148                                 perror(perror_msg);                     \
149                                 exit(0);                                \
150                         }                                               \
151                 }                                                       \
152                                                                         \
153                 tmpPtr = dlsym(lib_handle[LIBOSP_UIFW], #FUNCNAME);     \
154                 if (tmpPtr == NULL || dlerror() != NULL) {              \
155                         perror("dlsym failed : " #FUNCNAME);       \
156                         exit(0);                                        \
157                 }                                                       \
158                                                                         \
159                 memcpy(&FUNCNAME##p, &tmpPtr, sizeof(tmpPtr));     \
160                 probeBlockEnd();                                        \
161         }                                                               \
162         PRE_PROBEBLOCK()
163
164 #define AFTER(RET_VAL, APITYPE, CONTEXT_VAL, INPUTFORMAT, ...)  \
165         POST_PACK_PROBEBLOCK_BEGIN();                                           \
166         PREPARE_LOCAL_BUF();                                                    \
167         PACK_COMMON_BEGIN(MSG_PROBE_GL, vAPI_ID, INPUTFORMAT, __VA_ARGS__);\
168         PACK_COMMON_END(RET_VAL, error, blockresult);                                   \
169         PACK_GL_ADD(APITYPE, get_current_nsec() - start_nsec, CONTEXT_VAL);     \
170         FLUSH_LOCAL_BUF();                                                      \
171         POST_PACK_PROBEBLOCK_END()
172
173 #define AFTER_NO_PARAM(RETVAL, APITYPE, CONTEXTVALUE) \
174                 AFTER(RETVAL, APITYPE, CONTEXTVALUE, "", 0)
175
176 #endif /* DA_GLES20_H_ */
177