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 | |
Mathias Agopian | 2403533 | 2010-08-02 17:34:32 -0700 | [diff] [blame] | 34 | #include <utils/String8.h> |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 35 | |
Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame^] | 36 | #include "egldefs.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | #include "egl_impl.h" |
David Li | 864f839 | 2011-03-28 10:39:28 -0700 | [diff] [blame] | 38 | #include "egl_tls.h" |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 39 | #include "glesv2dbg.h" |
| 40 | #include "hooks.h" |
| 41 | #include "Loader.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 43 | #include "egl_display.h" |
| 44 | #include "egl_object.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | |
| 46 | // ---------------------------------------------------------------------------- |
| 47 | namespace android { |
| 48 | // ---------------------------------------------------------------------------- |
| 49 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 50 | egl_connection_t gEGLImpl[IMPL_NUM_IMPLEMENTATIONS]; |
| 51 | gl_hooks_t gHooks[2][IMPL_NUM_IMPLEMENTATIONS]; |
| 52 | gl_hooks_t gHooksNoContext; |
| 53 | pthread_key_t gGLWrapperKey = -1; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 54 | |
| 55 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 57 | #if EGL_TRACE |
| 58 | |
| 59 | EGLAPI pthread_key_t gGLTraceKey = -1; |
| 60 | |
| 61 | // ---------------------------------------------------------------------------- |
| 62 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 63 | int gEGLDebugLevel; |
| 64 | |
| 65 | static int sEGLTraceLevel; |
| 66 | static int sEGLApplicationTraceLevel; |
| 67 | |
| 68 | extern gl_hooks_t gHooksTrace; |
| 69 | extern gl_hooks_t gHooksDebug; |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 70 | |
| 71 | static inline void setGlTraceThreadSpecific(gl_hooks_t const *value) { |
| 72 | pthread_setspecific(gGLTraceKey, value); |
| 73 | } |
| 74 | |
| 75 | gl_hooks_t const* getGLTraceThreadSpecific() { |
| 76 | return static_cast<gl_hooks_t*>(pthread_getspecific(gGLTraceKey)); |
| 77 | } |
| 78 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 79 | void initEglTraceLevel() { |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 80 | char value[PROPERTY_VALUE_MAX]; |
| 81 | property_get("debug.egl.trace", value, "0"); |
| 82 | int propertyLevel = atoi(value); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 83 | int applicationLevel = sEGLApplicationTraceLevel; |
| 84 | sEGLTraceLevel = propertyLevel > applicationLevel ? propertyLevel : applicationLevel; |
David Li | 499c6f0 | 2011-04-08 18:43:16 -0700 | [diff] [blame] | 85 | |
David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 86 | property_get("debug.egl.debug_proc", value, ""); |
| 87 | long pid = getpid(); |
| 88 | char procPath[128] = {}; |
| 89 | sprintf(procPath, "/proc/%ld/cmdline", pid); |
| 90 | FILE * file = fopen(procPath, "r"); |
| 91 | if (file) |
| 92 | { |
| 93 | char cmdline[256] = {}; |
| 94 | if (fgets(cmdline, sizeof(cmdline) - 1, file)) |
| 95 | { |
David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 96 | if (!strcmp(value, cmdline)) |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 97 | sEGLTraceLevel = 1; |
David Li | 499c6f0 | 2011-04-08 18:43:16 -0700 | [diff] [blame] | 98 | } |
David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 99 | fclose(file); |
| 100 | } |
David Li | 499c6f0 | 2011-04-08 18:43:16 -0700 | [diff] [blame] | 101 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 102 | if (sEGLTraceLevel > 0) |
David Li | 85f33a7 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 103 | { |
| 104 | property_get("debug.egl.debug_port", value, "5039"); |
David Li | 499c6f0 | 2011-04-08 18:43:16 -0700 | [diff] [blame] | 105 | const unsigned short port = (unsigned short)atoi(value); |
| 106 | property_get("debug.egl.debug_forceUseFile", value, "0"); |
| 107 | const bool forceUseFile = (bool)atoi(value); |
| 108 | property_get("debug.egl.debug_maxFileSize", value, "8"); |
| 109 | const unsigned int maxFileSize = atoi(value) << 20; |
| 110 | property_get("debug.egl.debug_filePath", value, "/data/local/tmp/dump.gles2dbg"); |
| 111 | StartDebugServer(port, forceUseFile, maxFileSize, value); |
David Li | 85f33a7 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 112 | } |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 115 | void setGLHooksThreadSpecific(gl_hooks_t const *value) { |
| 116 | if (sEGLTraceLevel > 0) { |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 117 | setGlTraceThreadSpecific(value); |
| 118 | setGlThreadSpecific(&gHooksTrace); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 119 | } else if (sEGLTraceLevel > 0 && value != &gHooksNoContext) { |
David Li | 2f5a655 | 2011-03-01 16:08:10 -0800 | [diff] [blame] | 120 | setGlTraceThreadSpecific(value); |
| 121 | setGlThreadSpecific(&gHooksDebug); |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 122 | } else { |
| 123 | setGlThreadSpecific(value); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Global entry point to allow applications to modify their own trace level. |
| 129 | * The effective trace level is the max of this level and the value of debug.egl.trace. |
| 130 | */ |
| 131 | extern "C" |
| 132 | void setGLTraceLevel(int level) { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 133 | sEGLApplicationTraceLevel = level; |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | #else |
| 137 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 138 | void setGLHooksThreadSpecific(gl_hooks_t const *value) { |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 139 | setGlThreadSpecific(value); |
| 140 | } |
| 141 | |
| 142 | #endif |
| 143 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | /*****************************************************************************/ |
| 145 | |
Mathias Agopian | 6f08712 | 2010-09-23 16:38:38 -0700 | [diff] [blame] | 146 | static int gl_no_context() { |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 147 | if (egl_tls_t::logNoContextCall()) { |
Mathias Agopian | d274eae | 2009-07-31 16:21:17 -0700 | [diff] [blame] | 148 | LOGE("call to OpenGL ES API with no current context " |
| 149 | "(logged once per thread)"); |
| 150 | } |
Mathias Agopian | 6f08712 | 2010-09-23 16:38:38 -0700 | [diff] [blame] | 151 | return 0; |
Mathias Agopian | 05c5311 | 2010-09-23 11:32:52 -0700 | [diff] [blame] | 152 | } |
| 153 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | static void early_egl_init(void) |
| 155 | { |
| 156 | #if !USE_FAST_TLS_KEY |
| 157 | pthread_key_create(&gGLWrapperKey, NULL); |
| 158 | #endif |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 159 | #if EGL_TRACE |
| 160 | pthread_key_create(&gGLTraceKey, NULL); |
| 161 | initEglTraceLevel(); |
| 162 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | uint32_t addr = (uint32_t)((void*)gl_no_context); |
| 164 | android_memset32( |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 165 | (uint32_t*)(void*)&gHooksNoContext, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | addr, |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 167 | sizeof(gHooksNoContext)); |
Mathias Agopian | 05c5311 | 2010-09-23 11:32:52 -0700 | [diff] [blame] | 168 | |
Jack Palevich | a2dd6cf | 2010-10-26 15:21:24 -0700 | [diff] [blame] | 169 | setGLHooksThreadSpecific(&gHooksNoContext); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static pthread_once_t once_control = PTHREAD_ONCE_INIT; |
| 173 | static int sEarlyInitState = pthread_once(&once_control, &early_egl_init); |
| 174 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 175 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 177 | egl_display_t* validate_display(EGLDisplay dpy) { |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame] | 178 | egl_display_t * const dp = get_display(dpy); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 179 | if (!dp) |
| 180 | return setError(EGL_BAD_DISPLAY, (egl_display_t*)NULL); |
| 181 | if (!dp->isReady()) |
| 182 | return setError(EGL_NOT_INITIALIZED, (egl_display_t*)NULL); |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame] | 183 | |
| 184 | return dp; |
| 185 | } |
| 186 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 187 | egl_connection_t* validate_display_config(EGLDisplay dpy, EGLConfig config, |
| 188 | egl_display_t const*& dp) { |
Eric Hassold | 3ede7c1 | 2011-03-23 15:59:00 -0700 | [diff] [blame] | 189 | dp = validate_display(dpy); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 190 | if (!dp) |
| 191 | return (egl_connection_t*) NULL; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 193 | if (intptr_t(config) >= dp->numTotalConfigs) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL); |
| 195 | } |
Mathias Agopian | cee7939 | 2010-07-26 21:14:59 -0700 | [diff] [blame] | 196 | egl_connection_t* const cnx = &gEGLImpl[dp->configs[intptr_t(config)].impl]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | if (cnx->dso == 0) { |
| 198 | return setError(EGL_BAD_CONFIG, (egl_connection_t*)NULL); |
| 199 | } |
| 200 | return cnx; |
| 201 | } |
| 202 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 203 | // ---------------------------------------------------------------------------- |
| 204 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 205 | EGLImageKHR egl_get_image_for_current_context(EGLImageKHR image) |
| 206 | { |
Mathias Agopian | 9429e9c | 2009-08-21 02:18:25 -0700 | [diff] [blame] | 207 | ImageRef _i(image); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 208 | if (!_i.get()) |
| 209 | return EGL_NO_IMAGE_KHR; |
| 210 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 211 | EGLContext context = egl_tls_t::getContext(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 212 | if (context == EGL_NO_CONTEXT || image == EGL_NO_IMAGE_KHR) |
| 213 | return EGL_NO_IMAGE_KHR; |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 214 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 215 | egl_context_t const * const c = get_context(context); |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 216 | if (c == NULL) // this should never happen |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 217 | return EGL_NO_IMAGE_KHR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | |
Mathias Agopian | 5b287a6 | 2011-05-16 18:58:55 -0700 | [diff] [blame] | 219 | // here we don't validate the context because if it's been marked for |
| 220 | // termination, this call should still succeed since it's internal to |
| 221 | // EGL. |
| 222 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 223 | egl_image_t const * const i = get_image(image); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 224 | return i->images[c->impl]; |
| 225 | } |
| 226 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 227 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 228 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 229 | // this mutex protects: |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 230 | // d->disp[] |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 231 | // egl_init_drivers_locked() |
| 232 | // |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 233 | static EGLBoolean egl_init_drivers_locked() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | if (sEarlyInitState) { |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 235 | // initialized by static ctor. should be set here. |
| 236 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 239 | // get our driver loader |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 240 | Loader& loader(Loader::getInstance()); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 241 | |
| 242 | // dynamically load all our EGL implementations |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 243 | egl_connection_t* cnx; |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 244 | |
| 245 | cnx = &gEGLImpl[IMPL_SOFTWARE]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | if (cnx->dso == 0) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 247 | cnx->hooks[GLESv1_INDEX] = &gHooks[GLESv1_INDEX][IMPL_SOFTWARE]; |
| 248 | cnx->hooks[GLESv2_INDEX] = &gHooks[GLESv2_INDEX][IMPL_SOFTWARE]; |
| 249 | cnx->dso = loader.open(EGL_DEFAULT_DISPLAY, 0, cnx); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | cnx = &gEGLImpl[IMPL_HARDWARE]; |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 253 | if (cnx->dso == 0) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | char value[PROPERTY_VALUE_MAX]; |
| 255 | property_get("debug.egl.hw", value, "1"); |
| 256 | if (atoi(value) != 0) { |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 257 | cnx->hooks[GLESv1_INDEX] = &gHooks[GLESv1_INDEX][IMPL_HARDWARE]; |
| 258 | cnx->hooks[GLESv2_INDEX] = &gHooks[GLESv2_INDEX][IMPL_HARDWARE]; |
| 259 | cnx->dso = loader.open(EGL_DEFAULT_DISPLAY, 1, cnx); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | } else { |
| 261 | LOGD("3D hardware acceleration is disabled"); |
| 262 | } |
| 263 | } |
Mathias Agopian | a69e0ed | 2009-08-24 21:47:13 -0700 | [diff] [blame] | 264 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 265 | if (!gEGLImpl[IMPL_SOFTWARE].dso && !gEGLImpl[IMPL_HARDWARE].dso) { |
| 266 | return EGL_FALSE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 269 | return EGL_TRUE; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 272 | static pthread_mutex_t sInitDriverMutex = PTHREAD_MUTEX_INITIALIZER; |
| 273 | |
| 274 | EGLBoolean egl_init_drivers() { |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 275 | EGLBoolean res; |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 276 | pthread_mutex_lock(&sInitDriverMutex); |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 277 | res = egl_init_drivers_locked(); |
Mathias Agopian | 518ec11 | 2011-05-13 16:21:08 -0700 | [diff] [blame] | 278 | pthread_mutex_unlock(&sInitDriverMutex); |
Mathias Agopian | 923c661 | 2009-08-17 18:07:06 -0700 | [diff] [blame] | 279 | return res; |
| 280 | } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 281 | |
Mathias Agopian | 1cadb25 | 2011-05-23 17:26:14 -0700 | [diff] [blame^] | 282 | void gl_unimplemented() { |
| 283 | LOGE("called unimplemented OpenGL ES API"); |
| 284 | } |
| 285 | |
| 286 | // ---------------------------------------------------------------------------- |
| 287 | |
| 288 | #if USE_FAST_TLS_KEY |
| 289 | |
| 290 | // We have a dedicated TLS slot in bionic |
| 291 | static inline gl_hooks_t const * volatile * get_tls_hooks() { |
| 292 | volatile void *tls_base = __get_tls(); |
| 293 | gl_hooks_t const * volatile * tls_hooks = |
| 294 | reinterpret_cast<gl_hooks_t const * volatile *>(tls_base); |
| 295 | return tls_hooks; |
| 296 | } |
| 297 | |
| 298 | void setGlThreadSpecific(gl_hooks_t const *value) { |
| 299 | gl_hooks_t const * volatile * tls_hooks = get_tls_hooks(); |
| 300 | tls_hooks[TLS_SLOT_OPENGL_API] = value; |
| 301 | } |
| 302 | |
| 303 | gl_hooks_t const* getGlThreadSpecific() { |
| 304 | gl_hooks_t const * volatile * tls_hooks = get_tls_hooks(); |
| 305 | gl_hooks_t const* hooks = tls_hooks[TLS_SLOT_OPENGL_API]; |
| 306 | if (hooks) return hooks; |
| 307 | return &gHooksNoContext; |
| 308 | } |
| 309 | |
| 310 | #else |
| 311 | |
| 312 | void setGlThreadSpecific(gl_hooks_t const *value) { |
| 313 | pthread_setspecific(gGLWrapperKey, value); |
| 314 | } |
| 315 | |
| 316 | gl_hooks_t const* getGlThreadSpecific() { |
| 317 | gl_hooks_t const* hooks = static_cast<gl_hooks_t*>(pthread_getspecific(gGLWrapperKey)); |
| 318 | if (hooks) return hooks; |
| 319 | return &gHooksNoContext; |
| 320 | } |
| 321 | |
| 322 | #endif |
| 323 | |
| 324 | // ---------------------------------------------------------------------------- |
| 325 | // GL / EGL hooks |
| 326 | // ---------------------------------------------------------------------------- |
| 327 | |
| 328 | #undef GL_ENTRY |
| 329 | #undef EGL_ENTRY |
| 330 | #define GL_ENTRY(_r, _api, ...) #_api, |
| 331 | #define EGL_ENTRY(_r, _api, ...) #_api, |
| 332 | |
| 333 | char const * const gl_names[] = { |
| 334 | #include "entries.in" |
| 335 | NULL |
| 336 | }; |
| 337 | |
| 338 | char const * const egl_names[] = { |
| 339 | #include "egl_entries.in" |
| 340 | NULL |
| 341 | }; |
| 342 | |
| 343 | #undef GL_ENTRY |
| 344 | #undef EGL_ENTRY |
| 345 | |
| 346 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 347 | // ---------------------------------------------------------------------------- |
| 348 | }; // namespace android |
| 349 | // ---------------------------------------------------------------------------- |
| 350 | |