2 * Copyright (C) 2011-2015 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.
17 #include "anbox/graphics/emugl/RenderApi.h"
18 #include "anbox/graphics/emugl/DispatchTables.h"
20 #include "external/android-emugl/host/include/OpenGLESDispatch/EGLDispatch.h"
21 #include "external/android-emugl/host/include/OpenGLESDispatch/GLESv1Dispatch.h"
22 #include "external/android-emugl/host/include/OpenGLESDispatch/GLESv2Dispatch.h"
24 #include "external/android-emugl/shared/emugl/common/crash_reporter.h"
28 GLESv2Dispatch s_gles2;
29 GLESv1Dispatch s_gles1;
32 constexpr const char *default_egl_lib{"libEGL.so.1"};
33 constexpr const char *default_glesv2_lib{"libGLESv2.so.2"};
39 std::vector<GLLibrary> default_gl_libraries() {
40 return std::vector<GLLibrary>{
41 {GLLibrary::Type::EGL, default_egl_lib},
42 {GLLibrary::Type::GLESv2, default_glesv2_lib},
46 bool initialize(const std::vector<GLLibrary> &libs, emugl_logger_struct *log_funcs, logger_t crash_func) {
47 set_emugl_crash_reporter(crash_func);
49 set_emugl_logger(log_funcs->coarse);
50 set_emugl_cxt_logger(log_funcs->fine);
53 for (const auto &lib : libs) {
54 const auto path = lib.path.c_str();
56 case GLLibrary::Type::EGL:
57 if (!init_egl_dispatch(path))
60 case GLLibrary::Type::GLESv1:
61 if (!gles1_dispatch_init(path, &s_gles1))
64 case GLLibrary::Type::GLESv2:
65 if (!gles2_dispatch_init(path, &s_gles2))
73 // If we are not provided with a link to a OpenGL ES v1 implementation
74 // we assign dummy functions to all of the functions we would call.
75 // This allows us to still manage the major chunk of Android applications
76 // which are all >= GLESv2 until we have a proper GLESv1->GLESv2
77 // translation mechanism in place.
78 if (!s_gles1.initialized)
79 gles1_dispatch_init(nullptr, &s_gles1);
81 if (!s_egl.initialized || !s_gles2.initialized)
87 } // namespace graphics