blob: 2d0045e051ba3b32908100871bc459b6fa8fb965 [file] [log] [blame]
Mathias Agopianb1a39d62009-05-27 20:38:06 -07001/*
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
Jesse Hall7e5099a2012-08-01 17:10:25 -070029#define ATRACE_TAG ATRACE_TAG_GRAPHICS
30#include <utils/Trace.h>
31
Romain Guyf12fe432012-09-27 15:47:10 -070032#include <utils/CallStack.h>
33
Mathias Agopianb1a39d62009-05-27 20:38:06 -070034#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
Romain Guy761eaed2010-08-09 20:48:09 -070047#define DEBUG_CALL_GL_API 0
Romain Guyf12fe432012-09-27 15:47:10 -070048#define DEBUG_PRINT_CALL_STACK_ON_ERROR 0
Jesse Hall7e5099a2012-08-01 17:10:25 -070049#define SYSTRACE_CALL_GL_API 0
Romain Guy761eaed2010-08-09 20:48:09 -070050
Chet Haasee8b0fac2012-09-28 11:56:48 -070051#if USE_FAST_TLS_KEY
Mathias Agopianb1a39d62009-05-27 20:38:06 -070052
Mathias Agopian673d2db2009-10-14 02:39:53 -070053 #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
Mathias Agopianb1a39d62009-05-27 20:38:06 -070062 #define API_ENTRY(_api) __attribute__((naked)) _api
63
64 #define CALL_GL_API(_api, ...) \
65 asm volatile( \
Mathias Agopian673d2db2009-10-14 02:39:53 -070066 GET_TLS(r12) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070067 "ldr r12, [r12, %[tls]] \n" \
68 "cmp r12, #0 \n" \
69 "ldrne pc, [r12, %[api]] \n" \
Mathias Agopian6f087122010-09-23 16:38:38 -070070 "mov r0, #0 \n" \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070071 "bx lr \n" \
72 : \
73 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
Mathias Agopian618fa102009-10-14 02:06:37 -070074 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070075 : \
76 );
Mathias Agopian673d2db2009-10-14 02:39:53 -070077
Mathias Agopianb1a39d62009-05-27 20:38:06 -070078 #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
Romain Guy761eaed2010-08-09 20:48:09 -070086#if DEBUG_CALL_GL_API
87
Mathias Agopianb1a39d62009-05-27 20:38:06 -070088 #define CALL_GL_API(_api, ...) \
Mathias Agopian618fa102009-10-14 02:06:37 -070089 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
Romain Guy761eaed2010-08-09 20:48:09 -070090 _c->_api(__VA_ARGS__); \
91 GLenum status = GL_NO_ERROR; \
Romain Guyf12fe432012-09-27 15:47:10 -070092 bool error = false; \
Romain Guy761eaed2010-08-09 20:48:09 -070093 while ((status = glGetError()) != GL_NO_ERROR) { \
Steve Block9d453682011-12-20 16:23:08 +000094 ALOGD("[" #_api "] 0x%x", status); \
Romain Guyf12fe432012-09-27 15:47:10 -070095 error = true; \
96 } \
97 if (DEBUG_PRINT_CALL_STACK_ON_ERROR && error) { \
98 CallStack s; \
99 s.update(); \
100 s.dump("glGetError:" #_api); \
Romain Guy761eaed2010-08-09 20:48:09 -0700101 }
102
Jesse Hall7e5099a2012-08-01 17:10:25 -0700103#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
Romain Guy761eaed2010-08-09 20:48:09 -0700110#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
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700118 #define CALL_GL_API_RETURN(_api, ...) \
Mathias Agopian618fa102009-10-14 02:06:37 -0700119 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700120 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
Mathias Agopian48d438d2012-01-28 21:44:00 -0800134/*
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}