1 /* 2 * Copyright (C) 2018 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 "egl_wrapper_context.h" 18 #undef GET_CONTEXT 19 20 #include <dlfcn.h> 21 22 egl_wrapper_context_t* (*getEGLContext)(void) = NULL; 23 24 static egl_wrapper_context_t g_egl_wrapper_context; 25 egl(void)26static egl_wrapper_context_t *egl(void) { 27 return &g_egl_wrapper_context; 28 } 29 setContextAccessor(egl_wrapper_context_t * (* f)(void))30void egl_wrapper_context_t::setContextAccessor(egl_wrapper_context_t* (*f)(void)) { 31 getEGLContext = f; 32 } 33 34 std::mutex g_context_mutex; 35 getProc(const char * name,void * userData)36static void *getProc(const char *name, void *userData) { 37 return dlsym(userData, name); 38 } 39 setup()40__attribute__((constructor)) void setup() { 41 void *egl_handle = dlopen("/vendor/lib/gl_impl/swiftshader/libEGL_swiftshader.so", RTLD_NOW); 42 g_egl_wrapper_context.initDispatchByName(getProc, egl_handle); 43 g_egl_wrapper_context.setContextAccessor(egl); 44 } 45