TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / external / android-emugl / host / libs / libOpenGLESDispatch / EGLDispatch.cpp
1 /*
2 * Copyright (C) 2011 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 #include "OpenGLESDispatch/EGLDispatch.h"
17
18 #include "emugl/common/shared_library.h"
19
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 namespace {
24 constexpr const char *egl_lib_env_var{"ANBOX_EGL_LIB"};
25 }
26
27 EGLDispatch s_egl;
28
29 #define RENDER_EGL_LOAD_FIELD(return_type, function_name, signature) \
30     s_egl. function_name = (function_name ## _t) lib->findSymbol(#function_name);
31
32 #define RENDER_EGL_LOAD_OPTIONAL_FIELD(return_type, function_name, signature) \
33     if (s_egl.eglGetProcAddress) s_egl. function_name = \
34             (function_name ## _t) s_egl.eglGetProcAddress(#function_name); \
35     if (!s_egl.function_name || !s_egl.eglGetProcAddress) \
36             RENDER_EGL_LOAD_FIELD(return_type, function_name, signature)
37
38 bool init_egl_dispatch(const char *path) {
39     const char *libName = getenv(egl_lib_env_var);
40     if (!libName)
41       libName = path;
42     if (!libName)
43       return false;
44
45     char error[256];
46     emugl::SharedLibrary *lib = emugl::SharedLibrary::open(libName, error, sizeof(error));
47     if (!lib) {
48         printf("Failed to open %s: [%s]\n", libName, error);
49         return false;
50     }
51
52     LIST_RENDER_EGL_FUNCTIONS(RENDER_EGL_LOAD_FIELD)
53     LIST_RENDER_EGL_EXTENSIONS_FUNCTIONS(RENDER_EGL_LOAD_OPTIONAL_FIELD)
54
55     s_egl.initialized = true;
56
57     return true;
58 }