Add Android.bp support
Bug: 171711491
Adds stub X11 support so we don't depend on X11.
Change-Id: I76c7502d73994600a806fa08ce57633b585e4359
Change-Id: Ic7af4201e6b5b97bd9dcd403689a0c277db95290
diff --git a/stream-servers/apigen-codec-common/X11Support.cpp b/stream-servers/apigen-codec-common/X11Support.cpp
new file mode 100644
index 0000000..e4a5787
--- /dev/null
+++ b/stream-servers/apigen-codec-common/X11Support.cpp
@@ -0,0 +1,81 @@
+#include "X11Support.h"
+
+#include "base/SharedLibrary.h"
+
+#define DEFINE_DUMMY_IMPL(rettype, funcname, args) \
+ static rettype dummy_##funcname args { \
+ return (rettype)0; \
+ } \
+
+LIST_XLIB_FUNCTYPES(DEFINE_DUMMY_IMPL)
+LIST_GLX_FUNCTYPES(DEFINE_DUMMY_IMPL)
+
+class X11FunctionGetter {
+ public:
+ X11FunctionGetter() :
+ mX11Lib(android::base::SharedLibrary::open("libX11")),
+ mXextLib(android::base::SharedLibrary::open("libXext")) {
+
+#define X11_ASSIGN_DUMMY_IMPL(funcname) mApi.funcname = dummy_##funcname;
+
+ LIST_XLIB_FUNCS(X11_ASSIGN_DUMMY_IMPL)
+
+ if (!mX11Lib) return;
+ if (!mXextLib) return;
+
+#define X11_GET_FUNC(funcname) \
+ { \
+ auto f = mX11Lib->findSymbol(#funcname); \
+ if (f) mApi.funcname = (funcname##_t)f; \
+ } \
+
+ LIST_XLIB_FUNCS(X11_GET_FUNC);
+
+ }
+
+ X11Api* getApi() { return &mApi; }
+ private:
+ android::base::SharedLibrary* mX11Lib;
+ android::base::SharedLibrary* mXextLib;
+
+ X11Api mApi;
+};
+
+class GlxFunctionGetter {
+ public:
+ GlxFunctionGetter() :
+ mGlxLib(android::base::SharedLibrary::open("libGL")) {
+
+#define GLX_ASSIGN_DUMMY_IMPL(funcname) mApi.funcname = dummy_##funcname;
+
+ LIST_GLX_FUNCS(GLX_ASSIGN_DUMMY_IMPL)
+
+ if (!mGlxLib) return;
+
+#define GLX_GET_FUNC(funcname) \
+ { \
+ auto f = mGlxLib->findSymbol(#funcname); \
+ if (f) mApi.funcname = (funcname##_t)f; \
+ } \
+
+ LIST_GLX_FUNCS(GLX_GET_FUNC);
+
+ }
+
+ GlxApi* getApi() { return &mApi; }
+
+ private:
+ android::base::SharedLibrary* mGlxLib;
+
+ GlxApi mApi;
+};
+
+struct X11Api* getX11Api() {
+ static X11FunctionGetter* g = new X11FunctionGetter;
+ return g->getApi();
+}
+
+struct GlxApi* getGlxApi() {
+ static GlxFunctionGetter* g = new GlxFunctionGetter;
+ return g->getApi();
+}