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