blob: 865cf44362f0a8264919c1740747dd8d26ece908 [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
17#define LOG_TAG "GLES_CM"
18
19#include <ctype.h>
20#include <string.h>
21#include <errno.h>
22
23#include <sys/ioctl.h>
24
25#include <GLES/gl.h>
26#include <GLES/glext.h>
27
28#include <cutils/log.h>
29#include <cutils/properties.h>
30
31#include "hooks.h"
32
33using namespace android;
34
35// ----------------------------------------------------------------------------
36// extensions for the framework
37// ----------------------------------------------------------------------------
38
39void glColorPointerBounds(GLint size, GLenum type, GLsizei stride,
40 const GLvoid *ptr, GLsizei count) {
41 glColorPointer(size, type, stride, ptr);
42}
43void glNormalPointerBounds(GLenum type, GLsizei stride,
44 const GLvoid *pointer, GLsizei count) {
45 glNormalPointer(type, stride, pointer);
46}
47void glTexCoordPointerBounds(GLint size, GLenum type,
48 GLsizei stride, const GLvoid *pointer, GLsizei count) {
49 glTexCoordPointer(size, type, stride, pointer);
50}
51void glVertexPointerBounds(GLint size, GLenum type,
52 GLsizei stride, const GLvoid *pointer, GLsizei count) {
53 glVertexPointer(size, type, stride, pointer);
54}
55
56// ----------------------------------------------------------------------------
57// Actual GL entry-points
58// ----------------------------------------------------------------------------
59
60#if GL_LOGGER
61# include "gl_logger.h"
62# define GL_LOGGER_IMPL(_x) _x
63#else
64# define GL_LOGGER_IMPL(_x)
65#endif
66
67#undef API_ENTRY
68#undef CALL_GL_API
69#undef CALL_GL_API_RETURN
70
71#if USE_FAST_TLS_KEY
72
73 #define API_ENTRY(_api) __attribute__((naked)) _api
74
75 #define CALL_GL_API(_api, ...) \
76 asm volatile( \
77 "mov r12, #0xFFFF0FFF \n" \
78 "ldr r12, [r12, #-15] \n" \
79 "ldr r12, [r12, %[tls]] \n" \
80 "cmp r12, #0 \n" \
81 "ldrne pc, [r12, %[api]] \n" \
82 "bx lr \n" \
83 : \
84 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
85 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
86 : \
87 );
88
89 #define CALL_GL_API_RETURN(_api, ...) \
90 CALL_GL_API(_api, __VA_ARGS__) \
91 return 0; // placate gcc's warnings. never reached.
92
93#else
94
95 #define API_ENTRY(_api) _api
96
97 #define CALL_GL_API(_api, ...) \
98 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
99 GL_LOGGER_IMPL( log_##_api(__VA_ARGS__); ) \
100 _c->_api(__VA_ARGS__)
101
102 #define CALL_GL_API_RETURN(_api, ...) \
103 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
104 GL_LOGGER_IMPL( log_##_api(__VA_ARGS__); ) \
105 return _c->_api(__VA_ARGS__)
106
107#endif
108
109extern "C" {
110#include "gl_api.in"
111}
112
113#undef API_ENTRY
114#undef CALL_GL_API
115#undef CALL_GL_API_RETURN
116