2 ** Copyright 2007, The Android Open Source Project
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
8 ** http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_GLES_CM_HOOKS_H
18 #define ANDROID_GLES_CM_HOOKS_H
27 #include <EGL/eglext.h>
29 #include <GLES/glext.h>
30 #include <GLES2/gl2.h>
31 #include <GLES2/gl2ext.h>
34 #define USE_SLOW_BINDING 1
36 #define USE_SLOW_BINDING 0
39 #define NELEM(x) (sizeof(x)/sizeof(*(x)))
40 #define MAX_NUMBER_OF_GL_EXTENSIONS 64
43 #if defined(HAVE_ANDROID_OS) && !USE_SLOW_BINDING && __OPTIMIZE__
44 #define USE_FAST_TLS_KEY 1
46 #define USE_FAST_TLS_KEY 0
50 # include <bionic_tls.h> /* special private C library header */
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 // EGLDisplay are global, not attached to a given thread
58 const unsigned int NUM_DISPLAYS = 1;
63 IMPL_NUM_IMPLEMENTATIONS
71 // ----------------------------------------------------------------------------
77 #define GL_ENTRY(_r, _api, ...) _r (*_api)(__VA_ARGS__);
78 #define EGL_ENTRY(_r, _api, ...) _r (*_api)(__VA_ARGS__);
81 #include "EGL/egl_entries.in"
89 __eglMustCastToProperFunctionPointerType extensions[MAX_NUMBER_OF_GL_EXTENSIONS];
96 // ----------------------------------------------------------------------------
98 extern gl_hooks_t gHooks[2][IMPL_NUM_IMPLEMENTATIONS];
99 extern gl_hooks_t gHooksNoContext;
100 extern pthread_key_t gGLWrapperKey;
101 extern "C" void gl_unimplemented();
103 extern char const * const gl_names[];
104 extern char const * const egl_names[];
106 // ----------------------------------------------------------------------------
110 // We have a dedicated TLS slot in bionic
111 static inline gl_hooks_t const * volatile * get_tls_hooks() {
112 volatile void *tls_base = __get_tls();
113 gl_hooks_t const * volatile * tls_hooks =
114 reinterpret_cast<gl_hooks_t const * volatile *>(tls_base);
118 static inline void setGlThreadSpecific(gl_hooks_t const *value) {
119 gl_hooks_t const * volatile * tls_hooks = get_tls_hooks();
120 tls_hooks[TLS_SLOT_OPENGL_API] = value;
123 static gl_hooks_t const* getGlThreadSpecific() {
124 gl_hooks_t const * volatile * tls_hooks = get_tls_hooks();
125 gl_hooks_t const* hooks = tls_hooks[TLS_SLOT_OPENGL_API];
126 if (hooks) return hooks;
127 return &gHooksNoContext;
132 static inline void setGlThreadSpecific(gl_hooks_t const *value) {
133 pthread_setspecific(gGLWrapperKey, value);
136 static gl_hooks_t const* getGlThreadSpecific() {
137 gl_hooks_t const* hooks = static_cast<gl_hooks_t*>(pthread_getspecific(gGLWrapperKey));
138 if (hooks) return hooks;
139 return &gHooksNoContext;
145 // ----------------------------------------------------------------------------
146 }; // namespace android
147 // ----------------------------------------------------------------------------
149 #endif /* ANDROID_GLES_CM_HOOKS_H */