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