Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright 2007, The Android Open Source Project |
| 3 | ** |
| 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 |
| 7 | ** |
| 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | ** |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #include <ctype.h> |
| 18 | #include <string.h> |
| 19 | #include <errno.h> |
| 20 | |
| 21 | #include <sys/ioctl.h> |
| 22 | |
| 23 | #include <GLES2/gl2.h> |
| 24 | #include <GLES2/gl2ext.h> |
| 25 | |
| 26 | #include <cutils/log.h> |
| 27 | #include <cutils/properties.h> |
| 28 | |
Jesse Hall | 7e5099a | 2012-08-01 17:10:25 -0700 | [diff] [blame] | 29 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 30 | #include <utils/Trace.h> |
| 31 | |
Romain Guy | f12fe43 | 2012-09-27 15:47:10 -0700 | [diff] [blame] | 32 | #include <utils/CallStack.h> |
| 33 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 34 | #include "hooks.h" |
| 35 | #include "egl_impl.h" |
| 36 | |
| 37 | using namespace android; |
| 38 | |
| 39 | // ---------------------------------------------------------------------------- |
| 40 | // Actual GL entry-points |
| 41 | // ---------------------------------------------------------------------------- |
| 42 | |
| 43 | #undef API_ENTRY |
| 44 | #undef CALL_GL_API |
| 45 | #undef CALL_GL_API_RETURN |
| 46 | |
Chet Haase | 2da2c15 | 2012-10-04 17:15:59 -0700 | [diff] [blame] | 47 | #ifdef IS_MANTA |
| 48 | #define DEBUG_CALL_GL_API 1 |
| 49 | #else |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 50 | #define DEBUG_CALL_GL_API 0 |
Chet Haase | 2da2c15 | 2012-10-04 17:15:59 -0700 | [diff] [blame] | 51 | #endif |
Romain Guy | f12fe43 | 2012-09-27 15:47:10 -0700 | [diff] [blame] | 52 | #define DEBUG_PRINT_CALL_STACK_ON_ERROR 0 |
Jesse Hall | 7e5099a | 2012-08-01 17:10:25 -0700 | [diff] [blame] | 53 | #define SYSTRACE_CALL_GL_API 0 |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 54 | |
Chet Haase | 2da2c15 | 2012-10-04 17:15:59 -0700 | [diff] [blame] | 55 | #ifdef IS_MANTA |
| 56 | #undef USE_FAST_TLS_KEY |
| 57 | #endif |
| 58 | |
Chet Haase | e8b0fac | 2012-09-28 11:56:48 -0700 | [diff] [blame] | 59 | #if USE_FAST_TLS_KEY |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 60 | |
Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 61 | #ifdef HAVE_ARM_TLS_REGISTER |
| 62 | #define GET_TLS(reg) \ |
| 63 | "mrc p15, 0, " #reg ", c13, c0, 3 \n" |
| 64 | #else |
| 65 | #define GET_TLS(reg) \ |
| 66 | "mov " #reg ", #0xFFFF0FFF \n" \ |
| 67 | "ldr " #reg ", [" #reg ", #-15] \n" |
| 68 | #endif |
| 69 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 70 | #define API_ENTRY(_api) __attribute__((naked)) _api |
| 71 | |
| 72 | #define CALL_GL_API(_api, ...) \ |
| 73 | asm volatile( \ |
Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 74 | GET_TLS(r12) \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 75 | "ldr r12, [r12, %[tls]] \n" \ |
| 76 | "cmp r12, #0 \n" \ |
| 77 | "ldrne pc, [r12, %[api]] \n" \ |
Mathias Agopian | 6f08712 | 2010-09-23 16:38:38 -0700 | [diff] [blame] | 78 | "mov r0, #0 \n" \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 79 | "bx lr \n" \ |
| 80 | : \ |
| 81 | : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 82 | [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 83 | : \ |
| 84 | ); |
Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 85 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 86 | #define CALL_GL_API_RETURN(_api, ...) \ |
| 87 | CALL_GL_API(_api, __VA_ARGS__) \ |
| 88 | return 0; // placate gcc's warnings. never reached. |
| 89 | |
| 90 | #else |
| 91 | |
| 92 | #define API_ENTRY(_api) _api |
| 93 | |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 94 | #if DEBUG_CALL_GL_API |
| 95 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 96 | #define CALL_GL_API(_api, ...) \ |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 97 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 98 | _c->_api(__VA_ARGS__); \ |
| 99 | GLenum status = GL_NO_ERROR; \ |
Romain Guy | f12fe43 | 2012-09-27 15:47:10 -0700 | [diff] [blame] | 100 | bool error = false; \ |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 101 | while ((status = glGetError()) != GL_NO_ERROR) { \ |
Chet Haase | 2da2c15 | 2012-10-04 17:15:59 -0700 | [diff] [blame] | 102 | ALOGD("GL Error: [" #_api "] 0x%x", status); \ |
Romain Guy | f12fe43 | 2012-09-27 15:47:10 -0700 | [diff] [blame] | 103 | error = true; \ |
| 104 | } \ |
| 105 | if (DEBUG_PRINT_CALL_STACK_ON_ERROR && error) { \ |
| 106 | CallStack s; \ |
| 107 | s.update(); \ |
| 108 | s.dump("glGetError:" #_api); \ |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Jesse Hall | 7e5099a | 2012-08-01 17:10:25 -0700 | [diff] [blame] | 111 | #elif SYSTRACE_CALL_GL_API |
| 112 | |
| 113 | #define CALL_GL_API(_api, ...) \ |
| 114 | ATRACE_CALL(); \ |
| 115 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
| 116 | _c->_api(__VA_ARGS__); |
| 117 | |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 118 | #else |
| 119 | |
| 120 | #define CALL_GL_API(_api, ...) \ |
| 121 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
| 122 | _c->_api(__VA_ARGS__); |
| 123 | |
| 124 | #endif |
| 125 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 126 | #define CALL_GL_API_RETURN(_api, ...) \ |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 127 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 128 | return _c->_api(__VA_ARGS__) |
| 129 | |
| 130 | #endif |
| 131 | |
| 132 | |
| 133 | extern "C" { |
| 134 | #include "gl2_api.in" |
| 135 | #include "gl2ext_api.in" |
| 136 | } |
| 137 | |
| 138 | #undef API_ENTRY |
| 139 | #undef CALL_GL_API |
| 140 | #undef CALL_GL_API_RETURN |
| 141 | |
Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 142 | /* |
| 143 | * glGetString() is special because we expose some extensions in the wrapper |
| 144 | */ |
| 145 | |
| 146 | extern "C" const GLubyte * __glGetString(GLenum name); |
| 147 | |
| 148 | const GLubyte * glGetString(GLenum name) |
| 149 | { |
| 150 | const GLubyte * ret = egl_get_string_for_current_context(name); |
| 151 | if (ret == NULL) { |
| 152 | ret = __glGetString(name); |
| 153 | } |
| 154 | return ret; |
| 155 | } |