Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 1 | /* |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 2 | ** Copyright 2007, The Android Open Source Project |
| 3 | ** |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [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 |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 7 | ** |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 9 | ** |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [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 |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <ctype.h> |
| 18 | #include <string.h> |
| 19 | #include <errno.h> |
| 20 | |
| 21 | #include <sys/ioctl.h> |
| 22 | |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 23 | #include <GLES3/gl3.h> |
| 24 | #include <GLES3/gl3ext.h> |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 25 | #include <GLES2/gl2ext.h> |
| 26 | |
| 27 | #include <cutils/log.h> |
| 28 | #include <cutils/properties.h> |
| 29 | |
| 30 | #include "hooks.h" |
| 31 | #include "egl_impl.h" |
| 32 | |
| 33 | using namespace android; |
| 34 | |
| 35 | // ---------------------------------------------------------------------------- |
| 36 | // Actual GL entry-points |
| 37 | // ---------------------------------------------------------------------------- |
| 38 | |
| 39 | #undef API_ENTRY |
| 40 | #undef CALL_GL_API |
| 41 | #undef CALL_GL_API_RETURN |
| 42 | |
Chet Haase | e8b0fac | 2012-09-28 11:56:48 -0700 | [diff] [blame] | 43 | #if USE_FAST_TLS_KEY |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 44 | |
Duane Sand | 46b4253 | 2013-03-27 10:58:06 -0700 | [diff] [blame] | 45 | #if defined(__arm__) |
| 46 | |
Elliott Hughes | 288870e | 2013-02-13 17:30:54 -0800 | [diff] [blame] | 47 | #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n" |
Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 48 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 49 | #define API_ENTRY(_api) __attribute__((naked)) _api |
| 50 | |
| 51 | #define CALL_GL_API(_api, ...) \ |
| 52 | asm volatile( \ |
Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 53 | GET_TLS(r12) \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 54 | "ldr r12, [r12, %[tls]] \n" \ |
| 55 | "cmp r12, #0 \n" \ |
| 56 | "ldrne pc, [r12, %[api]] \n" \ |
Mathias Agopian | 6f08712 | 2010-09-23 16:38:38 -0700 | [diff] [blame] | 57 | "mov r0, #0 \n" \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 58 | "bx lr \n" \ |
| 59 | : \ |
| 60 | : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 61 | [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 62 | : \ |
| 63 | ); |
Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 64 | |
Duane Sand | 46b4253 | 2013-03-27 10:58:06 -0700 | [diff] [blame] | 65 | #elif defined(__mips__) |
| 66 | |
| 67 | #define API_ENTRY(_api) __attribute__((noinline)) _api |
| 68 | |
| 69 | #define CALL_GL_API(_api, ...) \ |
Jesse Hall | 441f694 | 2013-03-30 23:22:19 -0700 | [diff] [blame] | 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"); \ |
Duane Sand | 46b4253 | 2013-03-27 10:58:06 -0700 | [diff] [blame] | 74 | asm volatile( \ |
| 75 | ".set push\n\t" \ |
| 76 | ".set noreorder\n\t" \ |
| 77 | ".set mips32r2\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" \ |
| 84 | "1:\n\t" \ |
| 85 | "j %[fn]\n\t" \ |
| 86 | " move %[v0], $0\n\t" \ |
| 87 | ".set pop\n\t" \ |
Jesse Hall | 441f694 | 2013-03-30 23:22:19 -0700 | [diff] [blame] | 88 | : [fn] "=c"(_fn), \ |
| 89 | [tls] "=&r"(_tls), \ |
| 90 | [t0] "=&r"(_t0), \ |
| 91 | [v0] "=&r"(_v0) \ |
Duane Sand | 46b4253 | 2013-03-27 10:58:06 -0700 | [diff] [blame] | 92 | : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \ |
| 93 | [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \ |
| 94 | : \ |
| 95 | ); |
| 96 | |
| 97 | #else |
| 98 | |
| 99 | #error Unsupported architecture |
| 100 | |
| 101 | #endif |
| 102 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 103 | #define CALL_GL_API_RETURN(_api, ...) \ |
| 104 | CALL_GL_API(_api, __VA_ARGS__) \ |
| 105 | return 0; // placate gcc's warnings. never reached. |
| 106 | |
| 107 | #else |
| 108 | |
| 109 | #define API_ENTRY(_api) _api |
| 110 | |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 111 | #define CALL_GL_API(_api, ...) \ |
| 112 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
| 113 | _c->_api(__VA_ARGS__); |
| 114 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 115 | #define CALL_GL_API_RETURN(_api, ...) \ |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 116 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 117 | return _c->_api(__VA_ARGS__) |
| 118 | |
| 119 | #endif |
| 120 | |
| 121 | |
| 122 | extern "C" { |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 123 | #include "gl3_api.in" |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 124 | #include "gl2ext_api.in" |
Jesse Hall | 4774338 | 2013-02-08 11:13:46 -0800 | [diff] [blame] | 125 | #include "gl3ext_api.in" |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | #undef API_ENTRY |
| 129 | #undef CALL_GL_API |
| 130 | #undef CALL_GL_API_RETURN |
| 131 | |
Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 132 | /* |
| 133 | * glGetString() is special because we expose some extensions in the wrapper |
| 134 | */ |
| 135 | |
| 136 | extern "C" const GLubyte * __glGetString(GLenum name); |
| 137 | |
| 138 | const GLubyte * glGetString(GLenum name) |
| 139 | { |
| 140 | const GLubyte * ret = egl_get_string_for_current_context(name); |
| 141 | if (ret == NULL) { |
| 142 | ret = __glGetString(name); |
| 143 | } |
| 144 | return ret; |
| 145 | } |