OSDN Git Service

am 7212ff29: am 20e154f1: Merge "Second try at adding a compatibility symbol for...
[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 <GLES3/gl3.h>
24 #include <GLES3/gl3ext.h>
25 #include <GLES2/gl2ext.h>
26
27 #include <cutils/log.h>
28 #include <cutils/properties.h>
29
30 #include "hooks.h"
31 #include "egl_impl.h"
32
33 using namespace android;
34
35 // ----------------------------------------------------------------------------
36 // Actual GL entry-points
37 // ----------------------------------------------------------------------------
38
39 #undef API_ENTRY
40 #undef CALL_GL_API
41 #undef CALL_GL_API_RETURN
42
43 #if USE_FAST_TLS_KEY
44
45     #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
46
47     #define API_ENTRY(_api) __attribute__((naked)) _api
48
49     #define CALL_GL_API(_api, ...)                              \
50          asm volatile(                                          \
51             GET_TLS(r12)                                        \
52             "ldr   r12, [r12, %[tls]] \n"                       \
53             "cmp   r12, #0            \n"                       \
54             "ldrne pc,  [r12, %[api]] \n"                       \
55             "mov   r0, #0             \n"                       \
56             "bx    lr                 \n"                       \
57             :                                                   \
58             : [tls] "J"(TLS_SLOT_OPENGL_API*4),                 \
59               [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api))    \
60             :                                                   \
61             );
62
63     #define CALL_GL_API_RETURN(_api, ...) \
64         CALL_GL_API(_api, __VA_ARGS__) \
65         return 0; // placate gcc's warnings. never reached.
66
67 #else
68
69     #define API_ENTRY(_api) _api
70
71     #define CALL_GL_API(_api, ...)                                       \
72         gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;  \
73         _c->_api(__VA_ARGS__);
74
75     #define CALL_GL_API_RETURN(_api, ...)                                \
76         gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl;  \
77         return _c->_api(__VA_ARGS__)
78
79 #endif
80
81
82 extern "C" {
83 #include "gl3_api.in"
84 #include "gl2ext_api.in"
85 #include "gl3ext_api.in"
86 }
87
88 #undef API_ENTRY
89 #undef CALL_GL_API
90 #undef CALL_GL_API_RETURN
91
92 /*
93  * glGetString() is special because we expose some extensions in the wrapper
94  */
95
96 extern "C" const GLubyte * __glGetString(GLenum name);
97
98 const GLubyte * glGetString(GLenum name)
99 {
100     const GLubyte * ret = egl_get_string_for_current_context(name);
101     if (ret == NULL) {
102         ret = __glGetString(name);
103     }
104     return ret;
105 }