2 ** Copyright 2007, The Android Open Source Project
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
8 ** http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <sys/ioctl.h>
23 #include <GLES2/gl2.h>
24 #include <GLES2/gl2ext.h>
26 #include <cutils/log.h>
27 #include <cutils/properties.h>
29 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
30 #include <utils/Trace.h>
32 #include <utils/CallStack.h>
37 using namespace android;
39 // ----------------------------------------------------------------------------
40 // Actual GL entry-points
41 // ----------------------------------------------------------------------------
45 #undef CALL_GL_API_RETURN
47 #define DEBUG_CALL_GL_API 0
48 #define DEBUG_PRINT_CALL_STACK_ON_ERROR 0
49 #define SYSTRACE_CALL_GL_API 0
53 #ifdef HAVE_ARM_TLS_REGISTER
54 #define GET_TLS(reg) \
55 "mrc p15, 0, " #reg ", c13, c0, 3 \n"
57 #define GET_TLS(reg) \
58 "mov " #reg ", #0xFFFF0FFF \n" \
59 "ldr " #reg ", [" #reg ", #-15] \n"
62 #define API_ENTRY(_api) __attribute__((naked)) _api
64 #define CALL_GL_API(_api, ...) \
67 "ldr r12, [r12, %[tls]] \n" \
69 "ldrne pc, [r12, %[api]] \n" \
73 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
74 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
78 #define CALL_GL_API_RETURN(_api, ...) \
79 CALL_GL_API(_api, __VA_ARGS__) \
80 return 0; // placate gcc's warnings. never reached.
84 #define API_ENTRY(_api) _api
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; \
93 while ((status = glGetError()) != GL_NO_ERROR) { \
94 ALOGD("[" #_api "] 0x%x", status); \
97 if (DEBUG_PRINT_CALL_STACK_ON_ERROR && error) { \
100 s.dump("glGetError:" #_api); \
103 #elif SYSTRACE_CALL_GL_API
105 #define CALL_GL_API(_api, ...) \
107 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
108 _c->_api(__VA_ARGS__);
112 #define CALL_GL_API(_api, ...) \
113 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
114 _c->_api(__VA_ARGS__);
118 #define CALL_GL_API_RETURN(_api, ...) \
119 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
120 return _c->_api(__VA_ARGS__)
126 #include "gl2_api.in"
127 #include "gl2ext_api.in"
132 #undef CALL_GL_API_RETURN
135 * glGetString() is special because we expose some extensions in the wrapper
138 extern "C" const GLubyte * __glGetString(GLenum name);
140 const GLubyte * glGetString(GLenum name)
142 const GLubyte * ret = egl_get_string_for_current_context(name);
144 ret = __glGetString(name);