blob: fca42ec32a5a9dab72e9e291a34f4bb349c3eca8 [file] [log] [blame]
Mathias Agopianb1a39d62009-05-27 20:38:06 -07001/*
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
32using 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
Chet Haasee8b0fac2012-09-28 11:56:48 -070042#if USE_FAST_TLS_KEY
Mathias Agopianb1a39d62009-05-27 20:38:06 -070043
Elliott Hughes288870e2013-02-13 17:30:54 -080044 #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n"
Mathias Agopian673d2db2009-10-14 02:39:53 -070045
Mathias Agopianb1a39d62009-05-27 20:38:06 -070046 #define API_ENTRY(_api) __attribute__((naked)) _api
47
48 #define CALL_GL_API(_api, ...) \
49 asm volatile( \
Mathias Agopian673d2db2009-10-14 02:39:53 -070050 GET_TLS(r12) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070051 "ldr r12, [r12, %[tls]] \n" \
52 "cmp r12, #0 \n" \
53 "ldrne pc, [r12, %[api]] \n" \
Mathias Agopian6f087122010-09-23 16:38:38 -070054 "mov r0, #0 \n" \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070055 "bx lr \n" \
56 : \
57 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
Mathias Agopian618fa102009-10-14 02:06:37 -070058 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070059 : \
60 );
Mathias Agopian673d2db2009-10-14 02:39:53 -070061
Mathias Agopianb1a39d62009-05-27 20:38:06 -070062 #define CALL_GL_API_RETURN(_api, ...) \
63 CALL_GL_API(_api, __VA_ARGS__) \
64 return 0; // placate gcc's warnings. never reached.
65
66#else
67
68 #define API_ENTRY(_api) _api
69
Romain Guy761eaed2010-08-09 20:48:09 -070070 #define CALL_GL_API(_api, ...) \
71 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
72 _c->_api(__VA_ARGS__);
73
Mathias Agopianb1a39d62009-05-27 20:38:06 -070074 #define CALL_GL_API_RETURN(_api, ...) \
Mathias Agopian618fa102009-10-14 02:06:37 -070075 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070076 return _c->_api(__VA_ARGS__)
77
78#endif
79
80
81extern "C" {
82#include "gl2_api.in"
83#include "gl2ext_api.in"
84}
85
86#undef API_ENTRY
87#undef CALL_GL_API
88#undef CALL_GL_API_RETURN
89
Mathias Agopian48d438d2012-01-28 21:44:00 -080090/*
91 * glGetString() is special because we expose some extensions in the wrapper
92 */
93
94extern "C" const GLubyte * __glGetString(GLenum name);
95
96const GLubyte * glGetString(GLenum name)
97{
98 const GLubyte * ret = egl_get_string_for_current_context(name);
99 if (ret == NULL) {
100 ret = __glGetString(name);
101 }
102 return ret;
103}