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.
21 #include <sys/ioctl.h>
23 #include <GLES3/gl3.h>
24 #include <GLES3/gl3ext.h>
25 #include <GLES2/gl2ext.h>
27 #include <cutils/log.h>
28 #include <cutils/properties.h>
31 #include "../egl_impl.h"
33 using namespace android;
35 // ----------------------------------------------------------------------------
36 // Actual GL entry-points
37 // ----------------------------------------------------------------------------
41 #undef CALL_GL_API_RETURN
43 #if defined(__arm__) && !USE_SLOW_BINDING
45 #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
47 #define API_ENTRY(_api) __attribute__((noinline)) _api
49 #define CALL_GL_API(_api, ...) \
52 "ldr r12, [r12, %[tls]] \n" \
54 "ldrne pc, [r12, %[api]] \n" \
56 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
57 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
61 #elif defined(__i386__) && !USE_SLOW_BINDING
63 /* Tell gcc 4.4+ to always omit the frame pointer to have working code
64 * independ of compiler flag
66 #define API_ENTRY(_api) __attribute__((noinline)) \
67 __attribute__((optimize("omit-frame-pointer"))) \
70 /* pop %%ebp only because x86 doesn't support naked functions */
71 /* 4.4+ supports __attribute__((optimize)) that disable function
75 (__GNUC__ == 4 && __GNUC_MINOR__ < 4 )
76 #define PROLOGUE "pop %%ebp \n"
81 #define CALL_GL_API(_api, ...) \
84 "movl %%gs:0, %%ecx \n" \
85 "movl %c[tls](%%ecx), %%eax \n" \
86 "test %%eax, %%eax \n" \
87 "je out" #_api " \n" \
88 "movl %c[api](%%eax), %%ecx \n" \
90 "out" #_api ": ret \n" \
92 : [tls] "i"(TLS_SLOT_OPENGL_API*4), \
93 [api] "i"(__builtin_offsetof(gl_hooks_t, gl._api)) \
97 #elif defined(__mips__) && !USE_SLOW_BINDING
99 #define API_ENTRY(_api) __attribute__((noinline)) _api
101 #define CALL_GL_API(_api, ...) \
102 register unsigned int _t0 asm("t0"); \
103 register unsigned int _fn asm("t1"); \
104 register unsigned int _tls asm("v1"); \
105 register unsigned int _v0 asm("v0"); \
108 ".set noreorder\n\t" \
109 ".set mips32r2\n\t" \
110 "rdhwr %[tls], $29\n\t" \
111 "lw %[t0], %[OPENGL_API](%[tls])\n\t" \
112 "beqz %[t0], 1f\n\t" \
113 " move %[fn],$ra\n\t" \
114 "lw %[fn], %[API](%[t0])\n\t" \
115 "movz %[fn], $ra, %[fn]\n\t" \
118 " move %[v0], $0\n\t" \
124 : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \
125 [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \
131 #define API_ENTRY(_api) _api
133 #define CALL_GL_API(_api, ...) \
134 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
135 if (_c) return _c->_api(__VA_ARGS__);
139 #define CALL_GL_API_RETURN(_api, ...) \
140 CALL_GL_API(_api, __VA_ARGS__) \
146 #include "gl3_api.in"
147 #include "gl2ext_api.in"
148 #include "gl3ext_api.in"
153 #undef CALL_GL_API_RETURN
156 * glGetString() is special because we expose some extensions in the wrapper
159 extern "C" const GLubyte * __glGetString(GLenum name);
161 const GLubyte * glGetString(GLenum name)
163 const GLubyte * ret = egl_get_string_for_current_context(name);
165 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;
166 ret = _c->glGetString(name);