blob: b00af1b1a65d403412f701f43a60c7e69847e7fe [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
Mathias Agopianb1a39d62009-05-27 20:38:06 -070032#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
Romain Guy761eaed2010-08-09 20:48:09 -070045#define DEBUG_CALL_GL_API 0
Jesse Hall7e5099a2012-08-01 17:10:25 -070046#define SYSTRACE_CALL_GL_API 0
Romain Guy761eaed2010-08-09 20:48:09 -070047
Mathias Agopianb1a39d62009-05-27 20:38:06 -070048#if USE_FAST_TLS_KEY
49
Mathias Agopian673d2db2009-10-14 02:39:53 -070050 #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
Mathias Agopianb1a39d62009-05-27 20:38:06 -070059 #define API_ENTRY(_api) __attribute__((naked)) _api
60
61 #define CALL_GL_API(_api, ...) \
62 asm volatile( \
Mathias Agopian673d2db2009-10-14 02:39:53 -070063 GET_TLS(r12) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070064 "ldr r12, [r12, %[tls]] \n" \
65 "cmp r12, #0 \n" \
66 "ldrne pc, [r12, %[api]] \n" \
Mathias Agopian6f087122010-09-23 16:38:38 -070067 "mov r0, #0 \n" \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070068 "bx lr \n" \
69 : \
70 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
Mathias Agopian618fa102009-10-14 02:06:37 -070071 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070072 : \
73 );
Mathias Agopian673d2db2009-10-14 02:39:53 -070074
Mathias Agopianb1a39d62009-05-27 20:38:06 -070075 #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
Romain Guy761eaed2010-08-09 20:48:09 -070083#if DEBUG_CALL_GL_API
84
Mathias Agopianb1a39d62009-05-27 20:38:06 -070085 #define CALL_GL_API(_api, ...) \
Mathias Agopian618fa102009-10-14 02:06:37 -070086 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
Romain Guy761eaed2010-08-09 20:48:09 -070087 _c->_api(__VA_ARGS__); \
88 GLenum status = GL_NO_ERROR; \
89 while ((status = glGetError()) != GL_NO_ERROR) { \
Steve Block9d453682011-12-20 16:23:08 +000090 ALOGD("[" #_api "] 0x%x", status); \
Romain Guy761eaed2010-08-09 20:48:09 -070091 }
92
Jesse Hall7e5099a2012-08-01 17:10:25 -070093#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
Romain Guy761eaed2010-08-09 20:48:09 -0700100#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
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700108 #define CALL_GL_API_RETURN(_api, ...) \
Mathias Agopian618fa102009-10-14 02:06:37 -0700109 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700110 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
Mathias Agopian48d438d2012-01-28 21:44:00 -0800124/*
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}