| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [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 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <ctype.h> | 
| Mathias Agopian | d8fb7b5 | 2009-05-17 18:50:16 -0700 | [diff] [blame] | 18 | #include <stdlib.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | #include <string.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 21 | #include <hardware/gralloc.h> | 
|  | 22 | #include <system/window.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 |  | 
|  | 24 | #include <EGL/egl.h> | 
|  | 25 | #include <EGL/eglext.h> | 
|  | 26 | #include <GLES/gl.h> | 
|  | 27 | #include <GLES/glext.h> | 
|  | 28 |  | 
|  | 29 | #include <cutils/log.h> | 
|  | 30 | #include <cutils/atomic.h> | 
|  | 31 | #include <cutils/properties.h> | 
|  | 32 | #include <cutils/memory.h> | 
|  | 33 |  | 
| Romain Guy | e03de93 | 2011-07-11 15:33:51 -0700 | [diff] [blame] | 34 | #include <utils/CallStack.h> | 
| Mathias Agopian | 2403533 | 2010-08-02 17:34:32 -0700 | [diff] [blame] | 35 | #include <utils/String8.h> | 
| Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 36 |  | 
| Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 37 | #include "egldefs.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | #include "egl_impl.h" | 
| David Li | 864f839 | 2011-03-28 10:39:28 -0700 | [diff] [blame] | 39 | #include "egl_tls.h" | 
| Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 40 | #include "glestrace.h" | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 41 | #include "hooks.h" | 
|  | 42 | #include "Loader.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 44 | #include "egl_display.h" | 
|  | 45 | #include "egl_object.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 |  | 
|  | 47 | // ---------------------------------------------------------------------------- | 
|  | 48 | namespace android { | 
|  | 49 | // ---------------------------------------------------------------------------- | 
|  | 50 |  | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 51 | egl_connection_t gEGLImpl; | 
|  | 52 | gl_hooks_t gHooks[2]; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 53 | gl_hooks_t gHooksNoContext; | 
|  | 54 | pthread_key_t gGLWrapperKey = -1; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 55 |  | 
|  | 56 | // ---------------------------------------------------------------------------- | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 |  | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 58 | #if EGL_TRACE | 
|  | 59 |  | 
|  | 60 | EGLAPI pthread_key_t gGLTraceKey = -1; | 
|  | 61 |  | 
|  | 62 | // ---------------------------------------------------------------------------- | 
|  | 63 |  | 
| Siva Velusamy | b13c78f | 2012-03-09 14:51:28 -0800 | [diff] [blame] | 64 | /** | 
|  | 65 | * There are two different tracing methods: | 
|  | 66 | * 1. libs/EGL/trace.cpp: Traces all functions to logcat. | 
|  | 67 | *    To enable: | 
|  | 68 | *      - set system property "debug.egl.trace" to 1 to trace all apps. | 
|  | 69 | *      - or call setGLTraceLevel(1) from an app to enable tracing for that app. | 
|  | 70 | * 2. libs/GLES_trace: Traces all functions via protobuf to host. | 
|  | 71 | *    To enable: | 
|  | 72 | *        - set system property "debug.egl.debug_proc" to the application name. | 
|  | 73 | *      - or call setGLDebugLevel(1) from the app. | 
|  | 74 | */ | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 75 | static int sEGLTraceLevel; | 
|  | 76 | static int sEGLApplicationTraceLevel; | 
|  | 77 |  | 
| Siva Velusamy | b13c78f | 2012-03-09 14:51:28 -0800 | [diff] [blame] | 78 | int gEGLDebugLevel; | 
|  | 79 | static int sEGLApplicationDebugLevel; | 
|  | 80 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 81 | extern gl_hooks_t gHooksTrace; | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 82 |  | 
|  | 83 | static inline void setGlTraceThreadSpecific(gl_hooks_t const *value) { | 
|  | 84 | pthread_setspecific(gGLTraceKey, value); | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | gl_hooks_t const* getGLTraceThreadSpecific() { | 
|  | 88 | return static_cast<gl_hooks_t*>(pthread_getspecific(gGLTraceKey)); | 
|  | 89 | } | 
|  | 90 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 91 | void initEglTraceLevel() { | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 92 | char value[PROPERTY_VALUE_MAX]; | 
|  | 93 | property_get("debug.egl.trace", value, "0"); | 
|  | 94 | int propertyLevel = atoi(value); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 95 | int applicationLevel = sEGLApplicationTraceLevel; | 
|  | 96 | sEGLTraceLevel = propertyLevel > applicationLevel ? propertyLevel : applicationLevel; | 
| Siva Velusamy | b13c78f | 2012-03-09 14:51:28 -0800 | [diff] [blame] | 97 | } | 
| David Li | 499c6f0 | 2011-04-08 18:43:16 -0700 | [diff] [blame] | 98 |  | 
| Siva Velusamy | b13c78f | 2012-03-09 14:51:28 -0800 | [diff] [blame] | 99 | void initEglDebugLevel() { | 
|  | 100 | int propertyLevel = 0; | 
|  | 101 | char value[PROPERTY_VALUE_MAX]; | 
| David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 102 | property_get("debug.egl.debug_proc", value, ""); | 
| Siva Velusamy | b13c78f | 2012-03-09 14:51:28 -0800 | [diff] [blame] | 103 | if (strlen(value) > 0) { | 
|  | 104 | long pid = getpid(); | 
|  | 105 | char procPath[128] = {}; | 
|  | 106 | sprintf(procPath, "/proc/%ld/cmdline", pid); | 
|  | 107 | FILE * file = fopen(procPath, "r"); | 
|  | 108 | if (file) { | 
|  | 109 | char cmdline[256] = {}; | 
|  | 110 | if (fgets(cmdline, sizeof(cmdline) - 1, file)) { | 
|  | 111 | if (!strncmp(value, cmdline, strlen(value))) { | 
|  | 112 | // set EGL debug if the "debug.egl.debug_proc" property | 
|  | 113 | // matches the prefix of this application's command line | 
|  | 114 | propertyLevel = 1; | 
|  | 115 | } | 
| Siva Velusamy | 93a826f | 2011-12-14 12:19:56 -0800 | [diff] [blame] | 116 | } | 
| Siva Velusamy | b13c78f | 2012-03-09 14:51:28 -0800 | [diff] [blame] | 117 | fclose(file); | 
| David Li | 499c6f0 | 2011-04-08 18:43:16 -0700 | [diff] [blame] | 118 | } | 
| David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 119 | } | 
| David Li | 499c6f0 | 2011-04-08 18:43:16 -0700 | [diff] [blame] | 120 |  | 
| Siva Velusamy | b13c78f | 2012-03-09 14:51:28 -0800 | [diff] [blame] | 121 | gEGLDebugLevel = propertyLevel || sEGLApplicationDebugLevel; | 
| Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 122 | if (gEGLDebugLevel > 0) { | 
|  | 123 | GLTrace_start(); | 
| David Li | 85f33a7 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 124 | } | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 125 | } | 
|  | 126 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 127 | void setGLHooksThreadSpecific(gl_hooks_t const *value) { | 
|  | 128 | if (sEGLTraceLevel > 0) { | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 129 | setGlTraceThreadSpecific(value); | 
|  | 130 | setGlThreadSpecific(&gHooksTrace); | 
| Mathias Agopian | ccfa5c3 | 2011-09-01 14:55:00 -0700 | [diff] [blame] | 131 | } else if (gEGLDebugLevel > 0 && value != &gHooksNoContext) { | 
| David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 132 | setGlTraceThreadSpecific(value); | 
| Siva Velusamy | 0469dd6 | 2011-11-30 15:05:37 -0800 | [diff] [blame] | 133 | setGlThreadSpecific(GLTrace_getGLHooks()); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 134 | } else { | 
|  | 135 | setGlThreadSpecific(value); | 
|  | 136 | } | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | /* | 
|  | 140 | * Global entry point to allow applications to modify their own trace level. | 
|  | 141 | * The effective trace level is the max of this level and the value of debug.egl.trace. | 
|  | 142 | */ | 
|  | 143 | extern "C" | 
|  | 144 | void setGLTraceLevel(int level) { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 145 | sEGLApplicationTraceLevel = level; | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 146 | } | 
|  | 147 |  | 
| Siva Velusamy | b13c78f | 2012-03-09 14:51:28 -0800 | [diff] [blame] | 148 | /* | 
|  | 149 | * Global entry point to allow applications to modify their own debug level. | 
|  | 150 | * Debugging is enabled if either the application requested it, or if the system property | 
|  | 151 | * matches the application's name. | 
|  | 152 | */ | 
|  | 153 | void EGLAPI setGLDebugLevel(int level) { | 
|  | 154 | sEGLApplicationDebugLevel = level; | 
|  | 155 | } | 
|  | 156 |  | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 157 | #else | 
|  | 158 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 159 | void setGLHooksThreadSpecific(gl_hooks_t const *value) { | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 160 | setGlThreadSpecific(value); | 
|  | 161 | } | 
|  | 162 |  | 
|  | 163 | #endif | 
|  | 164 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | /*****************************************************************************/ | 
|  | 166 |  | 
| Mathias Agopian | 6f08712 | 2010-09-23 16:38:38 -0700 | [diff] [blame] | 167 | static int gl_no_context() { | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 168 | if (egl_tls_t::logNoContextCall()) { | 
| Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 169 | ALOGE("call to OpenGL ES API with no current context " | 
| Mathias Agopian | d274eae | 2009-07-31 16:21:17 -0700 | [diff] [blame] | 170 | "(logged once per thread)"); | 
| Mathias Agopian | ecfe091 | 2011-09-06 17:24:05 -0700 | [diff] [blame] | 171 | char value[PROPERTY_VALUE_MAX]; | 
|  | 172 | property_get("debug.egl.callstack", value, "0"); | 
|  | 173 | if (atoi(value)) { | 
|  | 174 | CallStack stack; | 
|  | 175 | stack.update(); | 
|  | 176 | stack.dump(); | 
|  | 177 | } | 
| Mathias Agopian | d274eae | 2009-07-31 16:21:17 -0700 | [diff] [blame] | 178 | } | 
| Mathias Agopian | 6f08712 | 2010-09-23 16:38:38 -0700 | [diff] [blame] | 179 | return 0; | 
| Mathias Agopian | 05c5311 | 2010-09-23 11:32:52 -0700 | [diff] [blame] | 180 | } | 
|  | 181 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | static void early_egl_init(void) | 
|  | 183 | { | 
|  | 184 | #if !USE_FAST_TLS_KEY | 
|  | 185 | pthread_key_create(&gGLWrapperKey, NULL); | 
|  | 186 | #endif | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 187 | #if EGL_TRACE | 
|  | 188 | pthread_key_create(&gGLTraceKey, NULL); | 
|  | 189 | initEglTraceLevel(); | 
| Siva Velusamy | b13c78f | 2012-03-09 14:51:28 -0800 | [diff] [blame] | 190 | initEglDebugLevel(); | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 191 | #endif | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | uint32_t addr = (uint32_t)((void*)gl_no_context); | 
|  | 193 | android_memset32( | 
| Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 194 | (uint32_t*)(void*)&gHooksNoContext, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | addr, | 
| Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 196 | sizeof(gHooksNoContext)); | 
| Mathias Agopian | 05c5311 | 2010-09-23 11:32:52 -0700 | [diff] [blame] | 197 |  | 
| Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 198 | setGLHooksThreadSpecific(&gHooksNoContext); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | } | 
|  | 200 |  | 
|  | 201 | static pthread_once_t once_control = PTHREAD_ONCE_INIT; | 
|  | 202 | static int sEarlyInitState = pthread_once(&once_control, &early_egl_init); | 
|  | 203 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 204 | // ---------------------------------------------------------------------------- | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 206 | egl_display_ptr validate_display(EGLDisplay dpy) { | 
|  | 207 | egl_display_ptr dp = get_display(dpy); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 208 | if (!dp) | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 209 | return setError(EGL_BAD_DISPLAY, egl_display_ptr(NULL)); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 210 | if (!dp->isReady()) | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 211 | return setError(EGL_NOT_INITIALIZED, egl_display_ptr(NULL)); | 
| Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame] | 212 |  | 
|  | 213 | return dp; | 
|  | 214 | } | 
|  | 215 |  | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 216 | egl_display_ptr validate_display_connection(EGLDisplay dpy, | 
|  | 217 | egl_connection_t*& cnx) { | 
|  | 218 | cnx = NULL; | 
|  | 219 | egl_display_ptr dp = validate_display(dpy); | 
| Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 220 | if (!dp) | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 221 | return dp; | 
|  | 222 | cnx = &gEGLImpl; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | if (cnx->dso == 0) { | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 224 | return setError(EGL_BAD_CONFIG, egl_display_ptr(NULL)); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | } | 
| Jesse Hall | b29e5e8 | 2012-04-04 16:53:42 -0700 | [diff] [blame] | 226 | return dp; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | } | 
|  | 228 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 229 | // ---------------------------------------------------------------------------- | 
|  | 230 |  | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 231 | const GLubyte * egl_get_string_for_current_context(GLenum name) { | 
|  | 232 | // NOTE: returning NULL here will fall-back to the default | 
|  | 233 | // implementation. | 
|  | 234 |  | 
|  | 235 | EGLContext context = egl_tls_t::getContext(); | 
|  | 236 | if (context == EGL_NO_CONTEXT) | 
|  | 237 | return NULL; | 
|  | 238 |  | 
|  | 239 | egl_context_t const * const c = get_context(context); | 
|  | 240 | if (c == NULL) // this should never happen, by construction | 
|  | 241 | return NULL; | 
|  | 242 |  | 
|  | 243 | if (name != GL_EXTENSIONS) | 
|  | 244 | return NULL; | 
|  | 245 |  | 
|  | 246 | return (const GLubyte *)c->gl_extensions.string(); | 
|  | 247 | } | 
|  | 248 |  | 
|  | 249 | // ---------------------------------------------------------------------------- | 
|  | 250 |  | 
| Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 251 | // this mutex protects: | 
| Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 252 | //    d->disp[] | 
| Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 253 | //    egl_init_drivers_locked() | 
|  | 254 | // | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 255 | static EGLBoolean egl_init_drivers_locked() { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | if (sEarlyInitState) { | 
| Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 257 | // initialized by static ctor. should be set here. | 
|  | 258 | return EGL_FALSE; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | } | 
|  | 260 |  | 
| Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 261 | // get our driver loader | 
| Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 262 | Loader& loader(Loader::getInstance()); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 263 |  | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 264 | // dynamically load our EGL implementation | 
|  | 265 | egl_connection_t* cnx = &gEGLImpl; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | if (cnx->dso == 0) { | 
| Mathias Agopian | 7773c43 | 2012-02-13 20:06:08 -0800 | [diff] [blame] | 267 | cnx->hooks[egl_connection_t::GLESv1_INDEX] = | 
|  | 268 | &gHooks[egl_connection_t::GLESv1_INDEX]; | 
|  | 269 | cnx->hooks[egl_connection_t::GLESv2_INDEX] = | 
|  | 270 | &gHooks[egl_connection_t::GLESv2_INDEX]; | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 271 | cnx->dso = loader.open(cnx); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | } | 
|  | 273 |  | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 274 | return cnx->dso ? EGL_TRUE : EGL_FALSE; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | } | 
|  | 276 |  | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 277 | static pthread_mutex_t sInitDriverMutex = PTHREAD_MUTEX_INITIALIZER; | 
|  | 278 |  | 
|  | 279 | EGLBoolean egl_init_drivers() { | 
| Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 280 | EGLBoolean res; | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 281 | pthread_mutex_lock(&sInitDriverMutex); | 
| Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 282 | res = egl_init_drivers_locked(); | 
| Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 283 | pthread_mutex_unlock(&sInitDriverMutex); | 
| Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 284 | return res; | 
|  | 285 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 286 |  | 
| Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 287 | void gl_unimplemented() { | 
| Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 288 | ALOGE("called unimplemented OpenGL ES API"); | 
| Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 289 | } | 
|  | 290 |  | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 291 | void gl_noop() { | 
|  | 292 | } | 
|  | 293 |  | 
| Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame] | 294 | // ---------------------------------------------------------------------------- | 
|  | 295 |  | 
|  | 296 | #if USE_FAST_TLS_KEY | 
|  | 297 |  | 
|  | 298 | // We have a dedicated TLS slot in bionic | 
|  | 299 | static inline gl_hooks_t const * volatile * get_tls_hooks() { | 
|  | 300 | volatile void *tls_base = __get_tls(); | 
|  | 301 | gl_hooks_t const * volatile * tls_hooks = | 
|  | 302 | reinterpret_cast<gl_hooks_t const * volatile *>(tls_base); | 
|  | 303 | return tls_hooks; | 
|  | 304 | } | 
|  | 305 |  | 
|  | 306 | void setGlThreadSpecific(gl_hooks_t const *value) { | 
|  | 307 | gl_hooks_t const * volatile * tls_hooks = get_tls_hooks(); | 
|  | 308 | tls_hooks[TLS_SLOT_OPENGL_API] = value; | 
|  | 309 | } | 
|  | 310 |  | 
|  | 311 | gl_hooks_t const* getGlThreadSpecific() { | 
|  | 312 | gl_hooks_t const * volatile * tls_hooks = get_tls_hooks(); | 
|  | 313 | gl_hooks_t const* hooks = tls_hooks[TLS_SLOT_OPENGL_API]; | 
|  | 314 | if (hooks) return hooks; | 
|  | 315 | return &gHooksNoContext; | 
|  | 316 | } | 
|  | 317 |  | 
|  | 318 | #else | 
|  | 319 |  | 
|  | 320 | void setGlThreadSpecific(gl_hooks_t const *value) { | 
|  | 321 | pthread_setspecific(gGLWrapperKey, value); | 
|  | 322 | } | 
|  | 323 |  | 
|  | 324 | gl_hooks_t const* getGlThreadSpecific() { | 
|  | 325 | gl_hooks_t const* hooks =  static_cast<gl_hooks_t*>(pthread_getspecific(gGLWrapperKey)); | 
|  | 326 | if (hooks) return hooks; | 
|  | 327 | return &gHooksNoContext; | 
|  | 328 | } | 
|  | 329 |  | 
|  | 330 | #endif | 
|  | 331 |  | 
|  | 332 | // ---------------------------------------------------------------------------- | 
|  | 333 | // GL / EGL hooks | 
|  | 334 | // ---------------------------------------------------------------------------- | 
|  | 335 |  | 
|  | 336 | #undef GL_ENTRY | 
|  | 337 | #undef EGL_ENTRY | 
|  | 338 | #define GL_ENTRY(_r, _api, ...) #_api, | 
|  | 339 | #define EGL_ENTRY(_r, _api, ...) #_api, | 
|  | 340 |  | 
|  | 341 | char const * const gl_names[] = { | 
|  | 342 | #include "entries.in" | 
|  | 343 | NULL | 
|  | 344 | }; | 
|  | 345 |  | 
|  | 346 | char const * const egl_names[] = { | 
|  | 347 | #include "egl_entries.in" | 
|  | 348 | NULL | 
|  | 349 | }; | 
|  | 350 |  | 
|  | 351 | #undef GL_ENTRY | 
|  | 352 | #undef EGL_ENTRY | 
|  | 353 |  | 
|  | 354 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 355 | // ---------------------------------------------------------------------------- | 
|  | 356 | }; // namespace android | 
|  | 357 | // ---------------------------------------------------------------------------- | 
|  | 358 |  |