2 ** Copyright 2007, The Android Open Source Project
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
8 ** http://www.apache.org/licenses/LICENSE-2.0
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
17 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
24 #include <hardware/gralloc.h>
25 #include <system/window.h>
28 #include <EGL/eglext.h>
30 #include <cutils/log.h>
31 #include <cutils/atomic.h>
32 #include <cutils/compiler.h>
33 #include <cutils/properties.h>
34 #include <cutils/memory.h>
36 #include <utils/KeyedVector.h>
37 #include <utils/SortedVector.h>
38 #include <utils/String8.h>
39 #include <utils/Trace.h>
41 #include "../egl_impl.h"
42 #include "../glestrace.h"
45 #include "egl_display.h"
46 #include "egl_object.h"
50 using namespace android;
52 // This extension has not been ratified yet, so can't be shipped.
53 // Implementation is incomplete and untested.
54 #define ENABLE_EGL_KHR_GL_COLORSPACE 0
56 // ----------------------------------------------------------------------------
60 struct extention_map_t {
62 __eglMustCastToProperFunctionPointerType address;
66 * This is the list of EGL extensions exposed to applications.
68 * Some of them (gBuiltinExtensionString) are implemented entirely in this EGL
69 * wrapper and are always available.
71 * The rest (gExtensionString) depend on support in the EGL driver, and are
72 * only available if the driver supports them. However, some of these must be
73 * supported because they are used by the Android system itself; these are
74 * listd as mandatory below and are required by the CDD. The system *assumes*
75 * the mandatory extensions are present and may not function properly if some
78 * NOTE: Both strings MUST have a single space as the last character.
80 extern char const * const gBuiltinExtensionString =
81 "EGL_KHR_get_all_proc_addresses "
82 "EGL_ANDROID_presentation_time "
83 "EGL_KHR_swap_buffers_with_damage "
85 extern char const * const gExtensionString =
86 "EGL_KHR_image " // mandatory
87 "EGL_KHR_image_base " // mandatory
88 "EGL_KHR_image_pixmap "
89 "EGL_KHR_lock_surface "
90 #if (ENABLE_EGL_KHR_GL_COLORSPACE != 0)
91 "EGL_KHR_gl_colorspace "
93 "EGL_KHR_gl_texture_2D_image "
94 "EGL_KHR_gl_texture_cubemap_image "
95 "EGL_KHR_gl_renderbuffer_image "
96 "EGL_KHR_reusable_sync "
98 "EGL_KHR_create_context "
99 "EGL_EXT_create_context_robustness "
100 "EGL_NV_system_time "
101 "EGL_ANDROID_image_native_buffer " // mandatory
102 "EGL_KHR_wait_sync " // strongly recommended
103 "EGL_ANDROID_recordable " // mandatory
104 "EGL_KHR_partial_update " // strongly recommended
105 "EGL_EXT_buffer_age " // strongly recommended with partial_update
106 "EGL_KHR_create_context_no_error "
109 // extensions not exposed to applications but used by the ANDROID system
110 // "EGL_ANDROID_blob_cache " // strongly recommended
111 // "EGL_IMG_hibernate_process " // optional
112 // "EGL_ANDROID_native_fence_sync " // strongly recommended
113 // "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1
114 // "EGL_ANDROID_image_crop " // optional
117 * EGL Extensions entry-points exposed to 3rd party applications
118 * (keep in sync with gExtensionString above)
121 static const extention_map_t sExtensionMap[] = {
122 // EGL_KHR_lock_surface
123 { "eglLockSurfaceKHR",
124 (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR },
125 { "eglUnlockSurfaceKHR",
126 (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR },
128 // EGL_KHR_image, EGL_KHR_image_base
129 { "eglCreateImageKHR",
130 (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR },
131 { "eglDestroyImageKHR",
132 (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },
134 // EGL_KHR_reusable_sync, EGL_KHR_fence_sync
135 { "eglCreateSyncKHR",
136 (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR },
137 { "eglDestroySyncKHR",
138 (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR },
139 { "eglClientWaitSyncKHR",
140 (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR },
141 { "eglSignalSyncKHR",
142 (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR },
143 { "eglGetSyncAttribKHR",
144 (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR },
146 // EGL_NV_system_time
147 { "eglGetSystemTimeFrequencyNV",
148 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV },
149 { "eglGetSystemTimeNV",
150 (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV },
154 (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR },
156 // EGL_ANDROID_presentation_time
157 { "eglPresentationTimeANDROID",
158 (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID },
160 // EGL_KHR_swap_buffers_with_damage
161 { "eglSwapBuffersWithDamageKHR",
162 (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR },
164 // EGL_KHR_partial_update
165 { "eglSetDamageRegionKHR",
166 (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR },
170 * These extensions entry-points should not be exposed to applications.
171 * They're used internally by the Android EGL layer.
173 #define FILTER_EXTENSIONS(procname) \
174 (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") || \
175 !strcmp((procname), "eglHibernateProcessIMG") || \
176 !strcmp((procname), "eglAwakenProcessIMG") || \
177 !strcmp((procname), "eglDupNativeFenceFDANDROID"))
181 // accesses protected by sExtensionMapMutex
182 static DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap;
183 static int sGLExtentionSlot = 0;
184 static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER;
186 static void(*findProcAddress(const char* name,
187 const extention_map_t* map, size_t n))() {
188 for (uint32_t i=0 ; i<n ; i++) {
189 if (!strcmp(name, map[i].name)) {
190 return map[i].address;
196 // ----------------------------------------------------------------------------
198 extern void setGLHooksThreadSpecific(gl_hooks_t const *value);
199 extern EGLBoolean egl_init_drivers();
200 extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS];
201 extern int getEGLDebugLevel();
202 extern void setEGLDebugLevel(int level);
203 extern gl_hooks_t gHooksTrace;
205 } // namespace android;
208 // ----------------------------------------------------------------------------
210 static inline void clearError() { egl_tls_t::clearError(); }
211 static inline EGLContext getContext() { return egl_tls_t::getContext(); }
213 // ----------------------------------------------------------------------------
215 EGLDisplay eglGetDisplay(EGLNativeDisplayType display)
219 uintptr_t index = reinterpret_cast<uintptr_t>(display);
220 if (index >= NUM_DISPLAYS) {
221 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
224 if (egl_init_drivers() == EGL_FALSE) {
225 return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
228 EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display);
232 // ----------------------------------------------------------------------------
234 // ----------------------------------------------------------------------------
236 EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
240 egl_display_ptr dp = get_display(dpy);
241 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
243 EGLBoolean res = dp->initialize(major, minor);
248 EGLBoolean eglTerminate(EGLDisplay dpy)
250 // NOTE: don't unload the drivers b/c some APIs can be called
251 // after eglTerminate() has been called. eglTerminate() only
252 // terminates an EGLDisplay, not a EGL itself.
256 egl_display_ptr dp = get_display(dpy);
257 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
259 EGLBoolean res = dp->terminate();
264 // ----------------------------------------------------------------------------
266 // ----------------------------------------------------------------------------
268 EGLBoolean eglGetConfigs( EGLDisplay dpy,
270 EGLint config_size, EGLint *num_config)
274 const egl_display_ptr dp = validate_display(dpy);
275 if (!dp) return EGL_FALSE;
278 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
281 EGLBoolean res = EGL_FALSE;
284 egl_connection_t* const cnx = &gEGLImpl;
286 res = cnx->egl.eglGetConfigs(
287 dp->disp.dpy, configs, config_size, num_config);
293 EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list,
294 EGLConfig *configs, EGLint config_size,
299 const egl_display_ptr dp = validate_display(dpy);
300 if (!dp) return EGL_FALSE;
303 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
306 EGLBoolean res = EGL_FALSE;
309 egl_connection_t* const cnx = &gEGLImpl;
312 char value[PROPERTY_VALUE_MAX];
313 property_get("debug.egl.force_msaa", value, "false");
315 if (!strcmp(value, "true")) {
316 size_t attribCount = 0;
317 EGLint attrib = attrib_list[0];
319 // Only enable MSAA if the context is OpenGL ES 2.0 and
320 // if no caveat is requested
321 const EGLint *attribRendererable = NULL;
322 const EGLint *attribCaveat = NULL;
324 // Count the number of attributes and look for
325 // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT
326 while (attrib != EGL_NONE) {
327 attrib = attrib_list[attribCount];
329 case EGL_RENDERABLE_TYPE:
330 attribRendererable = &attrib_list[attribCount];
332 case EGL_CONFIG_CAVEAT:
333 attribCaveat = &attrib_list[attribCount];
339 if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT &&
340 (!attribCaveat || attribCaveat[1] != EGL_NONE)) {
342 // Insert 2 extra attributes to force-enable MSAA 4x
343 EGLint aaAttribs[attribCount + 4];
344 aaAttribs[0] = EGL_SAMPLE_BUFFERS;
346 aaAttribs[2] = EGL_SAMPLES;
349 memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint));
352 EGLBoolean resAA = cnx->egl.eglChooseConfig(
353 dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA);
355 if (resAA == EGL_TRUE && numConfigAA > 0) {
356 ALOGD("Enabling MSAA 4x");
357 *num_config = numConfigAA;
364 res = cnx->egl.eglChooseConfig(
365 dp->disp.dpy, attrib_list, configs, config_size, num_config);
370 EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
371 EGLint attribute, EGLint *value)
375 egl_connection_t* cnx = NULL;
376 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
377 if (!dp) return EGL_FALSE;
379 return cnx->egl.eglGetConfigAttrib(
380 dp->disp.dpy, config, attribute, value);
383 // ----------------------------------------------------------------------------
385 // ----------------------------------------------------------------------------
387 // The EGL_KHR_gl_colorspace spec hasn't been ratified yet, so these haven't
388 // been added to the Khronos egl.h.
389 #define EGL_GL_COLORSPACE_KHR EGL_VG_COLORSPACE
390 #define EGL_GL_COLORSPACE_SRGB_KHR EGL_VG_COLORSPACE_sRGB
391 #define EGL_GL_COLORSPACE_LINEAR_KHR EGL_VG_COLORSPACE_LINEAR
393 // Turn linear formats into corresponding sRGB formats when colorspace is
394 // EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear
395 // formats when colorspace is EGL_GL_COLORSPACE_LINEAR_KHR. In any cases where
396 // the modification isn't possible, the original dataSpace is returned.
397 static android_dataspace modifyBufferDataspace( android_dataspace dataSpace,
399 if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) {
400 return HAL_DATASPACE_SRGB_LINEAR;
401 } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) {
402 return HAL_DATASPACE_SRGB;
407 EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
408 NativeWindowType window,
409 const EGLint *attrib_list)
413 egl_connection_t* cnx = NULL;
414 egl_display_ptr dp = validate_display_connection(dpy, cnx);
416 EGLDisplay iDpy = dp->disp.dpy;
418 int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
420 ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) "
421 "failed (%#x) (already connected to another API?)",
423 return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE);
426 // Set the native window's buffers format to match what this config requests.
427 // Whether to use sRGB gamma is not part of the EGLconfig, but is part
428 // of our native format. So if sRGB gamma is requested, we have to
429 // modify the EGLconfig's format before setting the native window's
432 // by default, just pick RGBA_8888
433 EGLint format = HAL_PIXEL_FORMAT_RGBA_8888;
434 android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN;
437 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a);
439 // alpha-channel requested, there's really only one suitable format
440 format = HAL_PIXEL_FORMAT_RGBA_8888;
444 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_RED_SIZE, &r);
445 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_GREEN_SIZE, &g);
446 cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_BLUE_SIZE, &b);
447 EGLint colorDepth = r + g + b;
448 if (colorDepth <= 16) {
449 format = HAL_PIXEL_FORMAT_RGB_565;
451 format = HAL_PIXEL_FORMAT_RGBX_8888;
455 // now select a corresponding sRGB format if needed
456 if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) {
457 for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) {
458 if (*attr == EGL_GL_COLORSPACE_KHR) {
459 if (ENABLE_EGL_KHR_GL_COLORSPACE) {
460 dataSpace = modifyBufferDataspace(dataSpace, *(attr+1));
462 // Normally we'd pass through unhandled attributes to
463 // the driver. But in case the driver implements this
464 // extension but we're disabling it, we want to prevent
465 // it getting through -- support will be broken without
467 ALOGE("sRGB window surfaces not supported");
468 return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
475 int err = native_window_set_buffers_format(window, format);
477 ALOGE("error setting native window pixel format: %s (%d)",
478 strerror(-err), err);
479 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
480 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
484 if (dataSpace != 0) {
485 int err = native_window_set_buffers_data_space(window, dataSpace);
487 ALOGE("error setting native window pixel dataSpace: %s (%d)",
488 strerror(-err), err);
489 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
490 return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
494 // the EGL spec requires that a new EGLSurface default to swap interval
495 // 1, so explicitly set that on the window here.
496 ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window);
497 anw->setSwapInterval(anw, 1);
499 EGLSurface surface = cnx->egl.eglCreateWindowSurface(
500 iDpy, config, window, attrib_list);
501 if (surface != EGL_NO_SURFACE) {
502 egl_surface_t* s = new egl_surface_t(dp.get(), config, window,
507 // EGLSurface creation failed
508 native_window_set_buffers_format(window, 0);
509 native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
511 return EGL_NO_SURFACE;
514 EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config,
515 NativePixmapType pixmap,
516 const EGLint *attrib_list)
520 egl_connection_t* cnx = NULL;
521 egl_display_ptr dp = validate_display_connection(dpy, cnx);
523 EGLSurface surface = cnx->egl.eglCreatePixmapSurface(
524 dp->disp.dpy, config, pixmap, attrib_list);
525 if (surface != EGL_NO_SURFACE) {
526 egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
531 return EGL_NO_SURFACE;
534 EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config,
535 const EGLint *attrib_list)
539 egl_connection_t* cnx = NULL;
540 egl_display_ptr dp = validate_display_connection(dpy, cnx);
542 EGLSurface surface = cnx->egl.eglCreatePbufferSurface(
543 dp->disp.dpy, config, attrib_list);
544 if (surface != EGL_NO_SURFACE) {
545 egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL,
550 return EGL_NO_SURFACE;
553 EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
557 const egl_display_ptr dp = validate_display(dpy);
558 if (!dp) return EGL_FALSE;
560 SurfaceRef _s(dp.get(), surface);
562 return setError(EGL_BAD_SURFACE, EGL_FALSE);
564 egl_surface_t * const s = get_surface(surface);
565 ANativeWindow* window = s->win.get();
567 int result = native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
569 ALOGE("eglDestroySurface: native_window_api_disconnect (win=%p) "
574 EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface);
575 if (result == EGL_TRUE) {
581 EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface,
582 EGLint attribute, EGLint *value)
586 const egl_display_ptr dp = validate_display(dpy);
587 if (!dp) return EGL_FALSE;
589 SurfaceRef _s(dp.get(), surface);
591 return setError(EGL_BAD_SURFACE, EGL_FALSE);
593 egl_surface_t const * const s = get_surface(surface);
594 return s->cnx->egl.eglQuerySurface(
595 dp->disp.dpy, s->surface, attribute, value);
598 void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {
602 const egl_display_ptr dp = validate_display(dpy);
607 SurfaceRef _s(dp.get(), surface);
609 setError(EGL_BAD_SURFACE, EGL_FALSE);
614 // ----------------------------------------------------------------------------
616 // ----------------------------------------------------------------------------
618 EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
619 EGLContext share_list, const EGLint *attrib_list)
623 egl_connection_t* cnx = NULL;
624 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
626 if (share_list != EGL_NO_CONTEXT) {
627 if (!ContextRef(dp.get(), share_list).get()) {
628 return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT);
630 egl_context_t* const c = get_context(share_list);
631 share_list = c->context;
633 EGLContext context = cnx->egl.eglCreateContext(
634 dp->disp.dpy, config, share_list, attrib_list);
635 if (context != EGL_NO_CONTEXT) {
636 // figure out if it's a GLESv1 or GLESv2
639 while (*attrib_list != EGL_NONE) {
640 GLint attr = *attrib_list++;
641 GLint value = *attrib_list++;
642 if (attr == EGL_CONTEXT_CLIENT_VERSION) {
644 version = egl_connection_t::GLESv1_INDEX;
645 } else if (value == 2 || value == 3) {
646 version = egl_connection_t::GLESv2_INDEX;
651 egl_context_t* c = new egl_context_t(dpy, context, config, cnx,
654 if (getEGLDebugLevel() > 0)
655 GLTrace_eglCreateContext(version, c);
660 return EGL_NO_CONTEXT;
663 EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
667 const egl_display_ptr dp = validate_display(dpy);
671 ContextRef _c(dp.get(), ctx);
673 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
675 egl_context_t * const c = get_context(ctx);
676 EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context);
677 if (result == EGL_TRUE) {
683 EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw,
684 EGLSurface read, EGLContext ctx)
688 egl_display_ptr dp = validate_display(dpy);
689 if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE);
691 // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not
692 // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is
693 // a valid but uninitialized display.
694 if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) ||
695 (draw != EGL_NO_SURFACE) ) {
696 if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE);
699 // get a reference to the object passed in
700 ContextRef _c(dp.get(), ctx);
701 SurfaceRef _d(dp.get(), draw);
702 SurfaceRef _r(dp.get(), read);
704 // validate the context (if not EGL_NO_CONTEXT)
705 if ((ctx != EGL_NO_CONTEXT) && !_c.get()) {
706 // EGL_NO_CONTEXT is valid
707 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
710 // these are the underlying implementation's object
711 EGLContext impl_ctx = EGL_NO_CONTEXT;
712 EGLSurface impl_draw = EGL_NO_SURFACE;
713 EGLSurface impl_read = EGL_NO_SURFACE;
715 // these are our objects structs passed in
716 egl_context_t * c = NULL;
717 egl_surface_t const * d = NULL;
718 egl_surface_t const * r = NULL;
720 // these are the current objects structs
721 egl_context_t * cur_c = get_context(getContext());
723 if (ctx != EGL_NO_CONTEXT) {
724 c = get_context(ctx);
725 impl_ctx = c->context;
727 // no context given, use the implementation of the current context
728 if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) {
729 // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT);
730 return setError(EGL_BAD_MATCH, EGL_FALSE);
733 // no current context
734 // not an error, there is just no current context.
739 // retrieve the underlying implementation's draw EGLSurface
740 if (draw != EGL_NO_SURFACE) {
741 if (!_d.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE);
742 d = get_surface(draw);
743 impl_draw = d->surface;
746 // retrieve the underlying implementation's read EGLSurface
747 if (read != EGL_NO_SURFACE) {
748 if (!_r.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE);
749 r = get_surface(read);
750 impl_read = r->surface;
754 EGLBoolean result = dp->makeCurrent(c, cur_c,
756 impl_draw, impl_read, impl_ctx);
758 if (result == EGL_TRUE) {
760 setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
761 egl_tls_t::setContext(ctx);
763 if (getEGLDebugLevel() > 0)
764 GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx);
770 setGLHooksThreadSpecific(&gHooksNoContext);
771 egl_tls_t::setContext(EGL_NO_CONTEXT);
774 // this will ALOGE the error
775 egl_connection_t* const cnx = &gEGLImpl;
776 result = setError(cnx->egl.eglGetError(), EGL_FALSE);
782 EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx,
783 EGLint attribute, EGLint *value)
787 const egl_display_ptr dp = validate_display(dpy);
788 if (!dp) return EGL_FALSE;
790 ContextRef _c(dp.get(), ctx);
791 if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE);
793 egl_context_t * const c = get_context(ctx);
794 return c->cnx->egl.eglQueryContext(
795 dp->disp.dpy, c->context, attribute, value);
799 EGLContext eglGetCurrentContext(void)
801 // could be called before eglInitialize(), but we wouldn't have a context
802 // then, and this function would correctly return EGL_NO_CONTEXT.
806 EGLContext ctx = getContext();
810 EGLSurface eglGetCurrentSurface(EGLint readdraw)
812 // could be called before eglInitialize(), but we wouldn't have a context
813 // then, and this function would correctly return EGL_NO_SURFACE.
817 EGLContext ctx = getContext();
819 egl_context_t const * const c = get_context(ctx);
820 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
822 case EGL_READ: return c->read;
823 case EGL_DRAW: return c->draw;
824 default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);
827 return EGL_NO_SURFACE;
830 EGLDisplay eglGetCurrentDisplay(void)
832 // could be called before eglInitialize(), but we wouldn't have a context
833 // then, and this function would correctly return EGL_NO_DISPLAY.
837 EGLContext ctx = getContext();
839 egl_context_t const * const c = get_context(ctx);
840 if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);
843 return EGL_NO_DISPLAY;
846 EGLBoolean eglWaitGL(void)
850 egl_connection_t* const cnx = &gEGLImpl;
852 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
854 return cnx->egl.eglWaitGL();
857 EGLBoolean eglWaitNative(EGLint engine)
861 egl_connection_t* const cnx = &gEGLImpl;
863 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
865 return cnx->egl.eglWaitNative(engine);
868 EGLint eglGetError(void)
870 EGLint err = EGL_SUCCESS;
871 egl_connection_t* const cnx = &gEGLImpl;
873 err = cnx->egl.eglGetError();
875 if (err == EGL_SUCCESS) {
876 err = egl_tls_t::getError();
881 static __eglMustCastToProperFunctionPointerType findBuiltinWrapper(
882 const char* procname) {
883 const egl_connection_t* cnx = &gEGLImpl;
886 proc = dlsym(cnx->libEgl, procname);
887 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
889 proc = dlsym(cnx->libGles2, procname);
890 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
892 proc = dlsym(cnx->libGles1, procname);
893 if (proc) return (__eglMustCastToProperFunctionPointerType)proc;
898 __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
900 // eglGetProcAddress() could be the very first function called
901 // in which case we must make sure we've initialized ourselves, this
902 // happens the first time egl_get_display() is called.
906 if (egl_init_drivers() == EGL_FALSE) {
907 setError(EGL_BAD_PARAMETER, NULL);
911 if (FILTER_EXTENSIONS(procname)) {
915 __eglMustCastToProperFunctionPointerType addr;
916 addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap));
917 if (addr) return addr;
919 addr = findBuiltinWrapper(procname);
920 if (addr) return addr;
922 // this protects accesses to sGLExtentionMap and sGLExtentionSlot
923 pthread_mutex_lock(&sExtensionMapMutex);
926 * Since eglGetProcAddress() is not associated to anything, it needs
927 * to return a function pointer that "works" regardless of what
928 * the current context is.
930 * For this reason, we return a "forwarder", a small stub that takes
931 * care of calling the function associated with the context
934 * We first look for extensions we've already resolved, if we're seeing
935 * this extension for the first time, we go through all our
936 * implementations and call eglGetProcAddress() and record the
937 * result in the appropriate implementation hooks and return the
938 * address of the forwarder corresponding to that hook set.
942 const String8 name(procname);
943 addr = sGLExtentionMap.valueFor(name);
944 const int slot = sGLExtentionSlot;
946 ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS,
947 "no more slots for eglGetProcAddress(\"%s\")",
951 gl_hooks_t *debugHooks = GLTrace_getGLHooks();
954 if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) {
957 egl_connection_t* const cnx = &gEGLImpl;
958 if (cnx->dso && cnx->egl.eglGetProcAddress) {
959 // Extensions are independent of the bound context
961 cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] =
962 cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] =
964 debugHooks->ext.extensions[slot] =
965 gHooksTrace.ext.extensions[slot] =
967 cnx->egl.eglGetProcAddress(procname);
968 if (addr) found = true;
972 addr = gExtensionForwarders[slot];
973 sGLExtentionMap.add(name, addr);
978 pthread_mutex_unlock(&sExtensionMapMutex);
982 class FrameCompletionThread : public Thread {
985 static void queueSync(EGLSyncKHR sync) {
986 static sp<FrameCompletionThread> thread(new FrameCompletionThread);
987 static bool running = false;
989 thread->run("GPUFrameCompletion");
993 Mutex::Autolock lock(thread->mMutex);
994 ScopedTrace st(ATRACE_TAG, String8::format("kicked off frame %d",
995 thread->mFramesQueued).string());
996 thread->mQueue.push_back(sync);
997 thread->mCondition.signal();
998 thread->mFramesQueued++;
999 ATRACE_INT("GPU Frames Outstanding", thread->mQueue.size());
1004 FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {}
1006 virtual bool threadLoop() {
1010 Mutex::Autolock lock(mMutex);
1011 while (mQueue.isEmpty()) {
1012 mCondition.wait(mMutex);
1015 frameNum = mFramesCompleted;
1017 EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
1019 ScopedTrace st(ATRACE_TAG, String8::format("waiting for frame %d",
1020 frameNum).string());
1021 EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR);
1022 if (result == EGL_FALSE) {
1023 ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError());
1024 } else if (result == EGL_TIMEOUT_EXPIRED_KHR) {
1025 ALOGE("FrameCompletion: timeout waiting for fence");
1027 eglDestroySyncKHR(dpy, sync);
1030 Mutex::Autolock lock(mMutex);
1033 ATRACE_INT("GPU Frames Outstanding", mQueue.size());
1038 uint32_t mFramesQueued;
1039 uint32_t mFramesCompleted;
1040 Vector<EGLSyncKHR> mQueue;
1041 Condition mCondition;
1045 EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw,
1046 EGLint *rects, EGLint n_rects)
1051 const egl_display_ptr dp = validate_display(dpy);
1052 if (!dp) return EGL_FALSE;
1054 SurfaceRef _s(dp.get(), draw);
1056 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1059 gl_hooks_t const *trace_hooks = getGLTraceThreadSpecific();
1060 if (getEGLDebugLevel() > 0) {
1061 if (trace_hooks == NULL) {
1062 if (GLTrace_start() < 0) {
1063 ALOGE("Disabling Tracer for OpenGL ES");
1064 setEGLDebugLevel(0);
1066 // switch over to the trace version of hooks
1067 EGLContext ctx = egl_tls_t::getContext();
1068 egl_context_t * const c = get_context(ctx);
1070 setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
1071 GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx);
1076 GLTrace_eglSwapBuffers(dpy, draw);
1077 } else if (trace_hooks != NULL) {
1078 // tracing is now disabled, so switch back to the non trace version
1079 EGLContext ctx = egl_tls_t::getContext();
1080 egl_context_t * const c = get_context(ctx);
1081 if (c) setGLHooksThreadSpecific(c->cnx->hooks[c->version]);
1086 egl_surface_t const * const s = get_surface(draw);
1088 if (CC_UNLIKELY(dp->traceGpuCompletion)) {
1089 EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL);
1090 if (sync != EGL_NO_SYNC_KHR) {
1091 FrameCompletionThread::queueSync(sync);
1095 if (CC_UNLIKELY(dp->finishOnSwap)) {
1097 egl_context_t * const c = get_context( egl_tls_t::getContext() );
1099 // glReadPixels() ensures that the frame is complete
1100 s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1,
1101 GL_RGBA,GL_UNSIGNED_BYTE,&pixel);
1106 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1109 Vector<android_native_rect_t> androidRects;
1110 for (int r = 0; r < n_rects; ++r) {
1112 int x = rects[offset];
1113 int y = rects[offset + 1];
1114 int width = rects[offset + 2];
1115 int height = rects[offset + 3];
1116 android_native_rect_t androidRect;
1117 androidRect.left = x;
1118 androidRect.top = y + height;
1119 androidRect.right = x + width;
1120 androidRect.bottom = y;
1121 androidRects.push_back(androidRect);
1123 native_window_set_surface_damage(s->win.get(), androidRects.array(),
1124 androidRects.size());
1126 if (s->cnx->egl.eglSwapBuffersWithDamageKHR) {
1127 return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface,
1130 return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);
1134 EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
1136 return eglSwapBuffersWithDamageKHR(dpy, surface, NULL, 0);
1139 EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface,
1140 NativePixmapType target)
1144 const egl_display_ptr dp = validate_display(dpy);
1145 if (!dp) return EGL_FALSE;
1147 SurfaceRef _s(dp.get(), surface);
1149 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1151 egl_surface_t const * const s = get_surface(surface);
1152 return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target);
1155 const char* eglQueryString(EGLDisplay dpy, EGLint name)
1159 const egl_display_ptr dp = validate_display(dpy);
1160 if (!dp) return (const char *) NULL;
1164 return dp->getVendorString();
1166 return dp->getVersionString();
1167 case EGL_EXTENSIONS:
1168 return dp->getExtensionString();
1169 case EGL_CLIENT_APIS:
1170 return dp->getClientApiString();
1172 return setError(EGL_BAD_PARAMETER, (const char *)0);
1175 EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name)
1179 const egl_display_ptr dp = validate_display(dpy);
1180 if (!dp) return (const char *) NULL;
1184 return dp->disp.queryString.vendor;
1186 return dp->disp.queryString.version;
1187 case EGL_EXTENSIONS:
1188 return dp->disp.queryString.extensions;
1189 case EGL_CLIENT_APIS:
1190 return dp->disp.queryString.clientApi;
1192 return setError(EGL_BAD_PARAMETER, (const char *)0);
1195 // ----------------------------------------------------------------------------
1197 // ----------------------------------------------------------------------------
1199 EGLBoolean eglSurfaceAttrib(
1200 EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
1204 const egl_display_ptr dp = validate_display(dpy);
1205 if (!dp) return EGL_FALSE;
1207 SurfaceRef _s(dp.get(), surface);
1209 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1211 egl_surface_t const * const s = get_surface(surface);
1212 if (s->cnx->egl.eglSurfaceAttrib) {
1213 return s->cnx->egl.eglSurfaceAttrib(
1214 dp->disp.dpy, s->surface, attribute, value);
1216 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1219 EGLBoolean eglBindTexImage(
1220 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1224 const egl_display_ptr dp = validate_display(dpy);
1225 if (!dp) return EGL_FALSE;
1227 SurfaceRef _s(dp.get(), surface);
1229 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1231 egl_surface_t const * const s = get_surface(surface);
1232 if (s->cnx->egl.eglBindTexImage) {
1233 return s->cnx->egl.eglBindTexImage(
1234 dp->disp.dpy, s->surface, buffer);
1236 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1239 EGLBoolean eglReleaseTexImage(
1240 EGLDisplay dpy, EGLSurface surface, EGLint buffer)
1244 const egl_display_ptr dp = validate_display(dpy);
1245 if (!dp) return EGL_FALSE;
1247 SurfaceRef _s(dp.get(), surface);
1249 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1251 egl_surface_t const * const s = get_surface(surface);
1252 if (s->cnx->egl.eglReleaseTexImage) {
1253 return s->cnx->egl.eglReleaseTexImage(
1254 dp->disp.dpy, s->surface, buffer);
1256 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1259 EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
1263 const egl_display_ptr dp = validate_display(dpy);
1264 if (!dp) return EGL_FALSE;
1266 EGLBoolean res = EGL_TRUE;
1267 egl_connection_t* const cnx = &gEGLImpl;
1268 if (cnx->dso && cnx->egl.eglSwapInterval) {
1269 res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval);
1276 // ----------------------------------------------------------------------------
1278 // ----------------------------------------------------------------------------
1280 EGLBoolean eglWaitClient(void)
1284 egl_connection_t* const cnx = &gEGLImpl;
1286 return setError(EGL_BAD_CONTEXT, EGL_FALSE);
1289 if (cnx->egl.eglWaitClient) {
1290 res = cnx->egl.eglWaitClient();
1292 res = cnx->egl.eglWaitGL();
1297 EGLBoolean eglBindAPI(EGLenum api)
1301 if (egl_init_drivers() == EGL_FALSE) {
1302 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1305 // bind this API on all EGLs
1306 EGLBoolean res = EGL_TRUE;
1307 egl_connection_t* const cnx = &gEGLImpl;
1308 if (cnx->dso && cnx->egl.eglBindAPI) {
1309 res = cnx->egl.eglBindAPI(api);
1314 EGLenum eglQueryAPI(void)
1318 if (egl_init_drivers() == EGL_FALSE) {
1319 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1322 egl_connection_t* const cnx = &gEGLImpl;
1323 if (cnx->dso && cnx->egl.eglQueryAPI) {
1324 return cnx->egl.eglQueryAPI();
1327 // or, it can only be OpenGL ES
1328 return EGL_OPENGL_ES_API;
1331 EGLBoolean eglReleaseThread(void)
1336 if (getEGLDebugLevel() > 0)
1337 GLTrace_eglReleaseThread();
1340 // If there is context bound to the thread, release it
1341 egl_display_t::loseCurrent(get_context(getContext()));
1343 egl_connection_t* const cnx = &gEGLImpl;
1344 if (cnx->dso && cnx->egl.eglReleaseThread) {
1345 cnx->egl.eglReleaseThread();
1347 egl_tls_t::clearTLS();
1351 EGLSurface eglCreatePbufferFromClientBuffer(
1352 EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,
1353 EGLConfig config, const EGLint *attrib_list)
1357 egl_connection_t* cnx = NULL;
1358 const egl_display_ptr dp = validate_display_connection(dpy, cnx);
1359 if (!dp) return EGL_FALSE;
1360 if (cnx->egl.eglCreatePbufferFromClientBuffer) {
1361 return cnx->egl.eglCreatePbufferFromClientBuffer(
1362 dp->disp.dpy, buftype, buffer, config, attrib_list);
1364 return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE);
1367 // ----------------------------------------------------------------------------
1368 // EGL_EGLEXT_VERSION 3
1369 // ----------------------------------------------------------------------------
1371 EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface,
1372 const EGLint *attrib_list)
1376 const egl_display_ptr dp = validate_display(dpy);
1377 if (!dp) return EGL_FALSE;
1379 SurfaceRef _s(dp.get(), surface);
1381 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1383 egl_surface_t const * const s = get_surface(surface);
1384 if (s->cnx->egl.eglLockSurfaceKHR) {
1385 return s->cnx->egl.eglLockSurfaceKHR(
1386 dp->disp.dpy, s->surface, attrib_list);
1388 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
1391 EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface)
1395 const egl_display_ptr dp = validate_display(dpy);
1396 if (!dp) return EGL_FALSE;
1398 SurfaceRef _s(dp.get(), surface);
1400 return setError(EGL_BAD_SURFACE, EGL_FALSE);
1402 egl_surface_t const * const s = get_surface(surface);
1403 if (s->cnx->egl.eglUnlockSurfaceKHR) {
1404 return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface);
1406 return setError(EGL_BAD_DISPLAY, EGL_FALSE);
1409 EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
1410 EGLClientBuffer buffer, const EGLint *attrib_list)
1414 const egl_display_ptr dp = validate_display(dpy);
1415 if (!dp) return EGL_NO_IMAGE_KHR;
1417 ContextRef _c(dp.get(), ctx);
1418 egl_context_t * const c = _c.get();
1420 EGLImageKHR result = EGL_NO_IMAGE_KHR;
1421 egl_connection_t* const cnx = &gEGLImpl;
1422 if (cnx->dso && cnx->egl.eglCreateImageKHR) {
1423 result = cnx->egl.eglCreateImageKHR(
1425 c ? c->context : EGL_NO_CONTEXT,
1426 target, buffer, attrib_list);
1431 EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
1435 const egl_display_ptr dp = validate_display(dpy);
1436 if (!dp) return EGL_FALSE;
1438 EGLBoolean result = EGL_FALSE;
1439 egl_connection_t* const cnx = &gEGLImpl;
1440 if (cnx->dso && cnx->egl.eglDestroyImageKHR) {
1441 result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img);
1446 // ----------------------------------------------------------------------------
1447 // EGL_EGLEXT_VERSION 5
1448 // ----------------------------------------------------------------------------
1451 EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list)
1455 const egl_display_ptr dp = validate_display(dpy);
1456 if (!dp) return EGL_NO_SYNC_KHR;
1458 EGLSyncKHR result = EGL_NO_SYNC_KHR;
1459 egl_connection_t* const cnx = &gEGLImpl;
1460 if (cnx->dso && cnx->egl.eglCreateSyncKHR) {
1461 result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list);
1466 EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
1470 const egl_display_ptr dp = validate_display(dpy);
1471 if (!dp) return EGL_FALSE;
1473 EGLBoolean result = EGL_FALSE;
1474 egl_connection_t* const cnx = &gEGLImpl;
1475 if (cnx->dso && cnx->egl.eglDestroySyncKHR) {
1476 result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync);
1481 EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) {
1484 const egl_display_ptr dp = validate_display(dpy);
1485 if (!dp) return EGL_FALSE;
1487 EGLBoolean result = EGL_FALSE;
1488 egl_connection_t* const cnx = &gEGLImpl;
1489 if (cnx->dso && cnx->egl.eglSignalSyncKHR) {
1490 result = cnx->egl.eglSignalSyncKHR(
1491 dp->disp.dpy, sync, mode);
1496 EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync,
1497 EGLint flags, EGLTimeKHR timeout)
1501 const egl_display_ptr dp = validate_display(dpy);
1502 if (!dp) return EGL_FALSE;
1504 EGLBoolean result = EGL_FALSE;
1505 egl_connection_t* const cnx = &gEGLImpl;
1506 if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) {
1507 result = cnx->egl.eglClientWaitSyncKHR(
1508 dp->disp.dpy, sync, flags, timeout);
1513 EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync,
1514 EGLint attribute, EGLint *value)
1518 const egl_display_ptr dp = validate_display(dpy);
1519 if (!dp) return EGL_FALSE;
1521 EGLBoolean result = EGL_FALSE;
1522 egl_connection_t* const cnx = &gEGLImpl;
1523 if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) {
1524 result = cnx->egl.eglGetSyncAttribKHR(
1525 dp->disp.dpy, sync, attribute, value);
1530 // ----------------------------------------------------------------------------
1531 // EGL_EGLEXT_VERSION 15
1532 // ----------------------------------------------------------------------------
1534 EGLint eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) {
1536 const egl_display_ptr dp = validate_display(dpy);
1537 if (!dp) return EGL_FALSE;
1538 EGLint result = EGL_FALSE;
1539 egl_connection_t* const cnx = &gEGLImpl;
1540 if (cnx->dso && cnx->egl.eglWaitSyncKHR) {
1541 result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags);
1546 // ----------------------------------------------------------------------------
1547 // ANDROID extensions
1548 // ----------------------------------------------------------------------------
1550 EGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync)
1554 const egl_display_ptr dp = validate_display(dpy);
1555 if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID;
1557 EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID;
1558 egl_connection_t* const cnx = &gEGLImpl;
1559 if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) {
1560 result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync);
1565 EGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface,
1566 EGLnsecsANDROID time)
1570 const egl_display_ptr dp = validate_display(dpy);
1575 SurfaceRef _s(dp.get(), surface);
1577 setError(EGL_BAD_SURFACE, EGL_FALSE);
1581 egl_surface_t const * const s = get_surface(surface);
1582 native_window_set_buffers_timestamp(s->win.get(), time);
1587 // ----------------------------------------------------------------------------
1588 // NVIDIA extensions
1589 // ----------------------------------------------------------------------------
1590 EGLuint64NV eglGetSystemTimeFrequencyNV()
1594 if (egl_init_drivers() == EGL_FALSE) {
1595 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1598 EGLuint64NV ret = 0;
1599 egl_connection_t* const cnx = &gEGLImpl;
1601 if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) {
1602 return cnx->egl.eglGetSystemTimeFrequencyNV();
1605 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
1608 EGLuint64NV eglGetSystemTimeNV()
1612 if (egl_init_drivers() == EGL_FALSE) {
1613 return setError(EGL_BAD_PARAMETER, EGL_FALSE);
1616 EGLuint64NV ret = 0;
1617 egl_connection_t* const cnx = &gEGLImpl;
1619 if (cnx->dso && cnx->egl.eglGetSystemTimeNV) {
1620 return cnx->egl.eglGetSystemTimeNV();
1623 return setErrorQuiet(EGL_BAD_DISPLAY, 0);
1626 // ----------------------------------------------------------------------------
1627 // Partial update extension
1628 // ----------------------------------------------------------------------------
1629 EGLBoolean eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface,
1630 EGLint *rects, EGLint n_rects)
1634 const egl_display_ptr dp = validate_display(dpy);
1636 setError(EGL_BAD_DISPLAY, EGL_FALSE);
1640 SurfaceRef _s(dp.get(), surface);
1642 setError(EGL_BAD_SURFACE, EGL_FALSE);
1646 egl_surface_t const * const s = get_surface(surface);
1647 if (s->cnx->egl.eglSetDamageRegionKHR) {
1648 return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface,