getProcAddress.cpp revision 1cadb25da1ed875bdd078270e642966724a0c39a
1/*
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
23#include "egldefs.h"
24#include "hooks.h"
25
26// ----------------------------------------------------------------------------
27namespace android {
28// ----------------------------------------------------------------------------
29
30#undef API_ENTRY
31#undef CALL_GL_EXTENSION_API
32#undef GL_EXTENSION
33#undef GL_EXTENSION_NAME
34#undef GL_EXTENSION_ARRAY
35#undef GL_EXTENSION_LIST
36#undef GET_TLS
37
38#if USE_FAST_TLS_KEY
39
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
67    #define GL_EXTENSION_NAME(_n)   __glExtFwd##_n
68
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
81    #warning "eglGetProcAddress() partially supported"
82
83#endif
84
85#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)
102
103
104GL_EXTENSION_LIST( GL_EXTENSION )
105
106#define GL_EXTENSION_ARRAY(_n)  GL_EXTENSION_NAME(_n),
107
108extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS] = {
109        GL_EXTENSION_LIST( GL_EXTENSION_ARRAY )
110 };
111
112#undef GET_TLS
113#undef GL_EXTENSION_LIST
114#undef GL_EXTENSION_ARRAY
115#undef GL_EXTENSION_NAME
116#undef GL_EXTENSION
117#undef API_ENTRY
118#undef CALL_GL_EXTENSION_API
119
120// ----------------------------------------------------------------------------
121}; // namespace android
122// ----------------------------------------------------------------------------
123
124