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