blob: 0f7481489f22b7994cc113fe6eb515ed99acfed7 [file] [log] [blame]
Jesse Hall47743382013-02-08 11:13:46 -08001/*
Mathias Agopianb1a39d62009-05-27 20:38:06 -07002 ** Copyright 2007, The Android Open Source Project
3 **
Jesse Hall47743382013-02-08 11:13:46 -08004 ** 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
Mathias Agopianb1a39d62009-05-27 20:38:06 -07007 **
Jesse Hall47743382013-02-08 11:13:46 -08008 ** http://www.apache.org/licenses/LICENSE-2.0
Mathias Agopianb1a39d62009-05-27 20:38:06 -07009 **
Jesse Hall47743382013-02-08 11:13:46 -080010 ** 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
Mathias Agopianb1a39d62009-05-27 20:38:06 -070014 ** 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
Jesse Hall47743382013-02-08 11:13:46 -080023#include <GLES3/gl3.h>
24#include <GLES3/gl3ext.h>
Mathias Agopianb1a39d62009-05-27 20:38:06 -070025#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
33using 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
Chet Haasee8b0fac2012-09-28 11:56:48 -070043#if USE_FAST_TLS_KEY
Mathias Agopianb1a39d62009-05-27 20:38:06 -070044
Mathias Agopian673d2db2009-10-14 02:39:53 -070045 #ifdef HAVE_ARM_TLS_REGISTER
46 #define GET_TLS(reg) \
47 "mrc p15, 0, " #reg ", c13, c0, 3 \n"
48 #else
49 #define GET_TLS(reg) \
50 "mov " #reg ", #0xFFFF0FFF \n" \
51 "ldr " #reg ", [" #reg ", #-15] \n"
52 #endif
53
Mathias Agopianb1a39d62009-05-27 20:38:06 -070054 #define API_ENTRY(_api) __attribute__((naked)) _api
55
56 #define CALL_GL_API(_api, ...) \
57 asm volatile( \
Mathias Agopian673d2db2009-10-14 02:39:53 -070058 GET_TLS(r12) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070059 "ldr r12, [r12, %[tls]] \n" \
60 "cmp r12, #0 \n" \
61 "ldrne pc, [r12, %[api]] \n" \
Mathias Agopian6f087122010-09-23 16:38:38 -070062 "mov r0, #0 \n" \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070063 "bx lr \n" \
64 : \
65 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
Mathias Agopian618fa102009-10-14 02:06:37 -070066 [api] "J"(__builtin_offsetof(gl_hooks_t, gl._api)) \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070067 : \
68 );
Mathias Agopian673d2db2009-10-14 02:39:53 -070069
Mathias Agopianb1a39d62009-05-27 20:38:06 -070070 #define CALL_GL_API_RETURN(_api, ...) \
71 CALL_GL_API(_api, __VA_ARGS__) \
72 return 0; // placate gcc's warnings. never reached.
73
74#else
75
76 #define API_ENTRY(_api) _api
77
Romain Guy761eaed2010-08-09 20:48:09 -070078 #define CALL_GL_API(_api, ...) \
79 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
80 _c->_api(__VA_ARGS__);
81
Mathias Agopianb1a39d62009-05-27 20:38:06 -070082 #define CALL_GL_API_RETURN(_api, ...) \
Mathias Agopian618fa102009-10-14 02:06:37 -070083 gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; \
Mathias Agopianb1a39d62009-05-27 20:38:06 -070084 return _c->_api(__VA_ARGS__)
85
86#endif
87
88
89extern "C" {
Jesse Hall47743382013-02-08 11:13:46 -080090#include "gl3_api.in"
Mathias Agopianb1a39d62009-05-27 20:38:06 -070091#include "gl2ext_api.in"
Jesse Hall47743382013-02-08 11:13:46 -080092#include "gl3ext_api.in"
Mathias Agopianb1a39d62009-05-27 20:38:06 -070093}
94
95#undef API_ENTRY
96#undef CALL_GL_API
97#undef CALL_GL_API_RETURN
98
Mathias Agopian48d438d2012-01-28 21:44:00 -080099/*
100 * glGetString() is special because we expose some extensions in the wrapper
101 */
102
103extern "C" const GLubyte * __glGetString(GLenum name);
104
105const GLubyte * glGetString(GLenum name)
106{
107 const GLubyte * ret = egl_get_string_for_current_context(name);
108 if (ret == NULL) {
109 ret = __glGetString(name);
110 }
111 return ret;
112}