• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/GLESv2Dispatch.h"
17 
18 #include "OpenGLESDispatch/EGLDispatch.h"
19 #include "OpenGLESDispatch/StaticDispatch.h"
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 
25 #define DEFAULT_GLES_V2_LIB EMUGL_LIBNAME("GLES_V2_translator")
26 
27 namespace gfxstream {
28 namespace gl {
29 
30 // An unimplemented function which prints out an error message.
31 // To make it consistent with the guest, all GLES2 functions not supported by
32 // the driver should be redirected to this function.
33 
gles2_unimplemented()34 void gles2_unimplemented() {
35     fprintf(stderr, "Called unimplemented GLES API\n");
36 }
37 
38 #define LOOKUP_SYMBOL_STATIC(return_type, function_name, signature, callargs)    \
39     dispatch_table->function_name =                                              \
40         reinterpret_cast<function_name##_t>(::translator::gles2::function_name); \
41     if ((!dispatch_table->function_name) && s_egl.eglGetProcAddress)             \
42         dispatch_table->function_name =                                          \
43             reinterpret_cast<function_name##_t>(s_egl.eglGetProcAddress(#function_name));
44 
gles2_dispatch_init(GLESv2Dispatch * dispatch_table)45 bool gles2_dispatch_init(GLESv2Dispatch* dispatch_table) {
46     if (dispatch_table->initialized) return true;
47 
48     LIST_GLES2_FUNCTIONS(LOOKUP_SYMBOL_STATIC,LOOKUP_SYMBOL_STATIC)
49 
50     dispatch_table->initialized = true;
51     return true;
52 }
53 
54 
gles2_dispatch_get_proc_func(const char * name,void * userData)55 void *gles2_dispatch_get_proc_func(const char *name, void *userData)
56 {
57     void* func = NULL;
58     func = gles2_dispatch_get_proc_func_static(name);
59 
60     // To make it consistent with the guest, redirect any unsupported functions
61     // to gles2_unimplemented.
62     if (!func) {
63         func = (void *)gles2_unimplemented;
64     }
65     return func;
66 }
67 
68 }  // namespace gl
69 }  // namespace gfxstream