Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright 2007, The Android Open Source Project |
| 3 | ** |
| 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 |
| 7 | ** |
| 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | ** |
| 10 | ** Unless required by applicable law or agreed to in writing, software |
| 11 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | ** See the License for the specific language governing permissions and |
| 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 19 | #include <ctype.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
| 22 | |
| 23 | #include <hardware/gralloc.h> |
| 24 | #include <system/window.h> |
| 25 | |
| 26 | #include <EGL/egl.h> |
| 27 | #include <EGL/eglext.h> |
| 28 | #include <GLES/gl.h> |
| 29 | #include <GLES/glext.h> |
| 30 | |
| 31 | #include <cutils/log.h> |
| 32 | #include <cutils/atomic.h> |
Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 33 | #include <cutils/compiler.h> |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 34 | #include <cutils/properties.h> |
| 35 | #include <cutils/memory.h> |
| 36 | |
| 37 | #include <utils/KeyedVector.h> |
| 38 | #include <utils/SortedVector.h> |
| 39 | #include <utils/String8.h> |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 40 | #include <utils/Trace.h> |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 41 | |
| 42 | #include "egl_impl.h" |
| 43 | #include "egl_tls.h" |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 44 | #include "glestrace.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 45 | #include "hooks.h" |
| 46 | |
| 47 | #include "egl_display.h" |
| 48 | #include "egl_impl.h" |
| 49 | #include "egl_object.h" |
| 50 | #include "egl_tls.h" |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 51 | #include "egldefs.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 52 | |
| 53 | using namespace android; |
| 54 | |
| 55 | // ---------------------------------------------------------------------------- |
| 56 | |
Mathias Agopian | bc2d79e | 2011-11-29 17:55:46 -0800 | [diff] [blame] | 57 | #define EGL_VERSION_HW_ANDROID 0x3143 |
| 58 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 59 | struct extention_map_t { |
| 60 | const char* name; |
| 61 | __eglMustCastToProperFunctionPointerType address; |
| 62 | }; |
| 63 | |
| 64 | static const extention_map_t sExtentionMap[] = { |
| 65 | { "eglLockSurfaceKHR", |
| 66 | (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, |
| 67 | { "eglUnlockSurfaceKHR", |
| 68 | (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, |
| 69 | { "eglCreateImageKHR", |
| 70 | (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, |
| 71 | { "eglDestroyImageKHR", |
| 72 | (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 73 | { "eglGetSystemTimeFrequencyNV", |
| 74 | (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV }, |
| 75 | { "eglGetSystemTimeNV", |
| 76 | (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV }, |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | // accesses protected by sExtensionMapMutex |
| 80 | static DefaultKeyedVector<String8, __eglMustCastToProperFunctionPointerType> sGLExtentionMap; |
| 81 | static int sGLExtentionSlot = 0; |
| 82 | static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER; |
| 83 | |
| 84 | static void(*findProcAddress(const char* name, |
| 85 | const extention_map_t* map, size_t n))() { |
| 86 | for (uint32_t i=0 ; i<n ; i++) { |
| 87 | if (!strcmp(name, map[i].name)) { |
| 88 | return map[i].address; |
| 89 | } |
| 90 | } |
| 91 | return NULL; |
| 92 | } |
| 93 | |
| 94 | // ---------------------------------------------------------------------------- |
| 95 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 96 | namespace android { |
| 97 | extern void setGLHooksThreadSpecific(gl_hooks_t const *value); |
| 98 | extern EGLBoolean egl_init_drivers(); |
| 99 | extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; |
| 100 | extern int gEGLDebugLevel; |
| 101 | extern gl_hooks_t gHooksTrace; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 102 | } // namespace android; |
| 103 | |
| 104 | // ---------------------------------------------------------------------------- |
| 105 | |
| 106 | static inline void clearError() { egl_tls_t::clearError(); } |
| 107 | static inline EGLContext getContext() { return egl_tls_t::getContext(); } |
| 108 | |
| 109 | // ---------------------------------------------------------------------------- |
| 110 | |
| 111 | EGLDisplay eglGetDisplay(EGLNativeDisplayType display) |
| 112 | { |
| 113 | clearError(); |
| 114 | |
| 115 | uint32_t index = uint32_t(display); |
| 116 | if (index >= NUM_DISPLAYS) { |
| 117 | return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); |
| 118 | } |
| 119 | |
| 120 | if (egl_init_drivers() == EGL_FALSE) { |
| 121 | return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY); |
| 122 | } |
| 123 | |
| 124 | EGLDisplay dpy = egl_display_t::getFromNativeDisplay(display); |
| 125 | return dpy; |
| 126 | } |
| 127 | |
| 128 | // ---------------------------------------------------------------------------- |
| 129 | // Initialization |
| 130 | // ---------------------------------------------------------------------------- |
| 131 | |
| 132 | EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) |
| 133 | { |
| 134 | clearError(); |
| 135 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 136 | egl_display_ptr dp = get_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 137 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 138 | |
| 139 | EGLBoolean res = dp->initialize(major, minor); |
| 140 | |
| 141 | return res; |
| 142 | } |
| 143 | |
| 144 | EGLBoolean eglTerminate(EGLDisplay dpy) |
| 145 | { |
| 146 | // NOTE: don't unload the drivers b/c some APIs can be called |
| 147 | // after eglTerminate() has been called. eglTerminate() only |
| 148 | // terminates an EGLDisplay, not a EGL itself. |
| 149 | |
| 150 | clearError(); |
| 151 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 152 | egl_display_ptr dp = get_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 153 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 154 | |
| 155 | EGLBoolean res = dp->terminate(); |
| 156 | |
| 157 | return res; |
| 158 | } |
| 159 | |
| 160 | // ---------------------------------------------------------------------------- |
| 161 | // configuration |
| 162 | // ---------------------------------------------------------------------------- |
| 163 | |
| 164 | EGLBoolean eglGetConfigs( EGLDisplay dpy, |
| 165 | EGLConfig *configs, |
| 166 | EGLint config_size, EGLint *num_config) |
| 167 | { |
| 168 | clearError(); |
| 169 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 170 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 171 | if (!dp) return EGL_FALSE; |
| 172 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 173 | if (num_config==0) { |
| 174 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 177 | EGLBoolean res = EGL_FALSE; |
| 178 | *num_config = 0; |
| 179 | |
| 180 | egl_connection_t* const cnx = &gEGLImpl; |
| 181 | if (cnx->dso) { |
| 182 | res = cnx->egl.eglGetConfigs( |
| 183 | dp->disp.dpy, configs, config_size, num_config); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 184 | } |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 185 | |
| 186 | return res; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, |
| 190 | EGLConfig *configs, EGLint config_size, |
| 191 | EGLint *num_config) |
| 192 | { |
| 193 | clearError(); |
| 194 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 195 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 196 | if (!dp) return EGL_FALSE; |
| 197 | |
| 198 | if (num_config==0) { |
| 199 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 200 | } |
| 201 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 202 | EGLBoolean res = EGL_FALSE; |
| 203 | *num_config = 0; |
| 204 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 205 | egl_connection_t* const cnx = &gEGLImpl; |
| 206 | if (cnx->dso) { |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 207 | res = cnx->egl.eglChooseConfig( |
| 208 | dp->disp.dpy, attrib_list, configs, config_size, num_config); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 209 | } |
| 210 | return res; |
| 211 | } |
| 212 | |
| 213 | EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, |
| 214 | EGLint attribute, EGLint *value) |
| 215 | { |
| 216 | clearError(); |
| 217 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 218 | egl_connection_t* cnx = NULL; |
| 219 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 220 | if (!dp) return EGL_FALSE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 221 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 222 | return cnx->egl.eglGetConfigAttrib( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 223 | dp->disp.dpy, config, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | // ---------------------------------------------------------------------------- |
| 227 | // surfaces |
| 228 | // ---------------------------------------------------------------------------- |
| 229 | |
| 230 | EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, |
| 231 | NativeWindowType window, |
| 232 | const EGLint *attrib_list) |
| 233 | { |
| 234 | clearError(); |
| 235 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 236 | egl_connection_t* cnx = NULL; |
| 237 | egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 238 | if (dp) { |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 239 | EGLDisplay iDpy = dp->disp.dpy; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 240 | EGLint format; |
| 241 | |
Mathias Agopian | 81a6335 | 2011-07-29 17:55:48 -0700 | [diff] [blame] | 242 | if (native_window_api_connect(window, NATIVE_WINDOW_API_EGL) != OK) { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 243 | ALOGE("EGLNativeWindowType %p already connected to another API", |
Mathias Agopian | 81a6335 | 2011-07-29 17:55:48 -0700 | [diff] [blame] | 244 | window); |
| 245 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); |
| 246 | } |
| 247 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 248 | // set the native window's buffers format to match this config |
| 249 | if (cnx->egl.eglGetConfigAttrib(iDpy, |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 250 | config, EGL_NATIVE_VISUAL_ID, &format)) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 251 | if (format != 0) { |
Jamie Gennis | bee205f | 2011-07-01 13:12:07 -0700 | [diff] [blame] | 252 | int err = native_window_set_buffers_format(window, format); |
| 253 | if (err != 0) { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 254 | ALOGE("error setting native window pixel format: %s (%d)", |
Jamie Gennis | bee205f | 2011-07-01 13:12:07 -0700 | [diff] [blame] | 255 | strerror(-err), err); |
Mathias Agopian | 81a6335 | 2011-07-29 17:55:48 -0700 | [diff] [blame] | 256 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); |
Jamie Gennis | bee205f | 2011-07-01 13:12:07 -0700 | [diff] [blame] | 257 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); |
| 258 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
Jamie Gennis | 5976946 | 2011-11-19 18:04:43 -0800 | [diff] [blame] | 262 | // the EGL spec requires that a new EGLSurface default to swap interval |
| 263 | // 1, so explicitly set that on the window here. |
| 264 | ANativeWindow* anw = reinterpret_cast<ANativeWindow*>(window); |
| 265 | anw->setSwapInterval(anw, 1); |
| 266 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 267 | EGLSurface surface = cnx->egl.eglCreateWindowSurface( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 268 | iDpy, config, window, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 269 | if (surface != EGL_NO_SURFACE) { |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 270 | egl_surface_t* s = new egl_surface_t(dp.get(), config, window, |
| 271 | surface, cnx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 272 | return s; |
| 273 | } |
Mathias Agopian | 81a6335 | 2011-07-29 17:55:48 -0700 | [diff] [blame] | 274 | |
| 275 | // EGLSurface creation failed |
| 276 | native_window_set_buffers_format(window, 0); |
| 277 | native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 278 | } |
| 279 | return EGL_NO_SURFACE; |
| 280 | } |
| 281 | |
| 282 | EGLSurface eglCreatePixmapSurface( EGLDisplay dpy, EGLConfig config, |
| 283 | NativePixmapType pixmap, |
| 284 | const EGLint *attrib_list) |
| 285 | { |
| 286 | clearError(); |
| 287 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 288 | egl_connection_t* cnx = NULL; |
| 289 | egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 290 | if (dp) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 291 | EGLSurface surface = cnx->egl.eglCreatePixmapSurface( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 292 | dp->disp.dpy, config, pixmap, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 293 | if (surface != EGL_NO_SURFACE) { |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 294 | egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, |
| 295 | surface, cnx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 296 | return s; |
| 297 | } |
| 298 | } |
| 299 | return EGL_NO_SURFACE; |
| 300 | } |
| 301 | |
| 302 | EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, |
| 303 | const EGLint *attrib_list) |
| 304 | { |
| 305 | clearError(); |
| 306 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 307 | egl_connection_t* cnx = NULL; |
| 308 | egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 309 | if (dp) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 310 | EGLSurface surface = cnx->egl.eglCreatePbufferSurface( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 311 | dp->disp.dpy, config, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 312 | if (surface != EGL_NO_SURFACE) { |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 313 | egl_surface_t* s = new egl_surface_t(dp.get(), config, NULL, |
| 314 | surface, cnx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 315 | return s; |
| 316 | } |
| 317 | } |
| 318 | return EGL_NO_SURFACE; |
| 319 | } |
| 320 | |
| 321 | EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) |
| 322 | { |
| 323 | clearError(); |
| 324 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 325 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 326 | if (!dp) return EGL_FALSE; |
| 327 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 328 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 329 | if (!_s.get()) |
| 330 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 331 | |
| 332 | egl_surface_t * const s = get_surface(surface); |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 333 | EGLBoolean result = s->cnx->egl.eglDestroySurface(dp->disp.dpy, s->surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 334 | if (result == EGL_TRUE) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 335 | _s.terminate(); |
| 336 | } |
| 337 | return result; |
| 338 | } |
| 339 | |
| 340 | EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface surface, |
| 341 | EGLint attribute, EGLint *value) |
| 342 | { |
| 343 | clearError(); |
| 344 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 345 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 346 | if (!dp) return EGL_FALSE; |
| 347 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 348 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 349 | if (!_s.get()) |
| 350 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 351 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 352 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 353 | return s->cnx->egl.eglQuerySurface( |
| 354 | dp->disp.dpy, s->surface, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 357 | void EGLAPI eglBeginFrame(EGLDisplay dpy, EGLSurface surface) { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 358 | ATRACE_CALL(); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 359 | clearError(); |
| 360 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 361 | const egl_display_ptr dp = validate_display(dpy); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 362 | if (!dp) { |
| 363 | return; |
| 364 | } |
| 365 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 366 | SurfaceRef _s(dp.get(), surface); |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 367 | if (!_s.get()) { |
| 368 | setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 369 | return; |
| 370 | } |
| 371 | |
| 372 | int64_t timestamp = systemTime(SYSTEM_TIME_MONOTONIC); |
| 373 | |
| 374 | egl_surface_t const * const s = get_surface(surface); |
| 375 | native_window_set_buffers_timestamp(s->win.get(), timestamp); |
| 376 | } |
| 377 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 378 | // ---------------------------------------------------------------------------- |
| 379 | // Contexts |
| 380 | // ---------------------------------------------------------------------------- |
| 381 | |
| 382 | EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, |
| 383 | EGLContext share_list, const EGLint *attrib_list) |
| 384 | { |
| 385 | clearError(); |
| 386 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 387 | egl_connection_t* cnx = NULL; |
| 388 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 389 | if (dpy) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 390 | if (share_list != EGL_NO_CONTEXT) { |
| 391 | egl_context_t* const c = get_context(share_list); |
| 392 | share_list = c->context; |
| 393 | } |
| 394 | EGLContext context = cnx->egl.eglCreateContext( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 395 | dp->disp.dpy, config, share_list, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 396 | if (context != EGL_NO_CONTEXT) { |
| 397 | // figure out if it's a GLESv1 or GLESv2 |
| 398 | int version = 0; |
| 399 | if (attrib_list) { |
| 400 | while (*attrib_list != EGL_NONE) { |
| 401 | GLint attr = *attrib_list++; |
| 402 | GLint value = *attrib_list++; |
| 403 | if (attr == EGL_CONTEXT_CLIENT_VERSION) { |
| 404 | if (value == 1) { |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 405 | version = egl_connection_t::GLESv1_INDEX; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 406 | } else if (value == 2) { |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 407 | version = egl_connection_t::GLESv2_INDEX; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | }; |
| 411 | } |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 412 | egl_context_t* c = new egl_context_t(dpy, context, config, cnx, |
| 413 | version); |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 414 | #if EGL_TRACE |
| 415 | if (gEGLDebugLevel > 0) |
| 416 | GLTrace_eglCreateContext(version, c); |
| 417 | #endif |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 418 | return c; |
Mathias Agopian | 500407a | 2012-09-24 17:57:48 -0700 | [diff] [blame] | 419 | } else { |
| 420 | EGLint error = eglGetError(); |
| 421 | ALOGE_IF(error == EGL_SUCCESS, |
| 422 | "eglCreateContext(%p, %p, %p, %p) returned EGL_NO_CONTEXT " |
| 423 | "but no EGL error!", |
| 424 | dpy, config, share_list, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | return EGL_NO_CONTEXT; |
| 428 | } |
| 429 | |
| 430 | EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) |
| 431 | { |
| 432 | clearError(); |
| 433 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 434 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 435 | if (!dp) |
| 436 | return EGL_FALSE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 437 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 438 | ContextRef _c(dp.get(), ctx); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 439 | if (!_c.get()) |
| 440 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 441 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 442 | egl_context_t * const c = get_context(ctx); |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 443 | EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 444 | if (result == EGL_TRUE) { |
| 445 | _c.terminate(); |
| 446 | } |
| 447 | return result; |
| 448 | } |
| 449 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 450 | EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, |
| 451 | EGLSurface read, EGLContext ctx) |
| 452 | { |
| 453 | clearError(); |
| 454 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 455 | egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 456 | if (!dp) return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 457 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 458 | // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not |
| 459 | // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is |
| 460 | // a valid but uninitialized display. |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 461 | if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || |
| 462 | (draw != EGL_NO_SURFACE) ) { |
| 463 | if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, EGL_FALSE); |
| 464 | } |
| 465 | |
| 466 | // get a reference to the object passed in |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 467 | ContextRef _c(dp.get(), ctx); |
| 468 | SurfaceRef _d(dp.get(), draw); |
| 469 | SurfaceRef _r(dp.get(), read); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 470 | |
| 471 | // validate the context (if not EGL_NO_CONTEXT) |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 472 | if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 473 | // EGL_NO_CONTEXT is valid |
| 474 | return EGL_FALSE; |
| 475 | } |
| 476 | |
| 477 | // these are the underlying implementation's object |
| 478 | EGLContext impl_ctx = EGL_NO_CONTEXT; |
| 479 | EGLSurface impl_draw = EGL_NO_SURFACE; |
| 480 | EGLSurface impl_read = EGL_NO_SURFACE; |
| 481 | |
| 482 | // these are our objects structs passed in |
| 483 | egl_context_t * c = NULL; |
| 484 | egl_surface_t const * d = NULL; |
| 485 | egl_surface_t const * r = NULL; |
| 486 | |
| 487 | // these are the current objects structs |
| 488 | egl_context_t * cur_c = get_context(getContext()); |
| 489 | |
| 490 | if (ctx != EGL_NO_CONTEXT) { |
| 491 | c = get_context(ctx); |
| 492 | impl_ctx = c->context; |
| 493 | } else { |
| 494 | // no context given, use the implementation of the current context |
| 495 | if (cur_c == NULL) { |
| 496 | // no current context |
| 497 | if (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE) { |
| 498 | // calling eglMakeCurrent( ..., !=0, !=0, EGL_NO_CONTEXT); |
| 499 | return setError(EGL_BAD_MATCH, EGL_FALSE); |
| 500 | } |
| 501 | // not an error, there is just no current context. |
| 502 | return EGL_TRUE; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | // retrieve the underlying implementation's draw EGLSurface |
| 507 | if (draw != EGL_NO_SURFACE) { |
| 508 | d = get_surface(draw); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 509 | impl_draw = d->surface; |
| 510 | } |
| 511 | |
| 512 | // retrieve the underlying implementation's read EGLSurface |
| 513 | if (read != EGL_NO_SURFACE) { |
| 514 | r = get_surface(read); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 515 | impl_read = r->surface; |
| 516 | } |
| 517 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 518 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 519 | EGLBoolean result = dp->makeCurrent(c, cur_c, |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 520 | draw, read, ctx, |
| 521 | impl_draw, impl_read, impl_ctx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 522 | |
| 523 | if (result == EGL_TRUE) { |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 524 | if (c) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 525 | setGLHooksThreadSpecific(c->cnx->hooks[c->version]); |
| 526 | egl_tls_t::setContext(ctx); |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 527 | #if EGL_TRACE |
| 528 | if (gEGLDebugLevel > 0) |
Siva Velusamy | 93a826f | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 529 | GLTrace_eglMakeCurrent(c->version, c->cnx->hooks[c->version], ctx); |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 530 | #endif |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 531 | _c.acquire(); |
| 532 | _r.acquire(); |
| 533 | _d.acquire(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 534 | } else { |
| 535 | setGLHooksThreadSpecific(&gHooksNoContext); |
| 536 | egl_tls_t::setContext(EGL_NO_CONTEXT); |
| 537 | } |
Mathias Agopian | 5fecea7 | 2011-08-25 18:38:24 -0700 | [diff] [blame] | 538 | } else { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 539 | // this will ALOGE the error |
Mathias Agopian | 5fecea7 | 2011-08-25 18:38:24 -0700 | [diff] [blame] | 540 | result = setError(c->cnx->egl.eglGetError(), EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 541 | } |
| 542 | return result; |
| 543 | } |
| 544 | |
| 545 | |
| 546 | EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, |
| 547 | EGLint attribute, EGLint *value) |
| 548 | { |
| 549 | clearError(); |
| 550 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 551 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 552 | if (!dp) return EGL_FALSE; |
| 553 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 554 | ContextRef _c(dp.get(), ctx); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 555 | if (!_c.get()) return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 556 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 557 | egl_context_t * const c = get_context(ctx); |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 558 | return c->cnx->egl.eglQueryContext( |
| 559 | dp->disp.dpy, c->context, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 560 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | EGLContext eglGetCurrentContext(void) |
| 564 | { |
| 565 | // could be called before eglInitialize(), but we wouldn't have a context |
| 566 | // then, and this function would correctly return EGL_NO_CONTEXT. |
| 567 | |
| 568 | clearError(); |
| 569 | |
| 570 | EGLContext ctx = getContext(); |
| 571 | return ctx; |
| 572 | } |
| 573 | |
| 574 | EGLSurface eglGetCurrentSurface(EGLint readdraw) |
| 575 | { |
| 576 | // could be called before eglInitialize(), but we wouldn't have a context |
| 577 | // then, and this function would correctly return EGL_NO_SURFACE. |
| 578 | |
| 579 | clearError(); |
| 580 | |
| 581 | EGLContext ctx = getContext(); |
| 582 | if (ctx) { |
| 583 | egl_context_t const * const c = get_context(ctx); |
| 584 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); |
| 585 | switch (readdraw) { |
| 586 | case EGL_READ: return c->read; |
| 587 | case EGL_DRAW: return c->draw; |
| 588 | default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); |
| 589 | } |
| 590 | } |
| 591 | return EGL_NO_SURFACE; |
| 592 | } |
| 593 | |
| 594 | EGLDisplay eglGetCurrentDisplay(void) |
| 595 | { |
| 596 | // could be called before eglInitialize(), but we wouldn't have a context |
| 597 | // then, and this function would correctly return EGL_NO_DISPLAY. |
| 598 | |
| 599 | clearError(); |
| 600 | |
| 601 | EGLContext ctx = getContext(); |
| 602 | if (ctx) { |
| 603 | egl_context_t const * const c = get_context(ctx); |
| 604 | if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE); |
| 605 | return c->dpy; |
| 606 | } |
| 607 | return EGL_NO_DISPLAY; |
| 608 | } |
| 609 | |
| 610 | EGLBoolean eglWaitGL(void) |
| 611 | { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 612 | clearError(); |
| 613 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 614 | egl_connection_t* const cnx = &gEGLImpl; |
| 615 | if (!cnx->dso) |
| 616 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 617 | |
| 618 | return cnx->egl.eglWaitGL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | EGLBoolean eglWaitNative(EGLint engine) |
| 622 | { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 623 | clearError(); |
| 624 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 625 | egl_connection_t* const cnx = &gEGLImpl; |
| 626 | if (!cnx->dso) |
| 627 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 628 | |
| 629 | return cnx->egl.eglWaitNative(engine); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | EGLint eglGetError(void) |
| 633 | { |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 634 | EGLint err = EGL_SUCCESS; |
| 635 | egl_connection_t* const cnx = &gEGLImpl; |
| 636 | if (cnx->dso) { |
| 637 | err = cnx->egl.eglGetError(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 638 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 639 | if (err == EGL_SUCCESS) { |
| 640 | err = egl_tls_t::getError(); |
| 641 | } |
| 642 | return err; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 645 | __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname) |
| 646 | { |
| 647 | // eglGetProcAddress() could be the very first function called |
| 648 | // in which case we must make sure we've initialized ourselves, this |
| 649 | // happens the first time egl_get_display() is called. |
| 650 | |
| 651 | clearError(); |
| 652 | |
| 653 | if (egl_init_drivers() == EGL_FALSE) { |
| 654 | setError(EGL_BAD_PARAMETER, NULL); |
| 655 | return NULL; |
| 656 | } |
| 657 | |
Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 658 | // These extensions should not be exposed to applications. They're used |
| 659 | // internally by the Android EGL layer. |
| 660 | if (!strcmp(procname, "eglSetBlobCacheFuncsANDROID") || |
Jamie Gennis | 331841b | 2012-09-06 14:52:00 -0700 | [diff] [blame] | 661 | !strcmp(procname, "eglDupNativeFenceFDANDROID") || |
Jamie Gennis | 010dd4f | 2012-09-09 17:46:17 -0700 | [diff] [blame] | 662 | !strcmp(procname, "eglWaitSyncANDROID") || |
Jesse Hall | 2583859 | 2012-04-05 15:53:28 -0700 | [diff] [blame] | 663 | !strcmp(procname, "eglHibernateProcessIMG") || |
| 664 | !strcmp(procname, "eglAwakenProcessIMG")) { |
Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 665 | return NULL; |
| 666 | } |
| 667 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 668 | __eglMustCastToProperFunctionPointerType addr; |
| 669 | addr = findProcAddress(procname, sExtentionMap, NELEM(sExtentionMap)); |
| 670 | if (addr) return addr; |
| 671 | |
Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 672 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 673 | // this protects accesses to sGLExtentionMap and sGLExtentionSlot |
| 674 | pthread_mutex_lock(&sExtensionMapMutex); |
| 675 | |
| 676 | /* |
| 677 | * Since eglGetProcAddress() is not associated to anything, it needs |
| 678 | * to return a function pointer that "works" regardless of what |
| 679 | * the current context is. |
| 680 | * |
| 681 | * For this reason, we return a "forwarder", a small stub that takes |
| 682 | * care of calling the function associated with the context |
| 683 | * currently bound. |
| 684 | * |
| 685 | * We first look for extensions we've already resolved, if we're seeing |
| 686 | * this extension for the first time, we go through all our |
| 687 | * implementations and call eglGetProcAddress() and record the |
| 688 | * result in the appropriate implementation hooks and return the |
| 689 | * address of the forwarder corresponding to that hook set. |
| 690 | * |
| 691 | */ |
| 692 | |
| 693 | const String8 name(procname); |
| 694 | addr = sGLExtentionMap.valueFor(name); |
| 695 | const int slot = sGLExtentionSlot; |
| 696 | |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 697 | ALOGE_IF(slot >= MAX_NUMBER_OF_GL_EXTENSIONS, |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 698 | "no more slots for eglGetProcAddress(\"%s\")", |
| 699 | procname); |
| 700 | |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 701 | #if EGL_TRACE |
| 702 | gl_hooks_t *debugHooks = GLTrace_getGLHooks(); |
| 703 | #endif |
| 704 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 705 | if (!addr && (slot < MAX_NUMBER_OF_GL_EXTENSIONS)) { |
| 706 | bool found = false; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 707 | |
| 708 | egl_connection_t* const cnx = &gEGLImpl; |
| 709 | if (cnx->dso && cnx->egl.eglGetProcAddress) { |
| 710 | found = true; |
| 711 | // Extensions are independent of the bound context |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 712 | cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = |
| 713 | cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 714 | #if EGL_TRACE |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 715 | debugHooks->ext.extensions[slot] = |
| 716 | gHooksTrace.ext.extensions[slot] = |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 717 | #endif |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 718 | cnx->egl.eglGetProcAddress(procname); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 719 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 720 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 721 | if (found) { |
| 722 | addr = gExtensionForwarders[slot]; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 723 | sGLExtentionMap.add(name, addr); |
| 724 | sGLExtentionSlot++; |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | pthread_mutex_unlock(&sExtensionMapMutex); |
| 729 | return addr; |
| 730 | } |
| 731 | |
Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 732 | class FrameCompletionThread : public Thread { |
| 733 | public: |
| 734 | |
| 735 | static void queueSync(EGLSyncKHR sync) { |
| 736 | static sp<FrameCompletionThread> thread(new FrameCompletionThread); |
| 737 | static bool running = false; |
| 738 | if (!running) { |
| 739 | thread->run("GPUFrameCompletion"); |
| 740 | running = true; |
| 741 | } |
| 742 | { |
| 743 | Mutex::Autolock lock(thread->mMutex); |
| 744 | ScopedTrace st(ATRACE_TAG, String8::format("kicked off frame %d", |
| 745 | thread->mFramesQueued).string()); |
| 746 | thread->mQueue.push_back(sync); |
| 747 | thread->mCondition.signal(); |
| 748 | thread->mFramesQueued++; |
| 749 | ATRACE_INT("GPU Frames Outstanding", thread->mQueue.size()); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | private: |
| 754 | FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {} |
| 755 | |
| 756 | virtual bool threadLoop() { |
| 757 | EGLSyncKHR sync; |
| 758 | uint32_t frameNum; |
| 759 | { |
| 760 | Mutex::Autolock lock(mMutex); |
| 761 | while (mQueue.isEmpty()) { |
| 762 | mCondition.wait(mMutex); |
| 763 | } |
| 764 | sync = mQueue[0]; |
| 765 | frameNum = mFramesCompleted; |
| 766 | } |
| 767 | EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 768 | { |
| 769 | ScopedTrace st(ATRACE_TAG, String8::format("waiting for frame %d", |
| 770 | frameNum).string()); |
| 771 | EGLint result = eglClientWaitSyncKHR(dpy, sync, 0, EGL_FOREVER_KHR); |
| 772 | if (result == EGL_FALSE) { |
| 773 | ALOGE("FrameCompletion: error waiting for fence: %#x", eglGetError()); |
| 774 | } else if (result == EGL_TIMEOUT_EXPIRED_KHR) { |
| 775 | ALOGE("FrameCompletion: timeout waiting for fence"); |
| 776 | } |
| 777 | eglDestroySyncKHR(dpy, sync); |
| 778 | } |
| 779 | { |
| 780 | Mutex::Autolock lock(mMutex); |
| 781 | mQueue.removeAt(0); |
| 782 | mFramesCompleted++; |
| 783 | ATRACE_INT("GPU Frames Outstanding", mQueue.size()); |
| 784 | } |
| 785 | return true; |
| 786 | } |
| 787 | |
| 788 | uint32_t mFramesQueued; |
| 789 | uint32_t mFramesCompleted; |
| 790 | Vector<EGLSyncKHR> mQueue; |
| 791 | Condition mCondition; |
| 792 | Mutex mMutex; |
| 793 | }; |
| 794 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 795 | EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) |
| 796 | { |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 797 | ATRACE_CALL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 798 | clearError(); |
| 799 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 800 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 801 | if (!dp) return EGL_FALSE; |
| 802 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 803 | SurfaceRef _s(dp.get(), draw); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 804 | if (!_s.get()) |
| 805 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 806 | |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 807 | #if EGL_TRACE |
| 808 | if (gEGLDebugLevel > 0) |
| 809 | GLTrace_eglSwapBuffers(dpy, draw); |
| 810 | #endif |
| 811 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 812 | egl_surface_t const * const s = get_surface(draw); |
Mathias Agopian | 7db993a | 2012-03-25 00:49:46 -0700 | [diff] [blame] | 813 | |
| 814 | if (CC_UNLIKELY(dp->finishOnSwap)) { |
| 815 | uint32_t pixel; |
| 816 | egl_context_t * const c = get_context( egl_tls_t::getContext() ); |
| 817 | if (c) { |
| 818 | // glReadPixels() ensures that the frame is complete |
| 819 | s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1, |
| 820 | GL_RGBA,GL_UNSIGNED_BYTE,&pixel); |
| 821 | } |
| 822 | } |
| 823 | |
Jamie Gennis | 28ef8d7 | 2012-04-05 20:34:54 -0700 | [diff] [blame] | 824 | EGLBoolean result = s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); |
| 825 | |
| 826 | if (CC_UNLIKELY(dp->traceGpuCompletion)) { |
| 827 | EGLSyncKHR sync = EGL_NO_SYNC_KHR; |
| 828 | { |
| 829 | sync = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL); |
| 830 | } |
| 831 | if (sync != EGL_NO_SYNC_KHR) { |
| 832 | FrameCompletionThread::queueSync(sync); |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | EGLBoolean eglCopyBuffers( EGLDisplay dpy, EGLSurface surface, |
| 840 | NativePixmapType target) |
| 841 | { |
| 842 | clearError(); |
| 843 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 844 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 845 | if (!dp) return EGL_FALSE; |
| 846 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 847 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 848 | if (!_s.get()) |
| 849 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 850 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 851 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 852 | return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | const char* eglQueryString(EGLDisplay dpy, EGLint name) |
| 856 | { |
| 857 | clearError(); |
| 858 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 859 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 860 | if (!dp) return (const char *) NULL; |
| 861 | |
| 862 | switch (name) { |
| 863 | case EGL_VENDOR: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 864 | return dp->getVendorString(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 865 | case EGL_VERSION: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 866 | return dp->getVersionString(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 867 | case EGL_EXTENSIONS: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 868 | return dp->getExtensionString(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 869 | case EGL_CLIENT_APIS: |
Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 870 | return dp->getClientApiString(); |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 871 | case EGL_VERSION_HW_ANDROID: |
| 872 | return dp->disp.queryString.version; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 873 | } |
| 874 | return setError(EGL_BAD_PARAMETER, (const char *)0); |
| 875 | } |
| 876 | |
| 877 | |
| 878 | // ---------------------------------------------------------------------------- |
| 879 | // EGL 1.1 |
| 880 | // ---------------------------------------------------------------------------- |
| 881 | |
| 882 | EGLBoolean eglSurfaceAttrib( |
| 883 | EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) |
| 884 | { |
| 885 | clearError(); |
| 886 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 887 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 888 | if (!dp) return EGL_FALSE; |
| 889 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 890 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 891 | if (!_s.get()) |
| 892 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 893 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 894 | egl_surface_t const * const s = get_surface(surface); |
| 895 | if (s->cnx->egl.eglSurfaceAttrib) { |
| 896 | return s->cnx->egl.eglSurfaceAttrib( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 897 | dp->disp.dpy, s->surface, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 898 | } |
| 899 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 900 | } |
| 901 | |
| 902 | EGLBoolean eglBindTexImage( |
| 903 | EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 904 | { |
| 905 | clearError(); |
| 906 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 907 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 908 | if (!dp) return EGL_FALSE; |
| 909 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 910 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 911 | if (!_s.get()) |
| 912 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 913 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 914 | egl_surface_t const * const s = get_surface(surface); |
| 915 | if (s->cnx->egl.eglBindTexImage) { |
| 916 | return s->cnx->egl.eglBindTexImage( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 917 | dp->disp.dpy, s->surface, buffer); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 918 | } |
| 919 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 920 | } |
| 921 | |
| 922 | EGLBoolean eglReleaseTexImage( |
| 923 | EGLDisplay dpy, EGLSurface surface, EGLint buffer) |
| 924 | { |
| 925 | clearError(); |
| 926 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 927 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 928 | if (!dp) return EGL_FALSE; |
| 929 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 930 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 931 | if (!_s.get()) |
| 932 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 933 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 934 | egl_surface_t const * const s = get_surface(surface); |
| 935 | if (s->cnx->egl.eglReleaseTexImage) { |
| 936 | return s->cnx->egl.eglReleaseTexImage( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 937 | dp->disp.dpy, s->surface, buffer); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 938 | } |
| 939 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
| 940 | } |
| 941 | |
| 942 | EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) |
| 943 | { |
| 944 | clearError(); |
| 945 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 946 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 947 | if (!dp) return EGL_FALSE; |
| 948 | |
| 949 | EGLBoolean res = EGL_TRUE; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 950 | egl_connection_t* const cnx = &gEGLImpl; |
| 951 | if (cnx->dso && cnx->egl.eglSwapInterval) { |
| 952 | res = cnx->egl.eglSwapInterval(dp->disp.dpy, interval); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 953 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 954 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 955 | return res; |
| 956 | } |
| 957 | |
| 958 | |
| 959 | // ---------------------------------------------------------------------------- |
| 960 | // EGL 1.2 |
| 961 | // ---------------------------------------------------------------------------- |
| 962 | |
| 963 | EGLBoolean eglWaitClient(void) |
| 964 | { |
| 965 | clearError(); |
| 966 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 967 | egl_connection_t* const cnx = &gEGLImpl; |
| 968 | if (!cnx->dso) |
| 969 | return setError(EGL_BAD_CONTEXT, EGL_FALSE); |
| 970 | |
| 971 | EGLBoolean res; |
| 972 | if (cnx->egl.eglWaitClient) { |
| 973 | res = cnx->egl.eglWaitClient(); |
| 974 | } else { |
| 975 | res = cnx->egl.eglWaitGL(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 976 | } |
| 977 | return res; |
| 978 | } |
| 979 | |
| 980 | EGLBoolean eglBindAPI(EGLenum api) |
| 981 | { |
| 982 | clearError(); |
| 983 | |
| 984 | if (egl_init_drivers() == EGL_FALSE) { |
| 985 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 986 | } |
| 987 | |
| 988 | // bind this API on all EGLs |
| 989 | EGLBoolean res = EGL_TRUE; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 990 | egl_connection_t* const cnx = &gEGLImpl; |
| 991 | if (cnx->dso && cnx->egl.eglBindAPI) { |
| 992 | res = cnx->egl.eglBindAPI(api); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 993 | } |
| 994 | return res; |
| 995 | } |
| 996 | |
| 997 | EGLenum eglQueryAPI(void) |
| 998 | { |
| 999 | clearError(); |
| 1000 | |
| 1001 | if (egl_init_drivers() == EGL_FALSE) { |
| 1002 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1003 | } |
| 1004 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1005 | egl_connection_t* const cnx = &gEGLImpl; |
| 1006 | if (cnx->dso && cnx->egl.eglQueryAPI) { |
| 1007 | return cnx->egl.eglQueryAPI(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1008 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1009 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1010 | // or, it can only be OpenGL ES |
| 1011 | return EGL_OPENGL_ES_API; |
| 1012 | } |
| 1013 | |
| 1014 | EGLBoolean eglReleaseThread(void) |
| 1015 | { |
| 1016 | clearError(); |
| 1017 | |
| 1018 | // If there is context bound to the thread, release it |
Mathias Agopian | fb87e54 | 2012-01-30 18:20:52 -0800 | [diff] [blame] | 1019 | egl_display_t::loseCurrent(get_context(getContext())); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1020 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1021 | egl_connection_t* const cnx = &gEGLImpl; |
| 1022 | if (cnx->dso && cnx->egl.eglReleaseThread) { |
| 1023 | cnx->egl.eglReleaseThread(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1024 | } |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1025 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1026 | egl_tls_t::clearTLS(); |
Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 1027 | #if EGL_TRACE |
| 1028 | if (gEGLDebugLevel > 0) |
| 1029 | GLTrace_eglReleaseThread(); |
| 1030 | #endif |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1031 | return EGL_TRUE; |
| 1032 | } |
| 1033 | |
| 1034 | EGLSurface eglCreatePbufferFromClientBuffer( |
| 1035 | EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, |
| 1036 | EGLConfig config, const EGLint *attrib_list) |
| 1037 | { |
| 1038 | clearError(); |
| 1039 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1040 | egl_connection_t* cnx = NULL; |
| 1041 | const egl_display_ptr dp = validate_display_connection(dpy, cnx); |
| 1042 | if (!dp) return EGL_FALSE; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1043 | if (cnx->egl.eglCreatePbufferFromClientBuffer) { |
| 1044 | return cnx->egl.eglCreatePbufferFromClientBuffer( |
Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 1045 | dp->disp.dpy, buftype, buffer, config, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1046 | } |
| 1047 | return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE); |
| 1048 | } |
| 1049 | |
| 1050 | // ---------------------------------------------------------------------------- |
| 1051 | // EGL_EGLEXT_VERSION 3 |
| 1052 | // ---------------------------------------------------------------------------- |
| 1053 | |
| 1054 | EGLBoolean eglLockSurfaceKHR(EGLDisplay dpy, EGLSurface surface, |
| 1055 | const EGLint *attrib_list) |
| 1056 | { |
| 1057 | clearError(); |
| 1058 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1059 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1060 | if (!dp) return EGL_FALSE; |
| 1061 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1062 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1063 | if (!_s.get()) |
| 1064 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1065 | |
| 1066 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1067 | if (s->cnx->egl.eglLockSurfaceKHR) { |
| 1068 | return s->cnx->egl.eglLockSurfaceKHR( |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1069 | dp->disp.dpy, s->surface, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1070 | } |
| 1071 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 1072 | } |
| 1073 | |
| 1074 | EGLBoolean eglUnlockSurfaceKHR(EGLDisplay dpy, EGLSurface surface) |
| 1075 | { |
| 1076 | clearError(); |
| 1077 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1078 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1079 | if (!dp) return EGL_FALSE; |
| 1080 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1081 | SurfaceRef _s(dp.get(), surface); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 1082 | if (!_s.get()) |
| 1083 | return setError(EGL_BAD_SURFACE, EGL_FALSE); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1084 | |
| 1085 | egl_surface_t const * const s = get_surface(surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1086 | if (s->cnx->egl.eglUnlockSurfaceKHR) { |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1087 | return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1088 | } |
| 1089 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); |
| 1090 | } |
| 1091 | |
| 1092 | EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, |
| 1093 | EGLClientBuffer buffer, const EGLint *attrib_list) |
| 1094 | { |
| 1095 | clearError(); |
| 1096 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1097 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1098 | if (!dp) return EGL_NO_IMAGE_KHR; |
| 1099 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1100 | ContextRef _c(dp.get(), ctx); |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1101 | egl_context_t * const c = _c.get(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1102 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1103 | EGLImageKHR result = EGL_NO_IMAGE_KHR; |
| 1104 | egl_connection_t* const cnx = &gEGLImpl; |
| 1105 | if (cnx->dso && cnx->egl.eglCreateImageKHR) { |
| 1106 | result = cnx->egl.eglCreateImageKHR( |
| 1107 | dp->disp.dpy, |
| 1108 | c ? c->context : EGL_NO_CONTEXT, |
| 1109 | target, buffer, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1110 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1111 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) |
| 1115 | { |
| 1116 | clearError(); |
| 1117 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1118 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1119 | if (!dp) return EGL_FALSE; |
| 1120 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1121 | egl_connection_t* const cnx = &gEGLImpl; |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1122 | if (cnx->dso && cnx->egl.eglDestroyImageKHR) { |
| 1123 | cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1124 | } |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1125 | return EGL_TRUE; |
| 1126 | } |
| 1127 | |
| 1128 | // ---------------------------------------------------------------------------- |
| 1129 | // EGL_EGLEXT_VERSION 5 |
| 1130 | // ---------------------------------------------------------------------------- |
| 1131 | |
| 1132 | |
| 1133 | EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) |
| 1134 | { |
| 1135 | clearError(); |
| 1136 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1137 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1138 | if (!dp) return EGL_NO_SYNC_KHR; |
| 1139 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1140 | EGLSyncKHR result = EGL_NO_SYNC_KHR; |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1141 | egl_connection_t* const cnx = &gEGLImpl; |
| 1142 | if (cnx->dso && cnx->egl.eglCreateSyncKHR) { |
| 1143 | result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1144 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1145 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) |
| 1149 | { |
| 1150 | clearError(); |
| 1151 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1152 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1153 | if (!dp) return EGL_FALSE; |
| 1154 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1155 | EGLBoolean result = EGL_FALSE; |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1156 | egl_connection_t* const cnx = &gEGLImpl; |
| 1157 | if (cnx->dso && cnx->egl.eglDestroySyncKHR) { |
| 1158 | result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1159 | } |
| 1160 | return result; |
| 1161 | } |
| 1162 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1163 | EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, |
| 1164 | EGLint flags, EGLTimeKHR timeout) |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1165 | { |
| 1166 | clearError(); |
| 1167 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1168 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1169 | if (!dp) return EGL_FALSE; |
| 1170 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1171 | EGLBoolean result = EGL_FALSE; |
| 1172 | egl_connection_t* const cnx = &gEGLImpl; |
| 1173 | if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) { |
| 1174 | result = cnx->egl.eglClientWaitSyncKHR( |
| 1175 | dp->disp.dpy, sync, flags, timeout); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1176 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1177 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1180 | EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, |
| 1181 | EGLint attribute, EGLint *value) |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1182 | { |
| 1183 | clearError(); |
| 1184 | |
Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 1185 | const egl_display_ptr dp = validate_display(dpy); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1186 | if (!dp) return EGL_FALSE; |
| 1187 | |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1188 | EGLBoolean result = EGL_FALSE; |
| 1189 | egl_connection_t* const cnx = &gEGLImpl; |
| 1190 | if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) { |
| 1191 | result = cnx->egl.eglGetSyncAttribKHR( |
| 1192 | dp->disp.dpy, sync, attribute, value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1193 | } |
Mathias Agopian | 7c0441a | 2012-02-14 17:14:36 -0800 | [diff] [blame] | 1194 | return result; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | // ---------------------------------------------------------------------------- |
| 1198 | // ANDROID extensions |
| 1199 | // ---------------------------------------------------------------------------- |
| 1200 | |
Jamie Gennis | 331841b | 2012-09-06 14:52:00 -0700 | [diff] [blame] | 1201 | EGLint eglDupNativeFenceFDANDROID(EGLDisplay dpy, EGLSyncKHR sync) |
| 1202 | { |
| 1203 | clearError(); |
| 1204 | |
| 1205 | const egl_display_ptr dp = validate_display(dpy); |
| 1206 | if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID; |
| 1207 | |
| 1208 | EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID; |
| 1209 | egl_connection_t* const cnx = &gEGLImpl; |
| 1210 | if (cnx->dso && cnx->egl.eglDupNativeFenceFDANDROID) { |
| 1211 | result = cnx->egl.eglDupNativeFenceFDANDROID(dp->disp.dpy, sync); |
| 1212 | } |
| 1213 | return result; |
| 1214 | } |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1215 | |
Jamie Gennis | 010dd4f | 2012-09-09 17:46:17 -0700 | [diff] [blame] | 1216 | EGLint eglWaitSyncANDROID(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) |
| 1217 | { |
| 1218 | clearError(); |
| 1219 | |
| 1220 | const egl_display_ptr dp = validate_display(dpy); |
| 1221 | if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID; |
| 1222 | |
| 1223 | EGLint result = EGL_FALSE; |
| 1224 | egl_connection_t* const cnx = &gEGLImpl; |
| 1225 | if (cnx->dso && cnx->egl.eglWaitSyncANDROID) { |
| 1226 | result = cnx->egl.eglWaitSyncANDROID(dp->disp.dpy, sync, flags); |
| 1227 | } |
| 1228 | return result; |
| 1229 | } |
| 1230 | |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1231 | // ---------------------------------------------------------------------------- |
| 1232 | // NVIDIA extensions |
| 1233 | // ---------------------------------------------------------------------------- |
| 1234 | EGLuint64NV eglGetSystemTimeFrequencyNV() |
| 1235 | { |
| 1236 | clearError(); |
| 1237 | |
| 1238 | if (egl_init_drivers() == EGL_FALSE) { |
| 1239 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1240 | } |
| 1241 | |
| 1242 | EGLuint64NV ret = 0; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1243 | egl_connection_t* const cnx = &gEGLImpl; |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1244 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1245 | if (cnx->dso && cnx->egl.eglGetSystemTimeFrequencyNV) { |
| 1246 | return cnx->egl.eglGetSystemTimeFrequencyNV(); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1247 | } |
| 1248 | |
Mathias Agopian | 0e8bbee | 2011-10-05 19:15:05 -0700 | [diff] [blame] | 1249 | return setErrorQuiet(EGL_BAD_DISPLAY, 0); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | EGLuint64NV eglGetSystemTimeNV() |
| 1253 | { |
| 1254 | clearError(); |
| 1255 | |
| 1256 | if (egl_init_drivers() == EGL_FALSE) { |
| 1257 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); |
| 1258 | } |
| 1259 | |
| 1260 | EGLuint64NV ret = 0; |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1261 | egl_connection_t* const cnx = &gEGLImpl; |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1262 | |
Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 1263 | if (cnx->dso && cnx->egl.eglGetSystemTimeNV) { |
| 1264 | return cnx->egl.eglGetSystemTimeNV(); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1265 | } |
| 1266 | |
Mathias Agopian | 0e8bbee | 2011-10-05 19:15:05 -0700 | [diff] [blame] | 1267 | return setErrorQuiet(EGL_BAD_DISPLAY, 0); |
Jonas Yang | 1c3d72a | 2011-08-26 20:04:39 +0800 | [diff] [blame] | 1268 | } |