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