df02d6f17f20add6b50504002262ff80c7d0d040
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / graphics / emugl / RenderApi.cpp
1 /*
2 * Copyright (C) 2011-2015 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 "anbox/graphics/emugl/RenderApi.h"
18 #include "anbox/graphics/emugl/DispatchTables.h"
19
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"
23
24 #include "external/android-emugl/shared/emugl/common/crash_reporter.h"
25
26 #include <string.h>
27
28 GLESv2Dispatch s_gles2;
29 GLESv1Dispatch s_gles1;
30
31 namespace {
32 constexpr const char *default_egl_lib{"libEGL.so.1"};
33 constexpr const char *default_glesv2_lib{"libGLESv2.so.2"};
34 }
35
36 namespace anbox {
37 namespace graphics {
38 namespace emugl {
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},
43   };
44 }
45
46 bool initialize(const std::vector<GLLibrary> &libs, emugl_logger_struct *log_funcs, logger_t crash_func) {
47   set_emugl_crash_reporter(crash_func);
48   if (log_funcs) {
49     set_emugl_logger(log_funcs->coarse);
50     set_emugl_cxt_logger(log_funcs->fine);
51   }
52
53   for (const auto &lib : libs) {
54     const auto path = lib.path.c_str();
55     switch (lib.type) {
56     case GLLibrary::Type::EGL:
57       if (!init_egl_dispatch(path))
58         return false;
59       break;
60     case GLLibrary::Type::GLESv1:
61       if (!gles1_dispatch_init(path, &s_gles1))
62         return false;
63       break;
64     case GLLibrary::Type::GLESv2:
65       if (!gles2_dispatch_init(path, &s_gles2))
66         return false;
67       break;
68     default:
69       break;
70     }
71   }
72
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);
80
81   if (!s_egl.initialized || !s_gles2.initialized)
82     return false;
83
84   return true;
85 }
86 }  // namespace emugl
87 }  // namespace graphics
88 }  // namespace anbox