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