Debian Codegraph @

libs/bluegl/src/BlueGLLinux.cpp

raw
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 <GL/gl.h>
18 #include <dlfcn.h>
19 #include <string.h>
20
21 namespace bluegl {
22
23 struct Driver {
24 void* (*glXGetProcAddress)(const GLubyte*);
25 void* library;
26 } g_driver = {nullptr, nullptr};
27
28 bool initBinder() {
29 const char* library_name = "libGL.so.1";
30 g_driver.library = dlopen(library_name, RTLD_GLOBAL | RTLD_NOW);
31
32 if (!g_driver.library) {
33 return false;
34 }
35
36 g_driver.glXGetProcAddress = (void *(*)(const GLubyte *))
37 dlsym(g_driver.library, "glXGetProcAddressARB");
38
39 return g_driver.glXGetProcAddress;
40 }
41
42 void* loadFunction(const char* name) {
43 return (void*) g_driver.glXGetProcAddress((const GLubyte*) name);
44 }
45
46 void shutdownBinder() {
47 dlclose(g_driver.library);
48 memset(&g_driver, 0, sizeof(g_driver));
49 }
50
51 } // namespace bluegl