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 // NOLINT: clang-tidy adds parentheses around 'params'.
31 #define API_ENTRY(fname,params,args) \
32 typedef void (GL_APIENTRY *FUNC_TYPE(fname)) params; // NOLINT
34 #define API_ENTRY_RET(rtype,fname,params,args) \
35 typedef rtype (GL_APIENTRY *FUNC_TYPE(fname)) params; // NOLINT
37 #include "ClientAPIExts.in"
42 // Define static table to store the function value for each
43 // client API. functions pointers will get initialized through
44 // ClientAPIExts::initClientFuncs function after each client API has been
47 #define API_ENTRY(fname,params,args) \
48 FUNC_TYPE(fname) (fname);
50 #define API_ENTRY_RET(rtype,fname,params,args) \
51 API_ENTRY(fname,params,args)
53 static struct _ext_table
55 #include "ClientAPIExts.in"
56 } s_client_extensions[2];
62 // This function initialized each entry in the s_client_extensions
63 // struct at the givven index using the givven client interface
65 void initClientFuncs(const EGLClient_glesInterface *iface, int idx)
67 #define API_ENTRY(fname,params,args) \
68 s_client_extensions[idx].fname = \
69 (FUNC_TYPE(fname))iface->getProcAddress(#fname);
71 #define API_ENTRY_RET(rtype,fname,params,args) \
72 API_ENTRY(fname,params,args)
75 // reset all func pointers to NULL
77 memset(&s_client_extensions[idx], 0, sizeof(struct _ext_table));
80 // And now query the GLES library for each proc address
82 #include "ClientAPIExts.in"
88 // Define implementation for each extension function which checks
89 // the current context version and calls to the correct client API
92 // NOLINT: clang-tidy adds parentheses around 'args'.
93 #define API_ENTRY(fname,params,args) \
94 static void _egl_ ## fname params \
96 EGLThreadInfo* thread = getEGLThreadInfo(); \
97 if (!thread->currentContext) { \
100 int idx = (int)thread->currentContext->majorVersion - 1; \
101 if (!s_client_extensions[idx].fname) { \
104 (*s_client_extensions[idx].fname) args; /* NOLINT */ \
107 #define API_ENTRY_RET(rtype,fname,params,args) \
108 static rtype _egl_ ## fname params \
110 EGLThreadInfo* thread = getEGLThreadInfo(); \
111 if (!thread->currentContext) { \
114 int idx = (int)thread->currentContext->majorVersion - 1; \
115 if (!s_client_extensions[idx].fname) { \
118 return (*s_client_extensions[idx].fname) args; /* NOLINT */ \
121 #include "ClientAPIExts.in"
126 // Define a table to map function names to the local _egl_ version of
127 // the extension function, to be used in eglGetProcAddress.
129 #define API_ENTRY(fname,params,args) \
130 { #fname, (void*)_egl_ ## fname},
131 #define API_ENTRY_RET(rtype,fname,params,args) \
132 API_ENTRY(fname,params,args)
134 static const struct _client_ext_funcs {
137 } s_client_ext_funcs[] = {
138 #include "ClientAPIExts.in"
140 static const int numExtFuncs = sizeof(s_client_ext_funcs) /
141 sizeof(s_client_ext_funcs[0]);
147 // returns the __egl_ version of the givven extension function name.
149 void* getProcAddress(const char *fname)
151 for (int i=0; i<numExtFuncs; i++) {
152 if (!strcmp(fname, s_client_ext_funcs[i].fname)) {
153 return s_client_ext_funcs[i].proc;
159 } // of namespace ClientAPIExts