1 #include "X11Support.h" 2 3 #include "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 mXextLib(android::base::SharedLibrary::open("libXext")) { 18 19 #define X11_ASSIGN_DUMMY_IMPL(funcname) mApi.funcname = dummy_##funcname; 20 21 LIST_XLIB_FUNCS(X11_ASSIGN_DUMMY_IMPL) 22 23 if (!mX11Lib) return; 24 if (!mXextLib) return; 25 26 #define X11_GET_FUNC(funcname) \ 27 { \ 28 auto f = mX11Lib->findSymbol(#funcname); \ 29 if (f) mApi.funcname = (funcname##_t)f; \ 30 } \ 31 32 LIST_XLIB_FUNCS(X11_GET_FUNC); 33 34 } 35 getApi()36 X11Api* getApi() { return &mApi; } 37 private: 38 android::base::SharedLibrary* mX11Lib; 39 android::base::SharedLibrary* mXextLib; 40 41 X11Api mApi; 42 }; 43 44 class GlxFunctionGetter { 45 public: GlxFunctionGetter()46 GlxFunctionGetter() : 47 mGlxLib(android::base::SharedLibrary::open("libGL")) { 48 49 #define GLX_ASSIGN_DUMMY_IMPL(funcname) mApi.funcname = dummy_##funcname; 50 51 LIST_GLX_FUNCS(GLX_ASSIGN_DUMMY_IMPL) 52 53 if (!mGlxLib) return; 54 55 #define GLX_GET_FUNC(funcname) \ 56 { \ 57 auto f = mGlxLib->findSymbol(#funcname); \ 58 if (f) mApi.funcname = (funcname##_t)f; \ 59 } \ 60 61 LIST_GLX_FUNCS(GLX_GET_FUNC); 62 63 } 64 getApi()65 GlxApi* getApi() { return &mApi; } 66 67 private: 68 android::base::SharedLibrary* mGlxLib; 69 70 GlxApi mApi; 71 }; 72 getX11Api()73AEMU_EXPORT struct X11Api* getX11Api() { 74 static X11FunctionGetter* g = new X11FunctionGetter; 75 return g->getApi(); 76 } 77 getGlxApi()78AEMU_EXPORT struct GlxApi* getGlxApi() { 79 static GlxFunctionGetter* g = new GlxFunctionGetter; 80 return g->getApi(); 81 } 82