blob: a1753435042e83acfcd2e0d671c73177a739e7fb [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
38void glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
39 const GLvoid *ptr, GLsizei count) {
40 glColorPointer(size, type, stride, ptr);
41}
42void glNormalPointerBounds(GLenum type, GLsizei stride,
43 const GLvoid *pointer, GLsizei count) {
44 glNormalPointer(type, stride, pointer);
45}
46void glTexCoordPointerBounds(GLint size, GLenum type,
47 GLsizei stride, const GLvoid *pointer, GLsizei count) {
48 glTexCoordPointer(size, type, stride, pointer);
49}
50void glVertexPointerBounds(GLint size, GLenum type,
51 GLsizei stride, const GLvoid *pointer, GLsizei count) {
52 glVertexPointer(size, type, stride, pointer);
53}
54
55// ----------------------------------------------------------------------------
56// Actual GL entry-points
57// ----------------------------------------------------------------------------
58
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059#undef API_ENTRY
60#undef CALL_GL_API
61#undef CALL_GL_API_RETURN
62
63#if USE_FAST_TLS_KEY
64
65 #define API_ENTRY(_api) __attribute__((naked)) _api
66
67 #define CALL_GL_API(_api, ...) \
68 asm volatile( \
69 "mov r12, #0xFFFF0FFF \n" \
70 "ldr r12, [r12, #-15] \n" \
71 "ldr r12, [r12, %[tls]] \n" \
72 "cmp r12, #0 \n" \
73 "ldrne pc, [r12, %[api]] \n" \
74 "bx lr \n" \
75 : \
76 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
77 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
78 : \
79 );
80
81 #define CALL_GL_API_RETURN(_api, ...) \
82 CALL_GL_API(_api, __VA_ARGS__) \
83 return 0; // placate gcc's warnings. never reached.
84
85#else
86
87 #define API_ENTRY(_api) _api
88
89 #define CALL_GL_API(_api, ...) \
90 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091 _c->_api(__VA_ARGS__)
92
93 #define CALL_GL_API_RETURN(_api, ...) \
94 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095 return _c->_api(__VA_ARGS__)
96
97#endif
98
Mathias Agopian076b1cc2009-04-10 14:24:30 -070099
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100extern "C" {
101#include "gl_api.in"
102}
103
104#undef API_ENTRY
105#undef CALL_GL_API
106#undef CALL_GL_API_RETURN
107
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700108
109/*
110 * These GL calls are special because they need to EGL to retrieve some
111 * informations before they can execute.
112 */
113
114extern "C" void __glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image);
115extern "C" void __glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image);
116
117
118void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
119{
120 GLeglImageOES implImage =
121 (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
122 __glEGLImageTargetTexture2DOES(target, implImage);
123}
124
125void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
126{
127 GLeglImageOES implImage =
128 (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
129 __glEGLImageTargetRenderbufferStorageOES(target, image);
130}
131