| 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 |  | 
|  | 42 | #if USE_FAST_TLS_KEY | 
|  | 43 |  | 
| Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 44 | #ifdef HAVE_ARM_TLS_REGISTER | 
|  | 45 | #define GET_TLS(reg) \ | 
|  | 46 | "mrc p15, 0, " #reg ", c13, c0, 3 \n" | 
|  | 47 | #else | 
|  | 48 | #define GET_TLS(reg) \ | 
|  | 49 | "mov   " #reg ", #0xFFFF0FFF      \n"  \ | 
|  | 50 | "ldr   " #reg ", [" #reg ", #-15] \n" | 
|  | 51 | #endif | 
|  | 52 |  | 
| Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 53 | #define API_ENTRY(_api) __attribute__((naked)) _api | 
|  | 54 |  | 
|  | 55 | #define CALL_GL_API(_api, ...)                              \ | 
|  | 56 | asm volatile(                                          \ | 
| Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 57 | GET_TLS(r12)                                        \ | 
| Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 58 | "ldr   r12, [r12, %[tls]] \n"                       \ | 
|  | 59 | "cmp   r12, #0            \n"                       \ | 
|  | 60 | "ldrne pc,  [r12, %[api]] \n"                       \ | 
|  | 61 | "bx    lr                 \n"                       \ | 
|  | 62 | :                                                   \ | 
|  | 63 | : [tls] "J"(TLS_SLOT_OPENGL_API*4),                 \ | 
| Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 64 | [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api))    \ | 
| Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 65 | :                                                   \ | 
|  | 66 | ); | 
| Mathias Agopian | 673d2db | 2009-10-14 02:39:53 -0700 | [diff] [blame] | 67 |  | 
| Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 68 | #define CALL_GL_API_RETURN(_api, ...) \ | 
|  | 69 | CALL_GL_API(_api, __VA_ARGS__) \ | 
|  | 70 | return 0; // placate gcc's warnings. never reached. | 
|  | 71 |  | 
|  | 72 | #else | 
|  | 73 |  | 
|  | 74 | #define API_ENTRY(_api) _api | 
|  | 75 |  | 
|  | 76 | #define CALL_GL_API(_api, ...)                                       \ | 
| Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 77 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;  \ | 
| Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 78 | _c->_api(__VA_ARGS__) | 
|  | 79 |  | 
|  | 80 | #define CALL_GL_API_RETURN(_api, ...)                                \ | 
| Mathias Agopian | 618fa10 | 2009-10-14 02:06:37 -0700 | [diff] [blame] | 81 | gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;  \ | 
| Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 82 | return _c->_api(__VA_ARGS__) | 
|  | 83 |  | 
|  | 84 | #endif | 
|  | 85 |  | 
|  | 86 |  | 
|  | 87 | extern "C" { | 
|  | 88 | #include "gl2_api.in" | 
|  | 89 | #include "gl2ext_api.in" | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | #undef API_ENTRY | 
|  | 93 | #undef CALL_GL_API | 
|  | 94 | #undef CALL_GL_API_RETURN | 
|  | 95 |  | 
|  | 96 |  | 
|  | 97 | /* | 
|  | 98 | * These GL calls are special because they need to EGL to retrieve some | 
|  | 99 | * informations before they can execute. | 
|  | 100 | */ | 
|  | 101 |  | 
|  | 102 | extern "C" void __glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image); | 
|  | 103 | extern "C" void __glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image); | 
|  | 104 |  | 
|  | 105 |  | 
|  | 106 | void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) | 
|  | 107 | { | 
|  | 108 | GLeglImageOES implImage = | 
|  | 109 | (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); | 
|  | 110 | __glEGLImageTargetTexture2DOES(target, implImage); | 
|  | 111 | } | 
|  | 112 |  | 
|  | 113 | void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) | 
|  | 114 | { | 
|  | 115 | GLeglImageOES implImage = | 
|  | 116 | (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image); | 
| Mathias Agopian | 8fb47ec | 2010-03-29 15:12:19 -0700 | [diff] [blame] | 117 | __glEGLImageTargetRenderbufferStorageOES(target, implImage); | 
| Mathias Agopian | b1a39d6 | 2009-05-27 20:38:06 -0700 | [diff] [blame] | 118 | } | 
|  | 119 |  |