| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 1 | /* | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2 |  ** Copyright 2007, The Android Open Source Project | 
 | 3 |  ** | 
| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 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 | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7 |  ** | 
| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 8 |  **     http://www.apache.org/licenses/LICENSE-2.0 | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9 |  ** | 
| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 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 | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14 |  ** limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <ctype.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | #include <errno.h> | 
| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 19 | #include <string.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | #include <sys/ioctl.h> | 
 | 21 |  | 
| Mathias Agopian | 5f1af04 | 2017-03-09 18:50:05 -0800 | [diff] [blame] | 22 | #include <log/log.h> | 
| Mark Salyzyn | a5e161b | 2016-09-29 08:08:05 -0700 | [diff] [blame] | 23 | #include <cutils/properties.h> | 
 | 24 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <GLES/gl.h> | 
 | 26 | #include <GLES/glext.h> | 
 | 27 |  | 
| Mathias Agopian | 39c24a2 | 2013-04-04 23:17:56 -0700 | [diff] [blame] | 28 | #include "../hooks.h" | 
 | 29 | #include "../egl_impl.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 |  | 
 | 31 | using namespace android; | 
 | 32 |  | 
 | 33 | // ---------------------------------------------------------------------------- | 
 | 34 | // extensions for the framework | 
 | 35 | // ---------------------------------------------------------------------------- | 
 | 36 |  | 
| Mathias Agopian | d373c63 | 2009-05-08 15:35:17 -0700 | [diff] [blame] | 37 | extern "C" { | 
 | 38 | GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride, | 
 | 39 |         const GLvoid *ptr, GLsizei count); | 
 | 40 | GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride, | 
 | 41 |         const GLvoid *pointer, GLsizei count); | 
 | 42 | GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type, | 
 | 43 |         GLsizei stride, const GLvoid *pointer, GLsizei count); | 
 | 44 | GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type, | 
 | 45 |         GLsizei stride, const GLvoid *pointer, GLsizei count); | 
| Jack Palevich | 66089a3 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 46 | GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type, | 
 | 47 |         GLsizei stride, const GLvoid *pointer, GLsizei count); | 
 | 48 | GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, | 
 | 49 |         GLsizei stride, const GLvoid *pointer, GLsizei count); | 
 | 50 | GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, | 
 | 51 |         GLsizei stride, const GLvoid *pointer, GLsizei count); | 
| Mathias Agopian | d373c63 | 2009-05-08 15:35:17 -0700 | [diff] [blame] | 52 | } | 
 | 53 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | void glColorPointerBounds(GLint size, GLenum type, GLsizei stride, | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 55 |         const GLvoid *ptr, GLsizei /*count*/) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 |     glColorPointer(size, type, stride, ptr); | 
 | 57 | } | 
 | 58 | void glNormalPointerBounds(GLenum type, GLsizei stride, | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 59 |         const GLvoid *pointer, GLsizei /*count*/) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 |     glNormalPointer(type, stride, pointer); | 
 | 61 | } | 
 | 62 | void glTexCoordPointerBounds(GLint size, GLenum type, | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 63 |         GLsizei stride, const GLvoid *pointer, GLsizei /*count*/) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 |     glTexCoordPointer(size, type, stride, pointer); | 
 | 65 | } | 
 | 66 | void glVertexPointerBounds(GLint size, GLenum type, | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 67 |         GLsizei stride, const GLvoid *pointer, GLsizei /*count*/) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 |     glVertexPointer(size, type, stride, pointer); | 
 | 69 | } | 
 | 70 |  | 
| Jack Palevich | 66089a3 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 71 | void GL_APIENTRY glPointSizePointerOESBounds(GLenum type, | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 72 |         GLsizei stride, const GLvoid *pointer, GLsizei /*count*/) { | 
| Jack Palevich | 66089a3 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 73 |     glPointSizePointerOES(type, stride, pointer); | 
 | 74 | } | 
 | 75 |  | 
 | 76 | GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type, | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 77 |         GLsizei stride, const GLvoid *pointer, GLsizei /*count*/) { | 
| Jack Palevich | 66089a3 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 78 |     glMatrixIndexPointerOES(size, type, stride, pointer); | 
 | 79 | } | 
 | 80 |  | 
 | 81 | GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type, | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 82 |         GLsizei stride, const GLvoid *pointer, GLsizei /*count*/) { | 
| Jack Palevich | 66089a3 | 2009-12-08 15:43:51 +0800 | [diff] [blame] | 83 |     glWeightPointerOES(size, type, stride, pointer); | 
 | 84 | } | 
 | 85 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | // ---------------------------------------------------------------------------- | 
 | 87 | // Actual GL entry-points | 
 | 88 | // ---------------------------------------------------------------------------- | 
 | 89 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | #undef API_ENTRY | 
 | 91 | #undef CALL_GL_API | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 92 | #undef CALL_GL_API_INTERNAL_CALL | 
 | 93 | #undef CALL_GL_API_INTERNAL_SET_RETURN_VALUE | 
 | 94 | #undef CALL_GL_API_INTERNAL_DO_RETURN | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | #undef CALL_GL_API_RETURN | 
 | 96 |  | 
| Jesse Hall | 30a41aa | 2014-05-30 23:32:12 -0700 | [diff] [blame] | 97 | #if USE_SLOW_BINDING | 
 | 98 |  | 
 | 99 |     #define API_ENTRY(_api) _api | 
 | 100 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 101 |     #define CALL_GL_API_INTERNAL_CALL(_api, ...)                         \ | 
| Jesse Hall | 30a41aa | 2014-05-30 23:32:12 -0700 | [diff] [blame] | 102 |         gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;  \ | 
 | 103 |         if (_c) return _c->_api(__VA_ARGS__); | 
 | 104 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 105 |     #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE return 0; | 
 | 106 |  | 
 | 107 |     // This stays blank, since void functions will implicitly return, and | 
 | 108 |     // all of the other functions will return 0 based on the previous macro. | 
 | 109 |     #define CALL_GL_API_INTERNAL_DO_RETURN | 
 | 110 |  | 
| Jesse Hall | 30a41aa | 2014-05-30 23:32:12 -0700 | [diff] [blame] | 111 | #elif defined(__arm__) | 
| Duane Sand | 46b4253 | 2013-03-27 10:58:06 -0700 | [diff] [blame] | 112 |  | 
| Elliott Hughes | 288870e | 2013-02-13 17:30:54 -0800 | [diff] [blame] | 113 |     #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n" | 
| Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 114 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 115 |     #define API_ENTRY(_api) __attribute__((naked,noinline)) _api | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 117 |     #define CALL_GL_API_INTERNAL_CALL(_api, ...)                 \ | 
 | 118 |         asm volatile(                                            \ | 
 | 119 |             GET_TLS(r12)                                         \ | 
 | 120 |             "ldr   r12, [r12, %[tls]] \n"                        \ | 
 | 121 |             "cmp   r12, #0            \n"                        \ | 
 | 122 |             "ldrne pc,  [r12, %[api]] \n"                        \ | 
 | 123 |             :                                                    \ | 
 | 124 |             : [tls] "J"(TLS_SLOT_OPENGL_API*4),                  \ | 
 | 125 |               [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \ | 
 | 126 |             : "r0", "r1", "r2", "r3", "r12"                      \ | 
 | 127 |         ); | 
 | 128 |  | 
 | 129 |     #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ | 
 | 130 |         asm volatile(                             \ | 
 | 131 |             "mov r0, #0 \n"                       \ | 
 | 132 |             :                                     \ | 
 | 133 |             :                                     \ | 
 | 134 |             : "r0"                                \ | 
 | 135 |         ); | 
 | 136 |  | 
 | 137 |  | 
 | 138 |     #define CALL_GL_API_INTERNAL_DO_RETURN \ | 
 | 139 |         asm volatile(                      \ | 
 | 140 |             "bx lr \n"                     \ | 
 | 141 |             :                              \ | 
 | 142 |             :                              \ | 
 | 143 |             : "r0"                         \ | 
 | 144 |         ); | 
| Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 145 |  | 
| Jesse Hall | 30a41aa | 2014-05-30 23:32:12 -0700 | [diff] [blame] | 146 | #elif defined(__aarch64__) | 
 | 147 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 148 |     #define API_ENTRY(_api) __attribute__((naked,noinline)) _api | 
| Jesse Hall | 30a41aa | 2014-05-30 23:32:12 -0700 | [diff] [blame] | 149 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 150 |     #define CALL_GL_API_INTERNAL_CALL(_api, ...)                    \ | 
| Jesse Hall | 30a41aa | 2014-05-30 23:32:12 -0700 | [diff] [blame] | 151 |         asm volatile(                                               \ | 
 | 152 |             "mrs x16, tpidr_el0\n"                                  \ | 
 | 153 |             "ldr x16, [x16, %[tls]]\n"                              \ | 
 | 154 |             "cbz x16, 1f\n"                                         \ | 
 | 155 |             "ldr x16, [x16, %[api]]\n"                              \ | 
 | 156 |             "br  x16\n"                                             \ | 
 | 157 |             "1:\n"                                                  \ | 
 | 158 |             :                                                       \ | 
 | 159 |             : [tls] "i" (TLS_SLOT_OPENGL_API * sizeof(void*)),      \ | 
 | 160 |               [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api))   \ | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 161 |             : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x16" \ | 
 | 162 |         ); | 
 | 163 |  | 
 | 164 |     #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ | 
 | 165 |         asm volatile(                             \ | 
 | 166 |             "mov w0, wzr \n"                      \ | 
 | 167 |             :                                     \ | 
 | 168 |             :                                     \ | 
 | 169 |             : "w0"                                \ | 
 | 170 |         ); | 
 | 171 |  | 
 | 172 |     #define CALL_GL_API_INTERNAL_DO_RETURN \ | 
 | 173 |         asm volatile(                      \ | 
 | 174 |             "ret \n"                       \ | 
 | 175 |             :                              \ | 
 | 176 |             :                              \ | 
 | 177 |             :                              \ | 
| Jesse Hall | 30a41aa | 2014-05-30 23:32:12 -0700 | [diff] [blame] | 178 |         ); | 
 | 179 |  | 
 | 180 | #elif defined(__i386__) | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 181 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 182 |     #define API_ENTRY(_api) __attribute__((naked,noinline)) _api | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 183 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 184 |     #define CALL_GL_API_INTERNAL_CALL(_api, ...)                    \ | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 185 |         __asm__ volatile(                                           \ | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 186 |             "mov %%gs:0, %%eax\n"                                   \ | 
 | 187 |             "mov %P[tls](%%eax), %%eax\n"                           \ | 
 | 188 |             "test %%eax, %%eax\n"                                   \ | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 189 |             "je 1f\n"                                               \ | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 190 |             "jmp *%P[api](%%eax)\n"                                 \ | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 191 |             "1:\n"                                                  \ | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 192 |             :                                                       \ | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 193 |             : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)),        \ | 
 | 194 |               [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api))   \ | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 195 |             : "cc", "%eax"                                          \ | 
 | 196 |         ); | 
 | 197 |  | 
 | 198 |     #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ | 
 | 199 |         __asm__ volatile(                         \ | 
 | 200 |             "xor %%eax, %%eax\n"                  \ | 
 | 201 |             :                                     \ | 
 | 202 |             :                                     \ | 
 | 203 |             : "%eax"                              \ | 
 | 204 |         ); | 
 | 205 |  | 
 | 206 |     #define CALL_GL_API_INTERNAL_DO_RETURN \ | 
 | 207 |         __asm__ volatile(                  \ | 
 | 208 |             "ret\n"                        \ | 
 | 209 |             :                              \ | 
 | 210 |             :                              \ | 
 | 211 |             :                              \ | 
 | 212 |         ); | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 213 |  | 
| Jesse Hall | 30a41aa | 2014-05-30 23:32:12 -0700 | [diff] [blame] | 214 | #elif defined(__x86_64__) | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 215 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 216 |     #define API_ENTRY(_api) __attribute__((naked,noinline)) _api | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 217 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 218 |     #define CALL_GL_API_INTERNAL_CALL(_api, ...)                    \ | 
 | 219 |         __asm__ volatile(                                           \ | 
 | 220 |             "mov %%fs:0, %%rax\n"                                   \ | 
 | 221 |             "mov %P[tls](%%rax), %%rax\n"                           \ | 
 | 222 |             "test %%rax, %%rax\n"                                   \ | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 223 |             "je 1f\n"                                               \ | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 224 |             "jmp *%P[api](%%rax)\n"                                 \ | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 225 |             "1:\n"                                                  \ | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 226 |             :                                                       \ | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 227 |             : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)),        \ | 
 | 228 |               [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api))   \ | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 229 |             : "cc", "%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9",   \ | 
 | 230 |               "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", \ | 
 | 231 |               "%xmm6", "%xmm7"                                      \ | 
 | 232 |         ); | 
 | 233 |  | 
 | 234 |     #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ | 
 | 235 |         __asm__ volatile(                         \ | 
 | 236 |             "xor %%eax, %%eax\n"                  \ | 
 | 237 |             :                                     \ | 
 | 238 |             :                                     \ | 
 | 239 |             : "%eax"                              \ | 
 | 240 |         ); | 
 | 241 |  | 
 | 242 |     #define CALL_GL_API_INTERNAL_DO_RETURN \ | 
 | 243 |         __asm__ volatile(                  \ | 
 | 244 |             "retq\n"                       \ | 
 | 245 |             :                              \ | 
 | 246 |             :                              \ | 
 | 247 |             :                              \ | 
 | 248 |         ); | 
| mwajdecz | c80aafa | 2014-05-26 13:56:37 +0200 | [diff] [blame] | 249 |  | 
| Xia Lifang | fd22314 | 2022-10-12 20:40:37 +0800 | [diff] [blame] | 250 | #elif defined(__riscv) | 
| Duane Sand | 6701fbe | 2014-11-26 13:17:40 -0800 | [diff] [blame] | 251 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 252 |     #define API_ENTRY(_api) __attribute__((naked,noinline)) _api | 
| Duane Sand | 6701fbe | 2014-11-26 13:17:40 -0800 | [diff] [blame] | 253 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 254 |     #define CALL_GL_API_INTERNAL_CALL(_api, ...)                 \ | 
| Duane Sand | 46b4253 | 2013-03-27 10:58:06 -0700 | [diff] [blame] | 255 |         asm volatile(                                            \ | 
| Xia Lifang | fd22314 | 2022-10-12 20:40:37 +0800 | [diff] [blame] | 256 |             "mv t0, tp\n"                                        \ | 
 | 257 |             "li t1, %[tls]\n"                                    \ | 
 | 258 |             "add t0, t0, t1\n"                                   \ | 
 | 259 |             "ld t0, 0(t0)\n"                                     \ | 
 | 260 |             "beqz t0, 1f\n"                                      \ | 
 | 261 |             "li t1, %[api]\n"                                    \ | 
 | 262 |             "add t0, t0, t1\n"                                   \ | 
 | 263 |             "ld t0, 0(t0)\n"                                     \ | 
 | 264 |             "jalr x0, t0\n"                                      \ | 
 | 265 |             "1:\n"                                               \ | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 266 |             :                                                    \ | 
| Xia Lifang | fd22314 | 2022-10-12 20:40:37 +0800 | [diff] [blame] | 267 |             : [tls] "i"(TLS_SLOT_OPENGL_API*sizeof(void *)),     \ | 
 | 268 |               [api] "i"(__builtin_offsetof(gl_hooks_t, gl._api)) \ | 
 | 269 |             : "t0", "t1", "t2", "a0", "a1", "a2", "a3", "a4",    \ | 
 | 270 |               "a5", "t6", "t3", "t4", "t5", "t6"                 \ | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 271 |         ); | 
 | 272 |  | 
| Xia Lifang | fd22314 | 2022-10-12 20:40:37 +0800 | [diff] [blame] | 273 |     #define CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ | 
 | 274 |         asm volatile(                             \ | 
 | 275 |             "li a0, 0\n"                          \ | 
 | 276 |             :                                     \ | 
 | 277 |             :                                     \ | 
 | 278 |             : "a0"                                \ | 
 | 279 |         ); | 
 | 280 |  | 
 | 281 |     #define CALL_GL_API_INTERNAL_DO_RETURN \ | 
 | 282 |         asm volatile(                      \ | 
 | 283 |             "ret\n"                        \ | 
 | 284 |             :                              \ | 
 | 285 |             :                              \ | 
 | 286 |             :                              \ | 
 | 287 |         ); | 
| Duane Sand | 46b4253 | 2013-03-27 10:58:06 -0700 | [diff] [blame] | 288 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | #endif | 
 | 290 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 291 | #define CALL_GL_API(_api, ...) \ | 
 | 292 |     CALL_GL_API_INTERNAL_CALL(_api, __VA_ARGS__) \ | 
 | 293 |     CALL_GL_API_INTERNAL_DO_RETURN | 
| Mathias Agopian | e0ea89c | 2013-06-14 19:08:36 -0700 | [diff] [blame] | 294 |  | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 295 | #define CALL_GL_API_RETURN(_api, ...) \ | 
 | 296 |     CALL_GL_API_INTERNAL_CALL(_api, __VA_ARGS__) \ | 
 | 297 |     CALL_GL_API_INTERNAL_SET_RETURN_VALUE \ | 
 | 298 |     CALL_GL_API_INTERNAL_DO_RETURN | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 299 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | extern "C" { | 
| Jesse Hall | bbbddb8 | 2014-05-13 21:13:14 -0700 | [diff] [blame] | 301 | #pragma GCC diagnostic ignored "-Wunused-parameter" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | #include "gl_api.in" | 
| Mathias Agopian | b519abb | 2009-04-23 18:05:44 -0700 | [diff] [blame] | 303 | #include "glext_api.in" | 
| Jesse Hall | bbbddb8 | 2014-05-13 21:13:14 -0700 | [diff] [blame] | 304 | #pragma GCC diagnostic warning "-Wunused-parameter" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | } | 
 | 306 |  | 
 | 307 | #undef API_ENTRY | 
 | 308 | #undef CALL_GL_API | 
| Stephen Hines | 3e8fce4 | 2016-03-22 23:35:27 -0700 | [diff] [blame] | 309 | #undef CALL_GL_API_INTERNAL_CALL | 
 | 310 | #undef CALL_GL_API_INTERNAL_SET_RETURN_VALUE | 
 | 311 | #undef CALL_GL_API_INTERNAL_DO_RETURN | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | #undef CALL_GL_API_RETURN | 
 | 313 |  | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 314 | /* | 
 | 315 |  * glGetString() is special because we expose some extensions in the wrapper | 
 | 316 |  */ | 
 | 317 |  | 
 | 318 | extern "C" const GLubyte * __glGetString(GLenum name); | 
 | 319 |  | 
| Mathias Agopian | e0ea89c | 2013-06-14 19:08:36 -0700 | [diff] [blame] | 320 | const GLubyte * glGetString(GLenum name) { | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 321 |     const GLubyte * ret = egl_get_string_for_current_context(name); | 
 | 322 |     if (ret == NULL) { | 
| Mathias Agopian | e0ea89c | 2013-06-14 19:08:36 -0700 | [diff] [blame] | 323 |         gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; | 
 | 324 |         ret = _c->glGetString(name); | 
| Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 325 |     } | 
 | 326 |     return ret; | 
 | 327 | } |