Use mesa gbm include file locations
[platform/adaptation/renesas_rcar/libegl.git] / egl.c
1 /*
2  * Copyright (c) 2013 Renesas Solutions Corp.
3  * Copyright (c) 2012 Carsten Munk <carsten.munk@gmail.com>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * Authors:
18  *  Takanari Hayama <taki@igel.co.jp>
19  *
20  */
21
22 /* EGL function pointers */
23 #define EGL_EGLEXT_PROTOTYPES
24 #include <EGL/egl.h>
25 #include <EGL/eglext.h>
26
27 #define IMG_LIBEGL_PATH "libEGL-pvr.so"
28
29 #if defined(DEBUG)
30 #       define EGL_DEBUG(s, x...)       { printf(s, ## x); }
31 #else
32 #       define EGL_DEBUG(s, x...)       { }
33 #endif
34
35 #ifndef EGL_WAYLAND_BUFFER_WL
36 /* TI headers don't define this */
37 #define EGL_WAYLAND_BUFFER_WL    0x31D5 /* eglCreateImageKHR target */
38 #endif
39
40 #include <dlfcn.h>
41 #include <stddef.h>
42 #include <stdlib.h>
43 #include <malloc.h>
44 #include <string.h>
45 #include <assert.h>
46
47 #include <sys/types.h>
48 #include <sys/stat.h>
49 #include <fcntl.h>
50
51 #define WANT_WAYLAND
52
53 #ifdef WANT_WAYLAND
54 #include <wayland-kms.h>
55 #include <gbm.h>
56 #endif
57
58 static EGLint(*_eglGetError) (void);
59
60 static EGLDisplay(*_eglGetDisplay) (EGLNativeDisplayType display_id);
61 static EGLBoolean(*_eglInitialize) (EGLDisplay dpy, EGLint * major,
62                                    EGLint * minor);
63 static EGLBoolean(*_eglTerminate) (EGLDisplay dpy);
64
65 static const char *(*_eglQueryString) (EGLDisplay dpy, EGLint name);
66
67 static EGLBoolean(*_eglGetConfigs) (EGLDisplay dpy, EGLConfig * configs,
68                                    EGLint config_size, EGLint * num_config);
69 static EGLBoolean(*_eglChooseConfig) (EGLDisplay dpy,
70                                      const EGLint * attrib_list,
71                                      EGLConfig * configs,
72                                      EGLint config_size, EGLint * num_config);
73 static EGLBoolean(*_eglGetConfigAttrib) (EGLDisplay dpy,
74                                         EGLConfig config,
75                                         EGLint attribute, EGLint * value);
76
77 static EGLSurface(*_eglCreateWindowSurface) (EGLDisplay dpy,
78                                             EGLConfig config,
79                                             EGLNativeWindowType win,
80                                             const EGLint * attrib_list);
81 static EGLSurface(*_eglCreatePbufferSurface) (EGLDisplay dpy,
82                                              EGLConfig config,
83                                              const EGLint * attrib_list);
84 static EGLSurface(*_eglCreatePixmapSurface) (EGLDisplay dpy,
85                                             EGLConfig config,
86                                             EGLNativePixmapType pixmap,
87                                             const EGLint * attrib_list);
88 static EGLBoolean(*_eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
89 static EGLBoolean(*_eglQuerySurface) (EGLDisplay dpy, EGLSurface surface,
90                                      EGLint attribute, EGLint * value);
91
92 static EGLBoolean(*_eglBindAPI) (EGLenum api);
93 static EGLenum(*_eglQueryAPI) (void);
94
95 static EGLBoolean(*_eglWaitClient) (void);
96
97 static EGLBoolean(*_eglReleaseThread) (void);
98
99 static EGLSurface(*_eglCreatePbufferFromClientBuffer) (EGLDisplay dpy,
100                                                       EGLenum buftype,
101                                                       EGLClientBuffer
102                                                       buffer,
103                                                       EGLConfig config,
104                                                       const EGLint *
105                                                       attrib_list);
106
107 static EGLBoolean(*_eglSurfaceAttrib) (EGLDisplay dpy,
108                                       EGLSurface surface,
109                                       EGLint attribute, EGLint value);
110 static EGLBoolean(*_eglBindTexImage) (EGLDisplay dpy, EGLSurface surface,
111                                      EGLint buffer);
112 static EGLBoolean(*_eglReleaseTexImage) (EGLDisplay dpy,
113                                         EGLSurface surface, EGLint buffer);
114
115 static EGLBoolean(*_eglSwapInterval) (EGLDisplay dpy, EGLint interval);
116
117 static EGLContext(*_eglCreateContext) (EGLDisplay dpy, EGLConfig config,
118                                       EGLContext share_context,
119                                       const EGLint * attrib_list);
120 static EGLBoolean(*_eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
121 static EGLBoolean(*_eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
122                                     EGLSurface read, EGLContext ctx);
123
124 static EGLContext(*_eglGetCurrentContext) (void);
125 static EGLSurface(*_eglGetCurrentSurface) (EGLint readdraw);
126 static EGLDisplay(*_eglGetCurrentDisplay) (void);
127 static EGLBoolean(*_eglQueryContext) (EGLDisplay dpy, EGLContext ctx,
128                                      EGLint attribute, EGLint * value);
129
130 static EGLBoolean(*_eglWaitGL) (void);
131 static EGLBoolean(*_eglWaitNative) (EGLint engine);
132 static EGLBoolean(*_eglSwapBuffers) (EGLDisplay dpy, EGLSurface surface);
133 static EGLBoolean(*_eglCopyBuffers) (EGLDisplay dpy, EGLSurface surface,
134                                     EGLNativePixmapType target);
135
136 static EGLImageKHR(*_eglCreateImageKHR) (EGLDisplay dpy, EGLContext ctx,
137                                         EGLenum target,
138                                         EGLClientBuffer buffer,
139                                         const EGLint * attrib_list);
140 static EGLBoolean(*_eglDestroyImageKHR) (EGLDisplay dpy, EGLImageKHR image);
141
142 static __eglMustCastToProperFunctionPointerType(*_eglGetProcAddress) (const char *procname);
143
144 static void *_libegl = NULL;
145
146 static void _init_egl()
147 {
148         const char *filename = (getenv("LIBEGL")) ? getenv("LIBEGL") : IMG_LIBEGL_PATH;
149         _libegl = dlopen(filename, RTLD_LAZY);
150 }
151
152 #define EGL_DLSYM(f)                    \
153         if (!_libegl) _init_egl();      \
154         if (!_##f) _##f = dlsym(_libegl, #f);   \
155
156 EGLint eglGetError(void)
157 {
158         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
159         EGL_DLSYM(eglGetError);
160         return _eglGetError();
161 }
162
163 #ifdef WANT_WAYLAND
164 static struct gbm_device *__gbm;
165 static struct wl_display *__wl_display = NULL;
166 #endif
167
168 EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id)
169 {
170         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
171         EGL_DLSYM(eglGetDisplay);
172
173 #ifdef WANT_WAYLAND
174         if (display_id) {
175                 void *head = *(void**)display_id;
176                 if (head == gbm_create_device)
177                         __gbm = (struct gbm_device*)display_id;
178                 if (head == &wl_display_interface)
179                         __wl_display = (struct wl_display*)display_id;
180         }
181 #endif
182
183 #if 0
184         {
185                 FILE *fp = fopen("/proc/self/maps", "r");
186                 char buf[BUFSIZ];
187                 int count;
188                 while(!feof(fp)) {
189                         count = fread(buf, 1, BUFSIZ, fp);
190                         fwrite(buf, count, 1, stdout);
191                 }
192                 fclose(fp);
193
194                 EGL_DEBUG("\n\n%s: %p\n", __func__, _eglGetDisplay);
195         }
196 #endif
197         return _eglGetDisplay(display_id);
198 }
199
200 EGLBoolean eglInitialize(EGLDisplay dpy, EGLint * major, EGLint * minor)
201 {
202         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
203         EGL_DLSYM(eglInitialize);
204         return _eglInitialize(dpy, major, minor);
205 }
206
207 EGLBoolean eglTerminate(EGLDisplay dpy)
208 {
209         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
210         EGL_DLSYM(eglTerminate);
211         return _eglTerminate(dpy);
212 }
213
214 #define EGL_WL_EXT_STRING "EGL_WL_bind_wayland_display "
215
216 const char *eglQueryString(EGLDisplay dpy, EGLint name)
217 {
218         static char *_eglextstr = NULL;
219         const char *ret;
220
221         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
222         EGL_DLSYM(eglQueryString);
223         ret = _eglQueryString(dpy, name);
224
225 #ifdef WANT_WAYLAND
226         if (name == EGL_EXTENSIONS) {
227                 assert(ret != NULL);
228
229                 if (!_eglextstr) {
230                         _eglextstr = calloc(1, strlen(ret) + strlen(EGL_WL_EXT_STRING) + 1);
231                         if (_eglextstr) {
232                                 strcat(_eglextstr, ret);
233                                 strcat(_eglextstr, EGL_WL_EXT_STRING);
234                         } else {
235                                 _eglextstr = (char*)ret;
236                         }
237                 }
238
239                 ret = _eglextstr;
240         }
241 #endif
242         return ret;
243 }
244
245 EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig * configs,
246                          EGLint config_size, EGLint * num_config)
247 {
248         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
249         EGL_DLSYM(eglGetConfigs);
250         return _eglGetConfigs(dpy, configs, config_size, num_config);
251 }
252
253 EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint * attrib_list,
254                            EGLConfig * configs, EGLint config_size,
255                            EGLint * num_config)
256 {
257         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
258         EGL_DLSYM(eglChooseConfig);
259         return _eglChooseConfig(dpy, attrib_list,
260                                configs, config_size, num_config);
261 }
262
263 EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
264                               EGLint attribute, EGLint * value)
265 {
266         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
267         EGL_DLSYM(eglGetConfigAttrib);
268         return _eglGetConfigAttrib(dpy, config, attribute, value);
269 }
270
271 EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
272                                   EGLNativeWindowType win,
273                                   const EGLint * attrib_list)
274 {
275         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
276         EGL_DLSYM(eglCreateWindowSurface);
277         return _eglCreateWindowSurface(dpy, config, win, attrib_list);
278 }
279
280 EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
281                                    const EGLint * attrib_list)
282 {
283         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
284         EGL_DLSYM(eglCreatePbufferSurface);
285         return _eglCreatePbufferSurface(dpy, config, attrib_list);
286 }
287
288 EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
289                                   EGLNativePixmapType pixmap,
290                                   const EGLint * attrib_list)
291 {
292         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
293         EGL_DLSYM(eglCreatePixmapSurface);
294         return _eglCreatePixmapSurface(dpy, config, pixmap, attrib_list);
295 }
296
297 EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
298 {
299         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
300         EGL_DLSYM(eglDestroySurface);
301         return _eglDestroySurface(dpy, surface);
302 }
303
304 EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
305                            EGLint attribute, EGLint * value)
306 {
307         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
308         EGL_DLSYM(eglQuerySurface);
309         return _eglQuerySurface(dpy, surface, attribute, value);
310 }
311
312 EGLBoolean eglBindAPI(EGLenum api)
313 {
314         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
315         EGL_DLSYM(eglBindAPI);
316         return _eglBindAPI(api);
317 }
318
319 EGLenum eglQueryAPI(void)
320 {
321         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
322         EGL_DLSYM(eglQueryAPI);
323         return _eglQueryAPI();
324 }
325
326 EGLBoolean eglWaitClient(void)
327 {
328         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
329         EGL_DLSYM(eglWaitClient);
330         return _eglWaitClient();
331 }
332
333 EGLBoolean eglReleaseThread(void)
334 {
335         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
336         EGL_DLSYM(eglReleaseThread);
337         return _eglReleaseThread();
338 }
339
340 EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
341                                             EGLClientBuffer buffer,
342                                             EGLConfig config,
343                                             const EGLint * attrib_list)
344 {
345         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
346         EGL_DLSYM(eglCreatePbufferFromClientBuffer);
347         return _eglCreatePbufferFromClientBuffer(dpy, buftype, buffer,
348                                                 config, attrib_list);
349 }
350
351 EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
352                             EGLint attribute, EGLint value)
353 {
354         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
355         EGL_DLSYM(eglSurfaceAttrib);
356         return _eglSurfaceAttrib(dpy, surface, attribute, value);
357 }
358
359 EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
360 {
361         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
362         EGL_DLSYM(eglBindTexImage);
363         return _eglBindTexImage(dpy, surface, buffer);
364 }
365
366 EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
367 {
368         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
369         EGL_DLSYM(eglReleaseTexImage);
370         return _eglReleaseTexImage(dpy, surface, buffer);
371 }
372
373 EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
374 {
375         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
376         EGL_DLSYM(eglSwapInterval);
377         return _eglSwapInterval(dpy, interval);
378 }
379
380 EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
381                             EGLContext share_context,
382                             const EGLint * attrib_list)
383 {
384         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
385         EGL_DLSYM(eglCreateContext);
386         return _eglCreateContext(dpy, config, share_context, attrib_list);
387 }
388
389 EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
390 {
391         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
392         EGL_DLSYM(eglDestroyContext);
393         return _eglDestroyContext(dpy, ctx);
394 }
395
396 EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw,
397                           EGLSurface read, EGLContext ctx)
398 {
399         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
400         EGL_DLSYM(eglMakeCurrent);
401         return _eglMakeCurrent(dpy, draw, read, ctx);
402 }
403
404 EGLContext eglGetCurrentContext(void)
405 {
406         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
407         EGL_DLSYM(eglGetCurrentContext);
408         return _eglGetCurrentContext();
409 }
410
411 EGLSurface eglGetCurrentSurface(EGLint readdraw)
412 {
413         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
414         EGL_DLSYM(eglGetCurrentSurface);
415         return _eglGetCurrentSurface(readdraw);
416 }
417
418 EGLDisplay eglGetCurrentDisplay(void)
419 {
420         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
421         EGL_DLSYM(eglGetCurrentDisplay);
422         return _eglGetCurrentDisplay();
423 }
424
425 EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx,
426                            EGLint attribute, EGLint * value)
427 {
428         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
429         EGL_DLSYM(eglQueryContext);
430         return _eglQueryContext(dpy, ctx, attribute, value);
431 }
432
433 EGLBoolean eglWaitGL(void)
434 {
435         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
436         EGL_DLSYM(eglWaitGL);
437         return _eglWaitGL();
438 }
439
440 EGLBoolean eglWaitNative(EGLint engine)
441 {
442         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
443         EGL_DLSYM(eglWaitNative);
444         return _eglWaitNative(engine);
445 }
446
447 EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
448 {
449         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
450         EGL_DLSYM(eglSwapBuffers);
451         return _eglSwapBuffers(dpy, surface);
452 }
453
454 EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface,
455                           EGLNativePixmapType target)
456 {
457         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
458         EGL_DLSYM(eglCopyBuffers);
459         return _eglCopyBuffers(dpy, surface, target);
460 }
461
462 static EGLImageKHR __eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx,
463                                          EGLenum target, EGLClientBuffer buffer,
464                                          const EGLint * attrib_list)
465 {
466         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
467         if (!_eglCreateImageKHR) {
468                 /* we can't EGL_DLSYM this, because it doesn't exist in libEGL.
469                  * IMG's libEGL. we also can't ask ourselves for the location of
470                  * eglGetProcAddress, otherwise we'll end up calling ourselves again, so
471                  * we must look up eglGetProcAddress first and ask SGX
472                  */
473                 EGL_DLSYM(eglGetProcAddress);
474                 _eglCreateImageKHR = (void*)_eglGetProcAddress("eglCreateImageKHR");
475         }
476
477         /*
478          * We consider EGL_WAYLAND_BUFFER_WL to be EGL_ANTIVE_PIXMAP_KHR.
479          * This way IMG EGL will pass the request to underlying WSEGL.
480          */
481         if (target == EGL_WAYLAND_BUFFER_WL) {
482                 EGL_DEBUG("%s: %s: mapping EGL_WAYLAND_BUFFER_WL to EGL_NATIVE_PIXMAP_KHR\n", __FILE__, __func__);
483                 target = EGL_NATIVE_PIXMAP_KHR;
484         }
485
486 #if 0
487         {
488                 int count = 0;
489                 EGLint *_attr, *_attr2, *head;
490                 
491                 _attr = attrib_list;
492                 while (*_attr != EGL_NONE) {
493                         count += 2;
494                         _attr++; _attr++;
495                 }
496                 count++;
497                 EGL_DEBUG("%s: %s: count=%d\n", __FILE__, __func__, count);
498                 head = _attr2 = alloca(sizeof(EGLint) * count);
499
500                 _attr = attrib_list;
501                 while (*_attr != EGL_NONE) {
502                         if (*_attr != EGL_WAYLAND_PLANE_WL) {
503                                 EGL_DEBUG("%s: %s: copying %x\n", __FILE__, __func__, *_attr);
504                                 *_attr2 = *_attr;
505                                 _attr2++; _attr++;
506
507                                 *_attr2 = *_attr;
508                                 _attr2++; _attr++;
509                         } else {
510                                 EGL_DEBUG("%s: %s: skipping %x\n", __FILE__, __func__, *_attr);
511                                 _attr++; _attr++;
512                         }
513                 }
514                 *_attr2 = - EGL_NONE;
515                 attrib_list = head;
516         }
517 #endif
518
519         EGL_DEBUG("%s: %s (target=%d, EGL_WAYLAND_BUFFER_WL=%d, EGL_NATIVE_PIXMAP_KHR=%d) : %p\n", __FILE__, __func__, target, EGL_WAYLAND_BUFFER_WL, EGL_NATIVE_PIXMAP_KHR, _eglCreateImageKHR);
520 //      return _eglCreateImageKHR(dpy, ctx, target, buffer, attrib_list);
521         return _eglCreateImageKHR(dpy, ctx, target, buffer, NULL);
522 }
523
524 #ifdef WANT_WAYLAND
525 static struct wl_kms *__wl_kms = NULL;
526
527 static EGLBoolean __eglBindWaylandDisplayWL(EGLDisplay dpy,
528                                               struct wl_display *display)
529 {
530         char *device_name = "/dev/dri/card0";
531         int fd = -1;
532
533         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
534         // TODO: create server side for wl_kms.
535         if (__wl_kms)
536                 return EGL_FALSE;
537
538         if (__gbm) {
539                 fd = gbm_device_get_fd(__gbm);
540                 device_name = _gbm_fd_get_device_name(fd);
541         } else {
542                 fd = open(device_name, O_RDWR);
543                 if (fd < 0)
544                         return EGL_FALSE;
545                 __gbm = gbm_create_device(fd);
546         }
547         EGL_DEBUG("%s: decice_name=%s\n", __func__, device_name);
548
549         __wl_kms = wayland_kms_init(display, __wl_display, device_name, fd);
550         return EGL_TRUE;
551 }
552
553 static EGLBoolean __eglUnbindWaylandDisplayWL(EGLDisplay dpy,
554                                                 struct wl_display *display)
555 {
556         // TODO: destroy wl_kms?
557         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
558         if (__wl_kms)
559                 wayland_kms_uninit(__wl_kms);
560
561         return EGL_TRUE;
562 }
563
564 static EGLBoolean __eglQueryWaylandBufferWL(EGLDisplay dpy, struct wl_resource *buffer,
565                                               EGLint attribute, EGLint * value)
566 {
567         int ret, val;
568         enum wl_kms_attribute attr;
569         EGLBoolean result = EGL_FALSE;
570
571         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
572         switch (attribute) {
573         case EGL_TEXTURE_FORMAT:
574                 attr = WL_KMS_TEXTURE_FORMAT;
575                 break;
576         case EGL_WIDTH:
577                 attr = WL_KMS_WIDTH;
578                 break;
579         case EGL_HEIGHT:
580                 attr = WL_KMS_HEIGHT;
581                 break;
582         default:
583                 return EGL_FALSE;
584         }
585         
586         ret = wayland_kms_query_buffer(__wl_kms, buffer, attr, &val);
587         if (!ret) { 
588                 *value = (EGLint)val;
589                 result = EGL_TRUE;
590         }
591
592         return result;
593 }
594 #endif
595
596 __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
597 {
598         EGL_DLSYM(eglGetProcAddress);
599
600         EGL_DEBUG("%s: %s(%s)\n", __FILE__, __func__, procname);
601         if (strcmp(procname, "eglCreateImageKHR") == 0) {
602                 return (__eglMustCastToProperFunctionPointerType)__eglCreateImageKHR;
603         }
604 #ifdef WANT_WAYLAND
605         else if (strcmp(procname, "eglBindWaylandDisplayWL") == 0) {
606                 return (__eglMustCastToProperFunctionPointerType)__eglBindWaylandDisplayWL;
607         } else if (strcmp(procname, "eglUnbindWaylandDisplayWL") == 0) {
608                 return (__eglMustCastToProperFunctionPointerType)__eglUnbindWaylandDisplayWL;
609         } else if (strcmp(procname, "eglQueryWaylandBufferWL") == 0) {
610                 return (__eglMustCastToProperFunctionPointerType)__eglQueryWaylandBufferWL;
611         }
612 #endif
613         return _eglGetProcAddress(procname);
614 }
615
616 EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
617 {
618         EGL_DEBUG("%s: %s\n", __FILE__, __func__);
619         EGL_DLSYM(eglDestroyImageKHR);
620         return _eglDestroyImageKHR(dpy, image);
621 }