tizen 2.4 release
[sdk/emulator-yagl.git] / EGL / yagl_egl_calls.c
1 /*
2  * YaGL
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact :
7  * Stanislav Vorobiov <s.vorobiov@samsung.com>
8  * Jinhyung Jo <jinhyung.jo@samsung.com>
9  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights
14  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  * copies of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27  * THE SOFTWARE.
28  *
29  * Contributors:
30  * - S-Core Co., Ltd
31  *
32  */
33
34 #include "yagl_host_egl_calls.h"
35 #include "yagl_impl.h"
36 #include "yagl_display.h"
37 #include "yagl_log.h"
38 #include "yagl_egl_state.h"
39 #include "yagl_state.h"
40 #include "yagl_malloc.h"
41 #include "yagl_surface.h"
42 #include "yagl_context.h"
43 #include "yagl_image.h"
44 #include "yagl_fence.h"
45 #include "yagl_backend.h"
46 #include "yagl_render.h"
47 #include "yagl_native_platform.h"
48 #include "yagl_native_display.h"
49 #include "yagl_native_drawable.h"
50 #include "yagl_transport_egl.h"
51 #include "yagl_client_interface.h"
52 #include "yagl_client_image.h"
53 #include "yagl_client_context.h"
54 #include "yagl_sharegroup.h"
55 #include "yagl_tex_image_binding.h"
56 #ifdef YAGL_PLATFORM_X11
57 #include "x11/yagl_x11_platform.h"
58 #endif
59 #include "EGL/eglmesaext.h"
60 #include <stdio.h>
61 #include <string.h>
62 #include <assert.h>
63 #include <dlfcn.h>
64 #include <stdlib.h>
65
66 #define YAGL_SET_ERR(err) \
67     yagl_set_error(err); \
68     YAGL_LOG_ERROR("error = 0x%X", err)
69
70 #define YAGL_UNIMPLEMENTED(func, ret) \
71     YAGL_LOG_FUNC_SET(func); \
72     YAGL_LOG_WARN("NOT IMPLEMENTED!!!"); \
73     return ret;
74
75 static int yagl_get_client_api(const EGLint *attrib_list, yagl_client_api *client_api)
76 {
77     int i = 0;
78
79     switch (yagl_get_api()) {
80     case EGL_OPENGL_ES_API:
81         *client_api = yagl_client_api_gles1;
82         if (attrib_list) {
83             while (attrib_list[i] != EGL_NONE) {
84                 switch (attrib_list[i]) {
85                 case EGL_CONTEXT_CLIENT_VERSION:
86                     if (attrib_list[i + 1] == 1) {
87                         *client_api = yagl_client_api_gles1;
88                     } else if (attrib_list[i + 1] == 2) {
89                         *client_api = yagl_client_api_gles2;
90                     } else if (attrib_list[i + 1] == 3) {
91                         *client_api = yagl_client_api_gles3;
92                     } else {
93                         return 0;
94                     }
95                     break;
96                 default:
97                     return 0;
98                 }
99
100                 i += 2;
101             }
102         }
103         break;
104     case EGL_OPENVG_API:
105         *client_api = yagl_client_api_ovg;
106         break;
107     case EGL_OPENGL_API:
108         *client_api = yagl_client_api_ogl;
109         break;
110     default:
111         return 0;
112     }
113     return 1;
114 }
115
116 static __inline int yagl_validate_display(EGLDisplay dpy_,
117                                           struct yagl_display **dpy)
118 {
119     YAGL_LOG_FUNC_SET(yagl_validate_display);
120
121     *dpy = yagl_display_get(dpy_);
122
123     if (!*dpy) {
124         YAGL_SET_ERR(EGL_BAD_DISPLAY);
125         return 0;
126     }
127
128     if (!yagl_display_is_prepared(*dpy)) {
129         YAGL_SET_ERR(EGL_NOT_INITIALIZED);
130         return 0;
131     }
132
133     return 1;
134 }
135
136 static __inline int yagl_validate_context(struct yagl_display *dpy,
137                                           EGLContext ctx_,
138                                           struct yagl_context **ctx)
139 {
140     YAGL_LOG_FUNC_SET(yagl_validate_context);
141
142     *ctx = yagl_display_context_acquire(dpy, ctx_);
143
144     if (!*ctx) {
145         YAGL_SET_ERR(EGL_BAD_CONTEXT);
146         return 0;
147     }
148
149     return 1;
150 }
151
152 static __inline int yagl_validate_surface(struct yagl_display *dpy,
153                                           EGLSurface sfc_,
154                                           struct yagl_surface **sfc)
155 {
156     YAGL_LOG_FUNC_SET(yagl_validate_surface);
157
158     *sfc = yagl_display_surface_acquire(dpy, sfc_);
159
160     if (!*sfc) {
161         YAGL_SET_ERR(EGL_BAD_SURFACE);
162         return 0;
163     }
164
165     return 1;
166 }
167
168 static __inline int yagl_validate_image(struct yagl_display *dpy,
169                                         EGLImageKHR image_,
170                                         struct yagl_image **image)
171 {
172     YAGL_LOG_FUNC_SET(yagl_validate_image);
173
174     *image = yagl_display_image_acquire(dpy, image_);
175
176     if (!*image) {
177         YAGL_SET_ERR(EGL_BAD_PARAMETER);
178         return 0;
179     }
180
181     return 1;
182 }
183
184 static __inline int yagl_validate_fence(struct yagl_display *dpy,
185                                         EGLSyncKHR sync_,
186                                         struct yagl_fence **fence)
187 {
188     YAGL_LOG_FUNC_SET(yagl_validate_fence);
189
190     *fence = yagl_display_fence_acquire(dpy, sync_);
191
192     if (!*fence) {
193         YAGL_SET_ERR(EGL_BAD_PARAMETER);
194         return 0;
195     }
196
197     return 1;
198 }
199
200 YAGL_API EGLint eglGetError()
201 {
202     EGLint retval;
203
204     YAGL_LOG_FUNC_ENTER(eglGetError, NULL);
205
206     retval = yagl_get_error();
207
208     YAGL_LOG_FUNC_EXIT_SPLIT(EGLint, retval);
209
210     return retval;
211 }
212
213 YAGL_API EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id)
214 {
215     struct yagl_native_platform *platform;
216     struct yagl_display *dpy;
217     EGLDisplay ret = EGL_NO_DISPLAY;
218
219     YAGL_LOG_FUNC_ENTER_SPLIT1(eglGetDisplay, EGLNativeDisplayType, display_id);
220
221     platform = yagl_guess_platform((yagl_os_display)display_id);
222
223     if (!platform) {
224         goto out;
225     }
226
227     dpy = yagl_display_add(platform, (yagl_os_display)display_id);
228
229     if (!dpy) {
230         YAGL_SET_ERR(EGL_BAD_DISPLAY);
231         YAGL_LOG_ERROR("unable to add display %p",
232                        (yagl_os_display)display_id);
233         goto out;
234     }
235
236     ret = (EGLDisplay)dpy->host_dpy;
237
238     YAGL_LOG_FUNC_EXIT_SPLIT(yagl_host_handle, dpy->host_dpy);
239
240     return ret;
241
242 out:
243     YAGL_LOG_FUNC_EXIT(NULL);
244
245     return ret;
246 }
247
248 YAGL_API EGLBoolean eglInitialize(EGLDisplay dpy_, EGLint* major, EGLint* minor)
249 {
250     EGLint error = 0;
251     struct yagl_display *dpy;
252
253     YAGL_LOG_FUNC_ENTER(eglInitialize, "dpy = %u", (yagl_host_handle)dpy_);
254
255     dpy = yagl_display_get(dpy_);
256
257     if (!dpy) {
258         YAGL_SET_ERR(EGL_BAD_DISPLAY);
259         goto fail;
260     }
261
262     if (!yagl_host_eglInitialize(dpy->host_dpy, major, minor, &error)) {
263         YAGL_SET_ERR(error);
264         goto fail;
265     }
266
267     yagl_display_prepare(dpy);
268
269     YAGL_LOG_FUNC_EXIT("major = %d, minor = %d",
270                        (major ? *major : -1),
271                        (minor ? *minor : -1));
272
273     return EGL_TRUE;
274
275 fail:
276     YAGL_LOG_FUNC_EXIT(NULL);
277
278     return EGL_FALSE;
279 }
280
281 YAGL_API EGLBoolean eglTerminate(EGLDisplay dpy_)
282 {
283     EGLint error = 0;
284     struct yagl_display *dpy;
285     EGLBoolean ret = EGL_FALSE;
286
287     YAGL_LOG_FUNC_ENTER(eglTerminate, "dpy = %u", (yagl_host_handle)dpy_);
288
289     if (!yagl_validate_display(dpy_, &dpy)) {
290         goto out;
291     }
292
293     ret = yagl_host_eglTerminate(dpy->host_dpy, &error);
294
295     if (ret) {
296         yagl_display_terminate(dpy);
297     } else {
298         YAGL_SET_ERR(error);
299     }
300
301 out:
302     YAGL_LOG_FUNC_EXIT(NULL);
303
304     return ret;
305 }
306
307 YAGL_API const char *eglQueryString(EGLDisplay dpy_, EGLint name)
308 {
309     const char *str = NULL;
310
311     YAGL_LOG_FUNC_ENTER(eglQueryString,
312                         "dpy = %u, name = %d",
313                         (yagl_host_handle)dpy_,
314                         name);
315
316     switch (name) {
317     case EGL_VENDOR:
318         str = "Samsung";
319         break;
320     case EGL_VERSION:
321         str = "1.4";
322         break;
323     case EGL_CLIENT_APIS:
324         if (yagl_get_host_gl_version() < yagl_gl_3_1_es3) {
325             str = "OpenGL_ES OpenGL_ES2";
326         } else {
327             str = "OpenGL_ES OpenGL_ES2 OpenGL_ES3";
328         }
329         break;
330     case EGL_EXTENSIONS:
331         str = yagl_display_get_extensions(yagl_display_get(dpy_));
332         break;
333     default:
334         YAGL_SET_ERR(EGL_BAD_PARAMETER);
335     }
336
337     YAGL_LOG_FUNC_EXIT("%s", str);
338
339     return str;
340 }
341
342 YAGL_API EGLBoolean eglGetConfigs(EGLDisplay dpy,
343                                   EGLConfig *configs,
344                                   EGLint config_size,
345                                   EGLint *num_config)
346 {
347     EGLint error = 0;
348
349     YAGL_LOG_FUNC_ENTER(eglGetConfigs,
350                         "dpy = %u, configs = %p, config_size = %d",
351                         (yagl_host_handle)dpy,
352                         configs,
353                         config_size);
354
355     if (!num_config) {
356         YAGL_SET_ERR(EGL_BAD_PARAMETER);
357         goto fail;
358     }
359
360     if (!yagl_host_eglGetConfigs((yagl_host_handle)dpy,
361                                  (yagl_host_handle*)configs,
362                                  config_size,
363                                  num_config,
364                                  &error)) {
365         YAGL_SET_ERR(error);
366         goto fail;
367     }
368
369     YAGL_LOG_FUNC_EXIT("num_config = %d", *num_config);
370
371     return EGL_TRUE;
372
373 fail:
374     YAGL_LOG_FUNC_EXIT(NULL);
375
376     return EGL_FALSE;
377 }
378
379 YAGL_API EGLBoolean eglChooseConfig(EGLDisplay dpy,
380                                     const EGLint *attrib_list,
381                                     EGLConfig *configs,
382                                     EGLint config_size,
383                                     EGLint *num_config)
384 {
385     EGLint error = 0;
386
387     YAGL_LOG_FUNC_ENTER(eglChooseConfig, "dpy = %u", (yagl_host_handle)dpy);
388
389     if (!num_config) {
390         YAGL_SET_ERR(EGL_BAD_PARAMETER);
391         goto fail;
392     }
393
394     if (!yagl_host_eglChooseConfig((yagl_host_handle)dpy,
395                                    attrib_list,
396                                    yagl_transport_attrib_list_count(attrib_list),
397                                    (yagl_host_handle*)configs,
398                                    config_size,
399                                    num_config,
400                                    &error)) {
401         YAGL_SET_ERR(error);
402         goto fail;
403     }
404
405     YAGL_LOG_FUNC_EXIT("num_config = %d", *num_config);
406
407     return EGL_TRUE;
408
409 fail:
410     YAGL_LOG_FUNC_EXIT(NULL);
411
412     return EGL_FALSE;
413 }
414
415 YAGL_API EGLBoolean eglGetConfigAttrib(EGLDisplay dpy_,
416                                        EGLConfig config,
417                                        EGLint attribute,
418                                        EGLint *value)
419 {
420     EGLint error = 0;
421     struct yagl_display *dpy = NULL;
422     EGLBoolean ret = EGL_FALSE;
423     int visual_id = 0, visual_type = 0;
424
425     YAGL_LOG_FUNC_ENTER(eglGetConfigAttrib,
426                         "dpy = %u, config = %u, attribute = 0x%X",
427                         (yagl_host_handle)dpy_,
428                         (yagl_host_handle)config,
429                         attribute);
430
431     if (!yagl_validate_display(dpy_, &dpy)) {
432         goto fail;
433     }
434
435     switch (attribute) {
436     case EGL_NATIVE_VISUAL_ID:
437     case EGL_NATIVE_VISUAL_TYPE:
438         if (!dpy->native_dpy->get_visual(dpy->native_dpy,
439                                          &visual_id,
440                                          &visual_type)) {
441             YAGL_SET_ERR(EGL_BAD_CONFIG);
442             YAGL_LOG_ERROR("get_visual failed");
443             goto fail;
444         }
445
446         if (attribute == EGL_NATIVE_VISUAL_ID) {
447             *value = visual_id;
448         } else {
449             *value = visual_type;
450         }
451
452         ret = EGL_TRUE;
453
454         break;
455     case EGL_Y_INVERTED_NOK:
456         if (dpy->native_dpy->platform->pixmaps_supported) {
457             *value = yagl_get_backend()->y_inverted;
458             ret = EGL_TRUE;
459             break;
460         }
461         /* Fall through. */
462     default:
463         ret = yagl_host_eglGetConfigAttrib((yagl_host_handle)dpy_,
464                                            (yagl_host_handle)config,
465                                            attribute,
466                                            value,
467                                            &error);
468
469         if (!ret) {
470             YAGL_SET_ERR(error);
471         }
472
473         break;
474     }
475
476     if (!ret) {
477         goto fail;
478     }
479
480     YAGL_LOG_FUNC_EXIT("value = 0x%X", (value ? *value : -1));
481
482     return ret;
483
484 fail:
485     YAGL_LOG_FUNC_EXIT(NULL);
486
487     return ret;
488 }
489
490 YAGL_API EGLSurface eglCreateWindowSurface(EGLDisplay dpy_,
491                                            EGLConfig config,
492                                            EGLNativeWindowType win,
493                                            const EGLint *attrib_list)
494 {
495     EGLint error = 0;
496     struct yagl_display *dpy = NULL;
497     struct yagl_native_drawable *native_win = NULL;
498     struct yagl_surface *surface = NULL;
499
500     YAGL_LOG_FUNC_ENTER(eglCreateWindowSurface,
501                         "dpy = %u, config = %u",
502                         (yagl_host_handle)dpy_,
503                         (yagl_host_handle)config);
504
505     if (!yagl_validate_display(dpy_, &dpy)) {
506         goto fail;
507     }
508
509     native_win = dpy->native_dpy->wrap_window(dpy->native_dpy,
510                                               (yagl_os_window)win);
511
512     if (!native_win) {
513         goto fail;
514     }
515
516     surface = yagl_get_backend()->create_window_surface(dpy,
517                                                         (yagl_host_handle)config,
518                                                         native_win,
519                                                         attrib_list);
520
521     if (!surface) {
522         native_win->destroy(native_win);
523         native_win = NULL;
524         goto fail;
525     }
526
527     if (!yagl_display_surface_add(dpy, surface)) {
528         yagl_host_eglDestroySurface(dpy->host_dpy, surface->res.handle, &error);
529         YAGL_SET_ERR(EGL_BAD_ALLOC);
530         goto fail;
531     }
532
533     yagl_surface_release(surface);
534
535     YAGL_LOG_FUNC_EXIT("%p", yagl_surface_get_handle(surface));
536
537     return yagl_surface_get_handle(surface);
538
539 fail:
540     yagl_surface_release(surface);
541
542     YAGL_LOG_FUNC_EXIT(NULL);
543
544     return EGL_NO_SURFACE;
545 }
546
547 YAGL_API EGLSurface eglCreatePbufferSurface(EGLDisplay dpy_,
548                                             EGLConfig config,
549                                             const EGLint *attrib_list)
550 {
551     EGLint error = 0;
552     struct yagl_display *dpy = NULL;
553     struct yagl_surface *surface = NULL;
554
555     YAGL_LOG_FUNC_ENTER(eglCreatePbufferSurface,
556                         "dpy = %u, config = %u",
557                         (yagl_host_handle)dpy_,
558                         (yagl_host_handle)config);
559
560     if (!yagl_validate_display(dpy_, &dpy)) {
561         goto fail;
562     }
563
564     surface = yagl_get_backend()->create_pbuffer_surface(dpy,
565                                                          (yagl_host_handle)config,
566                                                          attrib_list);
567
568     if (!surface) {
569         goto fail;
570     }
571
572     if (!yagl_display_surface_add(dpy, surface)) {
573         yagl_host_eglDestroySurface(dpy->host_dpy, surface->res.handle, &error);
574         YAGL_SET_ERR(EGL_BAD_ALLOC);
575         goto fail;
576     }
577
578     yagl_surface_release(surface);
579
580     YAGL_LOG_FUNC_EXIT("%p", yagl_surface_get_handle(surface));
581
582     return yagl_surface_get_handle(surface);
583
584 fail:
585     yagl_surface_release(surface);
586
587     YAGL_LOG_FUNC_EXIT(NULL);
588
589     return EGL_NO_SURFACE;
590 }
591
592 YAGL_API EGLSurface eglCreatePixmapSurface(EGLDisplay dpy_,
593                                            EGLConfig config,
594                                            EGLNativePixmapType pixmap,
595                                            const EGLint *attrib_list)
596 {
597     EGLint error = 0;
598     struct yagl_display *dpy = NULL;
599     struct yagl_native_drawable *native_pixmap = NULL;
600     struct yagl_surface *surface = NULL;
601
602     YAGL_LOG_FUNC_ENTER(eglCreatePixmapSurface,
603                         "dpy = %u, config = %u",
604                         (yagl_host_handle)dpy_,
605                         (yagl_host_handle)config);
606
607     if (!yagl_validate_display(dpy_, &dpy)) {
608         goto fail;
609     }
610
611     native_pixmap = dpy->native_dpy->wrap_pixmap(dpy->native_dpy,
612                                                  (yagl_os_pixmap)pixmap);
613
614     if (!native_pixmap) {
615         goto fail;
616     }
617
618     surface = yagl_get_backend()->create_pixmap_surface(dpy,
619                                                         (yagl_host_handle)config,
620                                                         native_pixmap,
621                                                         attrib_list);
622
623     if (!surface) {
624         native_pixmap->destroy(native_pixmap);
625         native_pixmap = NULL;
626         goto fail;
627     }
628
629     if (!yagl_display_surface_add(dpy, surface)) {
630         yagl_host_eglDestroySurface(dpy->host_dpy, surface->res.handle, &error);
631         YAGL_SET_ERR(EGL_BAD_ALLOC);
632         goto fail;
633     }
634
635     yagl_surface_release(surface);
636
637     YAGL_LOG_FUNC_EXIT("%p", yagl_surface_get_handle(surface));
638
639     return yagl_surface_get_handle(surface);
640
641 fail:
642     yagl_surface_release(surface);
643
644     YAGL_LOG_FUNC_EXIT(NULL);
645
646     return EGL_NO_SURFACE;
647 }
648
649 YAGL_API EGLBoolean eglDestroySurface(EGLDisplay dpy_, EGLSurface surface_)
650 {
651     EGLint error = 0;
652     EGLBoolean res = EGL_FALSE;
653     struct yagl_display *dpy = NULL;
654     struct yagl_surface *surface = NULL;
655
656     YAGL_LOG_FUNC_ENTER(eglDestroySurface,
657                         "dpy = %u, surface = %p",
658                         (yagl_host_handle)dpy_,
659                         surface_);
660
661     if (!yagl_validate_display(dpy_, &dpy)) {
662         goto out;
663     }
664
665     if (!yagl_validate_surface(dpy, surface_, &surface)) {
666         goto out;
667     }
668
669     if (!yagl_host_eglDestroySurface(dpy->host_dpy, surface->res.handle, &error)) {
670         YAGL_SET_ERR(error);
671         goto out;
672     }
673
674     if (!yagl_display_surface_remove(dpy, surface_)) {
675         YAGL_LOG_ERROR("we're the one who destroy the surface, but surface isn't there!");
676         YAGL_SET_ERR(EGL_BAD_SURFACE);
677         goto out;
678     }
679
680     res = EGL_TRUE;
681
682 out:
683     yagl_surface_release(surface);
684
685     YAGL_LOG_FUNC_EXIT("%d", ((res == EGL_TRUE) ? 1 : 0));
686
687     return res;
688 }
689
690 YAGL_API EGLBoolean eglQuerySurface(EGLDisplay dpy_,
691                                     EGLSurface surface_,
692                                     EGLint attribute,
693                                     EGLint *value)
694 {
695     EGLint error = 0;
696     EGLBoolean retval = EGL_FALSE;
697     struct yagl_display *dpy = NULL;
698     struct yagl_surface *surface = NULL;
699     void *ptr;
700     uint32_t stride;
701
702     YAGL_LOG_FUNC_ENTER(eglQuerySurface,
703                         "dpy = %u, surface = %p, attribute = 0x%X, value = %p",
704                         (yagl_host_handle)dpy_,
705                         surface_,
706                         attribute,
707                         value);
708
709     if (!yagl_validate_display(dpy_, &dpy)) {
710         goto out;
711     }
712
713     if (!yagl_validate_surface(dpy, surface_, &surface)) {
714         goto out;
715     }
716
717     switch (attribute) {
718     case EGL_BITMAP_POINTER_KHR:
719         ptr = yagl_surface_map(surface, &stride);
720         if (ptr) {
721             *value = (EGLint)ptr;
722             retval = EGL_TRUE;
723         } else {
724             YAGL_SET_ERR(EGL_BAD_ACCESS);
725         }
726         break;
727     case EGL_BITMAP_PITCH_KHR:
728         ptr = yagl_surface_map(surface, &stride);
729         if (ptr) {
730             *value = stride;
731             retval = EGL_TRUE;
732         } else {
733             YAGL_SET_ERR(EGL_BAD_ACCESS);
734         }
735         break;
736     case EGL_BITMAP_ORIGIN_KHR:
737         *value = EGL_UPPER_LEFT_KHR;
738         retval = EGL_TRUE;
739         break;
740     case EGL_BITMAP_PIXEL_RED_OFFSET_KHR:
741         *value = 16;
742         retval = EGL_TRUE;
743         break;
744     case EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR:
745         *value = 8;
746         retval = EGL_TRUE;
747         break;
748     case EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR:
749         *value = 0;
750         retval = EGL_TRUE;
751         break;
752     case EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR:
753         *value = 24;
754         retval = EGL_TRUE;
755         break;
756     case EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR:
757         *value = 0;
758         retval = EGL_TRUE;
759         break;
760     case EGL_BUFFER_AGE_EXT:
761         if (dpy->native_dpy->platform->buffer_age_supported &&
762             surface->native_drawable) {
763             *value = surface->native_drawable->get_buffer_age(surface->native_drawable);
764             retval = EGL_TRUE;
765             break;
766         }
767         /* Fall through. */
768     default:
769         retval = yagl_host_eglQuerySurface(dpy->host_dpy,
770                                            surface->res.handle,
771                                            attribute,
772                                            value,
773                                            &error);
774
775         if (!retval) {
776             YAGL_SET_ERR(error);
777         }
778
779         break;
780     }
781
782 out:
783     yagl_surface_release(surface);
784
785     YAGL_LOG_FUNC_EXIT("%d", ((retval == EGL_TRUE) ? 1 : 0));
786
787     return retval;
788 }
789
790 YAGL_API EGLBoolean eglBindAPI(EGLenum api)
791 {
792     YAGL_LOG_FUNC_ENTER_SPLIT1(eglBindAPI, EGLenum, api);
793
794     if (api != EGL_OPENGL_ES_API) {
795         YAGL_SET_ERR(EGL_BAD_PARAMETER);
796         return EGL_FALSE;
797     }
798
799     yagl_host_eglBindAPI(api);
800     yagl_set_api(api);
801
802     YAGL_LOG_FUNC_EXIT_SPLIT(EGLBoolean, EGL_TRUE);
803
804     return EGL_TRUE;
805 }
806
807 YAGL_API EGLenum eglQueryAPI()
808 {
809     EGLenum ret;
810
811     YAGL_LOG_FUNC_ENTER_SPLIT0(eglQueryAPI);
812
813     ret = yagl_get_api();
814
815     YAGL_LOG_FUNC_EXIT_SPLIT(EGLenum, ret);
816
817     return ret;
818 }
819
820 YAGL_API EGLBoolean eglWaitClient()
821 {
822     struct yagl_surface *draw_sfc;
823
824     YAGL_LOG_FUNC_ENTER_SPLIT0(eglWaitClient);
825
826     draw_sfc = yagl_get_draw_surface();
827
828     if (draw_sfc) {
829         draw_sfc->wait_gl(draw_sfc);
830     }
831
832     YAGL_LOG_FUNC_EXIT(NULL);
833
834     return EGL_TRUE;
835 }
836
837 YAGL_API EGLBoolean eglReleaseThread()
838 {
839     EGLint error = 0;
840
841     YAGL_LOG_FUNC_ENTER(eglReleaseThread, NULL);
842
843     if (!yagl_host_eglReleaseThread(&error)) {
844         YAGL_SET_ERR(error);
845         goto fail;
846     }
847
848     yagl_reset_state();
849
850     YAGL_LOG_FUNC_EXIT("1");
851
852     return EGL_TRUE;
853
854 fail:
855     YAGL_LOG_FUNC_EXIT(NULL);
856
857     return EGL_FALSE;
858 }
859
860 YAGL_API EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy,
861                                                      EGLenum buftype,
862                                                      EGLClientBuffer buffer,
863                                                      EGLConfig config,
864                                                      const EGLint *attrib_list)
865 {
866     YAGL_UNIMPLEMENTED(eglCreatePbufferFromClientBuffer, EGL_NO_SURFACE);
867 }
868
869 YAGL_API EGLBoolean eglSurfaceAttrib(EGLDisplay dpy_,
870                                      EGLSurface surface_,
871                                      EGLint attribute,
872                                      EGLint value)
873 {
874     EGLint error = 0;
875     EGLBoolean res = EGL_FALSE;
876     struct yagl_display *dpy = NULL;
877     struct yagl_surface *surface = NULL;
878
879     YAGL_LOG_FUNC_ENTER(eglSurfaceAttrib,
880                         "dpy = %u, surface = %p, attribute = 0x%X, value = 0x%X",
881                         (yagl_host_handle)dpy_,
882                         surface_,
883                         attribute,
884                         value);
885
886     if (!yagl_validate_display(dpy_, &dpy)) {
887         goto out;
888     }
889
890     if (!yagl_validate_surface(dpy, surface_, &surface)) {
891         goto out;
892     }
893
894     if (!yagl_host_eglSurfaceAttrib(dpy->host_dpy,
895                                     surface->res.handle,
896                                     attribute,
897                                     value,
898                                     &error)) {
899         YAGL_SET_ERR(error);
900         goto out;
901     }
902
903     res = EGL_TRUE;
904
905 out:
906     yagl_surface_release(surface);
907
908     YAGL_LOG_FUNC_EXIT("%d", ((res == EGL_TRUE) ? 1 : 0));
909
910     return res;
911 }
912
913 YAGL_API EGLBoolean eglBindTexImage(EGLDisplay dpy_,
914                                     EGLSurface surface_,
915                                     EGLint buffer)
916 {
917     EGLBoolean res = EGL_FALSE;
918     struct yagl_display *dpy = NULL;
919     struct yagl_surface *surface = NULL;
920     struct yagl_context *ctx = NULL;
921     struct yagl_client_interface *iface = NULL;
922     struct yagl_client_image *image = NULL;
923     struct yagl_tex_image_binding *binding = NULL;
924
925     YAGL_LOG_FUNC_ENTER(eglBindTexImage,
926                         "dpy = %u, surface = %p, buffer = 0x%X",
927                         (yagl_host_handle)dpy_,
928                         surface_,
929                         buffer);
930
931     iface = yagl_get_any_client_interface();
932
933     if (!iface) {
934         YAGL_SET_ERR(EGL_BAD_ALLOC);
935         goto out;
936     }
937
938     ctx = yagl_get_context();
939
940     if (!ctx) {
941         YAGL_LOG_WARN("No context");
942         res = EGL_TRUE;
943         goto out;
944     }
945
946     if (!yagl_validate_display(dpy_, &dpy)) {
947         goto out;
948     }
949
950     if (!yagl_validate_surface(dpy, surface_, &surface)) {
951         goto out;
952     }
953
954     if (buffer != EGL_BACK_BUFFER) {
955         YAGL_SET_ERR(EGL_BAD_PARAMETER);
956         goto out;
957     }
958
959     if (surface->type != EGL_PBUFFER_BIT) {
960         YAGL_SET_ERR(EGL_BAD_SURFACE);
961         goto out;
962     }
963
964     image = surface->create_image(surface, iface);
965
966     if (!image) {
967         goto out;
968     }
969
970     binding = yagl_surface_create_tex_image_binding(surface, iface);
971
972     if (!ctx->client_ctx->bind_tex_image(ctx->client_ctx, image, binding)) {
973         yagl_free(binding);
974         YAGL_SET_ERR(EGL_BAD_ACCESS);
975         goto out;
976     }
977
978     if (!yagl_surface_bind_tex_image(surface, binding)) {
979         iface->release_tex_image(iface, binding->cookie);
980         yagl_free(binding);
981         YAGL_SET_ERR(EGL_BAD_ACCESS);
982         goto out;
983     }
984
985     res = EGL_TRUE;
986
987 out:
988     yagl_surface_release(surface);
989     yagl_client_image_release(image);
990
991     YAGL_LOG_FUNC_EXIT("%d", ((res == EGL_TRUE) ? 1 : 0));
992
993     return res;
994 }
995
996 YAGL_API EGLBoolean eglReleaseTexImage(EGLDisplay dpy_,
997                                        EGLSurface surface_,
998                                        EGLint buffer)
999 {
1000     EGLBoolean res = EGL_FALSE;
1001     struct yagl_display *dpy = NULL;
1002     struct yagl_surface *surface = NULL;
1003
1004     YAGL_LOG_FUNC_ENTER(eglReleaseTexImage,
1005                         "dpy = %u, surface = %p, buffer = 0x%X",
1006                         (yagl_host_handle)dpy_,
1007                         surface_,
1008                         buffer);
1009
1010     if (!yagl_validate_display(dpy_, &dpy)) {
1011         goto out;
1012     }
1013
1014     if (!yagl_validate_surface(dpy, surface_, &surface)) {
1015         goto out;
1016     }
1017
1018     if (buffer != EGL_BACK_BUFFER) {
1019         YAGL_SET_ERR(EGL_BAD_PARAMETER);
1020         goto out;
1021     }
1022
1023     if (surface->type != EGL_PBUFFER_BIT) {
1024         YAGL_SET_ERR(EGL_BAD_SURFACE);
1025         goto out;
1026     }
1027
1028     yagl_surface_release_tex_image(surface);
1029
1030     res = EGL_TRUE;
1031
1032 out:
1033     yagl_surface_release(surface);
1034
1035     YAGL_LOG_FUNC_EXIT("%d", ((res == EGL_TRUE) ? 1 : 0));
1036
1037     return res;
1038 }
1039
1040 YAGL_API EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
1041 {
1042     struct yagl_surface *draw_sfc;
1043
1044     YAGL_LOG_FUNC_ENTER(eglSwapInterval,
1045                         "dpy = %u, interval = %d",
1046                         (yagl_host_handle)dpy,
1047                         interval);
1048
1049     draw_sfc = yagl_get_draw_surface();
1050
1051     if (draw_sfc && (draw_sfc->type == EGL_WINDOW_BIT)) {
1052         if (interval <= 0) {
1053             /*
1054              * Always make sure that swap interval is at least 1. Setting
1055              * to 0 makes little sense with tizen since tizen compositor
1056              * will still use a value of 1 and this will cause jagged rendering
1057              */
1058             interval = 1;
1059         }
1060
1061         draw_sfc->set_swap_interval(draw_sfc, interval);
1062     }
1063
1064     YAGL_LOG_FUNC_EXIT("1");
1065
1066     return EGL_TRUE;
1067 }
1068
1069 YAGL_API EGLContext eglCreateContext(EGLDisplay dpy_,
1070                                      EGLConfig config,
1071                                      EGLContext share_context_,
1072                                      const EGLint *attrib_list)
1073 {
1074     EGLint error = 0;
1075     struct yagl_display *dpy = NULL;
1076     struct yagl_context *share_context = NULL;
1077     struct yagl_sharegroup *sg = NULL;
1078     yagl_client_api client_api;
1079     struct yagl_client_interface *iface = NULL;
1080     yagl_host_handle host_context = 0;
1081     struct yagl_client_context *client_ctx = NULL;
1082     struct yagl_context *ctx = NULL;
1083
1084     YAGL_LOG_FUNC_ENTER(eglCreateContext,
1085                         "dpy = %u, config = %u, share_context = %u",
1086                         (yagl_host_handle)dpy_,
1087                         (yagl_host_handle)config,
1088                         (yagl_host_handle)share_context_);
1089
1090     if (!yagl_validate_display(dpy_, &dpy)) {
1091         goto out;
1092     }
1093
1094     if (share_context_) {
1095         if (!yagl_validate_context(dpy, share_context_, &share_context)) {
1096             goto out;
1097         }
1098         sg = share_context->client_ctx->sg;
1099         yagl_sharegroup_acquire(sg);
1100     } else {
1101         sg = yagl_sharegroup_create();
1102     }
1103
1104     if (!yagl_get_client_api(attrib_list, &client_api)) {
1105         YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
1106         goto out;
1107     }
1108
1109     if ((client_api == yagl_client_api_gles3) &&
1110         (yagl_get_host_gl_version() < yagl_gl_3_1_es3)) {
1111         YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
1112         goto out;
1113     }
1114
1115     iface = yagl_get_client_interface(client_api);
1116
1117     if (!iface) {
1118         YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
1119         goto out;
1120     }
1121
1122     host_context =
1123         yagl_host_eglCreateContext(dpy->host_dpy,
1124                                    (yagl_host_handle)config,
1125                                    (yagl_host_handle)share_context_,
1126                                    attrib_list,
1127                                    yagl_transport_attrib_list_count(attrib_list),
1128                                    &error);
1129
1130     if (!host_context) {
1131         YAGL_SET_ERR(error);
1132         goto out;
1133     }
1134
1135     client_ctx = iface->create_ctx(iface, client_api, sg);
1136
1137     ctx = yagl_context_create(host_context, dpy, client_ctx);
1138     assert(ctx);
1139
1140     yagl_display_context_add(dpy, ctx);
1141
1142     yagl_context_release(ctx);
1143
1144 out:
1145     yagl_sharegroup_release(sg);
1146     yagl_context_release(share_context);
1147
1148     YAGL_LOG_FUNC_EXIT("%u", host_context);
1149
1150     return (EGLContext)host_context;
1151 }
1152
1153 YAGL_API EGLBoolean eglDestroyContext(EGLDisplay dpy_, EGLContext ctx)
1154 {
1155     EGLint error = 0;
1156     struct yagl_display *dpy = NULL;
1157
1158     YAGL_LOG_FUNC_ENTER(eglDestroyContext,
1159                         "dpy = %u, ctx = %u",
1160                         (yagl_host_handle)dpy_,
1161                         (yagl_host_handle)ctx);
1162
1163     if (!yagl_validate_display(dpy_, &dpy)) {
1164         goto fail;
1165     }
1166
1167     if (!yagl_host_eglDestroyContext(dpy->host_dpy, (yagl_host_handle)ctx, &error)) {
1168         YAGL_SET_ERR(error);
1169         goto fail;
1170     }
1171
1172     yagl_display_context_remove(dpy, ctx);
1173
1174     YAGL_LOG_FUNC_EXIT("1");
1175
1176     return EGL_TRUE;
1177
1178 fail:
1179     YAGL_LOG_FUNC_EXIT(NULL);
1180
1181     return EGL_FALSE;
1182 }
1183
1184 YAGL_API EGLBoolean eglMakeCurrent(EGLDisplay dpy_,
1185                                    EGLSurface draw_,
1186                                    EGLSurface read_,
1187                                    EGLContext ctx_)
1188 {
1189     EGLBoolean res = EGL_FALSE;
1190     int bad_match = ctx_ ? (!draw_ ^ !read_) : (draw_ || read_);
1191     struct yagl_display *dpy = NULL;
1192     struct yagl_surface *draw = NULL;
1193     struct yagl_surface *read = NULL;
1194     struct yagl_context *ctx = NULL;
1195     struct yagl_context *prev_ctx = NULL;
1196
1197     YAGL_LOG_FUNC_ENTER(eglMakeCurrent,
1198                         "dpy = %u, draw = %p, read = %p, ctx = %u",
1199                         (yagl_host_handle)dpy_,
1200                         draw_,
1201                         read_,
1202                         (yagl_host_handle)ctx_);
1203
1204     if (bad_match) {
1205         YAGL_SET_ERR(EGL_BAD_MATCH);
1206         goto out;
1207     }
1208
1209     prev_ctx = yagl_get_context();
1210
1211     if (!draw_ && !read_ && !ctx_) {
1212         /*
1213          * Releasing context.
1214          */
1215
1216         if (prev_ctx) {
1217             if (dpy_ == EGL_NO_DISPLAY) {
1218                 /*
1219                  * Workaround for the case when dpy
1220                  * passed is EGL_NO_DISPLAY and we're releasing
1221                  * the current context.
1222                  */
1223
1224                 dpy_ = (EGLDisplay)prev_ctx->dpy->host_dpy;
1225                 dpy = prev_ctx->dpy;
1226             } else {
1227                 if (!yagl_validate_display(dpy_, &dpy)) {
1228                     goto out;
1229                 }
1230             }
1231         } else {
1232             /*
1233              * No current context and we're releasing, a no-op.
1234              */
1235             res = EGL_TRUE;
1236             goto out;
1237         }
1238     } else {
1239         /*
1240          * Making some context current.
1241          */
1242
1243         if (!yagl_validate_display(dpy_, &dpy)) {
1244             goto out;
1245         }
1246
1247         if (draw_ && !yagl_validate_surface(dpy, draw_, &draw)) {
1248             goto out;
1249         }
1250
1251         if (read_ && !yagl_validate_surface(dpy, read_, &read)) {
1252             goto out;
1253         }
1254
1255         ctx = yagl_display_context_acquire(dpy, ctx_);
1256
1257         /*
1258          * A workaround for EffectsApp. It incorrectly calls
1259          * eglMakeCurrent(dpy, draw, read, NULL) which is not allowed
1260          * according to EGL standard. i.e. non-NULL surfaces and NULL context
1261          * is not allowed.
1262          */
1263         if (draw && read && !ctx) {
1264             ctx = prev_ctx;
1265             yagl_context_acquire(ctx);
1266         }
1267
1268         if (!ctx) {
1269             YAGL_SET_ERR(EGL_BAD_CONTEXT);
1270             goto out;
1271         }
1272     }
1273
1274     if (ctx &&
1275         (ctx == prev_ctx) &&
1276         (ctx->dpy == dpy) &&
1277         (draw == yagl_get_draw_surface()) &&
1278         (read == yagl_get_read_surface())) {
1279         /*
1280          * Absolutely no change, skip.
1281          */
1282         res = EGL_TRUE;
1283
1284         goto out;
1285     }
1286
1287     if ((draw && yagl_surface_locked(draw)) ||
1288         (read && yagl_surface_locked(read))) {
1289         YAGL_SET_ERR(EGL_BAD_ACCESS);
1290         goto out;
1291     }
1292
1293     if (!yagl_set_context(ctx, draw, read)) {
1294         /*
1295          * Context and/or surfaces are already
1296          * current to some other thread.
1297          */
1298         YAGL_SET_ERR(EGL_BAD_ACCESS);
1299         goto out;
1300     }
1301
1302     yagl_render_invalidate(0);
1303
1304     yagl_host_eglMakeCurrent((yagl_host_handle)dpy_,
1305                              (draw ? draw->res.handle : 0),
1306                              (read ? read->res.handle : 0),
1307                              (ctx ? ctx->res.handle : 0));
1308
1309     if (ctx && !ctx->client_ctx_prepared) {
1310         ctx->client_ctx->prepare(ctx->client_ctx);
1311         ctx->client_ctx_prepared = 1;
1312     }
1313
1314     res = EGL_TRUE;
1315
1316 out:
1317     yagl_surface_release(draw);
1318     yagl_surface_release(read);
1319     yagl_context_release(ctx);
1320
1321     YAGL_LOG_FUNC_EXIT("%d", ((res == EGL_TRUE) ? 1 : 0));
1322
1323     return res;
1324 }
1325
1326 YAGL_API EGLContext eglGetCurrentContext(void)
1327 {
1328     struct yagl_context *ctx;
1329
1330     YAGL_LOG_FUNC_ENTER(eglGetCurrentContext, NULL);
1331
1332     ctx = yagl_get_context();
1333
1334     YAGL_LOG_FUNC_EXIT("%u", (ctx ? ctx->res.handle : 0));
1335
1336     return (ctx ? (EGLContext)ctx->res.handle : EGL_NO_CONTEXT);
1337 }
1338
1339 YAGL_API EGLSurface eglGetCurrentSurface(EGLint readdraw)
1340 {
1341     struct yagl_surface *sfc;
1342     EGLSurface ret = EGL_NO_SURFACE;
1343
1344     YAGL_LOG_FUNC_ENTER(eglGetCurrentSurface, NULL);
1345
1346     if (readdraw == EGL_READ) {
1347         sfc = yagl_get_read_surface();
1348         ret = (sfc ? yagl_surface_get_handle(sfc) : EGL_NO_SURFACE);
1349     } else if (readdraw == EGL_DRAW) {
1350         sfc = yagl_get_draw_surface();
1351         ret = (sfc ? yagl_surface_get_handle(sfc) : EGL_NO_SURFACE);
1352     } else {
1353         YAGL_SET_ERR(EGL_BAD_PARAMETER);
1354     }
1355
1356     YAGL_LOG_FUNC_EXIT("%p", ret);
1357
1358     return ret;
1359 }
1360
1361 YAGL_API EGLDisplay eglGetCurrentDisplay(void)
1362 {
1363     struct yagl_context *ctx;
1364
1365     YAGL_LOG_FUNC_ENTER(eglGetCurrentDisplay, NULL);
1366
1367     ctx = yagl_get_context();
1368
1369     YAGL_LOG_FUNC_EXIT("%u", (ctx ? ctx->dpy->host_dpy : 0));
1370
1371     return (ctx ? (EGLDisplay)ctx->dpy->host_dpy : EGL_NO_DISPLAY);
1372 }
1373
1374 YAGL_API EGLBoolean eglQueryContext(EGLDisplay dpy_,
1375                                     EGLContext ctx_,
1376                                     EGLint attribute,
1377                                     EGLint *value)
1378 {
1379     EGLint error = 0;
1380     EGLBoolean res = EGL_FALSE;
1381     struct yagl_display *dpy = NULL;
1382     struct yagl_context *ctx = NULL;
1383
1384     YAGL_LOG_FUNC_ENTER(eglQueryContext,
1385                         "dpy = %u, ctx = %u, attribute = 0x%X, value = %p",
1386                         (yagl_host_handle)dpy_,
1387                         (yagl_host_handle)ctx_,
1388                         attribute,
1389                         value);
1390
1391     if (!yagl_validate_display(dpy_, &dpy)) {
1392         goto out;
1393     }
1394
1395     if (!yagl_validate_context(dpy, ctx_, &ctx)) {
1396         goto out;
1397     }
1398
1399     res = EGL_TRUE;
1400
1401     switch (attribute) {
1402     case EGL_CONTEXT_CLIENT_TYPE:
1403         switch (ctx->client_ctx->client_api) {
1404         case yagl_client_api_gles1:
1405         case yagl_client_api_gles2:
1406         case yagl_client_api_gles3:
1407             if (value) {
1408                 *value = EGL_OPENGL_ES_API;
1409             }
1410             break;
1411         case yagl_client_api_ogl:
1412             if (value) {
1413                 *value = EGL_OPENGL_API;
1414             }
1415             break;
1416         case yagl_client_api_ovg:
1417             if (value) {
1418                 *value = EGL_OPENVG_API;
1419             }
1420             break;
1421         default:
1422             if (value) {
1423                 *value = EGL_NONE;
1424             }
1425             break;
1426         }
1427         break;
1428     case EGL_CONTEXT_CLIENT_VERSION:
1429         switch (ctx->client_ctx->client_api) {
1430         case yagl_client_api_gles1:
1431             if (value) {
1432                 *value = 1;
1433             }
1434             break;
1435         case yagl_client_api_gles2:
1436             if (value) {
1437                 *value = 2;
1438             }
1439             break;
1440         case yagl_client_api_gles3:
1441             if (value) {
1442                 *value = 3;
1443             }
1444             break;
1445         case yagl_client_api_ogl:
1446         case yagl_client_api_ovg:
1447         default:
1448             if (value) {
1449                 *value = 0;
1450             }
1451             break;
1452         }
1453         break;
1454     default:
1455         res = yagl_host_eglQueryContext(dpy->host_dpy,
1456                                         (yagl_host_handle)ctx_,
1457                                         attribute,
1458                                         value,
1459                                         &error);
1460
1461         if (!res) {
1462             YAGL_SET_ERR(error);
1463         }
1464
1465         break;
1466     }
1467
1468 out:
1469     yagl_context_release(ctx);
1470
1471     YAGL_LOG_FUNC_EXIT("%d", ((res == EGL_TRUE) ? 1 : 0));
1472
1473     return res;
1474 }
1475
1476 YAGL_API EGLBoolean eglWaitGL()
1477 {
1478     EGLBoolean ret;
1479
1480     YAGL_LOG_FUNC_ENTER_SPLIT0(eglWaitGL);
1481
1482     ret = eglWaitClient();
1483
1484     YAGL_LOG_FUNC_EXIT(NULL);
1485
1486     return ret;
1487 }
1488
1489 YAGL_API EGLBoolean eglWaitNative(EGLint engine)
1490 {
1491     struct yagl_surface *draw_sfc;
1492
1493     YAGL_LOG_FUNC_ENTER_SPLIT1(eglWaitNative, EGLint, engine);
1494
1495     draw_sfc = yagl_get_draw_surface();
1496
1497     if (draw_sfc) {
1498         draw_sfc->wait_x(draw_sfc);
1499     }
1500
1501     YAGL_LOG_FUNC_EXIT(NULL);
1502
1503     return EGL_TRUE;
1504 }
1505
1506 YAGL_API EGLBoolean eglSwapBuffers(EGLDisplay dpy_, EGLSurface surface_)
1507 {
1508     EGLBoolean res = EGL_FALSE;
1509     struct yagl_display *dpy = NULL;
1510     struct yagl_surface *surface = NULL;
1511
1512     YAGL_LOG_FUNC_ENTER(eglSwapBuffers,
1513                         "dpy = %u, surface = %p",
1514                         (yagl_host_handle)dpy_,
1515                         surface_);
1516
1517     if (!yagl_validate_display(dpy_, &dpy)) {
1518         goto out;
1519     }
1520
1521     if (!yagl_validate_surface(dpy, surface_, &surface)) {
1522         goto out;
1523     }
1524
1525     if ((yagl_get_draw_surface() != surface) &&
1526         (yagl_get_read_surface() != surface)) {
1527         YAGL_SET_ERR(EGL_BAD_SURFACE);
1528         goto out;
1529     }
1530
1531     if (yagl_surface_locked(surface)) {
1532         YAGL_SET_ERR(EGL_BAD_ACCESS);
1533         goto out;
1534     }
1535
1536     if (surface->type != EGL_WINDOW_BIT) {
1537         res = EGL_TRUE;
1538         goto out;
1539     }
1540
1541     if (!surface->swap_buffers(surface)) {
1542         goto out;
1543     }
1544
1545     res = EGL_TRUE;
1546
1547 #ifdef YAGL_PLATFORM_X11
1548     if (dpy->native_dpy->platform == &yagl_x11_platform) {
1549         /*
1550          * Normally one should not invalidate right after eglSwapBuffers,
1551          * instead invalidate should be called on first rendering call
1552          * after eglSwapBuffers (see yagl_render.h:yagl_render_invalidate).
1553          * But this doesn't work on Tizen mobile, without this invalidate
1554          * Tizen compositor may miss surface updates.
1555          * The problem is in "efl_sync" option of the compositor, which is 0
1556          * by default in upstream and 1 in Tizen. Setting it to 0 in
1557          * config doesn't seem to help, one had to manually change code:
1558          * e17-extra-modules/comp-tizen/src/e_mod_comp_cfdata.c:
1559          * cfg->efl_sync = 1;
1560          * to:
1561          * cfg->efl_sync = 0;
1562          * AND set efl_sync to 0 in config to make this work.
1563          * When efl_sync is set to 1 the compositor acts like this:
1564          * + For normal X11 windows nothing is changed
1565          * + For e17 windows (created via ecore_x_window_new) it doesn't redraw
1566          *   the screen on damage events, but only on special SYNC_DRAW_DONE
1567          *   events that are sent from _ecore_evas_x_flush_post, which is called
1568          *   after eglSwapBuffers, that's why things work when invalidate
1569          *   is inside eglSwapBuffers, it finishes the swap before sending
1570          *   SYNC_DRAW_DONE, but once we move invalidate to first rendering call
1571          *   after eglSwapBuffers SYNC_DRAW_DONE starts to come before
1572          *   uxa copy, thus, missing last frame.
1573          */
1574         yagl_render_invalidate(0);
1575     }
1576 #endif
1577
1578 out:
1579     yagl_surface_release(surface);
1580
1581     YAGL_LOG_FUNC_EXIT("%d", res);
1582
1583     return res;
1584 }
1585
1586 YAGL_API EGLBoolean eglCopyBuffers(EGLDisplay dpy_,
1587                                    EGLSurface surface_,
1588                                    EGLNativePixmapType target)
1589 {
1590     EGLBoolean res = EGL_FALSE;
1591     struct yagl_display *dpy = NULL;
1592     struct yagl_surface *surface = NULL;
1593
1594     YAGL_LOG_FUNC_ENTER(eglCopyBuffers,
1595                         "dpy = %u, surface = %p, target = %u",
1596                         (yagl_host_handle)dpy_,
1597                         surface_,
1598                         (uint32_t)target);
1599
1600     if (!yagl_validate_display(dpy_, &dpy)) {
1601         goto out;
1602     }
1603
1604     if (!yagl_validate_surface(dpy, surface_, &surface)) {
1605         goto out;
1606     }
1607
1608     if ((yagl_get_draw_surface() != surface) &&
1609         (yagl_get_read_surface() != surface)) {
1610         YAGL_SET_ERR(EGL_BAD_SURFACE);
1611         goto out;
1612     }
1613
1614     if (yagl_surface_locked(surface)) {
1615         YAGL_SET_ERR(EGL_BAD_ACCESS);
1616         goto out;
1617     }
1618
1619     if (!surface->copy_buffers(surface, target)) {
1620         goto out;
1621     }
1622
1623     res = EGL_TRUE;
1624
1625 out:
1626     yagl_surface_release(surface);
1627
1628     YAGL_LOG_FUNC_EXIT("%d", res);
1629
1630     return res;
1631 }
1632
1633 #ifndef EGL_NATIVE_SURFACE_TIZEN
1634 #define EGL_NATIVE_SURFACE_TIZEN 0x32A1
1635 #endif
1636
1637 YAGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy_,
1638                                        EGLContext ctx_,
1639                                        EGLenum target,
1640                                        EGLClientBuffer buffer,
1641                                        const EGLint *attrib_list)
1642 {
1643     EGLImageKHR ret = EGL_NO_IMAGE_KHR;
1644     struct yagl_client_interface *iface = NULL;
1645     struct yagl_display *dpy = NULL;
1646     struct yagl_context *ctx = NULL;
1647     struct yagl_native_drawable *native_buffer = NULL;
1648     struct yagl_image *image = NULL;
1649     int i = 0;
1650
1651     YAGL_LOG_FUNC_ENTER(eglCreateImageKHR,
1652                         "dpy = %u, ctx = %u, target = %u, buffer = %p",
1653                         (yagl_host_handle)dpy_,
1654                         (yagl_host_handle)ctx_,
1655                         target,
1656                         buffer);
1657
1658     iface = yagl_get_any_client_interface();
1659
1660     if (!iface) {
1661         YAGL_SET_ERR(EGL_BAD_ALLOC);
1662         goto out;
1663     }
1664
1665     if (!buffer) {
1666         YAGL_SET_ERR(EGL_BAD_PARAMETER);
1667         goto out;
1668     }
1669
1670     if (!yagl_validate_display(dpy_, &dpy)) {
1671         goto out;
1672     }
1673
1674     switch (target) {
1675     case EGL_NATIVE_PIXMAP_KHR:
1676         if (!dpy->native_dpy->platform->pixmaps_supported) {
1677             YAGL_SET_ERR(EGL_BAD_PARAMETER);
1678             goto out;
1679         }
1680
1681         if (attrib_list) {
1682             while (attrib_list[i] != EGL_NONE) {
1683                 switch (attrib_list[i]) {
1684                 case EGL_IMAGE_PRESERVED_KHR:
1685                     break;
1686                 default:
1687                     YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
1688                     goto out;
1689                 }
1690
1691                 i += 2;
1692             }
1693         }
1694
1695         native_buffer = dpy->native_dpy->wrap_pixmap(dpy->native_dpy,
1696                                                      (yagl_os_pixmap)buffer);
1697
1698         if (!native_buffer) {
1699             goto out;
1700         }
1701
1702         image = yagl_get_backend()->create_image_pixmap(dpy,
1703                                                         native_buffer,
1704                                                         iface);
1705
1706         if (!image) {
1707             native_buffer->destroy(native_buffer);
1708             goto out;
1709         }
1710
1711         break;
1712     case EGL_WAYLAND_BUFFER_WL:
1713         if (!dpy->native_dpy->WL_bind_wayland_display_supported) {
1714             YAGL_SET_ERR(EGL_BAD_PARAMETER);
1715             goto out;
1716         }
1717
1718         if (attrib_list) {
1719             while (attrib_list[i] != EGL_NONE) {
1720                 switch (attrib_list[i]) {
1721                 case EGL_IMAGE_PRESERVED_KHR:
1722                 case EGL_WAYLAND_PLANE_WL:
1723                     break;
1724                 default:
1725                     YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
1726                     goto out;
1727                 }
1728
1729                 i += 2;
1730             }
1731         }
1732
1733         image = yagl_get_backend()->create_image_wl_buffer(dpy,
1734                                                            (struct wl_resource*)buffer,
1735                                                            iface);
1736
1737         if (!image) {
1738             goto out;
1739         }
1740
1741         break;
1742     case EGL_GL_TEXTURE_2D_KHR:
1743         if (attrib_list) {
1744             while (attrib_list[i] != EGL_NONE) {
1745                 switch (attrib_list[i]) {
1746                 case EGL_IMAGE_PRESERVED_KHR:
1747                 case EGL_GL_TEXTURE_LEVEL_KHR:
1748                     break;
1749                 default:
1750                     YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
1751                     goto out;
1752                 }
1753
1754                 i += 2;
1755             }
1756         }
1757
1758         if (!yagl_validate_context(dpy, ctx_, &ctx)) {
1759             goto out;
1760         }
1761
1762         image = yagl_get_backend()->create_image_gl_texture_2d(dpy,
1763                                                                ctx,
1764                                                                (yagl_object_name)buffer,
1765                                                                iface);
1766
1767         if (!image) {
1768             goto out;
1769         }
1770
1771         break;
1772     case EGL_NATIVE_SURFACE_TIZEN:
1773         if (attrib_list) {
1774             while (attrib_list[i] != EGL_NONE) {
1775                 switch (attrib_list[i]) {
1776                 case EGL_IMAGE_PRESERVED_KHR:
1777                     break;
1778                 default:
1779                     YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
1780                     goto out;
1781                 }
1782
1783                 i += 2;
1784             }
1785         }
1786
1787         image = yagl_get_backend()->create_image_tizen_sfc(dpy,
1788                                                            buffer,
1789                                                            iface);
1790
1791         if (!image) {
1792             goto out;
1793         }
1794
1795         break;
1796     default:
1797         YAGL_SET_ERR(EGL_BAD_PARAMETER);
1798         goto out;
1799     }
1800
1801     if (!yagl_display_image_add(dpy, image)) {
1802         YAGL_SET_ERR(EGL_BAD_PARAMETER);
1803         goto out;
1804     }
1805
1806     ret = image->client_handle;
1807
1808 out:
1809     yagl_image_release(image);
1810
1811     yagl_context_release(ctx);
1812
1813     YAGL_LOG_FUNC_EXIT("%p", ret);
1814
1815     return ret;
1816 }
1817
1818 YAGL_API EGLBoolean eglDestroyImageKHR( EGLDisplay dpy_,
1819                                         EGLImageKHR image_ )
1820 {
1821     EGLBoolean res = EGL_FALSE;
1822     struct yagl_display *dpy = NULL;
1823     struct yagl_image *image = NULL;
1824
1825     YAGL_LOG_FUNC_ENTER(eglDestroyImageKHR,
1826                         "dpy = %u, image = %p",
1827                         (yagl_host_handle)dpy_,
1828                         image_);
1829
1830     if (!yagl_validate_display(dpy_, &dpy)) {
1831         goto out;
1832     }
1833
1834     if (!yagl_validate_image(dpy, image_, &image)) {
1835         goto out;
1836     }
1837
1838     if (!yagl_display_image_remove(dpy, image_)) {
1839         YAGL_LOG_ERROR("we're the one who destroy the image, but it isn't there!");
1840         YAGL_SET_ERR(EGL_BAD_PARAMETER);
1841         goto out;
1842     }
1843
1844     res = EGL_TRUE;
1845
1846 out:
1847     yagl_image_release(image);
1848
1849     YAGL_LOG_FUNC_EXIT("%d", ((res == EGL_TRUE) ? 1 : 0));
1850
1851     return res;
1852 }
1853
1854 YAGL_API EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy_,
1855                                       EGLSurface surface_,
1856                                       const EGLint *attrib_list)
1857 {
1858     EGLBoolean res = EGL_FALSE;
1859     struct yagl_display *dpy = NULL;
1860     struct yagl_surface *surface = NULL;
1861     int i = 0;
1862     int preserve = 0;
1863     EGLint hint = 0;
1864
1865     YAGL_LOG_FUNC_ENTER(eglLockSurfaceKHR,
1866                         "dpy = %u, surface = %p",
1867                         (yagl_host_handle)dpy_,
1868                         surface_);
1869
1870     if (!yagl_validate_display(dpy_, &dpy)) {
1871         goto out;
1872     }
1873
1874     if (!yagl_validate_surface(dpy, surface_, &surface)) {
1875         goto out;
1876     }
1877
1878     if (attrib_list) {
1879         while (attrib_list[i] != EGL_NONE) {
1880             switch (attrib_list[i]) {
1881             case EGL_MAP_PRESERVE_PIXELS_KHR:
1882                 preserve = attrib_list[i + 1];
1883                 break;
1884             case EGL_LOCK_USAGE_HINT_KHR:
1885                 break;
1886             default:
1887                 YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
1888                 goto out;
1889             }
1890
1891             i += 2;
1892         }
1893     }
1894
1895     if (preserve) {
1896         hint = EGL_READ_SURFACE_BIT_KHR | EGL_WRITE_SURFACE_BIT_KHR;
1897     } else {
1898         hint = EGL_WRITE_SURFACE_BIT_KHR;
1899     }
1900
1901     if (!yagl_surface_lock(surface, hint)) {
1902         YAGL_SET_ERR(EGL_BAD_ACCESS);
1903         goto out;
1904     }
1905
1906     res = EGL_TRUE;
1907
1908 out:
1909     yagl_surface_release(surface);
1910
1911     YAGL_LOG_FUNC_EXIT("%d", res);
1912
1913     return res;
1914 }
1915
1916 YAGL_API EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy_,
1917                                         EGLSurface surface_)
1918 {
1919     EGLBoolean res = EGL_FALSE;
1920     struct yagl_display *dpy = NULL;
1921     struct yagl_surface *surface = NULL;
1922
1923     YAGL_LOG_FUNC_ENTER(eglUnlockSurfaceKHR,
1924                         "dpy = %u, surface = %p",
1925                         (yagl_host_handle)dpy_,
1926                         surface_);
1927
1928     if (!yagl_validate_display(dpy_, &dpy)) {
1929         goto out;
1930     }
1931
1932     if (!yagl_validate_surface(dpy, surface_, &surface)) {
1933         goto out;
1934     }
1935
1936     if (!yagl_surface_unlock(surface)) {
1937         YAGL_SET_ERR(EGL_BAD_ACCESS);
1938         goto out;
1939     }
1940
1941     yagl_surface_invalidate(surface);
1942
1943     res = EGL_TRUE;
1944
1945 out:
1946     yagl_surface_release(surface);
1947
1948     YAGL_LOG_FUNC_EXIT("%d", res);
1949
1950     return res;
1951 }
1952
1953 YAGL_API EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy_, EGLenum type, const EGLint *attrib_list)
1954 {
1955     EGLSyncKHR ret = EGL_NO_SYNC_KHR;
1956     struct yagl_display *dpy = NULL;
1957     struct yagl_fence *fence = NULL;
1958
1959     YAGL_LOG_FUNC_ENTER(eglCreateSyncKHR, "dpy = %u, type = %u",
1960                         (yagl_host_handle)dpy_, type);
1961
1962     if (type != EGL_SYNC_FENCE_KHR) {
1963         YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
1964         goto out;
1965     }
1966
1967     if (attrib_list && (attrib_list[0] != EGL_NONE)) {
1968         YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
1969         goto out;
1970     }
1971
1972     if (!yagl_validate_display(dpy_, &dpy)) {
1973         goto out;
1974     }
1975
1976     fence = yagl_get_backend()->create_fence(dpy);
1977
1978     if (!fence) {
1979         YAGL_SET_ERR(EGL_BAD_ACCESS);
1980         goto out;
1981     }
1982
1983     yagl_display_fence_add(dpy, fence);
1984
1985     yagl_transport_flush(yagl_get_transport(), &fence->base);
1986
1987     ret = fence;
1988
1989 out:
1990     yagl_fence_release(fence);
1991
1992     YAGL_LOG_FUNC_EXIT("%p", ret);
1993
1994     return ret;
1995 }
1996
1997 YAGL_API EGLBoolean eglDestroySyncKHR(EGLDisplay dpy_, EGLSyncKHR sync_)
1998 {
1999     EGLBoolean res = EGL_FALSE;
2000     struct yagl_display *dpy = NULL;
2001     struct yagl_fence *fence = NULL;
2002
2003     YAGL_LOG_FUNC_ENTER(eglDestroySyncKHR, "dpy = %u, sync = %p",
2004                         (yagl_host_handle)dpy_, sync_);
2005
2006     if (!yagl_validate_display(dpy_, &dpy)) {
2007         goto out;
2008     }
2009
2010     if (!yagl_validate_fence(dpy, sync_, &fence)) {
2011         goto out;
2012     }
2013
2014     if (!yagl_display_fence_remove(dpy, sync_)) {
2015         YAGL_LOG_ERROR("we're the one who destroy the fence, but it isn't there!");
2016         YAGL_SET_ERR(EGL_BAD_PARAMETER);
2017         goto out;
2018     }
2019
2020     res = EGL_TRUE;
2021
2022 out:
2023     yagl_fence_release(fence);
2024
2025     YAGL_LOG_FUNC_EXIT("%d", res);
2026
2027     return res;
2028 }
2029
2030 YAGL_API EGLint eglClientWaitSyncKHR(EGLDisplay dpy_, EGLSyncKHR sync_, EGLint flags, EGLTimeKHR timeout)
2031 {
2032     EGLint res = EGL_FALSE;
2033     struct yagl_display *dpy = NULL;
2034     struct yagl_fence *fence = NULL;
2035
2036     YAGL_LOG_FUNC_ENTER(eglClientWaitSyncKHR, "dpy = %u, sync = %p, flags = 0x%X, timeout = %u",
2037                         (yagl_host_handle)dpy_, sync_, flags, (uint32_t)timeout);
2038
2039     if (!yagl_validate_display(dpy_, &dpy)) {
2040         goto out;
2041     }
2042
2043     if (!yagl_validate_fence(dpy, sync_, &fence)) {
2044         goto out;
2045     }
2046
2047     if (timeout == 0) {
2048         res = fence->base.signaled(&fence->base) ? EGL_CONDITION_SATISFIED_KHR
2049                                                  : EGL_TIMEOUT_EXPIRED_KHR;
2050     } else if (fence->base.wait(&fence->base)) {
2051         res = EGL_CONDITION_SATISFIED_KHR;
2052     } else {
2053         YAGL_SET_ERR(EGL_BAD_ACCESS);
2054     }
2055
2056 out:
2057     yagl_fence_release(fence);
2058
2059     YAGL_LOG_FUNC_EXIT("%d", res);
2060
2061     return res;
2062 }
2063
2064 YAGL_API EGLBoolean eglSignalSyncKHR(EGLDisplay dpy_, EGLSyncKHR sync_, EGLenum mode)
2065 {
2066     YAGL_LOG_FUNC_ENTER(eglSignalSyncKHR, "dpy = %u, sync = %p, mode = 0x%X",
2067                         (yagl_host_handle)dpy_, sync_, mode);
2068
2069     YAGL_SET_ERR(EGL_BAD_MATCH);
2070
2071     YAGL_LOG_FUNC_EXIT("%d", EGL_FALSE);
2072
2073     return EGL_FALSE;
2074 }
2075
2076 YAGL_API EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy_, EGLSyncKHR sync_, EGLint attribute, EGLint *value)
2077 {
2078     EGLBoolean res = EGL_FALSE;
2079     struct yagl_display *dpy = NULL;
2080     struct yagl_fence *fence = NULL;
2081
2082     YAGL_LOG_FUNC_ENTER(eglGetSyncAttribKHR, "dpy = %u, sync = %p, attribute = 0x%X",
2083                         (yagl_host_handle)dpy_, sync_, attribute);
2084
2085     if (!yagl_validate_display(dpy_, &dpy)) {
2086         goto out;
2087     }
2088
2089     if (!yagl_validate_fence(dpy, sync_, &fence)) {
2090         goto out;
2091     }
2092
2093     switch (attribute) {
2094     case EGL_SYNC_TYPE_KHR:
2095         *value = EGL_SYNC_FENCE_KHR;
2096         res = EGL_TRUE;
2097         break;
2098     case EGL_SYNC_STATUS_KHR:
2099         *value = fence->base.signaled(&fence->base) ? EGL_SIGNALED_KHR
2100                                                     : EGL_UNSIGNALED_KHR;
2101         res = EGL_TRUE;
2102         break;
2103     case EGL_SYNC_CONDITION_KHR:
2104         *value = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR;
2105         res = EGL_TRUE;
2106         break;
2107     default:
2108         YAGL_SET_ERR(EGL_BAD_ATTRIBUTE);
2109         break;
2110     }
2111
2112 out:
2113     yagl_fence_release(fence);
2114
2115     YAGL_LOG_FUNC_EXIT("%d", res);
2116
2117     return res;
2118 }
2119
2120 #ifdef YAGL_PLATFORM_WAYLAND
2121 struct wl_display;
2122 struct wl_resource;
2123
2124 YAGL_API EGLBoolean eglBindWaylandDisplayWL(EGLDisplay dpy_,
2125                                             struct wl_display *display)
2126 {
2127     EGLBoolean res = EGL_FALSE;
2128     struct yagl_display *dpy = NULL;
2129
2130     YAGL_LOG_FUNC_ENTER(eglBindWaylandDisplayWL,
2131                         "dpy = %u, display = %p",
2132                         (yagl_host_handle)dpy_,
2133                         display);
2134
2135     if (!yagl_validate_display(dpy_, &dpy)) {
2136         goto out;
2137     }
2138
2139     if (!display) {
2140         YAGL_SET_ERR(EGL_BAD_PARAMETER);
2141         goto out;
2142     }
2143
2144     if (!dpy->native_dpy->WL_bind_wayland_display_supported) {
2145         YAGL_SET_ERR(EGL_BAD_PARAMETER);
2146         goto out;
2147     }
2148
2149     res = yagl_native_display_bind_wl_display(dpy->native_dpy, display);
2150
2151 out:
2152     YAGL_LOG_FUNC_EXIT("%d", res);
2153
2154     return res;
2155 }
2156
2157 YAGL_API EGLBoolean eglUnbindWaylandDisplayWL(EGLDisplay dpy_,
2158                                               struct wl_display *display)
2159 {
2160     EGLBoolean res = EGL_FALSE;
2161     struct yagl_display *dpy = NULL;
2162
2163     YAGL_LOG_FUNC_ENTER(eglUnbindWaylandDisplayWL,
2164                         "dpy = %u, display = %p",
2165                         (yagl_host_handle)dpy_,
2166                         display);
2167
2168     if (!yagl_validate_display(dpy_, &dpy)) {
2169         goto out;
2170     }
2171
2172     if (!display) {
2173         YAGL_SET_ERR(EGL_BAD_PARAMETER);
2174         goto out;
2175     }
2176
2177     if (!dpy->native_dpy->WL_bind_wayland_display_supported) {
2178         YAGL_SET_ERR(EGL_BAD_PARAMETER);
2179         goto out;
2180     }
2181
2182     res = yagl_native_display_unbind_wl_display(dpy->native_dpy);
2183
2184 out:
2185     YAGL_LOG_FUNC_EXIT("%d", res);
2186
2187     return res;
2188 }
2189
2190 YAGL_API EGLBoolean eglQueryWaylandBufferWL(EGLDisplay dpy_,
2191                                             struct wl_resource *buffer,
2192                                             EGLint attribute,
2193                                             EGLint *value)
2194 {
2195     EGLBoolean res = EGL_FALSE;
2196     struct yagl_display *dpy = NULL;
2197
2198     YAGL_LOG_FUNC_ENTER(eglQueryWaylandBufferWL,
2199                         "dpy = %u, buffer = %p, attribute = 0x%X",
2200                         (yagl_host_handle)dpy_,
2201                         buffer,
2202                         attribute);
2203
2204     if (!yagl_validate_display(dpy_, &dpy)) {
2205         goto out;
2206     }
2207
2208     if (!buffer) {
2209         YAGL_SET_ERR(EGL_BAD_PARAMETER);
2210         goto out;
2211     }
2212
2213     if (!dpy->native_dpy->WL_bind_wayland_display_supported) {
2214         YAGL_SET_ERR(EGL_BAD_PARAMETER);
2215         goto out;
2216     }
2217
2218     res = yagl_native_display_query_wl_buffer(dpy->native_dpy,
2219                                               buffer,
2220                                               attribute,
2221                                               value);
2222
2223 out:
2224     YAGL_LOG_FUNC_EXIT("%d", res);
2225
2226     return res;
2227 }
2228 #endif
2229
2230 YAGL_API __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char* procname)
2231 {
2232     __eglMustCastToProperFunctionPointerType ret = NULL;
2233
2234     YAGL_LOG_FUNC_ENTER(eglGetProcAddress, "procname = %s", procname);
2235
2236     if (procname) {
2237         if (strncmp(procname, "gl", 2) == 0) {
2238
2239             struct yagl_context *ctx = yagl_get_context();
2240
2241             if (ctx) {
2242                 switch (ctx->client_ctx->client_api) {
2243                 case yagl_client_api_gles1:
2244                     ret = yagl_get_gles1_sym(procname);
2245                     break;
2246                 case yagl_client_api_gles2:
2247                 case yagl_client_api_gles3:
2248                     ret = yagl_get_gles2_sym(procname);
2249                     break;
2250                 default:
2251                     break;
2252                 }
2253             } else {
2254                 /*
2255                  * Workaround for evas, which foolishly calls this without
2256                  * context being set.
2257                  */
2258                 ret = yagl_get_gles2_sym(procname);
2259             }
2260         } else if (strncmp(procname, "egl", 3) == 0) {
2261             ret = dlsym(NULL, procname);
2262         }
2263     }
2264
2265     YAGL_LOG_FUNC_EXIT("%p", ret);
2266
2267     return ret;
2268 }