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>
33 using namespace android;
35 // ----------------------------------------------------------------------------
36 // Actual GL entry-points
37 // ----------------------------------------------------------------------------
41 #undef CALL_GL_API_RETURN
47 #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
49 #define API_ENTRY(_api) __attribute__((naked)) _api
51 #define CALL_GL_API(_api, ...) \
54 "ldr r12, [r12, %[tls]] \n" \
56 "ldrne pc, [r12, %[api]] \n" \
60 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
61 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
65 #elif defined(__mips__)
67 #define API_ENTRY(_api) __attribute__((noinline)) _api
69 #define CALL_GL_API(_api, ...) \
70 register unsigned int _t0 asm("t0"); \
71 register unsigned int _fn asm("t1"); \
72 register unsigned int _tls asm("v1"); \
73 register unsigned int _v0 asm("v0"); \
76 ".set noreorder\n\t" \
78 "rdhwr %[tls], $29\n\t" \
79 "lw %[t0], %[OPENGL_API](%[tls])\n\t" \
80 "beqz %[t0], 1f\n\t" \
81 " move %[fn],$ra\n\t" \
82 "lw %[fn], %[API](%[t0])\n\t" \
83 "movz %[fn], $ra, %[fn]\n\t" \
86 " move %[v0], $0\n\t" \
92 : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \
93 [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \
99 #error Unsupported architecture
103 #define CALL_GL_API_RETURN(_api, ...) \
104 CALL_GL_API(_api, __VA_ARGS__) \
105 return 0; // placate gcc's warnings. never reached.
109 #define API_ENTRY(_api) _api
111 #define CALL_GL_API(_api, ...) \
112 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
113 _c->_api(__VA_ARGS__);
115 #define CALL_GL_API_RETURN(_api, ...) \
116 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
117 return _c->_api(__VA_ARGS__)
123 #include "gl3_api.in"
124 #include "gl2ext_api.in"
125 #include "gl3ext_api.in"
130 #undef CALL_GL_API_RETURN
133 * glGetString() is special because we expose some extensions in the wrapper
136 extern "C" const GLubyte * __glGetString(GLenum name);
138 const GLubyte * glGetString(GLenum name)
140 const GLubyte * ret = egl_get_string_for_current_context(name);
142 ret = __glGetString(name);