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