getProcAddress.cpp revision 7f781d155221c4067c93f85b4153c204423f49f2
1/* 2 ** Copyright 2009, 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 <stdlib.h> 19#include <errno.h> 20 21#include <cutils/log.h> 22 23#include "hooks.h" 24 25// ---------------------------------------------------------------------------- 26namespace android { 27// ---------------------------------------------------------------------------- 28 29#undef API_ENTRY 30#undef CALL_GL_EXTENSION_API 31#undef GL_EXTENSION 32#undef GL_EXTENSION_NAME 33#undef GL_EXTENSION_ARRAY 34#undef GL_EXTENSION_LIST 35#undef GET_TLS 36 37#if defined(__arm__) 38 39 #ifdef HAVE_ARM_TLS_REGISTER 40 #define GET_TLS(reg) \ 41 "mrc p15, 0, " #reg ", c13, c0, 3 \n" 42 #else 43 #define GET_TLS(reg) \ 44 "mov " #reg ", #0xFFFF0FFF \n" \ 45 "ldr " #reg ", [" #reg ", #-15] \n" 46 #endif 47 48 #define API_ENTRY(_api) __attribute__((naked)) _api 49 50 #define CALL_GL_EXTENSION_API(_api) \ 51 asm volatile( \ 52 GET_TLS(r12) \ 53 "ldr r12, [r12, %[tls]] \n" \ 54 "cmp r12, #0 \n" \ 55 "ldrne r12, [r12, %[api]] \n" \ 56 "cmpne r12, #0 \n" \ 57 "bxne r12 \n" \ 58 "bx lr \n" \ 59 : \ 60 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ 61 [api] "J"(__builtin_offsetof(gl_hooks_t, \ 62 ext.extensions[_api])) \ 63 : \ 64 ); 65 66 #define GL_EXTENSION_NAME(_n) __glExtFwd##_n 67 68 #define GL_EXTENSION(_n) \ 69 void API_ENTRY(GL_EXTENSION_NAME(_n))() { \ 70 CALL_GL_EXTENSION_API(_n); \ 71 } 72 73 74#else 75 76 #define GL_EXTENSION_NAME(_n) NULL 77 78 #define GL_EXTENSION(_n) 79 80 #warning "eglGetProcAddress() partially supported on this architecture" 81 82#endif 83 84#define GL_EXTENSION_LIST(name) \ 85 name(0) name(1) name(2) name(3) \ 86 name(4) name(5) name(6) name(7) \ 87 name(8) name(9) name(10) name(11) \ 88 name(12) name(13) name(14) name(15) \ 89 name(16) name(17) name(18) name(19) \ 90 name(20) name(21) name(22) name(23) \ 91 name(24) name(25) name(26) name(27) \ 92 name(28) name(29) name(30) name(31) \ 93 name(32) name(33) name(34) name(35) \ 94 name(36) name(37) name(38) name(39) \ 95 name(40) name(41) name(42) name(43) \ 96 name(44) name(45) name(46) name(47) \ 97 name(48) name(49) name(50) name(51) \ 98 name(52) name(53) name(54) name(55) \ 99 name(56) name(57) name(58) name(59) \ 100 name(60) name(61) name(62) name(63) 101 102 103GL_EXTENSION_LIST( GL_EXTENSION ) 104 105#define GL_EXTENSION_ARRAY(_n) GL_EXTENSION_NAME(_n), 106 107extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS] = { 108 GL_EXTENSION_LIST( GL_EXTENSION_ARRAY ) 109 }; 110 111#undef GET_TLS 112#undef GL_EXTENSION_LIST 113#undef GL_EXTENSION_ARRAY 114#undef GL_EXTENSION_NAME 115#undef GL_EXTENSION 116#undef API_ENTRY 117#undef CALL_GL_EXTENSION_API 118 119// ---------------------------------------------------------------------------- 120}; // namespace android 121// ---------------------------------------------------------------------------- 122 123