gl2.cpp revision f12fe43e8c280923fde743f22cea238e48c929f1
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#define ATRACE_TAG ATRACE_TAG_GRAPHICS 30#include <utils/Trace.h> 31 32#include <utils/CallStack.h> 33 34#include "hooks.h" 35#include "egl_impl.h" 36 37using namespace android; 38 39// ---------------------------------------------------------------------------- 40// Actual GL entry-points 41// ---------------------------------------------------------------------------- 42 43#undef API_ENTRY 44#undef CALL_GL_API 45#undef CALL_GL_API_RETURN 46 47#define DEBUG_CALL_GL_API 0 48#define DEBUG_PRINT_CALL_STACK_ON_ERROR 0 49#define SYSTRACE_CALL_GL_API 0 50 51#if USE_FAST_TLS_KEY___ 52 53 #ifdef HAVE_ARM_TLS_REGISTER 54 #define GET_TLS(reg) \ 55 "mrc p15, 0, " #reg ", c13, c0, 3 \n" 56 #else 57 #define GET_TLS(reg) \ 58 "mov " #reg ", #0xFFFF0FFF \n" \ 59 "ldr " #reg ", [" #reg ", #-15] \n" 60 #endif 61 62 #define API_ENTRY(_api) __attribute__((naked)) _api 63 64 #define CALL_GL_API(_api, ...) \ 65 asm volatile( \ 66 GET_TLS(r12) \ 67 "ldr r12, [r12, %[tls]] \n" \ 68 "cmp r12, #0 \n" \ 69 "ldrne pc, [r12, %[api]] \n" \ 70 "mov r0, #0 \n" \ 71 "bx lr \n" \ 72 : \ 73 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \ 74 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \ 75 : \ 76 ); 77 78 #define CALL_GL_API_RETURN(_api, ...) \ 79 CALL_GL_API(_api, __VA_ARGS__) \ 80 return 0; // placate gcc's warnings. never reached. 81 82#else 83 84 #define API_ENTRY(_api) _api 85 86#if DEBUG_CALL_GL_API 87 88 #define CALL_GL_API(_api, ...) \ 89 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ 90 _c->_api(__VA_ARGS__); \ 91 GLenum status = GL_NO_ERROR; \ 92 bool error = false; \ 93 while ((status = glGetError()) != GL_NO_ERROR) { \ 94 ALOGD("[" #_api "] 0x%x", status); \ 95 error = true; \ 96 } \ 97 if (DEBUG_PRINT_CALL_STACK_ON_ERROR && error) { \ 98 CallStack s; \ 99 s.update(); \ 100 s.dump("glGetError:" #_api); \ 101 } 102 103#elif SYSTRACE_CALL_GL_API 104 105 #define CALL_GL_API(_api, ...) \ 106 ATRACE_CALL(); \ 107 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ 108 _c->_api(__VA_ARGS__); 109 110#else 111 112 #define CALL_GL_API(_api, ...) \ 113 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ 114 _c->_api(__VA_ARGS__); 115 116#endif 117 118 #define CALL_GL_API_RETURN(_api, ...) \ 119 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \ 120 return _c->_api(__VA_ARGS__) 121 122#endif 123 124 125extern "C" { 126#include "gl2_api.in" 127#include "gl2ext_api.in" 128} 129 130#undef API_ENTRY 131#undef CALL_GL_API 132#undef CALL_GL_API_RETURN 133 134/* 135 * glGetString() is special because we expose some extensions in the wrapper 136 */ 137 138extern "C" const GLubyte * __glGetString(GLenum name); 139 140const GLubyte * glGetString(GLenum name) 141{ 142 const GLubyte * ret = egl_get_string_for_current_context(name); 143 if (ret == NULL) { 144 ret = __glGetString(name); 145 } 146 return ret; 147} 148