Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 1 | /* |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 2 | ** Copyright 2007, The Android Open Source Project |
| 3 | ** |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 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 |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 7 | ** |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 9 | ** |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 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 |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 19 | #include <dlfcn.h> |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 20 | #include <ctype.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include <hardware/gralloc.h> |
| 25 | #include <system/window.h> |
| 26 | |
| 27 | #include <EGL/egl.h> |
| 28 | #include <EGL/eglext.h> |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 29 | |
| 30 | #include <cutils/log.h> |
| 31 | #include <cutils/atomic.h> |
Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 32 | #include <cutils/compiler.h> |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 33 | #include <cutils/properties.h> |
| 34 | #include <cutils/memory.h> |
| 35 | |
| 36 | #include <utils/KeyedVector.h> |
| 37 | #include <utils/SortedVector.h> |
| 38 | #include <utils/String8.h> |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 39 | #include <utils/Trace.h> |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 40 | |
Mathias Agopian | 39c24a2 | 2013-04-04 23:17:56 -0700 | [diff] [blame] | 41 | #include "../egl_impl.h" |
| 42 | #include "../glestrace.h" |
| 43 | #include "../hooks.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 44 | |
| 45 | #include "egl_display.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 46 | #include "egl_object.h" |
| 47 | #include "egl_tls.h" |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 48 | #include "egldefs.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 49 | |
| 50 | using namespace android; |
| 51 | |
| 52 | // ---------------------------------------------------------------------------- |
| 53 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 54 | namespace android { |
| 55 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 56 | struct extention_map_t { |
| 57 | const char* name; |
| 58 | __eglMustCastToProperFunctionPointerType address; |
| 59 | }; |
| 60 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 61 | /* |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 62 | * This is the list of EGL extensions exposed to applications. |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 63 | * |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 64 | * Some of them (gBuiltinExtensionString) are implemented entirely in this EGL |
| 65 | * wrapper and are always available. |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 66 | * |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 67 | * The rest (gExtensionString) depend on support in the EGL driver, and are |
| 68 | * only available if the driver supports them. However, some of these must be |
| 69 | * supported because they are used by the Android system itself; these are |
| 70 | * listd as mandatory below and are required by the CDD. The system *assumes* |
| 71 | * the mandatory extensions are present and may not function properly if some |
| 72 | * are missing. |
| 73 | * |
| 74 | * NOTE: Both strings MUST have a single space as the last character. |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 75 | */ |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 76 | extern char const * const gBuiltinExtensionString = |
| 77 | "EGL_KHR_get_all_proc_addresses " |
| 78 | "EGL_ANDROID_presentation_time " |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 79 | "EGL_KHR_swap_buffers_with_damage " |
Jesse Hall | 21558da | 2013-08-06 15:31:22 -0700 | [diff] [blame] | 80 | ; |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 81 | extern char const * const gExtensionString = |
| 82 | "EGL_KHR_image " // mandatory |
| 83 | "EGL_KHR_image_base " // mandatory |
| 84 | "EGL_KHR_image_pixmap " |
| 85 | "EGL_KHR_lock_surface " |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 86 | "EGL_KHR_gl_colorspace " |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 87 | "EGL_KHR_gl_texture_2D_image " |
Season Li | 000d88f | 2015-07-01 11:39:40 -0700 | [diff] [blame] | 88 | "EGL_KHR_gl_texture_3D_image " |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 89 | "EGL_KHR_gl_texture_cubemap_image " |
| 90 | "EGL_KHR_gl_renderbuffer_image " |
| 91 | "EGL_KHR_reusable_sync " |
| 92 | "EGL_KHR_fence_sync " |
Jamie Gennis | f6d1c39 | 2013-04-25 18:48:41 -0700 | [diff] [blame] | 93 | "EGL_KHR_create_context " |
Season Li | 000d88f | 2015-07-01 11:39:40 -0700 | [diff] [blame] | 94 | "EGL_KHR_config_attribs " |
| 95 | "EGL_KHR_surfaceless_context " |
| 96 | "EGL_KHR_stream " |
| 97 | "EGL_KHR_stream_fifo " |
| 98 | "EGL_KHR_stream_producer_eglsurface " |
| 99 | "EGL_KHR_stream_consumer_gltexture " |
| 100 | "EGL_KHR_stream_cross_process_fd " |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 101 | "EGL_EXT_create_context_robustness " |
| 102 | "EGL_NV_system_time " |
| 103 | "EGL_ANDROID_image_native_buffer " // mandatory |
Mathias Agopian | 2bb7168 | 2013-03-27 17:32:41 -0700 | [diff] [blame] | 104 | "EGL_KHR_wait_sync " // strongly recommended |
Jamie Gennis | dbe9245 | 2013-09-23 17:22:10 -0700 | [diff] [blame] | 105 | "EGL_ANDROID_recordable " // mandatory |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 106 | "EGL_KHR_partial_update " // strongly recommended |
| 107 | "EGL_EXT_buffer_age " // strongly recommended with partial_update |
Jesse Hall | 408e59f | 2015-04-24 01:40:42 -0700 | [diff] [blame] | 108 | "EGL_KHR_create_context_no_error " |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 109 | ; |
| 110 | |
| 111 | // extensions not exposed to applications but used by the ANDROID system |
| 112 | // "EGL_ANDROID_blob_cache " // strongly recommended |
| 113 | // "EGL_IMG_hibernate_process " // optional |
| 114 | // "EGL_ANDROID_native_fence_sync " // strongly recommended |
| 115 | // "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1 |
Jamie Gennis | dbe9245 | 2013-09-23 17:22:10 -0700 | [diff] [blame] | 116 | // "EGL_ANDROID_image_crop " // optional |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 117 | |
| 118 | /* |
| 119 | * EGL Extensions entry-points exposed to 3rd party applications |
| 120 | * (keep in sync with gExtensionString above) |
| 121 | * |
| 122 | */ |
| 123 | static const extention_map_t sExtensionMap[] = { |
| 124 | // EGL_KHR_lock_surface |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 125 | { "eglLockSurfaceKHR", |
| 126 | (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, |
| 127 | { "eglUnlockSurfaceKHR", |
| 128 | (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 129 | |
| 130 | // EGL_KHR_image, EGL_KHR_image_base |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 131 | { "eglCreateImageKHR", |
| 132 | (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, |
| 133 | { "eglDestroyImageKHR", |
| 134 | (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 135 | |
| 136 | // EGL_KHR_reusable_sync, EGL_KHR_fence_sync |
| 137 | { "eglCreateSyncKHR", |
| 138 | (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR }, |
| 139 | { "eglDestroySyncKHR", |
| 140 | (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR }, |
| 141 | { "eglClientWaitSyncKHR", |
| 142 | (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR }, |
| 143 | { "eglSignalSyncKHR", |
| 144 | (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR }, |
| 145 | { "eglGetSyncAttribKHR", |
| 146 | (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR }, |
| 147 | |
| 148 | // EGL_NV_system_time |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 149 | { "eglGetSystemTimeFrequencyNV", |
| 150 | (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV }, |
| 151 | { "eglGetSystemTimeNV", |
| 152 | (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV }, |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 153 | |
Mathias Agopian | 2bb7168 | 2013-03-27 17:32:41 -0700 | [diff] [blame] | 154 | // EGL_KHR_wait_sync |
| 155 | { "eglWaitSyncKHR", |
| 156 | (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR }, |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 157 | |
| 158 | // EGL_ANDROID_presentation_time |
| 159 | { "eglPresentationTimeANDROID", |
| 160 | (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID }, |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 161 | |
| 162 | // EGL_KHR_swap_buffers_with_damage |
| 163 | { "eglSwapBuffersWithDamageKHR", |
| 164 | (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR }, |
| 165 | |
| 166 | // EGL_KHR_partial_update |
| 167 | { "eglSetDamageRegionKHR", |
| 168 | (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR }, |
Season Li | 000d88f | 2015-07-01 11:39:40 -0700 | [diff] [blame] | 169 | |
| 170 | { "eglCreateStreamKHR", |
| 171 | (__eglMustCastToProperFunctionPointerType)&eglCreateStreamKHR }, |
| 172 | { "eglDestroyStreamKHR", |
| 173 | (__eglMustCastToProperFunctionPointerType)&eglDestroyStreamKHR }, |
| 174 | { "eglStreamAttribKHR", |
| 175 | (__eglMustCastToProperFunctionPointerType)&eglStreamAttribKHR }, |
| 176 | { "eglQueryStreamKHR", |
| 177 | (__eglMustCastToProperFunctionPointerType)&eglQueryStreamKHR }, |
| 178 | { "eglQueryStreamu64KHR", |
| 179 | (__eglMustCastToProperFunctionPointerType)&eglQueryStreamu64KHR }, |
| 180 | { "eglQueryStreamTimeKHR", |
| 181 | (__eglMustCastToProperFunctionPointerType)&eglQueryStreamTimeKHR }, |
| 182 | { "eglCreateStreamProducerSurfaceKHR", |
| 183 | (__eglMustCastToProperFunctionPointerType)&eglCreateStreamProducerSurfaceKHR }, |
| 184 | { "eglStreamConsumerGLTextureExternalKHR", |
| 185 | (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerGLTextureExternalKHR }, |
| 186 | { "eglStreamConsumerAcquireKHR", |
| 187 | (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerAcquireKHR }, |
| 188 | { "eglStreamConsumerReleaseKHR", |
| 189 | (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerReleaseKHR }, |
| 190 | { "eglGetStreamFileDescriptorKHR", |
| 191 | (__eglMustCastToProperFunctionPointerType)&eglGetStreamFileDescriptorKHR }, |
| 192 | { "eglCreateStreamFromFileDescriptorKHR", |
| 193 | (__eglMustCastToProperFunctionPointerType)&eglCreateStreamFromFileDescriptorKHR }, |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 196 | /* |
| 197 | * These extensions entry-points should not be exposed to applications. |
| 198 | * They're used internally by the Android EGL layer. |
| 199 | */ |
| 200 | #define FILTER_EXTENSIONS(procname) \ |
| 201 | (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") || \ |
| 202 | !strcmp((procname), "eglHibernateProcessIMG") || \ |
| 203 | !strcmp((procname), "eglAwakenProcessIMG") || \ |
| 204 | !strcmp((procname), "eglDupNativeFenceFDANDROID")) |
| 205 | |
| 206 | |
| 207 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 208 | // accesses protected by sExtensionMapMutex |
| 209 | static DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap; |
| 210 | static int sGLExtentionSlot = 0; |
| 211 | static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER; |
| 212 | |
| 213 | static void(*findProcAddress(const char* name, |
| 214 | const extention_map_t* map, size_t n))() { |
| 215 | for (uint32_t i=0 ; i<n ; i++) { |
| 216 | if (!strcmp(name, map[i].name)) { |
| 217 | return map[i].address; |
| 218 | } |
| 219 | } |
| 220 | return NULL; |
| 221 | } |
| 222 | |
| 223 | // ---------------------------------------------------------------------------- |
| 224 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 225 | extern void setGLHooksThreadSpecific(gl_hooks_t const *value); |
| 226 | extern EGLBoolean egl_init_drivers(); |
| 227 | extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; |
Siva Velusamy | a73a977 | 2012-12-18 14:56:55 -0800 | [diff] [blame] | 228 | extern int getEGLDebugLevel(); |
| 229 | extern void setEGLDebugLevel(int level); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 230 | extern gl_hooks_t gHooksTrace; |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 231 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 232 | } // namespace android; |
| 233 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 234 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 235 | // ---------------------------------------------------------------------------- |
| 236 | |
| 237 | static inline void clearError() { egl_tls_t::clearError(); } |
| 238 | static inline EGLContext getContext() { return egl_tls_t::getContext(); } |
| 239 | |
| 240 | // ---------------------------------------------------------------------------- |
| 241 | |
| 242 | EGLDisplay eglGetDisplay(EGLNativeDisplayType display) |
| 243 | { |
| 244 | clearError(); |
| 245 | |
Dan Stoza | c3289c4 | 2014-01-17 11:38:34 -0800 | [diff] [blame] | 246 | uintptr_t index = reinterpret_cast<uintptr_t>(display); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 247 | if (index >= NUM_DISPLAYS) { |
| 248 | return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); |
| 249 | } |
| 250 | |
| 251 | if (egl_init_drivers() == EGL_FALSE) { |
| 252 | return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); |
| 253 | } |
| 254 | |
| 255 | EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display); |
| 256 | return dpy; |
| 257 | } |
| 258 | |
| 259 | // ---------------------------------------------------------------------------- |
| 260 | // Initialization |
| 261 | // ---------------------------------------------------------------------------- |
| 262 | |
| 263 | EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) |
| 264 | { |
| 265 | clearError(); |
| 266 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 267 | egl_display_ptr dp = get_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 268 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 269 | |
| 270 | EGLBoolean res = dp->initialize(major, minor); |
| 271 | |
| 272 | return res; |
| 273 | } |
| 274 | |
| 275 | EGLBoolean eglTerminate(EGLDisplay dpy) |
| 276 | { |
| 277 | // NOTE: don't unload the drivers b/c some APIs can be called |
| 278 | // after eglTerminate() has been called. eglTerminate() only |
| 279 | // terminates an EGLDisplay, not a EGL itself. |
| 280 | |
| 281 | clearError(); |
| 282 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 283 | egl_display_ptr dp = get_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 284 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 285 | |
| 286 | EGLBoolean res = dp->terminate(); |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 287 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 288 | return res; |
| 289 | } |
| 290 | |
| 291 | // ---------------------------------------------------------------------------- |
| 292 | // configuration |
| 293 | // ---------------------------------------------------------------------------- |
| 294 | |
| 295 | EGLBoolean eglGetConfigs( EGLDisplay dpy, |
| 296 | EGLConfig *configs, |
| 297 | EGLint config_size, EGLint *num_config) |
| 298 | { |
| 299 | clearError(); |
| 300 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 301 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 302 | if (!dp) return EGL_FALSE; |
| 303 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 304 | if (num_config==0) { |
| 305 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 308 | EGLBoolean res = EGL_FALSE; |
| 309 | *num_config = 0; |
| 310 | |
| 311 | egl_connection_t* const cnx = &gEGLImpl; |
| 312 | if (cnx->dso) { |
| 313 | res = cnx->egl.eglGetConfigs( |
| 314 | dp->disp.dpy, configs, config_size, num_config); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 315 | } |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 316 | |
| 317 | return res; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, |
| 321 | EGLConfig *configs, EGLint config_size, |
| 322 | EGLint *num_config) |
| 323 | { |
| 324 | clearError(); |
| 325 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 326 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 327 | if (!dp) return EGL_FALSE; |
| 328 | |
| 329 | if (num_config==0) { |
| 330 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 331 | } |
| 332 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 333 | EGLBoolean res = EGL_FALSE; |
| 334 | *num_config = 0; |
| 335 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 336 | egl_connection_t* const cnx = &gEGLImpl; |
| 337 | if (cnx->dso) { |
Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 338 | if (attrib_list) { |
| 339 | char value[PROPERTY_VALUE_MAX]; |
| 340 | property_get("debug.egl.force_msaa", value, "false"); |
| 341 | |
| 342 | if (!strcmp(value, "true")) { |
| 343 | size_t attribCount = 0; |
| 344 | EGLint attrib = attrib_list[0]; |
| 345 | |
| 346 | // Only enable MSAA if the context is OpenGL ES 2.0 and |
Romain Guy | be3c3e4 | 2012-10-15 19:25:18 -0700 | [diff] [blame] | 347 | // if no caveat is requested |
Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 348 | const EGLint *attribRendererable = NULL; |
| 349 | const EGLint *attribCaveat = NULL; |
| 350 | |
| 351 | // Count the number of attributes and look for |
Romain Guy | be3c3e4 | 2012-10-15 19:25:18 -0700 | [diff] [blame] | 352 | // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT |
Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 353 | while (attrib != EGL_NONE) { |
| 354 | attrib = attrib_list[attribCount]; |
| 355 | switch (attrib) { |
| 356 | case EGL_RENDERABLE_TYPE: |
| 357 | attribRendererable = &attrib_list[attribCount]; |
| 358 | break; |
| 359 | case EGL_CONFIG_CAVEAT: |
| 360 | attribCaveat = &attrib_list[attribCount]; |
| 361 | break; |
| 362 | } |
| 363 | attribCount++; |
| 364 | } |
| 365 | |
| 366 | if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT && |
| 367 | (!attribCaveat || attribCaveat[1] != EGL_NONE)) { |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 368 | |
Romain Guy | 1cffc80 | 2012-10-15 18:13:05 -0700 | [diff] [blame] | 369 | // Insert 2 extra attributes to force-enable MSAA 4x |
| 370 | EGLint aaAttribs[attribCount + 4]; |
| 371 | aaAttribs[0] = EGL_SAMPLE_BUFFERS; |
| 372 | aaAttribs[1] = 1; |
| 373 | aaAttribs[2] = EGL_SAMPLES; |
| 374 | aaAttribs[3] = 4; |
| 375 | |
| 376 | memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint)); |
| 377 | |
| 378 | EGLint numConfigAA; |
| 379 | EGLBoolean resAA = cnx->egl.eglChooseConfig( |
| 380 | dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA); |
| 381 | |
| 382 | if (resAA == EGL_TRUE && numConfigAA > 0) { |
| 383 | ALOGD("Enabling MSAA 4x"); |
| 384 | *num_config = numConfigAA; |
| 385 | return resAA; |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 391 | res = cnx->egl.eglChooseConfig( |
| 392 | dp->disp.dpy, attrib_list, configs, config_size, num_config); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 393 | } |
| 394 | return res; |
| 395 | } |
| 396 | |
| 397 | EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, |
| 398 | EGLint attribute, EGLint *value) |
| 399 | { |
| 400 | clearError(); |
| 401 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 402 | egl_connection_t* cnx = NULL; |
| 403 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 404 | if (!dp) return EGL_FALSE; |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 405 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 406 | return cnx->egl.eglGetConfigAttrib( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 407 | dp->disp.dpy, config, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | // ---------------------------------------------------------------------------- |
| 411 | // surfaces |
| 412 | // ---------------------------------------------------------------------------- |
| 413 | |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 414 | // Turn linear formats into corresponding sRGB formats when colorspace is |
| 415 | // EGL_GL_COLORSPACE_SRGB_KHR, or turn sRGB formats into corresponding linear |
| 416 | // formats when colorspace is EGL_GL_COLORSPACE_LINEAR_KHR. In any cases where |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 417 | // the modification isn't possible, the original dataSpace is returned. |
| 418 | static android_dataspace modifyBufferDataspace( android_dataspace dataSpace, |
| 419 | EGLint colorspace) { |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 420 | if (colorspace == EGL_GL_COLORSPACE_LINEAR_KHR) { |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 421 | return HAL_DATASPACE_SRGB_LINEAR; |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 422 | } else if (colorspace == EGL_GL_COLORSPACE_SRGB_KHR) { |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 423 | return HAL_DATASPACE_SRGB; |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 424 | } |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 425 | return dataSpace; |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 428 | EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, |
| 429 | NativeWindowType window, |
| 430 | const EGLint *attrib_list) |
| 431 | { |
| 432 | clearError(); |
| 433 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 434 | egl_connection_t* cnx = NULL; |
| 435 | egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 436 | if (dp) { |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 437 | EGLDisplay iDpy = dp->disp.dpy; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 438 | |
Andy McFadden | d566ce3 | 2014-01-07 15:54:17 -0800 | [diff] [blame] | 439 | int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL); |
| 440 | if (result != OK) { |
| 441 | ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) " |
| 442 | "failed (%#x) (already connected to another API?)", |
| 443 | window, result); |
Jonathan Hamilton | 77a9b4a | 2013-07-17 09:41:42 -0700 | [diff] [blame] | 444 | return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); |
Mathias Agopian | 81a6335 | 2011-07-29 17:55:48 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Mathias Agopian | 0f288fc | 2013-08-21 16:36:34 -0700 | [diff] [blame] | 447 | // Set the native window's buffers format to match what this config requests. |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 448 | // Whether to use sRGB gamma is not part of the EGLconfig, but is part |
| 449 | // of our native format. So if sRGB gamma is requested, we have to |
| 450 | // modify the EGLconfig's format before setting the native window's |
| 451 | // format. |
Alistair Strachan | 733a807 | 2015-02-12 12:33:25 -0800 | [diff] [blame] | 452 | |
Mathias Agopian | 0f288fc | 2013-08-21 16:36:34 -0700 | [diff] [blame] | 453 | // by default, just pick RGBA_8888 |
| 454 | EGLint format = HAL_PIXEL_FORMAT_RGBA_8888; |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 455 | android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN; |
Mathias Agopian | 0f288fc | 2013-08-21 16:36:34 -0700 | [diff] [blame] | 456 | |
| 457 | EGLint a = 0; |
| 458 | cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a); |
| 459 | if (a > 0) { |
| 460 | // alpha-channel requested, there's really only one suitable format |
| 461 | format = HAL_PIXEL_FORMAT_RGBA_8888; |
| 462 | } else { |
| 463 | EGLint r, g, b; |
| 464 | r = g = b = 0; |
| 465 | cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_RED_SIZE, &r); |
| 466 | cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_GREEN_SIZE, &g); |
| 467 | cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_BLUE_SIZE, &b); |
| 468 | EGLint colorDepth = r + g + b; |
| 469 | if (colorDepth <= 16) { |
| 470 | format = HAL_PIXEL_FORMAT_RGB_565; |
| 471 | } else { |
| 472 | format = HAL_PIXEL_FORMAT_RGBX_8888; |
| 473 | } |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 474 | } |
Mathias Agopian | 0f288fc | 2013-08-21 16:36:34 -0700 | [diff] [blame] | 475 | |
| 476 | // now select a corresponding sRGB format if needed |
| 477 | if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) { |
| 478 | for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) { |
| 479 | if (*attr == EGL_GL_COLORSPACE_KHR) { |
Sandeep Shinde | 9c67bfd | 2015-02-10 16:04:15 +0530 | [diff] [blame^] | 480 | dataSpace = modifyBufferDataspace(dataSpace, *(attr+1)); |
Jamie Gennis | bee205f | 2011-07-01 13:12:07 -0700 | [diff] [blame] | 481 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 482 | } |
| 483 | } |
Alistair Strachan | 733a807 | 2015-02-12 12:33:25 -0800 | [diff] [blame] | 484 | |
Jesse Hall | c2e4122 | 2013-08-08 13:40:22 -0700 | [diff] [blame] | 485 | if (format != 0) { |
| 486 | int err = native_window_set_buffers_format(window, format); |
| 487 | if (err != 0) { |
| 488 | ALOGE("error setting native window pixel format: %s (%d)", |
| 489 | strerror(-err), err); |
| 490 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); |
| 491 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); |
| 492 | } |
| 493 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 494 | |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 495 | if (dataSpace != 0) { |
| 496 | int err = native_window_set_buffers_data_space(window, dataSpace); |
| 497 | if (err != 0) { |
| 498 | ALOGE("error setting native window pixel dataSpace: %s (%d)", |
| 499 | strerror(-err), err); |
| 500 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); |
| 501 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); |
| 502 | } |
| 503 | } |
| 504 | |
Jamie Gennis | 5976946 | 2011-11-19 18:04:43 -0800 | [diff] [blame] | 505 | // the EGL spec requires that a new EGLSurface default to swap interval |
| 506 | // 1, so explicitly set that on the window here. |
| 507 | ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window); |
| 508 | anw->setSwapInterval(anw, 1); |
| 509 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 510 | EGLSurface surface = cnx->egl.eglCreateWindowSurface( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 511 | iDpy, config, window, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 512 | if (surface != EGL_NO_SURFACE) { |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 513 | egl_surface_t* s = new egl_surface_t(dp.get(), config, window, |
| 514 | surface, cnx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 515 | return s; |
| 516 | } |
Mathias Agopian | 81a6335 | 2011-07-29 17:55:48 -0700 | [diff] [blame] | 517 | |
| 518 | // EGLSurface creation failed |
| 519 | native_window_set_buffers_format(window, 0); |
| 520 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 521 | } |
| 522 | return EGL_NO_SURFACE; |
| 523 | } |
| 524 | |
| 525 | EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config, |
| 526 | NativePixmapType pixmap, |
| 527 | const EGLint *attrib_list) |
| 528 | { |
| 529 | clearError(); |
| 530 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 531 | egl_connection_t* cnx = NULL; |
| 532 | egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 533 | if (dp) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 534 | EGLSurface surface = cnx->egl.eglCreatePixmapSurface( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 535 | dp->disp.dpy, config, pixmap, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 536 | if (surface != EGL_NO_SURFACE) { |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 537 | egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, |
| 538 | surface, cnx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 539 | return s; |
| 540 | } |
| 541 | } |
| 542 | return EGL_NO_SURFACE; |
| 543 | } |
| 544 | |
| 545 | EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, |
| 546 | const EGLint *attrib_list) |
| 547 | { |
| 548 | clearError(); |
| 549 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 550 | egl_connection_t* cnx = NULL; |
| 551 | egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 552 | if (dp) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 553 | EGLSurface surface = cnx->egl.eglCreatePbufferSurface( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 554 | dp->disp.dpy, config, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 555 | if (surface != EGL_NO_SURFACE) { |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 556 | egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, |
| 557 | surface, cnx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 558 | return s; |
| 559 | } |
| 560 | } |
| 561 | return EGL_NO_SURFACE; |
| 562 | } |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 563 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 564 | EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) |
| 565 | { |
| 566 | clearError(); |
| 567 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 568 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 569 | if (!dp) return EGL_FALSE; |
| 570 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 571 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 572 | if (!_s.get()) |
| 573 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 574 | |
| 575 | egl_surface_t * const s = get_surface(surface); |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 576 | EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 577 | if (result == EGL_TRUE) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 578 | _s.terminate(); |
| 579 | } |
| 580 | return result; |
| 581 | } |
| 582 | |
| 583 | EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, |
| 584 | EGLint attribute, EGLint *value) |
| 585 | { |
| 586 | clearError(); |
| 587 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 588 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 589 | if (!dp) return EGL_FALSE; |
| 590 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 591 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 592 | if (!_s.get()) |
| 593 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 594 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 595 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 596 | return s->cnx->egl.eglQuerySurface( |
| 597 | dp->disp.dpy, s->surface, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 600 | void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 601 | ATRACE_CALL(); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 602 | clearError(); |
| 603 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 604 | const egl_display_ptr dp = validate_display(dpy); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 605 | if (!dp) { |
| 606 | return; |
| 607 | } |
| 608 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 609 | SurfaceRef _s(dp.get(), surface); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 610 | if (!_s.get()) { |
| 611 | setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 612 | return; |
| 613 | } |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 614 | } |
| 615 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 616 | // ---------------------------------------------------------------------------- |
| 617 | // Contexts |
| 618 | // ---------------------------------------------------------------------------- |
| 619 | |
| 620 | EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, |
| 621 | EGLContext share_list, const EGLint *attrib_list) |
| 622 | { |
| 623 | clearError(); |
| 624 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 625 | egl_connection_t* cnx = NULL; |
| 626 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 627 | if (dp) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 628 | if (share_list != EGL_NO_CONTEXT) { |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 629 | if (!ContextRef(dp.get(), share_list).get()) { |
| 630 | return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT); |
| 631 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 632 | egl_context_t* const c = get_context(share_list); |
| 633 | share_list = c->context; |
| 634 | } |
| 635 | EGLContext context = cnx->egl.eglCreateContext( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 636 | dp->disp.dpy, config, share_list, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 637 | if (context != EGL_NO_CONTEXT) { |
| 638 | // figure out if it's a GLESv1 or GLESv2 |
| 639 | int version = 0; |
| 640 | if (attrib_list) { |
| 641 | while (*attrib_list != EGL_NONE) { |
| 642 | GLint attr = *attrib_list++; |
| 643 | GLint value = *attrib_list++; |
| 644 | if (attr == EGL_CONTEXT_CLIENT_VERSION) { |
| 645 | if (value == 1) { |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 646 | version = egl_connection_t::GLESv1_INDEX; |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 647 | } else if (value == 2 || value == 3) { |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 648 | version = egl_connection_t::GLESv2_INDEX; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | }; |
| 652 | } |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 653 | egl_context_t* c = new egl_context_t(dpy, context, config, cnx, |
| 654 | version); |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 655 | #if EGL_TRACE |
Siva Velusamy | a73a977 | 2012-12-18 14:56:55 -0800 | [diff] [blame] | 656 | if (getEGLDebugLevel() > 0) |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 657 | GLTrace_eglCreateContext(version, c); |
| 658 | #endif |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 659 | return c; |
| 660 | } |
| 661 | } |
| 662 | return EGL_NO_CONTEXT; |
| 663 | } |
| 664 | |
| 665 | EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) |
| 666 | { |
| 667 | clearError(); |
| 668 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 669 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 670 | if (!dp) |
| 671 | return EGL_FALSE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 672 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 673 | ContextRef _c(dp.get(), ctx); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 674 | if (!_c.get()) |
| 675 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 676 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 677 | egl_context_t * const c = get_context(ctx); |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 678 | EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 679 | if (result == EGL_TRUE) { |
| 680 | _c.terminate(); |
| 681 | } |
| 682 | return result; |
| 683 | } |
| 684 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 685 | EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, |
| 686 | EGLSurface read, EGLContext ctx) |
| 687 | { |
| 688 | clearError(); |
| 689 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 690 | egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 691 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 692 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 693 | // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not |
| 694 | // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is |
| 695 | // a valid but uninitialized display. |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 696 | if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || |
| 697 | (draw != EGL_NO_SURFACE) ) { |
| 698 | if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE); |
| 699 | } |
| 700 | |
| 701 | // get a reference to the object passed in |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 702 | ContextRef _c(dp.get(), ctx); |
| 703 | SurfaceRef _d(dp.get(), draw); |
| 704 | SurfaceRef _r(dp.get(), read); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 705 | |
| 706 | // validate the context (if not EGL_NO_CONTEXT) |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 707 | if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 708 | // EGL_NO_CONTEXT is valid |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 709 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | // these are the underlying implementation's object |
| 713 | EGLContext impl_ctx = EGL_NO_CONTEXT; |
| 714 | EGLSurface impl_draw = EGL_NO_SURFACE; |
| 715 | EGLSurface impl_read = EGL_NO_SURFACE; |
| 716 | |
| 717 | // these are our objects structs passed in |
| 718 | egl_context_t * c = NULL; |
| 719 | egl_surface_t const * d = NULL; |
| 720 | egl_surface_t const * r = NULL; |
| 721 | |
| 722 | // these are the current objects structs |
| 723 | egl_context_t * cur_c = get_context(getContext()); |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 724 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 725 | if (ctx != EGL_NO_CONTEXT) { |
| 726 | c = get_context(ctx); |
| 727 | impl_ctx = c->context; |
| 728 | } else { |
| 729 | // no context given, use the implementation of the current context |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 730 | if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) { |
| 731 | // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT); |
| 732 | return setError(EGL_BAD_MATCH, EGL_FALSE); |
| 733 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 734 | if (cur_c == NULL) { |
| 735 | // no current context |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 736 | // not an error, there is just no current context. |
| 737 | return EGL_TRUE; |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | // retrieve the underlying implementation's draw EGLSurface |
| 742 | if (draw != EGL_NO_SURFACE) { |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 743 | if (!_d.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 744 | d = get_surface(draw); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 745 | impl_draw = d->surface; |
| 746 | } |
| 747 | |
| 748 | // retrieve the underlying implementation's read EGLSurface |
| 749 | if (read != EGL_NO_SURFACE) { |
Michael Chock | 0673e1e | 2012-06-21 12:53:17 -0700 | [diff] [blame] | 750 | if (!_r.get()) return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 751 | r = get_surface(read); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 752 | impl_read = r->surface; |
| 753 | } |
| 754 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 755 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 756 | EGLBoolean result = dp->makeCurrent(c, cur_c, |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 757 | draw, read, ctx, |
| 758 | impl_draw, impl_read, impl_ctx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 759 | |
| 760 | if (result == EGL_TRUE) { |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 761 | if (c) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 762 | setGLHooksThreadSpecific(c->cnx->hooks[c->version]); |
| 763 | egl_tls_t::setContext(ctx); |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 764 | #if EGL_TRACE |
Siva Velusamy | a73a977 | 2012-12-18 14:56:55 -0800 | [diff] [blame] | 765 | if (getEGLDebugLevel() > 0) |
Siva Velusamy | 93a826f | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 766 | GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 767 | #endif |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 768 | _c.acquire(); |
| 769 | _r.acquire(); |
| 770 | _d.acquire(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 771 | } else { |
| 772 | setGLHooksThreadSpecific(&gHooksNoContext); |
| 773 | egl_tls_t::setContext(EGL_NO_CONTEXT); |
| 774 | } |
Mathias Agopian | 5fecea7 | 2011-08-25 18:38:24 -0700 | [diff] [blame] | 775 | } else { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 776 | // this will ALOGE the error |
Mathias Agopian | 63108c3 | 2013-09-06 13:36:49 -0700 | [diff] [blame] | 777 | egl_connection_t* const cnx = &gEGLImpl; |
| 778 | result = setError(cnx->egl.eglGetError(), EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 779 | } |
| 780 | return result; |
| 781 | } |
| 782 | |
| 783 | |
| 784 | EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, |
| 785 | EGLint attribute, EGLint *value) |
| 786 | { |
| 787 | clearError(); |
| 788 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 789 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 790 | if (!dp) return EGL_FALSE; |
| 791 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 792 | ContextRef _c(dp.get(), ctx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 793 | if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 794 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 795 | egl_context_t * const c = get_context(ctx); |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 796 | return c->cnx->egl.eglQueryContext( |
| 797 | dp->disp.dpy, c->context, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 798 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | EGLContext eglGetCurrentContext(void) |
| 802 | { |
| 803 | // could be called before eglInitialize(), but we wouldn't have a context |
| 804 | // then, and this function would correctly return EGL_NO_CONTEXT. |
| 805 | |
| 806 | clearError(); |
| 807 | |
| 808 | EGLContext ctx = getContext(); |
| 809 | return ctx; |
| 810 | } |
| 811 | |
| 812 | EGLSurface eglGetCurrentSurface(EGLint readdraw) |
| 813 | { |
| 814 | // could be called before eglInitialize(), but we wouldn't have a context |
| 815 | // then, and this function would correctly return EGL_NO_SURFACE. |
| 816 | |
| 817 | clearError(); |
| 818 | |
| 819 | EGLContext ctx = getContext(); |
| 820 | if (ctx) { |
| 821 | egl_context_t const * const c = get_context(ctx); |
| 822 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); |
| 823 | switch (readdraw) { |
| 824 | case EGL_READ: return c->read; |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 825 | case EGL_DRAW: return c->draw; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 826 | default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); |
| 827 | } |
| 828 | } |
| 829 | return EGL_NO_SURFACE; |
| 830 | } |
| 831 | |
| 832 | EGLDisplay eglGetCurrentDisplay(void) |
| 833 | { |
| 834 | // could be called before eglInitialize(), but we wouldn't have a context |
| 835 | // then, and this function would correctly return EGL_NO_DISPLAY. |
| 836 | |
| 837 | clearError(); |
| 838 | |
| 839 | EGLContext ctx = getContext(); |
| 840 | if (ctx) { |
| 841 | egl_context_t const * const c = get_context(ctx); |
| 842 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); |
| 843 | return c->dpy; |
| 844 | } |
| 845 | return EGL_NO_DISPLAY; |
| 846 | } |
| 847 | |
| 848 | EGLBoolean eglWaitGL(void) |
| 849 | { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 850 | clearError(); |
| 851 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 852 | egl_connection_t* const cnx = &gEGLImpl; |
| 853 | if (!cnx->dso) |
| 854 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 855 | |
| 856 | return cnx->egl.eglWaitGL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | EGLBoolean eglWaitNative(EGLint engine) |
| 860 | { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 861 | clearError(); |
| 862 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 863 | egl_connection_t* const cnx = &gEGLImpl; |
| 864 | if (!cnx->dso) |
| 865 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 866 | |
| 867 | return cnx->egl.eglWaitNative(engine); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | EGLint eglGetError(void) |
| 871 | { |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 872 | EGLint err = EGL_SUCCESS; |
| 873 | egl_connection_t* const cnx = &gEGLImpl; |
| 874 | if (cnx->dso) { |
| 875 | err = cnx->egl.eglGetError(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 876 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 877 | if (err == EGL_SUCCESS) { |
| 878 | err = egl_tls_t::getError(); |
| 879 | } |
| 880 | return err; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame] | 883 | static __eglMustCastToProperFunctionPointerType findBuiltinWrapper( |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 884 | const char* procname) { |
| 885 | const egl_connection_t* cnx = &gEGLImpl; |
| 886 | void* proc = NULL; |
| 887 | |
Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame] | 888 | proc = dlsym(cnx->libEgl, procname); |
| 889 | if (proc) return (__eglMustCastToProperFunctionPointerType)proc; |
| 890 | |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 891 | proc = dlsym(cnx->libGles2, procname); |
| 892 | if (proc) return (__eglMustCastToProperFunctionPointerType)proc; |
| 893 | |
| 894 | proc = dlsym(cnx->libGles1, procname); |
| 895 | if (proc) return (__eglMustCastToProperFunctionPointerType)proc; |
| 896 | |
| 897 | return NULL; |
| 898 | } |
| 899 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 900 | __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) |
| 901 | { |
| 902 | // eglGetProcAddress() could be the very first function called |
| 903 | // in which case we must make sure we've initialized ourselves, this |
| 904 | // happens the first time egl_get_display() is called. |
| 905 | |
| 906 | clearError(); |
| 907 | |
| 908 | if (egl_init_drivers() == EGL_FALSE) { |
| 909 | setError(EGL_BAD_PARAMETER, NULL); |
| 910 | return NULL; |
| 911 | } |
| 912 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 913 | if (FILTER_EXTENSIONS(procname)) { |
Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 914 | return NULL; |
| 915 | } |
| 916 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 917 | __eglMustCastToProperFunctionPointerType addr; |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 918 | addr = findProcAddress(procname, sExtensionMap, NELEM(sExtensionMap)); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 919 | if (addr) return addr; |
| 920 | |
Michael Chock | c0ec5e2 | 2014-01-27 08:14:33 -0800 | [diff] [blame] | 921 | addr = findBuiltinWrapper(procname); |
Jesse Hall | c07b520 | 2013-07-04 12:08:16 -0700 | [diff] [blame] | 922 | if (addr) return addr; |
Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 923 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 924 | // this protects accesses to sGLExtentionMap and sGLExtentionSlot |
| 925 | pthread_mutex_lock(&sExtensionMapMutex); |
| 926 | |
| 927 | /* |
| 928 | * Since eglGetProcAddress() is not associated to anything, it needs |
| 929 | * to return a function pointer that "works" regardless of what |
| 930 | * the current context is. |
| 931 | * |
| 932 | * For this reason, we return a "forwarder", a small stub that takes |
| 933 | * care of calling the function associated with the context |
| 934 | * currently bound. |
| 935 | * |
| 936 | * We first look for extensions we've already resolved, if we're seeing |
| 937 | * this extension for the first time, we go through all our |
| 938 | * implementations and call eglGetProcAddress() and record the |
| 939 | * result in the appropriate implementation hooks and return the |
| 940 | * address of the forwarder corresponding to that hook set. |
| 941 | * |
| 942 | */ |
| 943 | |
| 944 | const String8 name(procname); |
| 945 | addr = sGLExtentionMap.valueFor(name); |
| 946 | const int slot = sGLExtentionSlot; |
| 947 | |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 948 | ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS, |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 949 | "no more slots for eglGetProcAddress(\"%s\")", |
| 950 | procname); |
| 951 | |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 952 | #if EGL_TRACE |
| 953 | gl_hooks_t *debugHooks = GLTrace_getGLHooks(); |
| 954 | #endif |
| 955 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 956 | if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { |
| 957 | bool found = false; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 958 | |
| 959 | egl_connection_t* const cnx = &gEGLImpl; |
| 960 | if (cnx->dso && cnx->egl.eglGetProcAddress) { |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 961 | // Extensions are independent of the bound context |
luliuhui | 69d1007 | 2012-08-30 11:15:36 +0800 | [diff] [blame] | 962 | addr = |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 963 | cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = |
| 964 | cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 965 | #if EGL_TRACE |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 966 | debugHooks->ext.extensions[slot] = |
| 967 | gHooksTrace.ext.extensions[slot] = |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 968 | #endif |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 969 | cnx->egl.eglGetProcAddress(procname); |
luliuhui | 69d1007 | 2012-08-30 11:15:36 +0800 | [diff] [blame] | 970 | if (addr) found = true; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 971 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 972 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 973 | if (found) { |
| 974 | addr = gExtensionForwarders[slot]; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 975 | sGLExtentionMap.add(name, addr); |
| 976 | sGLExtentionSlot++; |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | pthread_mutex_unlock(&sExtensionMapMutex); |
| 981 | return addr; |
| 982 | } |
| 983 | |
Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 984 | class FrameCompletionThread : public Thread { |
| 985 | public: |
| 986 | |
| 987 | static void queueSync(EGLSyncKHR sync) { |
| 988 | static sp<FrameCompletionThread> thread(new FrameCompletionThread); |
| 989 | static bool running = false; |
| 990 | if (!running) { |
| 991 | thread->run("GPUFrameCompletion"); |
| 992 | running = true; |
| 993 | } |
| 994 | { |
| 995 | Mutex::Autolock lock(thread->mMutex); |
| 996 | ScopedTrace st(ATRACE_TAG, String8::format("kicked off frame %d", |
| 997 | thread->mFramesQueued).string()); |
| 998 | thread->mQueue.push_back(sync); |
| 999 | thread->mCondition.signal(); |
| 1000 | thread->mFramesQueued++; |
| 1001 | ATRACE_INT("GPU Frames Outstanding", thread->mQueue.size()); |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | private: |
| 1006 | FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {} |
| 1007 | |
| 1008 | virtual bool threadLoop() { |
| 1009 | EGLSyncKHR sync; |
| 1010 | uint32_t frameNum; |
| 1011 | { |
| 1012 | Mutex::Autolock lock(mMutex); |
| 1013 | while (mQueue.isEmpty()) { |
| 1014 | mCondition.wait(mMutex); |
| 1015 | } |
| 1016 | sync = mQueue[0]; |
| 1017 | frameNum = mFramesCompleted; |
| 1018 | } |
| 1019 | EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 1020 | { |
| 1021 | ScopedTrace st(ATRACE_TAG, String8::format("waiting for frame %d", |
| 1022 | frameNum).string()); |
| 1023 | EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR); |
| 1024 | if (result == EGL_FALSE) { |
| 1025 | ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError()); |
| 1026 | } else if (result == EGL_TIMEOUT_EXPIRED_KHR) { |
| 1027 | ALOGE("FrameCompletion: timeout waiting for fence"); |
| 1028 | } |
| 1029 | eglDestroySyncKHR(dpy, sync); |
| 1030 | } |
| 1031 | { |
| 1032 | Mutex::Autolock lock(mMutex); |
| 1033 | mQueue.removeAt(0); |
| 1034 | mFramesCompleted++; |
| 1035 | ATRACE_INT("GPU Frames Outstanding", mQueue.size()); |
| 1036 | } |
| 1037 | return true; |
| 1038 | } |
| 1039 | |
| 1040 | uint32_t mFramesQueued; |
| 1041 | uint32_t mFramesCompleted; |
| 1042 | Vector<EGLSyncKHR> mQueue; |
| 1043 | Condition mCondition; |
| 1044 | Mutex mMutex; |
| 1045 | }; |
| 1046 | |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 1047 | EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface draw, |
| 1048 | EGLint *rects, EGLint n_rects) |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1049 | { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 1050 | ATRACE_CALL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1051 | clearError(); |
| 1052 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1053 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1054 | if (!dp) return EGL_FALSE; |
| 1055 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1056 | SurfaceRef _s(dp.get(), draw); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1057 | if (!_s.get()) |
| 1058 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1059 | |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 1060 | #if EGL_TRACE |
Siva Velusamy | a73a977 | 2012-12-18 14:56:55 -0800 | [diff] [blame] | 1061 | gl_hooks_t const *trace_hooks = getGLTraceThreadSpecific(); |
| 1062 | if (getEGLDebugLevel() > 0) { |
| 1063 | if (trace_hooks == NULL) { |
| 1064 | if (GLTrace_start() < 0) { |
| 1065 | ALOGE("Disabling Tracer for OpenGL ES"); |
| 1066 | setEGLDebugLevel(0); |
| 1067 | } else { |
| 1068 | // switch over to the trace version of hooks |
| 1069 | EGLContext ctx = egl_tls_t::getContext(); |
| 1070 | egl_context_t * const c = get_context(ctx); |
| 1071 | if (c) { |
| 1072 | setGLHooksThreadSpecific(c->cnx->hooks[c->version]); |
| 1073 | GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); |
| 1074 | } |
| 1075 | } |
| 1076 | } |
| 1077 | |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 1078 | GLTrace_eglSwapBuffers(dpy, draw); |
Siva Velusamy | a73a977 | 2012-12-18 14:56:55 -0800 | [diff] [blame] | 1079 | } else if (trace_hooks != NULL) { |
| 1080 | // tracing is now disabled, so switch back to the non trace version |
| 1081 | EGLContext ctx = egl_tls_t::getContext(); |
| 1082 | egl_context_t * const c = get_context(ctx); |
| 1083 | if (c) setGLHooksThreadSpecific(c->cnx->hooks[c->version]); |
| 1084 | GLTrace_stop(); |
| 1085 | } |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 1086 | #endif |
| 1087 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1088 | egl_surface_t const * const s = get_surface(draw); |
Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 1089 | |
Mathias Agopian | ed6d08b | 2013-04-16 16:39:46 -0700 | [diff] [blame] | 1090 | if (CC_UNLIKELY(dp->traceGpuCompletion)) { |
| 1091 | EGLSyncKHR sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL); |
| 1092 | if (sync != EGL_NO_SYNC_KHR) { |
| 1093 | FrameCompletionThread::queueSync(sync); |
| 1094 | } |
| 1095 | } |
| 1096 | |
Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 1097 | if (CC_UNLIKELY(dp->finishOnSwap)) { |
| 1098 | uint32_t pixel; |
| 1099 | egl_context_t * const c = get_context( egl_tls_t::getContext() ); |
| 1100 | if (c) { |
| 1101 | // glReadPixels() ensures that the frame is complete |
| 1102 | s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1, |
| 1103 | GL_RGBA,GL_UNSIGNED_BYTE,&pixel); |
| 1104 | } |
| 1105 | } |
| 1106 | |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 1107 | if (n_rects == 0) { |
| 1108 | return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); |
| 1109 | } |
| 1110 | |
| 1111 | Vector<android_native_rect_t> androidRects; |
| 1112 | for (int r = 0; r < n_rects; ++r) { |
| 1113 | int offset = r * 4; |
| 1114 | int x = rects[offset]; |
| 1115 | int y = rects[offset + 1]; |
| 1116 | int width = rects[offset + 2]; |
| 1117 | int height = rects[offset + 3]; |
| 1118 | android_native_rect_t androidRect; |
| 1119 | androidRect.left = x; |
| 1120 | androidRect.top = y + height; |
| 1121 | androidRect.right = x + width; |
| 1122 | androidRect.bottom = y; |
| 1123 | androidRects.push_back(androidRect); |
| 1124 | } |
| 1125 | native_window_set_surface_damage(s->win.get(), androidRects.array(), |
| 1126 | androidRects.size()); |
| 1127 | |
| 1128 | if (s->cnx->egl.eglSwapBuffersWithDamageKHR) { |
| 1129 | return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface, |
| 1130 | rects, n_rects); |
| 1131 | } else { |
| 1132 | return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) |
| 1137 | { |
| 1138 | return eglSwapBuffersWithDamageKHR(dpy, surface, NULL, 0); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, |
| 1142 | NativePixmapType target) |
| 1143 | { |
| 1144 | clearError(); |
| 1145 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1146 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1147 | if (!dp) return EGL_FALSE; |
| 1148 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1149 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1150 | if (!_s.get()) |
| 1151 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1152 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1153 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1154 | return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | const char* eglQueryString(EGLDisplay dpy, EGLint name) |
| 1158 | { |
| 1159 | clearError(); |
| 1160 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1161 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1162 | if (!dp) return (const char *) NULL; |
| 1163 | |
| 1164 | switch (name) { |
| 1165 | case EGL_VENDOR: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1166 | return dp->getVendorString(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1167 | case EGL_VERSION: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1168 | return dp->getVersionString(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1169 | case EGL_EXTENSIONS: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1170 | return dp->getExtensionString(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1171 | case EGL_CLIENT_APIS: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 1172 | return dp->getClientApiString(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1173 | } |
| 1174 | return setError(EGL_BAD_PARAMETER, (const char *)0); |
| 1175 | } |
| 1176 | |
Mathias Agopian | ca08833 | 2013-03-28 17:44:13 -0700 | [diff] [blame] | 1177 | EGLAPI const char* eglQueryStringImplementationANDROID(EGLDisplay dpy, EGLint name) |
| 1178 | { |
| 1179 | clearError(); |
| 1180 | |
| 1181 | const egl_display_ptr dp = validate_display(dpy); |
| 1182 | if (!dp) return (const char *) NULL; |
| 1183 | |
| 1184 | switch (name) { |
| 1185 | case EGL_VENDOR: |
| 1186 | return dp->disp.queryString.vendor; |
| 1187 | case EGL_VERSION: |
| 1188 | return dp->disp.queryString.version; |
| 1189 | case EGL_EXTENSIONS: |
| 1190 | return dp->disp.queryString.extensions; |
| 1191 | case EGL_CLIENT_APIS: |
| 1192 | return dp->disp.queryString.clientApi; |
| 1193 | } |
| 1194 | return setError(EGL_BAD_PARAMETER, (const char *)0); |
| 1195 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1196 | |
| 1197 | // ---------------------------------------------------------------------------- |
| 1198 | // EGL 1.1 |
| 1199 | // ---------------------------------------------------------------------------- |
| 1200 | |
| 1201 | EGLBoolean eglSurfaceAttrib( |
| 1202 | EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) |
| 1203 | { |
| 1204 | clearError(); |
| 1205 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1206 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1207 | if (!dp) return EGL_FALSE; |
| 1208 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1209 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1210 | if (!_s.get()) |
| 1211 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1212 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1213 | egl_surface_t const * const s = get_surface(surface); |
| 1214 | if (s->cnx->egl.eglSurfaceAttrib) { |
| 1215 | return s->cnx->egl.eglSurfaceAttrib( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1216 | dp->disp.dpy, s->surface, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1217 | } |
| 1218 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1219 | } |
| 1220 | |
| 1221 | EGLBoolean eglBindTexImage( |
| 1222 | EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 1223 | { |
| 1224 | clearError(); |
| 1225 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1226 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1227 | if (!dp) return EGL_FALSE; |
| 1228 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1229 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1230 | if (!_s.get()) |
| 1231 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1232 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1233 | egl_surface_t const * const s = get_surface(surface); |
| 1234 | if (s->cnx->egl.eglBindTexImage) { |
| 1235 | return s->cnx->egl.eglBindTexImage( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1236 | dp->disp.dpy, s->surface, buffer); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1237 | } |
| 1238 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1239 | } |
| 1240 | |
| 1241 | EGLBoolean eglReleaseTexImage( |
| 1242 | EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 1243 | { |
| 1244 | clearError(); |
| 1245 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1246 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1247 | if (!dp) return EGL_FALSE; |
| 1248 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1249 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1250 | if (!_s.get()) |
| 1251 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1252 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1253 | egl_surface_t const * const s = get_surface(surface); |
| 1254 | if (s->cnx->egl.eglReleaseTexImage) { |
| 1255 | return s->cnx->egl.eglReleaseTexImage( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1256 | dp->disp.dpy, s->surface, buffer); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1257 | } |
| 1258 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1259 | } |
| 1260 | |
| 1261 | EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) |
| 1262 | { |
| 1263 | clearError(); |
| 1264 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1265 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1266 | if (!dp) return EGL_FALSE; |
| 1267 | |
| 1268 | EGLBoolean res = EGL_TRUE; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1269 | egl_connection_t* const cnx = &gEGLImpl; |
| 1270 | if (cnx->dso && cnx->egl.eglSwapInterval) { |
| 1271 | res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1272 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1273 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1274 | return res; |
| 1275 | } |
| 1276 | |
| 1277 | |
| 1278 | // ---------------------------------------------------------------------------- |
| 1279 | // EGL 1.2 |
| 1280 | // ---------------------------------------------------------------------------- |
| 1281 | |
| 1282 | EGLBoolean eglWaitClient(void) |
| 1283 | { |
| 1284 | clearError(); |
| 1285 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1286 | egl_connection_t* const cnx = &gEGLImpl; |
| 1287 | if (!cnx->dso) |
| 1288 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 1289 | |
| 1290 | EGLBoolean res; |
| 1291 | if (cnx->egl.eglWaitClient) { |
| 1292 | res = cnx->egl.eglWaitClient(); |
| 1293 | } else { |
| 1294 | res = cnx->egl.eglWaitGL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1295 | } |
| 1296 | return res; |
| 1297 | } |
| 1298 | |
| 1299 | EGLBoolean eglBindAPI(EGLenum api) |
| 1300 | { |
| 1301 | clearError(); |
| 1302 | |
| 1303 | if (egl_init_drivers() == EGL_FALSE) { |
| 1304 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1305 | } |
| 1306 | |
| 1307 | // bind this API on all EGLs |
| 1308 | EGLBoolean res = EGL_TRUE; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1309 | egl_connection_t* const cnx = &gEGLImpl; |
| 1310 | if (cnx->dso && cnx->egl.eglBindAPI) { |
| 1311 | res = cnx->egl.eglBindAPI(api); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1312 | } |
| 1313 | return res; |
| 1314 | } |
| 1315 | |
| 1316 | EGLenum eglQueryAPI(void) |
| 1317 | { |
| 1318 | clearError(); |
| 1319 | |
| 1320 | if (egl_init_drivers() == EGL_FALSE) { |
| 1321 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1322 | } |
| 1323 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1324 | egl_connection_t* const cnx = &gEGLImpl; |
| 1325 | if (cnx->dso && cnx->egl.eglQueryAPI) { |
| 1326 | return cnx->egl.eglQueryAPI(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1327 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1328 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1329 | // or, it can only be OpenGL ES |
| 1330 | return EGL_OPENGL_ES_API; |
| 1331 | } |
| 1332 | |
| 1333 | EGLBoolean eglReleaseThread(void) |
| 1334 | { |
| 1335 | clearError(); |
| 1336 | |
Mathias Agopian | 4e620dd | 2013-05-30 16:07:36 -0700 | [diff] [blame] | 1337 | #if EGL_TRACE |
| 1338 | if (getEGLDebugLevel() > 0) |
| 1339 | GLTrace_eglReleaseThread(); |
| 1340 | #endif |
| 1341 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1342 | // If there is context bound to the thread, release it |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 1343 | egl_display_t::loseCurrent(get_context(getContext())); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1344 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1345 | egl_connection_t* const cnx = &gEGLImpl; |
| 1346 | if (cnx->dso && cnx->egl.eglReleaseThread) { |
| 1347 | cnx->egl.eglReleaseThread(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1348 | } |
| 1349 | egl_tls_t::clearTLS(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1350 | return EGL_TRUE; |
| 1351 | } |
| 1352 | |
| 1353 | EGLSurface eglCreatePbufferFromClientBuffer( |
| 1354 | EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, |
| 1355 | EGLConfig config, const EGLint *attrib_list) |
| 1356 | { |
| 1357 | clearError(); |
| 1358 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1359 | egl_connection_t* cnx = NULL; |
| 1360 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 1361 | if (!dp) return EGL_FALSE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1362 | if (cnx->egl.eglCreatePbufferFromClientBuffer) { |
| 1363 | return cnx->egl.eglCreatePbufferFromClientBuffer( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 1364 | dp->disp.dpy, buftype, buffer, config, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1365 | } |
| 1366 | return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE); |
| 1367 | } |
| 1368 | |
| 1369 | // ---------------------------------------------------------------------------- |
| 1370 | // EGL_EGLEXT_VERSION 3 |
| 1371 | // ---------------------------------------------------------------------------- |
| 1372 | |
| 1373 | EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, |
| 1374 | const EGLint *attrib_list) |
| 1375 | { |
| 1376 | clearError(); |
| 1377 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1378 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1379 | if (!dp) return EGL_FALSE; |
| 1380 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1381 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1382 | if (!_s.get()) |
| 1383 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1384 | |
| 1385 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1386 | if (s->cnx->egl.eglLockSurfaceKHR) { |
| 1387 | return s->cnx->egl.eglLockSurfaceKHR( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1388 | dp->disp.dpy, s->surface, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1389 | } |
| 1390 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 1391 | } |
| 1392 | |
| 1393 | EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) |
| 1394 | { |
| 1395 | clearError(); |
| 1396 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1397 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1398 | if (!dp) return EGL_FALSE; |
| 1399 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1400 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1401 | if (!_s.get()) |
| 1402 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1403 | |
| 1404 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1405 | if (s->cnx->egl.eglUnlockSurfaceKHR) { |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1406 | return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1407 | } |
| 1408 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 1409 | } |
| 1410 | |
| 1411 | EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, |
| 1412 | EGLClientBuffer buffer, const EGLint *attrib_list) |
| 1413 | { |
| 1414 | clearError(); |
| 1415 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1416 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1417 | if (!dp) return EGL_NO_IMAGE_KHR; |
| 1418 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1419 | ContextRef _c(dp.get(), ctx); |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1420 | egl_context_t * const c = _c.get(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1421 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1422 | EGLImageKHR result = EGL_NO_IMAGE_KHR; |
| 1423 | egl_connection_t* const cnx = &gEGLImpl; |
| 1424 | if (cnx->dso && cnx->egl.eglCreateImageKHR) { |
| 1425 | result = cnx->egl.eglCreateImageKHR( |
| 1426 | dp->disp.dpy, |
| 1427 | c ? c->context : EGL_NO_CONTEXT, |
| 1428 | target, buffer, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1429 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1430 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) |
| 1434 | { |
| 1435 | clearError(); |
| 1436 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1437 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1438 | if (!dp) return EGL_FALSE; |
| 1439 | |
Steven Holte | 646a5c5 | 2012-06-04 20:02:11 -0700 | [diff] [blame] | 1440 | EGLBoolean result = EGL_FALSE; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1441 | egl_connection_t* const cnx = &gEGLImpl; |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1442 | if (cnx->dso && cnx->egl.eglDestroyImageKHR) { |
Steven Holte | 646a5c5 | 2012-06-04 20:02:11 -0700 | [diff] [blame] | 1443 | result = cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1444 | } |
Steven Holte | 646a5c5 | 2012-06-04 20:02:11 -0700 | [diff] [blame] | 1445 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | // ---------------------------------------------------------------------------- |
| 1449 | // EGL_EGLEXT_VERSION 5 |
| 1450 | // ---------------------------------------------------------------------------- |
| 1451 | |
| 1452 | |
| 1453 | EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) |
| 1454 | { |
| 1455 | clearError(); |
| 1456 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1457 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1458 | if (!dp) return EGL_NO_SYNC_KHR; |
| 1459 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1460 | EGLSyncKHR result = EGL_NO_SYNC_KHR; |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1461 | egl_connection_t* const cnx = &gEGLImpl; |
| 1462 | if (cnx->dso && cnx->egl.eglCreateSyncKHR) { |
| 1463 | result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1464 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1465 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) |
| 1469 | { |
| 1470 | clearError(); |
| 1471 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1472 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1473 | if (!dp) return EGL_FALSE; |
| 1474 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1475 | EGLBoolean result = EGL_FALSE; |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1476 | egl_connection_t* const cnx = &gEGLImpl; |
| 1477 | if (cnx->dso && cnx->egl.eglDestroySyncKHR) { |
| 1478 | result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1479 | } |
| 1480 | return result; |
| 1481 | } |
| 1482 | |
Mathias Agopian | e9b3dfb | 2013-03-27 14:30:19 -0700 | [diff] [blame] | 1483 | EGLBoolean eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) { |
| 1484 | clearError(); |
| 1485 | |
| 1486 | const egl_display_ptr dp = validate_display(dpy); |
| 1487 | if (!dp) return EGL_FALSE; |
| 1488 | |
| 1489 | EGLBoolean result = EGL_FALSE; |
| 1490 | egl_connection_t* const cnx = &gEGLImpl; |
| 1491 | if (cnx->dso && cnx->egl.eglSignalSyncKHR) { |
| 1492 | result = cnx->egl.eglSignalSyncKHR( |
| 1493 | dp->disp.dpy, sync, mode); |
| 1494 | } |
| 1495 | return result; |
| 1496 | } |
| 1497 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1498 | EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, |
| 1499 | EGLint flags, EGLTimeKHR timeout) |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1500 | { |
| 1501 | clearError(); |
| 1502 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1503 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1504 | if (!dp) return EGL_FALSE; |
| 1505 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1506 | EGLBoolean result = EGL_FALSE; |
| 1507 | egl_connection_t* const cnx = &gEGLImpl; |
| 1508 | if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) { |
| 1509 | result = cnx->egl.eglClientWaitSyncKHR( |
| 1510 | dp->disp.dpy, sync, flags, timeout); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1511 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1512 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1515 | EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, |
| 1516 | EGLint attribute, EGLint *value) |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1517 | { |
| 1518 | clearError(); |
| 1519 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1520 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1521 | if (!dp) return EGL_FALSE; |
| 1522 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1523 | EGLBoolean result = EGL_FALSE; |
| 1524 | egl_connection_t* const cnx = &gEGLImpl; |
| 1525 | if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) { |
| 1526 | result = cnx->egl.eglGetSyncAttribKHR( |
| 1527 | dp->disp.dpy, sync, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1528 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1529 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Season Li | 000d88f | 2015-07-01 11:39:40 -0700 | [diff] [blame] | 1532 | EGLStreamKHR eglCreateStreamKHR(EGLDisplay dpy, const EGLint *attrib_list) |
| 1533 | { |
| 1534 | clearError(); |
| 1535 | |
| 1536 | const egl_display_ptr dp = validate_display(dpy); |
| 1537 | if (!dp) return EGL_NO_STREAM_KHR; |
| 1538 | |
| 1539 | EGLStreamKHR result = EGL_NO_STREAM_KHR; |
| 1540 | egl_connection_t* const cnx = &gEGLImpl; |
| 1541 | if (cnx->dso && cnx->egl.eglCreateStreamKHR) { |
| 1542 | result = cnx->egl.eglCreateStreamKHR( |
| 1543 | dp->disp.dpy, attrib_list); |
| 1544 | } |
| 1545 | return result; |
| 1546 | } |
| 1547 | |
| 1548 | EGLBoolean eglDestroyStreamKHR(EGLDisplay dpy, EGLStreamKHR stream) |
| 1549 | { |
| 1550 | clearError(); |
| 1551 | |
| 1552 | const egl_display_ptr dp = validate_display(dpy); |
| 1553 | if (!dp) return EGL_FALSE; |
| 1554 | |
| 1555 | EGLBoolean result = EGL_FALSE; |
| 1556 | egl_connection_t* const cnx = &gEGLImpl; |
| 1557 | if (cnx->dso && cnx->egl.eglDestroyStreamKHR) { |
| 1558 | result = cnx->egl.eglDestroyStreamKHR( |
| 1559 | dp->disp.dpy, stream); |
| 1560 | } |
| 1561 | return result; |
| 1562 | } |
| 1563 | |
| 1564 | EGLBoolean eglStreamAttribKHR(EGLDisplay dpy, EGLStreamKHR stream, |
| 1565 | EGLenum attribute, EGLint value) |
| 1566 | { |
| 1567 | clearError(); |
| 1568 | |
| 1569 | const egl_display_ptr dp = validate_display(dpy); |
| 1570 | if (!dp) return EGL_FALSE; |
| 1571 | |
| 1572 | EGLBoolean result = EGL_FALSE; |
| 1573 | egl_connection_t* const cnx = &gEGLImpl; |
| 1574 | if (cnx->dso && cnx->egl.eglStreamAttribKHR) { |
| 1575 | result = cnx->egl.eglStreamAttribKHR( |
| 1576 | dp->disp.dpy, stream, attribute, value); |
| 1577 | } |
| 1578 | return result; |
| 1579 | } |
| 1580 | |
| 1581 | EGLBoolean eglQueryStreamKHR(EGLDisplay dpy, EGLStreamKHR stream, |
| 1582 | EGLenum attribute, EGLint *value) |
| 1583 | { |
| 1584 | clearError(); |
| 1585 | |
| 1586 | const egl_display_ptr dp = validate_display(dpy); |
| 1587 | if (!dp) return EGL_FALSE; |
| 1588 | |
| 1589 | EGLBoolean result = EGL_FALSE; |
| 1590 | egl_connection_t* const cnx = &gEGLImpl; |
| 1591 | if (cnx->dso && cnx->egl.eglQueryStreamKHR) { |
| 1592 | result = cnx->egl.eglQueryStreamKHR( |
| 1593 | dp->disp.dpy, stream, attribute, value); |
| 1594 | } |
| 1595 | return result; |
| 1596 | } |
| 1597 | |
| 1598 | EGLBoolean eglQueryStreamu64KHR(EGLDisplay dpy, EGLStreamKHR stream, |
| 1599 | EGLenum attribute, EGLuint64KHR *value) |
| 1600 | { |
| 1601 | clearError(); |
| 1602 | |
| 1603 | const egl_display_ptr dp = validate_display(dpy); |
| 1604 | if (!dp) return EGL_FALSE; |
| 1605 | |
| 1606 | EGLBoolean result = EGL_FALSE; |
| 1607 | egl_connection_t* const cnx = &gEGLImpl; |
| 1608 | if (cnx->dso && cnx->egl.eglQueryStreamu64KHR) { |
| 1609 | result = cnx->egl.eglQueryStreamu64KHR( |
| 1610 | dp->disp.dpy, stream, attribute, value); |
| 1611 | } |
| 1612 | return result; |
| 1613 | } |
| 1614 | |
| 1615 | EGLBoolean eglQueryStreamTimeKHR(EGLDisplay dpy, EGLStreamKHR stream, |
| 1616 | EGLenum attribute, EGLTimeKHR *value) |
| 1617 | { |
| 1618 | clearError(); |
| 1619 | |
| 1620 | const egl_display_ptr dp = validate_display(dpy); |
| 1621 | if (!dp) return EGL_FALSE; |
| 1622 | |
| 1623 | EGLBoolean result = EGL_FALSE; |
| 1624 | egl_connection_t* const cnx = &gEGLImpl; |
| 1625 | if (cnx->dso && cnx->egl.eglQueryStreamTimeKHR) { |
| 1626 | result = cnx->egl.eglQueryStreamTimeKHR( |
| 1627 | dp->disp.dpy, stream, attribute, value); |
| 1628 | } |
| 1629 | return result; |
| 1630 | } |
| 1631 | |
| 1632 | EGLSurface eglCreateStreamProducerSurfaceKHR(EGLDisplay dpy, EGLConfig config, |
| 1633 | EGLStreamKHR stream, const EGLint *attrib_list) |
| 1634 | { |
| 1635 | clearError(); |
| 1636 | |
| 1637 | egl_display_ptr dp = validate_display(dpy); |
| 1638 | if (!dp) return EGL_NO_SURFACE; |
| 1639 | |
| 1640 | egl_connection_t* const cnx = &gEGLImpl; |
| 1641 | if (cnx->dso && cnx->egl.eglCreateStreamProducerSurfaceKHR) { |
| 1642 | EGLSurface surface = cnx->egl.eglCreateStreamProducerSurfaceKHR( |
| 1643 | dp->disp.dpy, config, stream, attrib_list); |
| 1644 | if (surface != EGL_NO_SURFACE) { |
| 1645 | egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, |
| 1646 | surface, cnx); |
| 1647 | return s; |
| 1648 | } |
| 1649 | } |
| 1650 | return EGL_NO_SURFACE; |
| 1651 | } |
| 1652 | |
| 1653 | EGLBoolean eglStreamConsumerGLTextureExternalKHR(EGLDisplay dpy, |
| 1654 | EGLStreamKHR stream) |
| 1655 | { |
| 1656 | clearError(); |
| 1657 | |
| 1658 | const egl_display_ptr dp = validate_display(dpy); |
| 1659 | if (!dp) return EGL_FALSE; |
| 1660 | |
| 1661 | EGLBoolean result = EGL_FALSE; |
| 1662 | egl_connection_t* const cnx = &gEGLImpl; |
| 1663 | if (cnx->dso && cnx->egl.eglStreamConsumerGLTextureExternalKHR) { |
| 1664 | result = cnx->egl.eglStreamConsumerGLTextureExternalKHR( |
| 1665 | dp->disp.dpy, stream); |
| 1666 | } |
| 1667 | return result; |
| 1668 | } |
| 1669 | |
| 1670 | EGLBoolean eglStreamConsumerAcquireKHR(EGLDisplay dpy, |
| 1671 | EGLStreamKHR stream) |
| 1672 | { |
| 1673 | clearError(); |
| 1674 | |
| 1675 | const egl_display_ptr dp = validate_display(dpy); |
| 1676 | if (!dp) return EGL_FALSE; |
| 1677 | |
| 1678 | EGLBoolean result = EGL_FALSE; |
| 1679 | egl_connection_t* const cnx = &gEGLImpl; |
| 1680 | if (cnx->dso && cnx->egl.eglStreamConsumerAcquireKHR) { |
| 1681 | result = cnx->egl.eglStreamConsumerAcquireKHR( |
| 1682 | dp->disp.dpy, stream); |
| 1683 | } |
| 1684 | return result; |
| 1685 | } |
| 1686 | |
| 1687 | EGLBoolean eglStreamConsumerReleaseKHR(EGLDisplay dpy, |
| 1688 | EGLStreamKHR stream) |
| 1689 | { |
| 1690 | clearError(); |
| 1691 | |
| 1692 | const egl_display_ptr dp = validate_display(dpy); |
| 1693 | if (!dp) return EGL_FALSE; |
| 1694 | |
| 1695 | EGLBoolean result = EGL_FALSE; |
| 1696 | egl_connection_t* const cnx = &gEGLImpl; |
| 1697 | if (cnx->dso && cnx->egl.eglStreamConsumerReleaseKHR) { |
| 1698 | result = cnx->egl.eglStreamConsumerReleaseKHR( |
| 1699 | dp->disp.dpy, stream); |
| 1700 | } |
| 1701 | return result; |
| 1702 | } |
| 1703 | |
| 1704 | EGLNativeFileDescriptorKHR eglGetStreamFileDescriptorKHR( |
| 1705 | EGLDisplay dpy, EGLStreamKHR stream) |
| 1706 | { |
| 1707 | clearError(); |
| 1708 | |
| 1709 | const egl_display_ptr dp = validate_display(dpy); |
| 1710 | if (!dp) return EGL_NO_FILE_DESCRIPTOR_KHR; |
| 1711 | |
| 1712 | EGLNativeFileDescriptorKHR result = EGL_NO_FILE_DESCRIPTOR_KHR; |
| 1713 | egl_connection_t* const cnx = &gEGLImpl; |
| 1714 | if (cnx->dso && cnx->egl.eglGetStreamFileDescriptorKHR) { |
| 1715 | result = cnx->egl.eglGetStreamFileDescriptorKHR( |
| 1716 | dp->disp.dpy, stream); |
| 1717 | } |
| 1718 | return result; |
| 1719 | } |
| 1720 | |
| 1721 | EGLStreamKHR eglCreateStreamFromFileDescriptorKHR( |
| 1722 | EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor) |
| 1723 | { |
| 1724 | clearError(); |
| 1725 | |
| 1726 | const egl_display_ptr dp = validate_display(dpy); |
| 1727 | if (!dp) return EGL_NO_STREAM_KHR; |
| 1728 | |
| 1729 | EGLStreamKHR result = EGL_NO_STREAM_KHR; |
| 1730 | egl_connection_t* const cnx = &gEGLImpl; |
| 1731 | if (cnx->dso && cnx->egl.eglCreateStreamFromFileDescriptorKHR) { |
| 1732 | result = cnx->egl.eglCreateStreamFromFileDescriptorKHR( |
| 1733 | dp->disp.dpy, file_descriptor); |
| 1734 | } |
| 1735 | return result; |
| 1736 | } |
| 1737 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1738 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 2bb7168 | 2013-03-27 17:32:41 -0700 | [diff] [blame] | 1739 | // EGL_EGLEXT_VERSION 15 |
| 1740 | // ---------------------------------------------------------------------------- |
| 1741 | |
| 1742 | EGLint eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) { |
| 1743 | clearError(); |
| 1744 | const egl_display_ptr dp = validate_display(dpy); |
| 1745 | if (!dp) return EGL_FALSE; |
| 1746 | EGLint result = EGL_FALSE; |
| 1747 | egl_connection_t* const cnx = &gEGLImpl; |
| 1748 | if (cnx->dso && cnx->egl.eglWaitSyncKHR) { |
| 1749 | result = cnx->egl.eglWaitSyncKHR(dp->disp.dpy, sync, flags); |
| 1750 | } |
| 1751 | return result; |
| 1752 | } |
| 1753 | |
| 1754 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1755 | // ANDROID extensions |
| 1756 | // ---------------------------------------------------------------------------- |
| 1757 | |
Jamie Gennis | 331841b | 2012-09-06 14:52:00 -0700 | [diff] [blame] | 1758 | EGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync) |
| 1759 | { |
| 1760 | clearError(); |
| 1761 | |
| 1762 | const egl_display_ptr dp = validate_display(dpy); |
| 1763 | if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID; |
| 1764 | |
| 1765 | EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID; |
| 1766 | egl_connection_t* const cnx = &gEGLImpl; |
| 1767 | if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) { |
| 1768 | result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync); |
| 1769 | } |
| 1770 | return result; |
| 1771 | } |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1772 | |
Andy McFadden | 7284145 | 2013-03-01 16:25:32 -0800 | [diff] [blame] | 1773 | EGLBoolean eglPresentationTimeANDROID(EGLDisplay dpy, EGLSurface surface, |
| 1774 | EGLnsecsANDROID time) |
| 1775 | { |
| 1776 | clearError(); |
| 1777 | |
| 1778 | const egl_display_ptr dp = validate_display(dpy); |
| 1779 | if (!dp) { |
| 1780 | return EGL_FALSE; |
| 1781 | } |
| 1782 | |
| 1783 | SurfaceRef _s(dp.get(), surface); |
| 1784 | if (!_s.get()) { |
| 1785 | setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1786 | return EGL_FALSE; |
| 1787 | } |
| 1788 | |
| 1789 | egl_surface_t const * const s = get_surface(surface); |
| 1790 | native_window_set_buffers_timestamp(s->win.get(), time); |
| 1791 | |
| 1792 | return EGL_TRUE; |
| 1793 | } |
| 1794 | |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1795 | // ---------------------------------------------------------------------------- |
| 1796 | // NVIDIA extensions |
| 1797 | // ---------------------------------------------------------------------------- |
| 1798 | EGLuint64NV eglGetSystemTimeFrequencyNV() |
| 1799 | { |
| 1800 | clearError(); |
| 1801 | |
| 1802 | if (egl_init_drivers() == EGL_FALSE) { |
| 1803 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1804 | } |
| 1805 | |
| 1806 | EGLuint64NV ret = 0; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1807 | egl_connection_t* const cnx = &gEGLImpl; |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1808 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1809 | if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) { |
| 1810 | return cnx->egl.eglGetSystemTimeFrequencyNV(); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1811 | } |
| 1812 | |
Mathias Agopian | 0e8bbee | 2011-10-05 19:15:05 -0700 | [diff] [blame] | 1813 | return setErrorQuiet(EGL_BAD_DISPLAY, 0); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | EGLuint64NV eglGetSystemTimeNV() |
| 1817 | { |
| 1818 | clearError(); |
| 1819 | |
| 1820 | if (egl_init_drivers() == EGL_FALSE) { |
| 1821 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1822 | } |
| 1823 | |
| 1824 | EGLuint64NV ret = 0; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1825 | egl_connection_t* const cnx = &gEGLImpl; |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1826 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1827 | if (cnx->dso && cnx->egl.eglGetSystemTimeNV) { |
| 1828 | return cnx->egl.eglGetSystemTimeNV(); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1829 | } |
| 1830 | |
Mathias Agopian | 0e8bbee | 2011-10-05 19:15:05 -0700 | [diff] [blame] | 1831 | return setErrorQuiet(EGL_BAD_DISPLAY, 0); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1832 | } |
Dan Stoza | a894d08 | 2015-02-19 15:27:36 -0800 | [diff] [blame] | 1833 | |
| 1834 | // ---------------------------------------------------------------------------- |
| 1835 | // Partial update extension |
| 1836 | // ---------------------------------------------------------------------------- |
| 1837 | EGLBoolean eglSetDamageRegionKHR(EGLDisplay dpy, EGLSurface surface, |
| 1838 | EGLint *rects, EGLint n_rects) |
| 1839 | { |
| 1840 | clearError(); |
| 1841 | |
| 1842 | const egl_display_ptr dp = validate_display(dpy); |
| 1843 | if (!dp) { |
| 1844 | setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 1845 | return EGL_FALSE; |
| 1846 | } |
| 1847 | |
| 1848 | SurfaceRef _s(dp.get(), surface); |
| 1849 | if (!_s.get()) { |
| 1850 | setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 1851 | return EGL_FALSE; |
| 1852 | } |
| 1853 | |
| 1854 | egl_surface_t const * const s = get_surface(surface); |
| 1855 | if (s->cnx->egl.eglSetDamageRegionKHR) { |
| 1856 | return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface, |
| 1857 | rects, n_rects); |
| 1858 | } |
| 1859 | |
| 1860 | return EGL_FALSE; |
| 1861 | } |