[FIX] build for new projects with PRIVATE_CAPI_APPFW
[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 /*
35  * TODO find this headers. need for EGL_Context and other
36 #include <egl.h>
37 #include <eglext.h>
38 #include <gl2.h>
39 #include <gl2ext.h>
40 */
41
42 #include <Evas_GL.h>
43 #include <Evas.h>
44
45 #include <errno.h>
46 #include "daprobe.h"
47 #include "dahelper.h"
48
49 /* TODO add egl header for next */
50 #define EGLContext void *
51 extern EGLContext eglGetCurrentContext(void);
52
53 #define NO_RETURN_FORMAT "%s"
54 #define NO_RETURN_VALUE 0
55 #define APITYPE_INIT 0
56 #define APITYPE_CONTEXT 1
57 #define APITYPE_NO_CONTEXT 2
58
59 #define FUNC(FUNCNAME) FUNCNAME
60 #define FUNCSTR(FUNCNAME) #FUNCNAME
61 #define FUNCID(FUNCNAME) API_ID_##FUNCNAME
62
63 #define PACK_GL_ADD_COMMON(GL_api_type, GL_elapsed_time)                        \
64         do {    /* PACK_GL_ADD_COMMON */                                        \
65                 BUF_PTR = pack_int64(BUF_PTR, voidp_to_uint64((void *)eglGetCurrentContext()));\
66                 BUF_PTR = pack_int32(BUF_PTR, (uint32_t)GL_api_type);   \
67                 BUF_PTR = pack_int64(BUF_PTR, (uint64_t)GL_elapsed_time); \
68         } while (0)
69
70 #define PACK_GL_ADD(GL_api_type, GL_elapsed_time, GL_context_value)             \
71         do {    /* PACK_GL_ADD */                                               \
72                 PACK_GL_ADD_COMMON(GL_api_type, GL_elapsed_time);               \
73                 BUF_PTR = pack_string(BUF_PTR, GL_context_value);       \
74         } while (0)
75
76 #define PACK_GL_SHADER(GL_api_type, GL_elapsed_time, GL_shader, GL_shader_size) \
77         do {    /* PACK_GL_SHADER */                                            \
78                 PACK_GL_ADD_COMMON(GL_api_type, GL_elapsed_time);               \
79                 uint32_t min = (sizeof(LOCAL_BUF) - (BUF_PTR - LOCAL_BUF));     \
80                 if (min > MAX_SHADER_LEN)                                       \
81                         min = MAX_SHADER_LEN;                                   \
82                 BUF_PTR = pack_string_to_file(BUF_PTR, GL_shader,               \
83                                               GL_shader_size, min);             \
84         } while (0)
85
86 #define BEFORE(FUNCNAME)                                                \
87         DECLARE_VARIABLE_STANDARD_NORET;                                \
88         GLenum error = GL_NO_ERROR;                                     \
89         static methodType FUNCNAME ## p = 0;                            \
90         int32_t vAPI_ID = API_ID_ ## FUNCNAME;                          \
91         uint64_t start_nsec = 0;                                        \
92         PRE_PROBEBLOCK();                                               \
93         if(blockresult != 0)                                            \
94                 start_nsec = get_current_nsec();                        \
95         if(!FUNCNAME##p) {                                              \
96                 init_probe_gl(#FUNCNAME, (void **)&FUNCNAME##p,         \
97                               LIBGLES20, blockresult, vAPI_ID);         \
98         }
99
100 #define INIT_LIB_ID_STR(LIB_ID, LIB_STR, KEYS)                                                  \
101                 if (lib_handle[LIB_ID] == ((void *) 0)) {               \
102                         lib_handle[LIB_ID] = dlopen(LIB_STR, RTLD_LAZY | RTLD_GLOBAL); \
103                         if (lib_handle[LIB_ID] == ((void *) 0)) {       \
104                                 char perror_msg[128];                   \
105                                 sprintf(perror_msg, "dlopen failed : [%s],%s", \
106                                         __FUNCTION__, LIB_STR);                 \
107                                 perror(perror_msg);                             \
108                                 exit(0);                                \
109                         }                                               \
110                 }
111
112 #define INIT_LIB(LIB_ID, KEYS)                                          \
113         INIT_LIB_ID_STR(LIB_ID, lib_string[LIB_ID], KEYS)
114
115
116 #define BEFORE_EGL_NATIVE(FUNCNAME)                                     \
117         DECLARE_VARIABLE_STANDARD_NORET;                                \
118         GLenum error = EGL_SUCCESS;                                     \
119         static methodType FUNCNAME ## p = 0;                            \
120         int32_t vAPI_ID = API_ID_ ## FUNCNAME;                          \
121         uint64_t start_nsec = 0;                                        \
122         PRE_PROBEBLOCK();                                               \
123         if(blockresult != 0)                                            \
124                 start_nsec = get_current_nsec();                        \
125         if(!FUNCNAME##p)                                                \
126                 init_probe_egl(#FUNCNAME, (void **)&FUNCNAME##p, LIBEGL)
127
128 #define EGL_GET_ERROR()                                                 \
129         if (blockresult != 0) {                                         \
130                 error = eglGetError();                                  \
131         }
132
133 #define AFTER(RET_TYPE, RET_VAL, APITYPE, CONTEXT_VAL, INPUTFORMAT, ...)        \
134         POST_PACK_PROBEBLOCK_BEGIN();                                           \
135         PREPARE_LOCAL_BUF();                                                    \
136         PACK_COMMON_BEGIN(MSG_PROBE_GL, vAPI_ID, INPUTFORMAT, __VA_ARGS__);     \
137         PACK_COMMON_END(RET_TYPE, RET_VAL, error, blockresult);                 \
138         PACK_GL_ADD(APITYPE, get_current_nsec() - start_nsec, CONTEXT_VAL);     \
139         FLUSH_LOCAL_BUF();                                                      \
140         POST_PACK_PROBEBLOCK_END()
141
142 #define AFTER_NO_PARAM(RET_TYPE, RETVAL, APITYPE, CONTEXTVALUE) \
143                 AFTER(RET_TYPE, RETVAL, APITYPE, CONTEXTVALUE, "", 0)
144
145 #define GL_GET_ERROR()                                                  \
146         if (blockresult != 0) {                                         \
147                 error = glGetError();                                   \
148         }
149
150 #define AFTER_SHADER(RET_TYPE, RET_VAL, APITYPE, CONTEXT_VAL, CONTEXT_SIZE, INPUTFORMAT, ...)   \
151         POST_PACK_PROBEBLOCK_BEGIN();                                           \
152         PREPARE_LOCAL_BUF();                                                    \
153         PACK_COMMON_BEGIN(MSG_PROBE_GL, vAPI_ID, INPUTFORMAT, __VA_ARGS__);     \
154         PACK_COMMON_END(RET_TYPE, RET_VAL, error, blockresult);                 \
155         PACK_GL_SHADER(APITYPE, get_current_nsec() - start_nsec, CONTEXT_VAL, CONTEXT_SIZE);    \
156         FLUSH_LOCAL_BUF();                                                      \
157         POST_PACK_PROBEBLOCK_END()
158
159 #endif /* DA_GLES20_H_ */
160