4e0f8eed57c697c3745b3179907b34edd24797be
[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                 }                                                       \
77                                                                         \
78                 /* TODO: add library init event here */                 \
79                                                                         \
80                 tmpPtr = dlsym(lib_handle[LIBGLES20], #FUNCNAME);  \
81                 if (tmpPtr == NULL || dlerror() != NULL) {              \
82                         perror("dlsym failed : " #FUNCNAME);       \
83                         exit(0);                                        \
84                 }                                                       \
85                                                                         \
86                 memcpy(&FUNCNAME##p, &tmpPtr, sizeof(tmpPtr));     \
87                 probeBlockEnd();                                        \
88         }                                                               \
89         PRE_PROBEBLOCK()
90
91 #define BEFORE_EGL(FUNCNAME)                                    \
92         DECLARE_VARIABLE_STANDARD_NORET;                        \
93         GLenum error = GL_NO_ERROR;                             \
94         static methodType FUNCNAME ## p = 0;                    \
95         void* tmpPtr = 0;                                       \
96         int32_t vAPI_ID = API_ID_ ## FUNCNAME;                  \
97         uint64_t start_nsec = get_current_nsec();                       \
98         if(!FUNCNAME##p) {                                              \
99                 probeBlockStart();                                      \
100                 if (lib_handle[LIBEGL] == ((void *) 0)) {               \
101                         lib_handle[LIBEGL] = dlopen(lib_string[LIBEGL], RTLD_LAZY | RTLD_GLOBAL); \
102                         if (lib_handle[LIBEGL] == ((void *) 0)) {       \
103                                 char perror_msg[128];                   \
104                                 sprintf(perror_msg, "dlopen failed : %s", \
105                                         lib_string[LIBEGL]);            \
106                                 perror(perror_msg);                     \
107                                 exit(0);                                \
108                         }                                               \
109                 }                                                       \
110                                                                         \
111                 tmpPtr = dlsym(lib_handle[LIBEGL], #FUNCNAME);     \
112                 if (tmpPtr == NULL || dlerror() != NULL) {              \
113                         perror("dlsym failed : " #FUNCNAME);       \
114                         exit(0);                                        \
115                 }                                                       \
116                                                                         \
117                 memcpy(&FUNCNAME##p, &tmpPtr, sizeof(tmpPtr));     \
118                 probeBlockEnd();                                        \
119         }                                                               \
120         PRE_PROBEBLOCK()
121
122 #define BEFORE_OSP_UIFW(FUNCNAME)                                       \
123         DECLARE_VARIABLE_STANDARD_NORET;                        \
124         GLenum error = GL_NO_ERROR;                             \
125         static methodType FUNCNAME ## p = 0;                    \
126         void* tmpPtr = 0;                                       \
127         int32_t vAPI_ID = API_ID_ ## FUNCNAME;                  \
128         uint64_t start_nsec = get_current_nsec();                               \
129         if(!FUNCNAME##p) {                                              \
130                 probeBlockStart();                                      \
131                 if (lib_handle[LIBOSP_UIFW] == ((void *) 0)) {          \
132                         lib_handle[LIBOSP_UIFW] = dlopen(lib_string[LIBOSP_UIFW], RTLD_LAZY); \
133                         if (lib_handle[LIBOSP_UIFW] == ((void *) 0)) {       \
134                                 char perror_msg[128];                   \
135                                 sprintf(perror_msg, "dlopen failed : %s", \
136                                         lib_string[LIBOSP_UIFW]);               \
137                                 perror(perror_msg);                     \
138                                 exit(0);                                \
139                         }                                               \
140                 }                                                       \
141                                                                         \
142                 tmpPtr = dlsym(lib_handle[LIBOSP_UIFW], #FUNCNAME);     \
143                 if (tmpPtr == NULL || dlerror() != NULL) {              \
144                         perror("dlsym failed : " #FUNCNAME);       \
145                         exit(0);                                        \
146                 }                                                       \
147                                                                         \
148                 memcpy(&FUNCNAME##p, &tmpPtr, sizeof(tmpPtr));     \
149                 probeBlockEnd();                                        \
150         }                                                               \
151         PRE_PROBEBLOCK()
152
153 #define AFTER(RET_VAL, APITYPE, CONTEXT_VAL, INPUTFORMAT, ...)  \
154         POST_PACK_PROBEBLOCK_BEGIN();                                           \
155         PREPARE_LOCAL_BUF();                                                    \
156         PACK_COMMON_BEGIN(MSG_PROBE_GL, vAPI_ID, INPUTFORMAT, __VA_ARGS__);\
157         PACK_COMMON_END(RET_VAL, error, blockresult);                                   \
158         PACK_GL_ADD(APITYPE, get_current_nsec() - start_nsec, CONTEXT_VAL);     \
159         FLUSH_LOCAL_BUF();                                                      \
160         POST_PACK_PROBEBLOCK_END()
161
162 #define AFTER_NO_PARAM(RETVAL, APITYPE, CONTEXTVALUE) \
163                 AFTER(RETVAL, APITYPE, CONTEXTVALUE, "", 0)
164
165 #endif /* DA_GLES20_H_ */
166