TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / external / android-emugl / host / libs / libOpenGLESDispatch / GLESv1Dispatch.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/GLESv1Dispatch.h"
17 #include "OpenGLESDispatch/EGLDispatch.h"
18
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #include "emugl/common/shared_library.h"
23
24 extern EGLDispatch s_egl;
25
26 static emugl::SharedLibrary *s_gles1_lib = NULL;
27
28 static void gles1_unimplemented() {
29     fprintf(stderr, "Called unimplemented GLESv1 API\n");
30 }
31
32 static void gles1_dummy() {}
33
34 #define ASSIGN_DUMMY(return_type, function_name, signature, call_args) do { \
35     dispatch_table-> function_name = reinterpret_cast<function_name ## _t>(gles1_dummy); \
36   } while(0);
37
38
39 #define LOOKUP_SYMBOL(return_type,function_name,signature,callargs) \
40     dispatch_table-> function_name = reinterpret_cast< function_name ## _t >( \
41             s_gles1_lib->findSymbol(#function_name));
42
43 #define LOOKUP_EXT_SYMBOL(return_type,function_name,signature,callargs) \
44     dispatch_table-> function_name = reinterpret_cast< function_name ## _t >( \
45             s_egl.eglGetProcAddress(#function_name));
46
47 namespace {
48 constexpr const char *glesv1_lib_env_var{"ANBOX_GLESv1_LIB"};
49 }
50
51 bool gles1_dispatch_init(const char *path, GLESv1Dispatch* dispatch_table) {
52     if (!dispatch_table)
53         return false;
54
55     // If no path is given we assign dummy functions to all GL calls
56     // we would have loaded from a real implementation.
57     if (!path) {
58         LIST_GLES1_FUNCTIONS(ASSIGN_DUMMY, ASSIGN_DUMMY);
59         return true;
60     }
61
62     const char* libName = getenv(glesv1_lib_env_var);
63     if (!libName)
64       libName = path;
65     if (!libName)
66         return false;
67
68     char error[256];
69     s_gles1_lib = emugl::SharedLibrary::open(libName, error, sizeof(error));
70     if (!s_gles1_lib) {
71         fprintf(stderr, "%s: Could not load %s [%s]\n", __FUNCTION__,
72                 libName, error);
73         return false;
74     }
75
76     LIST_GLES1_FUNCTIONS(LOOKUP_SYMBOL,LOOKUP_EXT_SYMBOL)
77
78     dispatch_table->initialized = true;
79
80     return true;
81 }
82
83 //
84 // This function is called only during initialization of the decoder before
85 // any thread has been created - hence it should NOT be thread safe.
86 //
87 void *gles1_dispatch_get_proc_func(const char *name, void *userData)
88 {
89     void* func = NULL;
90     if (s_gles1_lib && !func) {
91         func = (void *)s_gles1_lib->findSymbol(name);
92     }
93
94     if (!func) {
95         func = (void *)s_egl.eglGetProcAddress(name);
96     }
97
98     // To make it consistent with the guest, redirect any unsupported functions
99     // to gles1_unimplemented.
100     if (!func) {
101         func = (void *)gles1_unimplemented;
102     }
103     return func;
104 }