gl2.cpp revision c2774f9b7341980c626c52a70e4fdf64d1b426e8
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 <cutils/log.h> 24#include <cutils/properties.h> 25 26#include "../hooks.h" 27#include "../egl_impl.h" 28 29using namespace android; 30 31// ---------------------------------------------------------------------------- 32// Actual GL entry-points 33// ---------------------------------------------------------------------------- 34 35#undef API_ENTRY 36#undef CALL_GL_API 37#undef CALL_GL_API_RETURN 38 39#if defined(__arm__) && !USE_SLOW_BINDING 40 41 #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n" 42 43 #define API_ENTRY(_api) __attribute__((noinline)) _api 44 45 #define CALL_GL_API(_api, ...) \ 46 asm volatile( \ 47 GET_TLS(r12) \ 48 "ldr r12, [r12, %[tls]] \n" \ 49 "cmp r12, #0 \n" \ 50 "ldrne pc, [r12, %[api]] \n" \ 51 : \ 52 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ 53 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \ 54 : \ 55 ); 56 57#elif defined(__i386__) && !USE_SLOW_BINDING 58 59 #define API_ENTRY(_api) __attribute__((noinline)) _api 60 61 #define CALL_GL_API(_api, ...) \ 62 register void** fn; \ 63 __asm__ volatile( \ 64 "mov %%gs:0, %[fn]\n" \ 65 "mov %P[tls](%[fn]), %[fn]\n" \ 66 "test %[fn], %[fn]\n" \ 67 "je 1f\n" \ 68 "jmp *%P[api](%[fn])\n" \ 69 "1:\n" \ 70 : [fn] "=r" (fn) \ 71 : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)), \ 72 [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api)) \ 73 : "cc" \ 74 ); 75 76#elif defined(__x86_64__) && !USE_SLOW_BINDING 77 78 #define API_ENTRY(_api) __attribute__((noinline)) _api 79 80 #define CALL_GL_API(_api, ...) \ 81 register void** fn; \ 82 __asm__ volatile( \ 83 "mov %%fs:0, %[fn]\n" \ 84 "mov %P[tls](%[fn]), %[fn]\n" \ 85 "test %[fn], %[fn]\n" \ 86 "je 1f\n" \ 87 "jmp *%P[api](%[fn])\n" \ 88 "1:\n" \ 89 : [fn] "=r" (fn) \ 90 : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)), \ 91 [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api)) \ 92 : "cc" \ 93 ); 94 95#elif defined(__mips__) && !USE_SLOW_BINDING 96 97 #define API_ENTRY(_api) __attribute__((noinline)) _api 98 99 #define CALL_GL_API(_api, ...) \ 100 register unsigned int _t0 asm("t0"); \ 101 register unsigned int _fn asm("t1"); \ 102 register unsigned int _tls asm("v1"); \ 103 register unsigned int _v0 asm("v0"); \ 104 asm volatile( \ 105 ".set push\n\t" \ 106 ".set noreorder\n\t" \ 107 ".set mips32r2\n\t" \ 108 "rdhwr %[tls], $29\n\t" \ 109 "lw %[t0], %[OPENGL_API](%[tls])\n\t" \ 110 "beqz %[t0], 1f\n\t" \ 111 " move %[fn],$ra\n\t" \ 112 "lw %[fn], %[API](%[t0])\n\t" \ 113 "movz %[fn], $ra, %[fn]\n\t" \ 114 "1:\n\t" \ 115 "j %[fn]\n\t" \ 116 " move %[v0], $0\n\t" \ 117 ".set pop\n\t" \ 118 : [fn] "=c"(_fn), \ 119 [tls] "=&r"(_tls), \ 120 [t0] "=&r"(_t0), \ 121 [v0] "=&r"(_v0) \ 122 : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \ 123 [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \ 124 : \ 125 ); 126 127#else 128 129 #define API_ENTRY(_api) _api 130 131 #define CALL_GL_API(_api, ...) \ 132 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ 133 if (_c) return _c->_api(__VA_ARGS__); 134 135#endif 136 137#define CALL_GL_API_RETURN(_api, ...) \ 138 CALL_GL_API(_api, __VA_ARGS__) \ 139 return 0; 140 141 142 143extern "C" { 144#pragma GCC diagnostic ignored "-Wunused-parameter" 145#include "gl2_api.in" 146#include "gl2ext_api.in" 147#pragma GCC diagnostic warning "-Wunused-parameter" 148} 149 150#undef API_ENTRY 151#undef CALL_GL_API 152#undef CALL_GL_API_RETURN 153 154/* 155 * glGetString() is special because we expose some extensions in the wrapper 156 */ 157 158extern "C" const GLubyte * __glGetString(GLenum name); 159 160const GLubyte * glGetString(GLenum name) 161{ 162 const GLubyte * ret = egl_get_string_for_current_context(name); 163 if (ret == NULL) { 164 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; 165 ret = _c->glGetString(name); 166 } 167 return ret; 168} 169