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 <GLES2/gl2.h>
24 #include <GLES2/gl2ext.h>
26 #include <cutils/log.h>
27 #include <cutils/properties.h>
32 using namespace android;
34 // ----------------------------------------------------------------------------
35 // Actual GL entry-points
36 // ----------------------------------------------------------------------------
40 #undef CALL_GL_API_RETURN
46 #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
48 #define API_ENTRY(_api) __attribute__((naked)) _api
50 #define CALL_GL_API(_api, ...) \
53 "ldr r12, [r12, %[tls]] \n" \
55 "ldrne pc, [r12, %[api]] \n" \
59 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
60 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
64 #elif defined(__mips__)
66 #define API_ENTRY(_api) __attribute__((noinline)) _api
68 #define CALL_GL_API(_api, ...) \
69 register unsigned int t0 asm("t0"); \
70 register unsigned int fn asm("t1"); \
71 register unsigned int tls asm("v1"); \
72 register unsigned int v0 asm("v0"); \
75 ".set noreorder\n\t" \
77 "rdhwr %[tls], $29\n\t" \
78 "lw %[t0], %[OPENGL_API](%[tls])\n\t" \
79 "beqz %[t0], 1f\n\t" \
80 " move %[fn],$ra\n\t" \
81 "lw %[fn], %[API](%[t0])\n\t" \
82 "movz %[fn], $ra, %[fn]\n\t" \
85 " move %[v0], $0\n\t" \
91 : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \
92 [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \
98 #error Unsupported architecture
102 #define CALL_GL_API_RETURN(_api, ...) \
103 CALL_GL_API(_api, __VA_ARGS__) \
104 return 0; // placate gcc's warnings. never reached.
108 #define API_ENTRY(_api) _api
110 #define CALL_GL_API(_api, ...) \
111 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
112 _c->_api(__VA_ARGS__);
114 #define CALL_GL_API_RETURN(_api, ...) \
115 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
116 return _c->_api(__VA_ARGS__)
122 #include "gl2_api.in"
123 #include "gl2ext_api.in"
128 #undef CALL_GL_API_RETURN
131 * glGetString() is special because we expose some extensions in the wrapper
134 extern "C" const GLubyte * __glGetString(GLenum name);
136 const GLubyte * glGetString(GLenum name)
138 const GLubyte * ret = egl_get_string_for_current_context(name);
140 ret = __glGetString(name);