blob: fb890fc618b406e5e642d895e4e04b0abcea147f [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
29#include "hooks.h"
30#include "egl_impl.h"
31
32using namespace android;
33
34// ----------------------------------------------------------------------------
35// Actual GL entry-points
36// ----------------------------------------------------------------------------
37
38#undef API_ENTRY
39#undef CALL_GL_API
40#undef CALL_GL_API_RETURN
41
Chet Haasee8b0fac2012-09-28 11:56:48 -070042#if USE_FAST_TLS_KEY
Mathias Agopianb1a39d62009-05-27 20:38:06 -070043
Duane Sand46b42532013-03-27 10:58:06 -070044 #if defined(__arm__)
45
Elliott Hughes288870e2013-02-13 17:30:54 -080046 #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
Mathias Agopian673d2db2009-10-14 02:39:53 -070047
Mathias Agopianb1a39d62009-05-27 20:38:06 -070048 #define API_ENTRY(_api) __attribute__((naked)) _api
49
50 #define CALL_GL_API(_api, ...) \
51 asm volatile( \
Mathias Agopian673d2db2009-10-14 02:39:53 -070052 GET_TLS(r12) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070053 "ldr r12, [r12, %[tls]] \n" \
54 "cmp r12, #0 \n" \
55 "ldrne pc, [r12, %[api]] \n" \
Mathias Agopian6f087122010-09-23 16:38:38 -070056 "mov r0, #0 \n" \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070057 "bx lr \n" \
58 : \
59 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
Mathias Agopian618fa102009-10-14 02:06:37 -070060 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070061 : \
62 );
Mathias Agopian673d2db2009-10-14 02:39:53 -070063
Duane Sand46b42532013-03-27 10:58:06 -070064 #elif defined(__mips__)
65
66 #define API_ENTRY(_api) __attribute__((noinline)) _api
67
68 #define CALL_GL_API(_api, ...) \
69 register unsigned int t0 asm("t0"); \
70 register unsigned int fn asm("t1"); \
71 register unsigned int tls asm("v1"); \
72 register unsigned int v0 asm("v0"); \
73 asm volatile( \
74 ".set push\n\t" \
75 ".set noreorder\n\t" \
76 ".set mips32r2\n\t" \
77 "rdhwr %[tls], $29\n\t" \
78 "lw %[t0], %[OPENGL_API](%[tls])\n\t" \
79 "beqz %[t0], 1f\n\t" \
80 " move %[fn],$ra\n\t" \
81 "lw %[fn], %[API](%[t0])\n\t" \
82 "movz %[fn], $ra, %[fn]\n\t" \
83 "1:\n\t" \
84 "j %[fn]\n\t" \
85 " move %[v0], $0\n\t" \
86 ".set pop\n\t" \
87 : [fn] "=c"(fn), \
88 [tls] "=&r"(tls), \
89 [t0] "=&r"(t0), \
90 [v0] "=&r"(v0) \
91 : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \
92 [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \
93 : \
94 );
95
96 #else
97
98 #error Unsupported architecture
99
100 #endif
101
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700102 #define CALL_GL_API_RETURN(_api, ...) \
103 CALL_GL_API(_api, __VA_ARGS__) \
104 return 0; // placate gcc's warnings. never reached.
105
106#else
107
108 #define API_ENTRY(_api) _api
109
Romain Guy761eaed2010-08-09 20:48:09 -0700110 #define CALL_GL_API(_api, ...) \
111 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
112 _c->_api(__VA_ARGS__);
113
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700114 #define CALL_GL_API_RETURN(_api, ...) \
Mathias Agopian618fa102009-10-14 02:06:37 -0700115 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
Mathias Agopianb1a39d62009-05-27 20:38:06 -0700116 return _c->_api(__VA_ARGS__)
117
118#endif
119
120
121extern "C" {
122#include "gl2_api.in"
123#include "gl2ext_api.in"
124}
125
126#undef API_ENTRY
127#undef CALL_GL_API
128#undef CALL_GL_API_RETURN
129
Mathias Agopian48d438d2012-01-28 21:44:00 -0800130/*
131 * glGetString() is special because we expose some extensions in the wrapper
132 */
133
134extern "C" const GLubyte * __glGetString(GLenum name);
135
136const GLubyte * glGetString(GLenum name)
137{
138 const GLubyte * ret = egl_get_string_for_current_context(name);
139 if (ret == NULL) {
140 ret = __glGetString(name);
141 }
142 return ret;
143}