2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "ClientAPIExts.h"
17 #include "ThreadInfo.h"
19 #include <GLES/glext.h>
20 #include "eglContext.h"
22 namespace ClientAPIExts
26 // define function pointer type for each extention function
27 // typename has the form __egl_{funcname}_t
29 #define FUNC_TYPE(fname) __egl_ ## fname ## _t
30 #define API_ENTRY(fname,params,args) \
31 typedef void (GL_APIENTRY *FUNC_TYPE(fname)) params;
33 #define API_ENTRY_RET(rtype,fname,params,args) \
34 typedef rtype (GL_APIENTRY *FUNC_TYPE(fname)) params;
36 #include "ClientAPIExts.in"
41 // Define static table to store the function value for each
42 // client API. functions pointers will get initialized through
43 // ClientAPIExts::initClientFuncs function after each client API has been
46 #define API_ENTRY(fname,params,args) \
47 FUNC_TYPE(fname) fname;
49 #define API_ENTRY_RET(rtype,fname,params,args) \
50 API_ENTRY(fname,params,args)
52 static struct _ext_table
54 #include "ClientAPIExts.in"
55 } s_client_extensions[2];
61 // This function initialized each entry in the s_client_extensions
62 // struct at the givven index using the givven client interface
64 void initClientFuncs(const EGLClient_glesInterface *iface, int idx)
66 #define API_ENTRY(fname,params,args) \
67 s_client_extensions[idx].fname = \
68 (FUNC_TYPE(fname))iface->getProcAddress(#fname);
70 #define API_ENTRY_RET(rtype,fname,params,args) \
71 API_ENTRY(fname,params,args)
74 // reset all func pointers to NULL
76 memset(&s_client_extensions[idx], 0, sizeof(struct _ext_table));
79 // And now query the GLES library for each proc address
81 #include "ClientAPIExts.in"
87 // Define implementation for each extension function which checks
88 // the current context version and calls to the correct client API
91 #define API_ENTRY(fname,params,args) \
92 static void _egl_ ## fname params \
94 EGLThreadInfo* thread = getEGLThreadInfo(); \
95 if (!thread->currentContext) { \
98 int idx = (int)thread->currentContext->version - 1; \
99 if (!s_client_extensions[idx].fname) { \
102 (*s_client_extensions[idx].fname) args; \
105 #define API_ENTRY_RET(rtype,fname,params,args) \
106 static rtype _egl_ ## fname params \
108 EGLThreadInfo* thread = getEGLThreadInfo(); \
109 if (!thread->currentContext) { \
112 int idx = (int)thread->currentContext->version - 1; \
113 if (!s_client_extensions[idx].fname) { \
116 return (*s_client_extensions[idx].fname) args; \
119 #include "ClientAPIExts.in"
124 // Define a table to map function names to the local _egl_ version of
125 // the extension function, to be used in eglGetProcAddress.
127 #define API_ENTRY(fname,params,args) \
128 { #fname, (void*)_egl_ ## fname},
129 #define API_ENTRY_RET(rtype,fname,params,args) \
130 API_ENTRY(fname,params,args)
132 static const struct _client_ext_funcs {
135 } s_client_ext_funcs[] = {
136 #include "ClientAPIExts.in"
138 static const int numExtFuncs = sizeof(s_client_ext_funcs) /
139 sizeof(s_client_ext_funcs[0]);
145 // returns the __egl_ version of the givven extension function name.
147 void* getProcAddress(const char *fname)
149 for (int i=0; i<numExtFuncs; i++) {
150 if (!strcmp(fname, s_client_ext_funcs[i].fname)) {
151 return s_client_ext_funcs[i].proc;
157 } // of namespace ClientAPIExts