blob: 48fd27877bca0960256e06477d15fca347ea29be [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
29#include "hooks.h"
Mathias Agopian076b1cc2009-04-10 14:24:30 -070030#include "egl_impl.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031
32using namespace android;
33
Mathias Agopian7d21a742009-10-08 15:58:11 -070034// set this to 1 for crude GL debugging
35#define CHECK_FOR_GL_ERRORS 0
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037// ----------------------------------------------------------------------------
38// extensions for the framework
39// ----------------------------------------------------------------------------
40
Mathias Agopiand373c632009-05-08 15:35:17 -070041extern "C" {
42GL_API void GL_APIENTRY glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
43 const GLvoid *ptr, GLsizei count);
44GL_API void GL_APIENTRY glNormalPointerBounds(GLenum type, GLsizei stride,
45 const GLvoid *pointer, GLsizei count);
46GL_API void GL_APIENTRY glTexCoordPointerBounds(GLint size, GLenum type,
47 GLsizei stride, const GLvoid *pointer, GLsizei count);
48GL_API void GL_APIENTRY glVertexPointerBounds(GLint size, GLenum type,
49 GLsizei stride, const GLvoid *pointer, GLsizei count);
Jack Palevich66089a32009-12-08 15:43:51 +080050GL_API void GL_APIENTRY glPointSizePointerOESBounds(GLenum type,
51 GLsizei stride, const GLvoid *pointer, GLsizei count);
52GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type,
53 GLsizei stride, const GLvoid *pointer, GLsizei count);
54GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type,
55 GLsizei stride, const GLvoid *pointer, GLsizei count);
Mathias Agopiand373c632009-05-08 15:35:17 -070056}
57
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058void glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
59 const GLvoid *ptr, GLsizei count) {
60 glColorPointer(size, type, stride, ptr);
61}
62void glNormalPointerBounds(GLenum type, GLsizei stride,
63 const GLvoid *pointer, GLsizei count) {
64 glNormalPointer(type, stride, pointer);
65}
66void glTexCoordPointerBounds(GLint size, GLenum type,
67 GLsizei stride, const GLvoid *pointer, GLsizei count) {
68 glTexCoordPointer(size, type, stride, pointer);
69}
70void glVertexPointerBounds(GLint size, GLenum type,
71 GLsizei stride, const GLvoid *pointer, GLsizei count) {
72 glVertexPointer(size, type, stride, pointer);
73}
74
Jack Palevich66089a32009-12-08 15:43:51 +080075void GL_APIENTRY glPointSizePointerOESBounds(GLenum type,
76 GLsizei stride, const GLvoid *pointer, GLsizei count) {
77 glPointSizePointerOES(type, stride, pointer);
78}
79
80GL_API void GL_APIENTRY glMatrixIndexPointerOESBounds(GLint size, GLenum type,
81 GLsizei stride, const GLvoid *pointer, GLsizei count) {
82 glMatrixIndexPointerOES(size, type, stride, pointer);
83}
84
85GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type,
86 GLsizei stride, const GLvoid *pointer, GLsizei count) {
87 glWeightPointerOES(size, type, stride, pointer);
88}
89
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090// ----------------------------------------------------------------------------
91// Actual GL entry-points
92// ----------------------------------------------------------------------------
93
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094#undef API_ENTRY
95#undef CALL_GL_API
96#undef CALL_GL_API_RETURN
97
Mathias Agopian7d21a742009-10-08 15:58:11 -070098#if USE_FAST_TLS_KEY && !CHECK_FOR_GL_ERRORS
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099
Elliott Hughes288870e2013-02-13 17:30:54 -0800100 #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
Mathias Agopian673d2db2009-10-14 02:39:53 -0700101
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 #define API_ENTRY(_api) __attribute__((naked)) _api
103
104 #define CALL_GL_API(_api, ...) \
105 asm volatile( \
Mathias Agopian673d2db2009-10-14 02:39:53 -0700106 GET_TLS(r12) \
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107 "ldr r12, [r12, %[tls]] \n" \
108 "cmp r12, #0 \n" \
109 "ldrne pc, [r12, %[api]] \n" \
Mathias Agopian6f087122010-09-23 16:38:38 -0700110 "mov r0, #0 \n" \
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111 "bx lr \n" \
112 : \
113 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
114 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
115 : \
116 );
Mathias Agopian673d2db2009-10-14 02:39:53 -0700117
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118 #define CALL_GL_API_RETURN(_api, ...) \
119 CALL_GL_API(_api, __VA_ARGS__) \
120 return 0; // placate gcc's warnings. never reached.
121
122#else
123
Mathias Agopian7d21a742009-10-08 15:58:11 -0700124 #if CHECK_FOR_GL_ERRORS
125
126 #define CHECK_GL_ERRORS(_api) \
127 do { GLint err = glGetError(); \
Steve Blocke6f43dd2012-01-06 19:20:56 +0000128 ALOGE_IF(err != GL_NO_ERROR, "%s failed (0x%04X)", #_api, err); \
Mathias Agopian7d21a742009-10-08 15:58:11 -0700129 } while(false);
130
131 #else
132
133 #define CHECK_GL_ERRORS(_api) do { } while(false);
134
135 #endif
136
137
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138 #define API_ENTRY(_api) _api
139
140 #define CALL_GL_API(_api, ...) \
141 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
Mathias Agopian7d21a742009-10-08 15:58:11 -0700142 _c->_api(__VA_ARGS__); \
143 CHECK_GL_ERRORS(_api)
144
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145 #define CALL_GL_API_RETURN(_api, ...) \
146 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800147 return _c->_api(__VA_ARGS__)
148
149#endif
150
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700151
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800152extern "C" {
153#include "gl_api.in"
Mathias Agopianb519abb2009-04-23 18:05:44 -0700154#include "glext_api.in"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800155}
156
157#undef API_ENTRY
158#undef CALL_GL_API
159#undef CALL_GL_API_RETURN
160
Mathias Agopian48d438d2012-01-28 21:44:00 -0800161/*
162 * glGetString() is special because we expose some extensions in the wrapper
163 */
164
165extern "C" const GLubyte * __glGetString(GLenum name);
166
167const GLubyte * glGetString(GLenum name)
168{
169 const GLubyte * ret = egl_get_string_for_current_context(name);
170 if (ret == NULL) {
171 ret = __glGetString(name);
172 }
173 return ret;
174}