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 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 32 | #include "hooks.h" |
| 33 | #include "egl_impl.h" |
| 34 | |
| 35 | using namespace android; |
| 36 | |
| 37 | // ---------------------------------------------------------------------------- |
| 38 | // Actual GL entry-points |
| 39 | // ---------------------------------------------------------------------------- |
| 40 | |
| 41 | #undef API_ENTRY |
| 42 | #undef CALL_GL_API |
| 43 | #undef CALL_GL_API_RETURN |
| 44 | |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 45 | #define DEBUG_CALL_GL_API 0 |
Jesse Hall | 7e5099a | 2012-08-01 17:10:25 -0700 | [diff] [blame] | 46 | #define SYSTRACE_CALL_GL_API 0 |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 47 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 48 | #if USE_FAST_TLS_KEY |
| 49 | |
Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 50 | #ifdef HAVE_ARM_TLS_REGISTER |
| 51 | #define GET_TLS(reg) \ |
| 52 | "mrc p15, 0, " #reg ", c13, c0, 3 \n" |
| 53 | #else |
| 54 | #define GET_TLS(reg) \ |
| 55 | "mov " #reg ", #0xFFFF0FFF \n" \ |
| 56 | "ldr " #reg ", [" #reg ", #-15] \n" |
| 57 | #endif |
| 58 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 59 | #define API_ENTRY(_api) __attribute__((naked)) _api |
| 60 | |
| 61 | #define CALL_GL_API(_api, ...) \ |
| 62 | asm volatile( \ |
Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 63 | GET_TLS(r12) \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 64 | "ldr r12, [r12, %[tls]] \n" \ |
| 65 | "cmp r12, #0 \n" \ |
| 66 | "ldrne pc, [r12, %[api]] \n" \ |
Mathias Agopian | 6f08712 | 2010-09-23 16:38:38 -0700 | [diff] [blame] | 67 | "mov r0, #0 \n" \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 68 | "bx lr \n" \ |
| 69 | : \ |
| 70 | : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 71 | [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 72 | : \ |
| 73 | ); |
Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 74 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 75 | #define CALL_GL_API_RETURN(_api, ...) \ |
| 76 | CALL_GL_API(_api, __VA_ARGS__) \ |
| 77 | return 0; // placate gcc's warnings. never reached. |
| 78 | |
| 79 | #else |
| 80 | |
| 81 | #define API_ENTRY(_api) _api |
| 82 | |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 83 | #if DEBUG_CALL_GL_API |
| 84 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 85 | #define CALL_GL_API(_api, ...) \ |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 86 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 87 | _c->_api(__VA_ARGS__); \ |
| 88 | GLenum status = GL_NO_ERROR; \ |
| 89 | while ((status = glGetError()) != GL_NO_ERROR) { \ |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 90 | ALOGD("[" #_api "] 0x%x", status); \ |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Jesse Hall | 7e5099a | 2012-08-01 17:10:25 -0700 | [diff] [blame] | 93 | #elif SYSTRACE_CALL_GL_API |
| 94 | |
| 95 | #define CALL_GL_API(_api, ...) \ |
| 96 | ATRACE_CALL(); \ |
| 97 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
| 98 | _c->_api(__VA_ARGS__); |
| 99 | |
Romain Guy | 761eaed | 2010-08-09 20:48:09 -0700 | [diff] [blame] | 100 | #else |
| 101 | |
| 102 | #define CALL_GL_API(_api, ...) \ |
| 103 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
| 104 | _c->_api(__VA_ARGS__); |
| 105 | |
| 106 | #endif |
| 107 | |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 108 | #define CALL_GL_API_RETURN(_api, ...) \ |
Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 109 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ |
Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 110 | return _c->_api(__VA_ARGS__) |
| 111 | |
| 112 | #endif |
| 113 | |
| 114 | |
| 115 | extern "C" { |
| 116 | #include "gl2_api.in" |
| 117 | #include "gl2ext_api.in" |
| 118 | } |
| 119 | |
| 120 | #undef API_ENTRY |
| 121 | #undef CALL_GL_API |
| 122 | #undef CALL_GL_API_RETURN |
| 123 | |
Mathias Agopian | 48d438d | 2012-01-28 21:44:00 -0800 | [diff] [blame] | 124 | /* |
| 125 | * glGetString() is special because we expose some extensions in the wrapper |
| 126 | */ |
| 127 | |
| 128 | extern "C" const GLubyte * __glGetString(GLenum name); |
| 129 | |
| 130 | const GLubyte * glGetString(GLenum name) |
| 131 | { |
| 132 | const GLubyte * ret = egl_get_string_for_current_context(name); |
| 133 | if (ret == NULL) { |
| 134 | ret = __glGetString(name); |
| 135 | } |
| 136 | return ret; |
| 137 | } |