| 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 |  | 
|  | 17 | #ifndef ANDROID_GLES_CM_HOOKS_H | 
|  | 18 | #define ANDROID_GLES_CM_HOOKS_H | 
|  | 19 |  | 
|  | 20 | #include <ctype.h> | 
|  | 21 | #include <string.h> | 
|  | 22 | #include <errno.h> | 
|  | 23 |  | 
| Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 24 | #include <pthread.h> | 
|  | 25 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include <EGL/egl.h> | 
| Mathias Agopian | 53238bd | 2009-04-22 18:24:18 -0700 | [diff] [blame] | 27 | #include <EGL/eglext.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <GLES/gl.h> | 
| Mathias Agopian | 53238bd | 2009-04-22 18:24:18 -0700 | [diff] [blame] | 29 | #include <GLES/glext.h> | 
| Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 30 | #include <GLES2/gl2.h> | 
|  | 31 | #include <GLES2/gl2ext.h> | 
|  | 32 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | #if !defined(__arm__) | 
|  | 34 | #define USE_SLOW_BINDING            1 | 
|  | 35 | #else | 
|  | 36 | #define USE_SLOW_BINDING            0 | 
|  | 37 | #endif | 
|  | 38 | #undef NELEM | 
|  | 39 | #define NELEM(x)                    (sizeof(x)/sizeof(*(x))) | 
|  | 40 | #define MAX_NUMBER_OF_GL_EXTENSIONS 32 | 
|  | 41 |  | 
|  | 42 |  | 
| Mathias Agopian | 53238bd | 2009-04-22 18:24:18 -0700 | [diff] [blame] | 43 | #if defined(HAVE_ANDROID_OS) && !USE_SLOW_BINDING && __OPTIMIZE__ | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | #define USE_FAST_TLS_KEY            1 | 
|  | 45 | #else | 
|  | 46 | #define USE_FAST_TLS_KEY            0 | 
|  | 47 | #endif | 
|  | 48 |  | 
|  | 49 | #if USE_FAST_TLS_KEY | 
|  | 50 | #   include <bionic_tls.h>  /* special private C library header */ | 
|  | 51 | #endif | 
|  | 52 |  | 
|  | 53 | // ---------------------------------------------------------------------------- | 
|  | 54 | namespace android { | 
|  | 55 | // ---------------------------------------------------------------------------- | 
|  | 56 |  | 
|  | 57 | //  EGLDisplay are global, not attached to a given thread | 
|  | 58 | const unsigned int NUM_DISPLAYS = 1; | 
|  | 59 |  | 
|  | 60 | enum { | 
|  | 61 | IMPL_HARDWARE = 0, | 
|  | 62 | IMPL_SOFTWARE, | 
| Mathias Agopian | 53238bd | 2009-04-22 18:24:18 -0700 | [diff] [blame] | 63 |  | 
|  | 64 | IMPL_NUM_DRIVERS_IMPLEMENTATIONS, | 
|  | 65 |  | 
|  | 66 | IMPL_CONTEXT_LOST = IMPL_NUM_DRIVERS_IMPLEMENTATIONS, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | IMPL_NO_CONTEXT, | 
|  | 68 |  | 
|  | 69 | IMPL_NUM_IMPLEMENTATIONS | 
|  | 70 | }; | 
|  | 71 |  | 
|  | 72 | // ---------------------------------------------------------------------------- | 
|  | 73 |  | 
|  | 74 | // GL / EGL hooks | 
|  | 75 |  | 
|  | 76 | #undef GL_ENTRY | 
|  | 77 | #undef EGL_ENTRY | 
|  | 78 | #define GL_ENTRY(_r, _api, ...) _r (*_api)(__VA_ARGS__); | 
|  | 79 | #define EGL_ENTRY(_r, _api, ...) _r (*_api)(__VA_ARGS__); | 
|  | 80 |  | 
|  | 81 | struct gl_hooks_t { | 
|  | 82 | struct gl_t { | 
| Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 83 | #include "GLES_CM/gl_entries.in" | 
|  | 84 | #include "GLES_CM/glext_entries.in" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | } gl; | 
| Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 86 | struct gl2_t { | 
|  | 87 | #include "GLES2/gl2_entries.in" | 
|  | 88 | #include "GLES2/gl2ext_entries.in" | 
|  | 89 | } gl2; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | struct egl_t { | 
| Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 91 | #include "EGL/egl_entries.in" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | } egl; | 
|  | 93 | struct gl_ext_t { | 
|  | 94 | void (*extensions[MAX_NUMBER_OF_GL_EXTENSIONS])(void); | 
|  | 95 | } ext; | 
|  | 96 | }; | 
|  | 97 | #undef GL_ENTRY | 
|  | 98 | #undef EGL_ENTRY | 
|  | 99 |  | 
|  | 100 |  | 
|  | 101 | // ---------------------------------------------------------------------------- | 
|  | 102 |  | 
|  | 103 | extern gl_hooks_t gHooks[IMPL_NUM_IMPLEMENTATIONS]; | 
|  | 104 | extern pthread_key_t gGLWrapperKey; | 
| Mathias Agopian | de58697 | 2009-05-28 17:39:03 -0700 | [diff] [blame] | 105 | extern "C" void gl_unimplemented(); | 
|  | 106 |  | 
|  | 107 | extern char const * const gl_names[]; | 
|  | 108 | extern char const * const gl2_names[]; | 
|  | 109 | extern char const * const egl_names[]; | 
|  | 110 |  | 
|  | 111 | // ---------------------------------------------------------------------------- | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 |  | 
|  | 113 | #if USE_FAST_TLS_KEY | 
|  | 114 |  | 
|  | 115 | // We have a dedicated TLS slot in bionic | 
|  | 116 | static inline gl_hooks_t const * volatile * get_tls_hooks() { | 
|  | 117 | volatile void *tls_base = __get_tls(); | 
|  | 118 | gl_hooks_t const * volatile * tls_hooks = | 
|  | 119 | reinterpret_cast<gl_hooks_t const * volatile *>(tls_base); | 
|  | 120 | return tls_hooks; | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | static inline void setGlThreadSpecific(gl_hooks_t const *value) { | 
|  | 124 | gl_hooks_t const * volatile * tls_hooks = get_tls_hooks(); | 
|  | 125 | tls_hooks[TLS_SLOT_OPENGL_API] = value; | 
|  | 126 | } | 
|  | 127 |  | 
|  | 128 | static gl_hooks_t const* getGlThreadSpecific() { | 
|  | 129 | gl_hooks_t const * volatile * tls_hooks = get_tls_hooks(); | 
|  | 130 | gl_hooks_t const* hooks = tls_hooks[TLS_SLOT_OPENGL_API]; | 
|  | 131 | if (hooks) return hooks; | 
|  | 132 | return &gHooks[IMPL_NO_CONTEXT]; | 
|  | 133 | } | 
|  | 134 |  | 
|  | 135 | #else | 
|  | 136 |  | 
|  | 137 | static inline void setGlThreadSpecific(gl_hooks_t const *value) { | 
|  | 138 | pthread_setspecific(gGLWrapperKey, value); | 
|  | 139 | } | 
|  | 140 |  | 
|  | 141 | static gl_hooks_t const* getGlThreadSpecific() { | 
|  | 142 | gl_hooks_t const* hooks =  static_cast<gl_hooks_t*>(pthread_getspecific(gGLWrapperKey)); | 
|  | 143 | if (hooks) return hooks; | 
|  | 144 | return &gHooks[IMPL_NO_CONTEXT]; | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | #endif | 
|  | 148 |  | 
|  | 149 |  | 
|  | 150 | // ---------------------------------------------------------------------------- | 
|  | 151 | }; // namespace android | 
|  | 152 | // ---------------------------------------------------------------------------- | 
|  | 153 |  | 
|  | 154 | #endif /* ANDROID_GLES_CM_HOOKS_H */ |