1 /*
2  * Copyright (C) 2018 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 <OpenGLESDispatch/EGLDispatch.h>
18 #include <OpenGLESDispatch/GLESv3Dispatch.h>
19 
20 #include <dlfcn.h>
21 #include <stdio.h>
22 
23 #define DEFAULT_GLESv2_LIB "libGLESv2_swiftshader.so"
24 
25 GLESv3Dispatch s_gles3;
26 
27 #define LOOKUP_SYMBOL(return_type, function_name, signature, callargs)        \
28     s_gles3.function_name = (function_name##_t)dlsym(handle, #function_name); \
29     if ((!s_gles3.function_name) && s_egl.eglGetProcAddress)                  \
30         s_gles3.function_name = (function_name##_t)s_egl.eglGetProcAddress(#function_name);
31 
gles3_dispatch_init()32 bool gles3_dispatch_init() {
33     void* handle = dlopen(DEFAULT_GLESv2_LIB, RTLD_NOW);
34     if (!handle) {
35         printf("Failed to open %s\n", dlerror());
36         return false;
37     }
38 
39     LIST_GLES3_FUNCTIONS(LOOKUP_SYMBOL, LOOKUP_SYMBOL)
40 
41     return true;
42 }
43