Add coding style guide.
[platform/core/uifw/coregl.git] / src / wraps / coregl_egl.c
1 #include <stdio.h>
2 #include <dlfcn.h>
3
4 # include <EGL/eglplatform.h>
5 # include "../headers/egl.h"
6
7 typedef void (*_eng_fn) (void);
8
9 ///////////////////////////////////////
10 // Disable dlog for debugging urgent issues //
11 //#define LOG_TAG "CoreGL_EGL"
12 //#include <dlog.h>
13 #define LOGE(...) fprintf(stderr, __VA_ARGS__)
14 #define LOGW(...) fprintf(stderr, __VA_ARGS__)
15 #define LOGD(...) fprintf(stderr, __VA_ARGS__)
16 ///////////////////////////////////////
17
18 #define COREGL_API           __attribute__((visibility("default")))
19
20 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     COREGL_API extern RET_TYPE FUNC_NAME PARAM_LIST;
21 #define _COREGL_EXT_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)
22 # include "../headers/sym_egl.h"
23 #undef _COREGL_EXT_SYMBOL
24 #undef _COREGL_SYMBOL
25
26 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)     RET_TYPE (*ovr_##FUNC_NAME) PARAM_LIST = NULL;
27 #define _COREGL_EXT_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)
28 # include "../headers/sym_egl.h"
29 #undef _COREGL_EXT_SYMBOL
30 #undef _COREGL_SYMBOL
31
32 #define INIT_EXPORT()
33
34 void *lib_handle = NULL;
35
36 __attribute__((constructor))
37 int
38 coregl_glwrap_init()
39 {
40         lib_handle = dlopen("libCOREGL.so", RTLD_NOW);
41         if (!lib_handle) {
42                 LOGE(" \E[40;31;1m%s\E[0m\n\n", dlerror());
43                 LOGE(" \E[40;31;1mInvalid library link! (Check linkage of libEGL -> libCOREGL)\E[0m\n");
44                 return 0;
45         }
46
47 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) \
48    ovr_##FUNC_NAME = (__typeof__(ovr_##FUNC_NAME))dlsym(lib_handle, "coregl_api_"#FUNC_NAME); \
49         if (ovr_##FUNC_NAME == NULL) \
50         { \
51                 LOGE("\E[40;31;1mCan't find a symbol '%s'!\E[0m\n\n", #FUNC_NAME); \
52                 LOGE("\E[40;31;1mInvalid library link! (Check linkage of libEGL -> libCOREGL)\E[0m\n"); \
53         }
54
55 #define _COREGL_EXT_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST)
56 #include "../headers/sym_egl.h"
57 #undef _COREGL_EXT_SYMBOL
58 #undef _COREGL_SYMBOL
59
60         return 1;
61 }
62
63
64 EGLint
65 eglGetError(void)
66 {
67         INIT_EXPORT();
68         return ovr_eglGetError();
69 }
70
71 EGLDisplay
72 eglGetDisplay(EGLNativeDisplayType display_id)
73 {
74         INIT_EXPORT();
75         return ovr_eglGetDisplay(display_id);
76 }
77
78 EGLBoolean
79 eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
80 {
81         INIT_EXPORT();
82         return ovr_eglInitialize(dpy, major, minor);
83 }
84
85 EGLBoolean
86 eglTerminate(EGLDisplay dpy)
87 {
88         INIT_EXPORT();
89         return ovr_eglTerminate(dpy);
90 }
91
92 EGLBoolean
93 eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size,
94               EGLint *num_config)
95 {
96         INIT_EXPORT();
97         return ovr_eglGetConfigs(dpy, configs, config_size, num_config);
98 }
99
100 EGLBoolean
101 eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs,
102                 EGLint config_size, EGLint *num_config)
103 {
104         INIT_EXPORT();
105         return ovr_eglChooseConfig(dpy, attrib_list, configs, config_size, num_config);
106 }
107
108 EGLBoolean
109 eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute,
110                    EGLint *value)
111 {
112         INIT_EXPORT();
113         return ovr_eglGetConfigAttrib(dpy, config, attribute, value);
114 }
115
116
117 EGLSurface
118 eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
119                        EGLNativeWindowType win, const EGLint *attrib_list)
120 {
121         INIT_EXPORT();
122         return ovr_eglCreateWindowSurface(dpy, config, win, attrib_list);
123 }
124
125 EGLSurface
126 eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
127                         const EGLint *attrib_list)
128 {
129         INIT_EXPORT();
130         return ovr_eglCreatePbufferSurface(dpy, config, attrib_list);
131 }
132
133 EGLSurface
134 eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
135                        EGLNativePixmapType pixmap, const EGLint *attrib_list)
136 {
137         INIT_EXPORT();
138         return ovr_eglCreatePixmapSurface(dpy, config, pixmap, attrib_list);
139 }
140
141 EGLBoolean
142 eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
143 {
144         INIT_EXPORT();
145         return ovr_eglDestroySurface(dpy, surface);
146 }
147
148 EGLBoolean
149 eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute,
150                 EGLint *value)
151 {
152         INIT_EXPORT();
153         return ovr_eglQuerySurface(dpy, surface, attribute, value);
154 }
155
156 EGLBoolean
157 eglBindAPI(EGLenum api)
158 {
159         INIT_EXPORT();
160         return ovr_eglBindAPI(api);
161 }
162
163 EGLenum
164 eglQueryAPI(void)
165 {
166         INIT_EXPORT();
167         return ovr_eglQueryAPI();
168 }
169
170 EGLBoolean
171 eglWaitClient(void)
172 {
173         INIT_EXPORT();
174         return ovr_eglWaitClient();
175 }
176
177 EGLBoolean
178 eglReleaseThread(void)
179 {
180         INIT_EXPORT();
181         return ovr_eglReleaseThread();
182 }
183
184 EGLSurface
185 eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
186                                  EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
187 {
188         INIT_EXPORT();
189         return ovr_eglCreatePbufferFromClientBuffer(dpy, buftype, buffer, config,
190                         attrib_list);
191 }
192
193 EGLBoolean
194 eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute,
195                  EGLint value)
196 {
197         INIT_EXPORT();
198         return ovr_eglSurfaceAttrib(dpy, surface, attribute, value);
199 }
200
201 EGLBoolean
202 eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
203 {
204         INIT_EXPORT();
205         return ovr_eglBindTexImage(dpy, surface, buffer);
206 }
207
208 EGLBoolean
209 eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
210 {
211         INIT_EXPORT();
212         return ovr_eglReleaseTexImage(dpy, surface, buffer);
213 }
214
215 EGLBoolean
216 eglSwapInterval(EGLDisplay dpy, EGLint interval)
217 {
218         INIT_EXPORT();
219         return ovr_eglSwapInterval(dpy, interval);
220 }
221
222 EGLContext
223 eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context,
224                  const EGLint *attrib_list)
225 {
226         INIT_EXPORT();
227         return ovr_eglCreateContext(dpy, config, share_context, attrib_list);
228 }
229
230 EGLBoolean
231 eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
232 {
233         INIT_EXPORT();
234         return ovr_eglDestroyContext(dpy, ctx);
235 }
236
237 EGLBoolean
238 eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
239 {
240         INIT_EXPORT();
241         return ovr_eglMakeCurrent(dpy, draw, read, ctx);
242 }
243
244 EGLContext
245 eglGetCurrentContext(void)
246 {
247         INIT_EXPORT();
248         return ovr_eglGetCurrentContext();
249 }
250
251 EGLSurface
252 eglGetCurrentSurface(EGLint readdraw)
253 {
254         INIT_EXPORT();
255         return ovr_eglGetCurrentSurface(readdraw);
256 }
257
258 EGLDisplay
259 eglGetCurrentDisplay(void)
260 {
261         INIT_EXPORT();
262         return ovr_eglGetCurrentDisplay();
263 }
264
265 EGLBoolean
266 eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
267 {
268         INIT_EXPORT();
269         return ovr_eglQueryContext(dpy, ctx, attribute, value);
270 }
271
272 EGLBoolean
273 eglWaitGL(void)
274 {
275         INIT_EXPORT();
276         return ovr_eglWaitGL();
277 }
278
279 EGLBoolean
280 eglWaitNative(EGLint engine)
281 {
282         INIT_EXPORT();
283         return ovr_eglWaitNative(engine);
284 }
285
286 EGLBoolean
287 eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
288 {
289         INIT_EXPORT();
290         return ovr_eglSwapBuffers(dpy, surface);
291 }
292
293 EGLBoolean
294 eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
295 {
296         INIT_EXPORT();
297         return ovr_eglCopyBuffers(dpy, surface, target);
298 }
299
300 _eng_fn
301 eglGetProcAddress(const char *procname)
302 {
303         INIT_EXPORT();
304         return ovr_eglGetProcAddress(procname);
305 }
306
307 const char *
308 eglQueryString(EGLDisplay dpy, EGLint name)
309 {
310         INIT_EXPORT();
311         return ovr_eglQueryString(dpy, name);
312 }
313