blob: 3204d9af90d8974c6dba0d21a09677d45a895b42 [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
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);
47}
48
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049void glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
50 const GLvoid *ptr, GLsizei count) {
51 glColorPointer(size, type, stride, ptr);
52}
53void glNormalPointerBounds(GLenum type, GLsizei stride,
54 const GLvoid *pointer, GLsizei count) {
55 glNormalPointer(type, stride, pointer);
56}
57void glTexCoordPointerBounds(GLint size, GLenum type,
58 GLsizei stride, const GLvoid *pointer, GLsizei count) {
59 glTexCoordPointer(size, type, stride, pointer);
60}
61void glVertexPointerBounds(GLint size, GLenum type,
62 GLsizei stride, const GLvoid *pointer, GLsizei count) {
63 glVertexPointer(size, type, stride, pointer);
64}
65
66// ----------------------------------------------------------------------------
67// Actual GL entry-points
68// ----------------------------------------------------------------------------
69
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070#undef API_ENTRY
71#undef CALL_GL_API
72#undef CALL_GL_API_RETURN
73
74#if USE_FAST_TLS_KEY
75
76 #define API_ENTRY(_api) __attribute__((naked)) _api
77
78 #define CALL_GL_API(_api, ...) \
79 asm volatile( \
80 "mov r12, #0xFFFF0FFF \n" \
81 "ldr r12, [r12, #-15] \n" \
82 "ldr r12, [r12, %[tls]] \n" \
83 "cmp r12, #0 \n" \
84 "ldrne pc, [r12, %[api]] \n" \
85 "bx lr \n" \
86 : \
87 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
88 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
89 : \
90 );
91
92 #define CALL_GL_API_RETURN(_api, ...) \
93 CALL_GL_API(_api, __VA_ARGS__) \
94 return 0; // placate gcc's warnings. never reached.
95
96#else
97
98 #define API_ENTRY(_api) _api
99
100 #define CALL_GL_API(_api, ...) \
101 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 _c->_api(__VA_ARGS__)
103
104 #define CALL_GL_API_RETURN(_api, ...) \
105 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106 return _c->_api(__VA_ARGS__)
107
108#endif
109
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700110
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111extern "C" {
112#include "gl_api.in"
Mathias Agopianb519abb2009-04-23 18:05:44 -0700113#include "glext_api.in"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800114}
115
116#undef API_ENTRY
117#undef CALL_GL_API
118#undef CALL_GL_API_RETURN
119
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700120
121/*
122 * These GL calls are special because they need to EGL to retrieve some
123 * informations before they can execute.
124 */
125
126extern "C" void __glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image);
127extern "C" void __glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image);
128
129
130void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
131{
132 GLeglImageOES implImage =
133 (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
134 __glEGLImageTargetTexture2DOES(target, implImage);
135}
136
137void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
138{
139 GLeglImageOES implImage =
140 (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
141 __glEGLImageTargetRenderbufferStorageOES(target, image);
142}
143