OSDN Git Service

Merge "utils: Allow non android namespaces to use ALOGD_IF_SLOW"
[android-x86/frameworks-native.git] / opengl / libs / GLES2 / gl2.cpp
1 /* 
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 #include <ctype.h>
18 #include <string.h>
19 #include <errno.h>
20
21 #include <sys/ioctl.h>
22
23 #include <GLES2/gl2.h>
24 #include <GLES2/gl2ext.h>
25
26 #include <cutils/log.h>
27 #include <cutils/properties.h>
28
29 #include "hooks.h"
30 #include "egl_impl.h"
31
32 using namespace android;
33
34 // ----------------------------------------------------------------------------
35 // Actual GL entry-points
36 // ----------------------------------------------------------------------------
37
38 #undef API_ENTRY
39 #undef CALL_GL_API
40 #undef CALL_GL_API_RETURN
41
42 #if USE_FAST_TLS_KEY
43
44   #if defined(__arm__)
45
46     #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
47
48     #define API_ENTRY(_api) __attribute__((naked)) _api
49
50     #define CALL_GL_API(_api, ...)                              \
51          asm volatile(                                          \
52             GET_TLS(r12)                                        \
53             "ldr   r12, [r12, %[tls]] \n"                       \
54             "cmp   r12, #0            \n"                       \
55             "ldrne pc,  [r12, %[api]] \n"                       \
56             "mov   r0, #0             \n"                       \
57             "bx    lr                 \n"                       \
58             :                                                   \
59             : [tls] "J"(TLS_SLOT_OPENGL_API*4),                 \
60               [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api))    \
61             :                                                   \
62             );
63
64   #elif defined(__mips__)
65
66     #define API_ENTRY(_api) __attribute__((noinline)) _api
67
68     #define CALL_GL_API(_api, ...)                               \
69         register unsigned int t0 asm("t0");                      \
70         register unsigned int fn asm("t1");                      \
71         register unsigned int tls asm("v1");                     \
72         register unsigned int v0 asm("v0");                      \
73         asm volatile(                                            \
74             ".set  push\n\t"                                     \
75             ".set  noreorder\n\t"                                \
76             ".set mips32r2\n\t"                                  \
77             "rdhwr %[tls], $29\n\t"                              \
78             "lw    %[t0], %[OPENGL_API](%[tls])\n\t"             \
79             "beqz  %[t0], 1f\n\t"                                \
80             " move %[fn],$ra\n\t"                                \
81             "lw    %[fn], %[API](%[t0])\n\t"                     \
82             "movz  %[fn], $ra, %[fn]\n\t"                        \
83             "1:\n\t"                                             \
84             "j     %[fn]\n\t"                                    \
85             " move %[v0], $0\n\t"                                \
86             ".set  pop\n\t"                                      \
87             : [fn] "=c"(fn),                                     \
88               [tls] "=&r"(tls),                                  \
89               [t0] "=&r"(t0),                                    \
90               [v0] "=&r"(v0)                                     \
91             : [OPENGL_API] "I"(TLS_SLOT_OPENGL_API*4),           \
92               [API] "I"(__builtin_offsetof(gl_hooks_t, gl._api)) \
93             :                                                    \
94             );
95
96   #else
97
98     #error Unsupported architecture
99
100   #endif
101
102     #define CALL_GL_API_RETURN(_api, ...) \
103         CALL_GL_API(_api, __VA_ARGS__) \
104         return 0; // placate gcc's warnings. never reached.
105
106 #else
107
108     #define API_ENTRY(_api) _api
109
110     #define CALL_GL_API(_api, ...)                                       \
111         gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;  \
112         _c->_api(__VA_ARGS__);
113
114     #define CALL_GL_API_RETURN(_api, ...)                                \
115         gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;  \
116         return _c->_api(__VA_ARGS__)
117
118 #endif
119
120
121 extern "C" {
122 #include "gl2_api.in"
123 #include "gl2ext_api.in"
124 }
125
126 #undef API_ENTRY
127 #undef CALL_GL_API
128 #undef CALL_GL_API_RETURN
129
130 /*
131  * glGetString() is special because we expose some extensions in the wrapper
132  */
133
134 extern "C" const GLubyte * __glGetString(GLenum name);
135
136 const GLubyte * glGetString(GLenum name)
137 {
138     const GLubyte * ret = egl_get_string_for_current_context(name);
139     if (ret == NULL) {
140         ret = __glGetString(name);
141     }
142     return ret;
143 }