• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "X11Support.h"
2 
3 #include "aemu/base/SharedLibrary.h"
4 
5 #define DEFINE_DUMMY_IMPL(rettype, funcname, args) \
6     static rettype dummy_##funcname args { \
7         return (rettype)0; \
8     } \
9 
10 LIST_XLIB_FUNCTYPES(DEFINE_DUMMY_IMPL)
11 LIST_GLX_FUNCTYPES(DEFINE_DUMMY_IMPL)
12 
13 class X11FunctionGetter {
14     public:
X11FunctionGetter()15         X11FunctionGetter() :
16             mX11Lib(android::base::SharedLibrary::open("libX11")) {
17 
18 #define X11_ASSIGN_DUMMY_IMPL(funcname) mApi.funcname = dummy_##funcname;
19 
20                 LIST_XLIB_FUNCS(X11_ASSIGN_DUMMY_IMPL)
21 
22             if (!mX11Lib) return;
23 
24 #define X11_GET_FUNC(funcname) \
25             { \
26                 auto f = mX11Lib->findSymbol(#funcname); \
27                 if (f) mApi.funcname = (funcname##_t)f; \
28             } \
29 
30                 LIST_XLIB_FUNCS(X11_GET_FUNC);
31 
32             }
33 
getApi()34         X11Api* getApi() { return &mApi; }
35     private:
36         android::base::SharedLibrary* mX11Lib;
37 
38         X11Api mApi;
39 };
40 
41 class GlxFunctionGetter {
42     public:
43         // Important: Use libGL.so.1 explicitly, because it will always link to
44         // the vendor-specific version of the library. libGL.so might in some
45         // cases, depending on bad ldconfig configurations, link to the wrapper
46         // lib that doesn't behave the same.
GlxFunctionGetter()47         GlxFunctionGetter() :
48             mGlxLib(android::base::SharedLibrary::open("libGL.so.1")) {
49 
50 #define GLX_ASSIGN_DUMMY_IMPL(funcname) mApi.funcname = dummy_##funcname;
51 
52                 LIST_GLX_FUNCS(GLX_ASSIGN_DUMMY_IMPL)
53 
54             if (!mGlxLib) return;
55 
56 #define GLX_GET_FUNC(funcname) \
57                 { \
58                 auto f = mGlxLib->findSymbol(#funcname); \
59                 if (f) mApi.funcname = (funcname##_t)f; \
60                 } \
61 
62                 LIST_GLX_FUNCS(GLX_GET_FUNC);
63 
64             }
65 
getApi()66         GlxApi* getApi() { return &mApi; }
67 
68     private:
69         android::base::SharedLibrary* mGlxLib;
70 
71         GlxApi mApi;
72 };
73 
getX11Api()74 AEMU_EXPORT struct X11Api* getX11Api() {
75     static X11FunctionGetter* g = new X11FunctionGetter;
76     return g->getApi();
77 }
78 
getGlxApi()79 AEMU_EXPORT struct GlxApi* getGlxApi() {
80     static GlxFunctionGetter* g = new GlxFunctionGetter;
81     return g->getApi();
82 }
83