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(__mips__) && !USE_SLOW_BINDING
63 #define API_ENTRY(_api) __attribute__((noinline)) _api
65 #define CALL_GL_API(_api, ...) \
66 register unsigned int _t0 asm("t0"); \
67 register unsigned int _fn asm("t1"); \
68 register unsigned int _tls asm("v1"); \
69 register unsigned int _v0 asm("v0"); \
72 ".set noreorder\n\t" \
74 "rdhwr %[tls], $29\n\t" \
75 "lw %[t0], %[OPENGL_API](%[tls])\n\t" \
76 "beqz %[t0], 1f\n\t" \
77 " move %[fn],$ra\n\t" \
78 "lw %[fn], %[API](%[t0])\n\t" \
79 "movz %[fn], $ra, %[fn]\n\t" \
82 " move %[v0], $0\n\t" \
88 : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \
89 [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \
95 #define API_ENTRY(_api) _api
97 #define CALL_GL_API(_api, ...) \
98 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
99 if (_c) return _c->_api(__VA_ARGS__);
103 #define CALL_GL_API_RETURN(_api, ...) \
104 CALL_GL_API(_api, __VA_ARGS__) \
110 #include "gl3_api.in"
111 #include "gl2ext_api.in"
112 #include "gl3ext_api.in"
117 #undef CALL_GL_API_RETURN
120 * glGetString() is special because we expose some extensions in the wrapper
123 extern "C" const GLubyte * __glGetString(GLenum name);
125 const GLubyte * glGetString(GLenum name)
127 const GLubyte * ret = egl_get_string_for_current_context(name);
129 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;
130 ret = _c->glGetString(name);