blob: 812e26d10cb8f00cd3b45906f5ddefc3b7455c67 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Agopian9d17c052009-05-28 17:39:03 -070024#include <pthread.h>
25
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026#include <EGL/egl.h>
Mathias Agopiane29254e2009-04-22 18:24:18 -070027#include <EGL/eglext.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028#include <GLES/gl.h>
Mathias Agopiane29254e2009-04-22 18:24:18 -070029#include <GLES/glext.h>
Mathias Agopian2820bd42009-05-27 20:38:06 -070030#include <GLES2/gl2.h>
31#include <GLES2/gl2ext.h>
32
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033#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)))
Mathias Agopian3944eab2010-08-02 17:34:32 -070040#define MAX_NUMBER_OF_GL_EXTENSIONS 64
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
42
Mathias Agopiane29254e2009-04-22 18:24:18 -070043#if defined(HAVE_ANDROID_OS) && !USE_SLOW_BINDING && __OPTIMIZE__
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044#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// ----------------------------------------------------------------------------
54namespace android {
55// ----------------------------------------------------------------------------
56
57// EGLDisplay are global, not attached to a given thread
58const unsigned int NUM_DISPLAYS = 1;
59
60enum {
61 IMPL_HARDWARE = 0,
62 IMPL_SOFTWARE,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 IMPL_NUM_IMPLEMENTATIONS
64};
65
Mathias Agopian6fc56992009-10-14 02:06:37 -070066enum {
67 GLESv1_INDEX = 0,
68 GLESv2_INDEX = 1,
69};
70
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071// ----------------------------------------------------------------------------
72
73// GL / EGL hooks
74
75#undef GL_ENTRY
76#undef EGL_ENTRY
77#define GL_ENTRY(_r, _api, ...) _r (*_api)(__VA_ARGS__);
78#define EGL_ENTRY(_r, _api, ...) _r (*_api)(__VA_ARGS__);
79
Mathias Agopian6fc56992009-10-14 02:06:37 -070080struct egl_t {
81 #include "EGL/egl_entries.in"
82};
83
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084struct gl_hooks_t {
85 struct gl_t {
Mathias Agopian6fc56992009-10-14 02:06:37 -070086 #include "entries.in"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 } gl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 struct gl_ext_t {
Mathias Agopian3944eab2010-08-02 17:34:32 -070089 __eglMustCastToProperFunctionPointerType extensions[MAX_NUMBER_OF_GL_EXTENSIONS];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 } ext;
91};
92#undef GL_ENTRY
93#undef EGL_ENTRY
94
95
96// ----------------------------------------------------------------------------
97
Mathias Agopian6fc56992009-10-14 02:06:37 -070098extern gl_hooks_t gHooks[2][IMPL_NUM_IMPLEMENTATIONS];
99extern gl_hooks_t gHooksNoContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100extern pthread_key_t gGLWrapperKey;
Mathias Agopian9d17c052009-05-28 17:39:03 -0700101extern "C" void gl_unimplemented();
102
103extern char const * const gl_names[];
Mathias Agopian9d17c052009-05-28 17:39:03 -0700104extern char const * const egl_names[];
105
106// ----------------------------------------------------------------------------
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107
108#if USE_FAST_TLS_KEY
109
110// We have a dedicated TLS slot in bionic
111static 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);
115 return tls_hooks;
116}
117
118static 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;
121}
122
123static 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;
Mathias Agopian6fc56992009-10-14 02:06:37 -0700127 return &gHooksNoContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128}
129
130#else
131
132static inline void setGlThreadSpecific(gl_hooks_t const *value) {
133 pthread_setspecific(gGLWrapperKey, value);
134}
135
136static gl_hooks_t const* getGlThreadSpecific() {
137 gl_hooks_t const* hooks = static_cast<gl_hooks_t*>(pthread_getspecific(gGLWrapperKey));
138 if (hooks) return hooks;
Mathias Agopian6fc56992009-10-14 02:06:37 -0700139 return &gHooksNoContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140}
141
142#endif
143
Jack Palevichd4d0fb92010-10-26 15:21:24 -0700144#if EGL_TRACE
145
146extern gl_hooks_t const* getGLTraceThreadSpecific();
147
148#endif
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
150// ----------------------------------------------------------------------------
151}; // namespace android
152// ----------------------------------------------------------------------------
153
154#endif /* ANDROID_GLES_CM_HOOKS_H */