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