blob: f89c865761a4d98ad4a252361b108317a66cb9aa [file] [log] [blame]
Mathias Agopian24035332010-08-02 17:34:32 -07001/*
2 ** Copyright 2009, 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 <stdlib.h>
19#include <errno.h>
20
21#include <cutils/log.h>
22
Mathias Agopian1cadb252011-05-23 17:26:14 -070023#include "egldefs.h"
Mathias Agopian24035332010-08-02 17:34:32 -070024#include "hooks.h"
25
26// ----------------------------------------------------------------------------
27namespace android {
28// ----------------------------------------------------------------------------
29
30#undef API_ENTRY
Mathias Agopian7f781d12010-08-09 18:35:43 -070031#undef CALL_GL_EXTENSION_API
Mathias Agopian24035332010-08-02 17:34:32 -070032#undef GL_EXTENSION
33#undef GL_EXTENSION_NAME
Mathias Agopian7f781d12010-08-09 18:35:43 -070034#undef GL_EXTENSION_ARRAY
35#undef GL_EXTENSION_LIST
36#undef GET_TLS
Mathias Agopian24035332010-08-02 17:34:32 -070037
Mathias Agopian1cadb252011-05-23 17:26:14 -070038#if USE_FAST_TLS_KEY
Mathias Agopian24035332010-08-02 17:34:32 -070039
40 #ifdef HAVE_ARM_TLS_REGISTER
41 #define GET_TLS(reg) \
42 "mrc p15, 0, " #reg ", c13, c0, 3 \n"
43 #else
44 #define GET_TLS(reg) \
45 "mov " #reg ", #0xFFFF0FFF \n" \
46 "ldr " #reg ", [" #reg ", #-15] \n"
47 #endif
48
49 #define API_ENTRY(_api) __attribute__((naked)) _api
50
51 #define CALL_GL_EXTENSION_API(_api) \
52 asm volatile( \
53 GET_TLS(r12) \
54 "ldr r12, [r12, %[tls]] \n" \
55 "cmp r12, #0 \n" \
56 "ldrne r12, [r12, %[api]] \n" \
57 "cmpne r12, #0 \n" \
58 "bxne r12 \n" \
59 "bx lr \n" \
60 : \
61 : [tls] "J"(TLS_SLOT_OPENGL_API*4), \
62 [api] "J"(__builtin_offsetof(gl_hooks_t, \
63 ext.extensions[_api])) \
64 : \
65 );
66
Mathias Agopian7f781d12010-08-09 18:35:43 -070067 #define GL_EXTENSION_NAME(_n) __glExtFwd##_n
Mathias Agopian24035332010-08-02 17:34:32 -070068
69 #define GL_EXTENSION(_n) \
70 void API_ENTRY(GL_EXTENSION_NAME(_n))() { \
71 CALL_GL_EXTENSION_API(_n); \
72 }
73
74
75#else
76
77 #define GL_EXTENSION_NAME(_n) NULL
78
79 #define GL_EXTENSION(_n)
80
Mathias Agopian1cadb252011-05-23 17:26:14 -070081 #warning "eglGetProcAddress() partially supported"
Mathias Agopian24035332010-08-02 17:34:32 -070082
83#endif
84
Mathias Agopian7f781d12010-08-09 18:35:43 -070085#define GL_EXTENSION_LIST(name) \
86 name(0) name(1) name(2) name(3) \
87 name(4) name(5) name(6) name(7) \
88 name(8) name(9) name(10) name(11) \
89 name(12) name(13) name(14) name(15) \
90 name(16) name(17) name(18) name(19) \
91 name(20) name(21) name(22) name(23) \
92 name(24) name(25) name(26) name(27) \
93 name(28) name(29) name(30) name(31) \
94 name(32) name(33) name(34) name(35) \
95 name(36) name(37) name(38) name(39) \
96 name(40) name(41) name(42) name(43) \
97 name(44) name(45) name(46) name(47) \
98 name(48) name(49) name(50) name(51) \
99 name(52) name(53) name(54) name(55) \
100 name(56) name(57) name(58) name(59) \
101 name(60) name(61) name(62) name(63)
Mathias Agopian24035332010-08-02 17:34:32 -0700102
Mathias Agopian24035332010-08-02 17:34:32 -0700103
Mathias Agopian7f781d12010-08-09 18:35:43 -0700104GL_EXTENSION_LIST( GL_EXTENSION )
Mathias Agopian24035332010-08-02 17:34:32 -0700105
Mathias Agopian7f781d12010-08-09 18:35:43 -0700106#define GL_EXTENSION_ARRAY(_n) GL_EXTENSION_NAME(_n),
Mathias Agopian24035332010-08-02 17:34:32 -0700107
108extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS] = {
Mathias Agopian7f781d12010-08-09 18:35:43 -0700109 GL_EXTENSION_LIST( GL_EXTENSION_ARRAY )
Mathias Agopian24035332010-08-02 17:34:32 -0700110 };
111
Mathias Agopian7f781d12010-08-09 18:35:43 -0700112#undef GET_TLS
113#undef GL_EXTENSION_LIST
114#undef GL_EXTENSION_ARRAY
Mathias Agopian24035332010-08-02 17:34:32 -0700115#undef GL_EXTENSION_NAME
116#undef GL_EXTENSION
117#undef API_ENTRY
Mathias Agopian7f781d12010-08-09 18:35:43 -0700118#undef CALL_GL_EXTENSION_API
Mathias Agopian24035332010-08-02 17:34:32 -0700119
120// ----------------------------------------------------------------------------
121}; // namespace android
122// ----------------------------------------------------------------------------
123