blob: 587339150db50629f4dec818fc264880027315b7 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080017#include <ctype.h>
18#include <string.h>
19#include <errno.h>
20
21#include <sys/ioctl.h>
22
23#include <GLES/gl.h>
24#include <GLES/glext.h>
25
26#include <cutils/log.h>
27#include <cutils/properties.h>
28
Mathias Agopian39c24a22013-04-04 23:17:56 -070029#include "../hooks.h"
30#include "../egl_impl.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031
32using namespace android;
33
34// ----------------------------------------------------------------------------
35// extensions for the framework
36// ----------------------------------------------------------------------------
37
Mathias Agopiand373c632009-05-08 15:35:17 -070038extern "C" {
39GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
40 const GLvoid *ptr, GLsizei count);
41GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride,
42 const GLvoid *pointer, GLsizei count);
43GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type,
44 GLsizei stride, const GLvoid *pointer, GLsizei count);
45GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type,
46 GLsizei stride, const GLvoid *pointer, GLsizei count);
Jack Palevich66089a32009-12-08 15:43:51 +080047GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type,
48 GLsizei stride, const GLvoid *pointer, GLsizei count);
49GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type,
50 GLsizei stride, const GLvoid *pointer, GLsizei count);
51GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type,
52 GLsizei stride, const GLvoid *pointer, GLsizei count);
Mathias Agopiand373c632009-05-08 15:35:17 -070053}
54
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055void glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070056 const GLvoid *ptr, GLsizei /*count*/) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057 glColorPointer(size, type, stride, ptr);
58}
59void glNormalPointerBounds(GLenum type, GLsizei stride,
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070060 const GLvoid *pointer, GLsizei /*count*/) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 glNormalPointer(type, stride, pointer);
62}
63void glTexCoordPointerBounds(GLint size, GLenum type,
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070064 GLsizei stride, const GLvoid *pointer, GLsizei /*count*/) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 glTexCoordPointer(size, type, stride, pointer);
66}
67void glVertexPointerBounds(GLint size, GLenum type,
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070068 GLsizei stride, const GLvoid *pointer, GLsizei /*count*/) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 glVertexPointer(size, type, stride, pointer);
70}
71
Jack Palevich66089a32009-12-08 15:43:51 +080072void GL_APIENTRY glPointSizePointerOESBounds(GLenum type,
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070073 GLsizei stride, const GLvoid *pointer, GLsizei /*count*/) {
Jack Palevich66089a32009-12-08 15:43:51 +080074 glPointSizePointerOES(type, stride, pointer);
75}
76
77GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type,
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070078 GLsizei stride, const GLvoid *pointer, GLsizei /*count*/) {
Jack Palevich66089a32009-12-08 15:43:51 +080079 glMatrixIndexPointerOES(size, type, stride, pointer);
80}
81
82GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type,
Mark Salyzyn92dc3fc2014-03-12 13:12:44 -070083 GLsizei stride, const GLvoid *pointer, GLsizei /*count*/) {
Jack Palevich66089a32009-12-08 15:43:51 +080084 glWeightPointerOES(size, type, stride, pointer);
85}
86
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080087// ----------------------------------------------------------------------------
88// Actual GL entry-points
89// ----------------------------------------------------------------------------
90
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091#undef API_ENTRY
92#undef CALL_GL_API
93#undef CALL_GL_API_RETURN
94
Mathias Agopiane0ea89c2013-06-14 19:08:36 -070095#if defined(__arm__) && !USE_SLOW_BINDING
Duane Sand46b42532013-03-27 10:58:06 -070096
Elliott Hughes288870e2013-02-13 17:30:54 -080097 #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
Mathias Agopian673d2db2009-10-14 02:39:53 -070098
Mathias Agopiane0ea89c2013-06-14 19:08:36 -070099 #define API_ENTRY(_api) __attribute__((noinline)) _api
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100
101 #define CALL_GL_API(_api, ...) \
102 asm volatile( \
Mathias Agopian673d2db2009-10-14 02:39:53 -0700103 GET_TLS(r12) \
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104 "ldr r12, [r12, %[tls]] \n" \
105 "cmp r12, #0 \n" \
106 "ldrne pc, [r12, %[api]] \n" \
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107 : \
108 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
109 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
110 : \
111 );
Mathias Agopian673d2db2009-10-14 02:39:53 -0700112
mwajdeczc80aafa2014-05-26 13:56:37 +0200113#elif defined(__i386__) && !USE_SLOW_BINDING
114
115 #define API_ENTRY(_api) __attribute__((noinline)) _api
116
117 #define CALL_GL_API(_api, ...) \
118 register void* fn; \
119 __asm__ volatile( \
120 "mov %%gs:0, %[fn]\n" \
121 "mov %P[tls](%[fn]), %[fn]\n" \
122 "test %[fn], %[fn]\n" \
123 "je 1f\n" \
124 "jmp *%P[api](%[fn])\n" \
125 "1:\n" \
126 : [fn] "=r" (fn) \
127 : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)), \
128 [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api)) \
129 : "cc" \
130 );
131
132#elif defined(__x86_64__) && !USE_SLOW_BINDING
133
134 #define API_ENTRY(_api) __attribute__((noinline)) _api
135
136 #define CALL_GL_API(_api, ...) \
137 register void** fn; \
138 __asm__ volatile( \
139 "mov %%fs:0, %[fn]\n" \
140 "mov %P[tls](%[fn]), %[fn]\n" \
141 "test %[fn], %[fn]\n" \
142 "je 1f\n" \
143 "jmp *%P[api](%[fn])\n" \
144 "1:\n" \
145 : [fn] "=r" (fn) \
146 : [tls] "i" (TLS_SLOT_OPENGL_API*sizeof(void*)), \
147 [api] "i" (__builtin_offsetof(gl_hooks_t, gl._api)) \
148 : "cc" \
149 );
150
Mathias Agopiane0ea89c2013-06-14 19:08:36 -0700151#elif defined(__mips__) && !USE_SLOW_BINDING
Duane Sand46b42532013-03-27 10:58:06 -0700152
153 #define API_ENTRY(_api) __attribute__((noinline)) _api
154
155 #define CALL_GL_API(_api, ...) \
Jesse Hall441f6942013-03-30 23:22:19 -0700156 register unsigned int _t0 asm("t0"); \
157 register unsigned int _fn asm("t1"); \
158 register unsigned int _tls asm("v1"); \
159 register unsigned int _v0 asm("v0"); \
Duane Sand46b42532013-03-27 10:58:06 -0700160 asm volatile( \
161 ".set push\n\t" \
162 ".set noreorder\n\t" \
163 ".set mips32r2\n\t" \
164 "rdhwr %[tls], $29\n\t" \
165 "lw %[t0], %[OPENGL_API](%[tls])\n\t" \
166 "beqz %[t0], 1f\n\t" \
167 " move %[fn], $ra\n\t" \
168 "lw %[fn], %[API](%[t0])\n\t" \
169 "movz %[fn], $ra, %[fn]\n\t" \
170 "1:\n\t" \
171 "j %[fn]\n\t" \
172 " move %[v0], $0\n\t" \
173 ".set pop\n\t" \
Jesse Hall441f6942013-03-30 23:22:19 -0700174 : [fn] "=c"(_fn), \
175 [tls] "=&r"(_tls), \
176 [t0] "=&r"(_t0), \
177 [v0] "=&r"(_v0) \
Duane Sand46b42532013-03-27 10:58:06 -0700178 : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4), \
179 [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \
180 : \
181 );
182
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800183#else
184
185 #define API_ENTRY(_api) _api
186
Mathias Agopiane0ea89c2013-06-14 19:08:36 -0700187 #define CALL_GL_API(_api, ...) \
188 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
189 if (_c) return _c->_api(__VA_ARGS__);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800190
191#endif
192
Mathias Agopiane0ea89c2013-06-14 19:08:36 -0700193#define CALL_GL_API_RETURN(_api, ...) \
194 CALL_GL_API(_api, __VA_ARGS__) \
195 return 0;
196
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700197
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800198extern "C" {
199#include "gl_api.in"
Mathias Agopianb519abb2009-04-23 18:05:44 -0700200#include "glext_api.in"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800201}
202
203#undef API_ENTRY
204#undef CALL_GL_API
205#undef CALL_GL_API_RETURN
206
Mathias Agopian48d438d2012-01-28 21:44:00 -0800207/*
208 * glGetString() is special because we expose some extensions in the wrapper
209 */
210
211extern "C" const GLubyte * __glGetString(GLenum name);
212
Mathias Agopiane0ea89c2013-06-14 19:08:36 -0700213const GLubyte * glGetString(GLenum name) {
Mathias Agopian48d438d2012-01-28 21:44:00 -0800214 const GLubyte * ret = egl_get_string_for_current_context(name);
215 if (ret == NULL) {
Mathias Agopiane0ea89c2013-06-14 19:08:36 -0700216 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;
217 ret = _c->glGetString(name);
Mathias Agopian48d438d2012-01-28 21:44:00 -0800218 }
219 return ret;
220}