• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 #include <pthread.h>
25 
26 #include <EGL/egl.h>
27 #include <EGL/eglext.h>
28 #include <GLES/gl.h>
29 #include <GLES/glext.h>
30 #include <GLES2/gl2.h>
31 #include <GLES2/gl2ext.h>
32 #include <GLES3/gl3.h>
33 #include <GLES3/gl31.h>
34 #include <GLES3/gl32.h>
35 
36 // set to 1 for debugging
37 #define USE_SLOW_BINDING    0
38 
39 #undef NELEM
40 #define NELEM(x)            (sizeof(x)/sizeof(*(x)))
41 
42 // maximum number of GL extensions that can be used simultaneously in
43 // a given process. this limitation exists because we need to have
44 // a static function for each extension and currently these static functions
45 // are generated at compile time.
46 #define MAX_NUMBER_OF_GL_EXTENSIONS 256
47 
48 
49 #include <bionic_tls.h>  /* special private C library header */
50 
51 // ----------------------------------------------------------------------------
52 namespace android {
53 // ----------------------------------------------------------------------------
54 
55 // GL / EGL hooks
56 
57 #undef GL_ENTRY
58 #undef EGL_ENTRY
59 #define GL_ENTRY(_r, _api, ...) _r (*(_api))(__VA_ARGS__);
60 #define EGL_ENTRY(_r, _api, ...) _r (*(_api))(__VA_ARGS__);
61 
62 struct platform_impl_t {
63     #include "platform_entries.in"
64 };
65 
66 struct egl_t {
67     #include "EGL/egl_entries.in"
68 };
69 
70 struct gl_hooks_t {
71     struct gl_t {
72         #include "entries.in"
73     } gl;
74     struct gl_ext_t {
75         __eglMustCastToProperFunctionPointerType extensions[MAX_NUMBER_OF_GL_EXTENSIONS];
76     } ext;
77 };
78 #undef GL_ENTRY
79 #undef EGL_ENTRY
80 
81 EGLAPI void setGlThreadSpecific(gl_hooks_t const *value);
82 
83 // We have a dedicated TLS slot in bionic
get_tls_hooks()84 inline gl_hooks_t const * volatile * get_tls_hooks() {
85     volatile void *tls_base = __get_tls();
86     gl_hooks_t const * volatile * tls_hooks =
87             reinterpret_cast<gl_hooks_t const * volatile *>(tls_base);
88     return tls_hooks;
89 }
90 
getGlThreadSpecific()91 inline EGLAPI gl_hooks_t const* getGlThreadSpecific() {
92     gl_hooks_t const * volatile * tls_hooks = get_tls_hooks();
93     gl_hooks_t const* hooks = tls_hooks[TLS_SLOT_OPENGL_API];
94     return hooks;
95 }
96 
97 // ----------------------------------------------------------------------------
98 }; // namespace android
99 // ----------------------------------------------------------------------------
100 
101 #endif /* ANDROID_GLES_CM_HOOKS_H */
102