blob: cd70ac8813b2042c868f479e50489b13c427b992 [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
Chet Haase2da2c152012-10-04 17:15:59 -070047#ifdef IS_MANTA
48#define DEBUG_CALL_GL_API 1
49#else
Romain Guy761eaed2010-08-09 20:48:09 -070050#define DEBUG_CALL_GL_API 0
Chet Haase2da2c152012-10-04 17:15:59 -070051#endif
Romain Guyf12fe432012-09-27 15:47:10 -070052#define DEBUG_PRINT_CALL_STACK_ON_ERROR 0
Jesse Hall7e5099a2012-08-01 17:10:25 -070053#define SYSTRACE_CALL_GL_API 0
Romain Guy761eaed2010-08-09 20:48:09 -070054
Chet Haase2da2c152012-10-04 17:15:59 -070055#ifdef IS_MANTA
56#undef USE_FAST_TLS_KEY
57#endif
58
Chet Haasee8b0fac2012-09-28 11:56:48 -070059#if USE_FAST_TLS_KEY
Mathias Agopianb1a39d62009-05-27 20:38:06 -070060
Mathias Agopian673d2db2009-10-14 02:39:53 -070061 #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
Mathias Agopianb1a39d62009-05-27 20:38:06 -070070 #define API_ENTRY(_api) __attribute__((naked)) _api
71
72 #define CALL_GL_API(_api, ...) \
73 asm volatile( \
Mathias Agopian673d2db2009-10-14 02:39:53 -070074 GET_TLS(r12) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070075 "ldr r12, [r12, %[tls]] \n" \
76 "cmp r12, #0 \n" \
77 "ldrne pc, [r12, %[api]] \n" \
Mathias Agopian6f087122010-09-23 16:38:38 -070078 "mov r0, #0 \n" \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070079 "bx lr \n" \
80 : \
81 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
Mathias Agopian618fa102009-10-14 02:06:37 -070082 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070083 : \
84 );
Mathias Agopian673d2db2009-10-14 02:39:53 -070085
Mathias Agopianb1a39d62009-05-27 20:38:06 -070086 #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
Romain Guy761eaed2010-08-09 20:48:09 -070094#if DEBUG_CALL_GL_API
95
Mathias Agopianb1a39d62009-05-27 20:38:06 -070096 #define CALL_GL_API(_api, ...) \
Mathias Agopian618fa102009-10-14 02:06:37 -070097 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
Romain Guy761eaed2010-08-09 20:48:09 -070098 _c->_api(__VA_ARGS__); \
99 GLenum status = GL_NO_ERROR; \
Romain Guyf12fe432012-09-27 15:47:10 -0700100 bool error = false; \
Romain Guy761eaed2010-08-09 20:48:09 -0700101 while ((status = glGetError()) != GL_NO_ERROR) { \
Chet Haase2da2c152012-10-04 17:15:59 -0700102 ALOGD("GL Error: [" #_api "] 0x%x", status); \
Romain Guyf12fe432012-09-27 15:47:10 -0700103 error = true; \
104 } \
105 if (DEBUG_PRINT_CALL_STACK_ON_ERROR && error) { \
106 CallStack s; \
107 s.update(); \
108 s.dump("glGetError:" #_api); \
Romain Guy761eaed2010-08-09 20:48:09 -0700109 }
110
Jesse Hall7e5099a2012-08-01 17:10:25 -0700111#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
Romain Guy761eaed2010-08-09 20:48:09 -0700118#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
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700126 #define CALL_GL_API_RETURN(_api, ...) \
Mathias Agopian618fa102009-10-14 02:06:37 -0700127 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700128 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
Mathias Agopian48d438d2012-01-28 21:44:00 -0800142/*
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}