2 * Copyright (C) 2011 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.
16 #include "OpenGLESDispatch/GLESv1Dispatch.h"
17 #include "OpenGLESDispatch/EGLDispatch.h"
22 #include "emugl/common/shared_library.h"
24 extern EGLDispatch s_egl;
26 static emugl::SharedLibrary *s_gles1_lib = NULL;
28 static void gles1_unimplemented() {
29 fprintf(stderr, "Called unimplemented GLESv1 API\n");
32 static void gles1_dummy() {}
34 #define ASSIGN_DUMMY(return_type, function_name, signature, call_args) do { \
35 dispatch_table-> function_name = reinterpret_cast<function_name ## _t>(gles1_dummy); \
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));
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));
48 constexpr const char *glesv1_lib_env_var{"ANBOX_GLESv1_LIB"};
51 bool gles1_dispatch_init(const char *path, GLESv1Dispatch* dispatch_table) {
55 // If no path is given we assign dummy functions to all GL calls
56 // we would have loaded from a real implementation.
58 LIST_GLES1_FUNCTIONS(ASSIGN_DUMMY, ASSIGN_DUMMY);
62 const char* libName = getenv(glesv1_lib_env_var);
69 s_gles1_lib = emugl::SharedLibrary::open(libName, error, sizeof(error));
71 fprintf(stderr, "%s: Could not load %s [%s]\n", __FUNCTION__,
76 LIST_GLES1_FUNCTIONS(LOOKUP_SYMBOL,LOOKUP_EXT_SYMBOL)
78 dispatch_table->initialized = true;
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.
87 void *gles1_dispatch_get_proc_func(const char *name, void *userData)
90 if (s_gles1_lib && !func) {
91 func = (void *)s_gles1_lib->findSymbol(name);
95 func = (void *)s_egl.eglGetProcAddress(name);
98 // To make it consistent with the guest, redirect any unsupported functions
99 // to gles1_unimplemented.
101 func = (void *)gles1_unimplemented;