[virglrenderer-devel] [PATCH 4/4] vrend: add simple program to print host info (v2)

Gert Wollny gert.wollny at collabora.com
Wed Jun 13 10:42:06 UTC 2018


Add a program vrend-host-info that prints the host GL and virglrenderer
version to stdout. This program can be used to inject information about
the host into guest running in Qemu as a smbios OEM string (assuming bash
as shell):

  qemu -smbios type=11,value="$(virgl-host-info)" ...

which can then be read inside the guest running

  sudo dmiinfo -t 11

v2: fix copyright string (Elie Tournier)

Signed-off-by: Gert Wollny <gert.wollny at collabora.com>
---
 src/Makefile.am       |  5 +++
 src/virgl_host_info.c | 94 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+)
 create mode 100644 src/virgl_host_info.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 43a5fbc..5b15908 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -38,6 +38,9 @@ libvrend_la_SOURCES = \
         vrend_blitter.h \
         iov.c
 
+bin_PROGRAMS = virgl-host-info
+virgl_host_info_SOURCES = virgl_host_info.c
+
 if HAVE_EPOXY_EGL
 libvrend_la_SOURCES += \
         virgl_egl.h \
@@ -53,6 +56,8 @@ endif
 lib_LTLIBRARIES = libvirglrenderer.la
 noinst_LTLIBRARIES = libvrend.la
 
+virgl_host_info_LDADD = libvirglrenderer.la libvrend.la
+
 GM_LDFLAGS = -Wl,-Bsymbolic -version-number 0:2 -no-undefined
 
 libvirglrenderer_la_SOURCES = virglrenderer.c
diff --git a/src/virgl_host_info.c b/src/virgl_host_info.c
new file mode 100644
index 0000000..636703b
--- /dev/null
+++ b/src/virgl_host_info.c
@@ -0,0 +1,94 @@
+/**************************************************************************
+ *
+ * Copyright (C) 2018 Collabora Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "config.h"
+#include "virglrenderer.h"
+#ifdef HAVE_EPOXY_GLX_H
+#include "virgl_glx.h"
+#endif
+#ifdef HAVE_EPOXY_EGL_H
+#include "virgl_glx.h"
+#endif
+
+#include "virgl_egl.h"
+#include "os/os_misc.h"
+#include <stdio.h>
+
+static void print_glx_context_info(void)
+{
+#ifdef HAVE_EPOXY_GLX_H
+   struct virgl_gl_ctx_param glx_params = {3,3,false};
+   virgl_renderer_gl_context virgl_ctx;
+   struct virgl_glx *context;
+
+   context = virgl_glx_init();
+   virgl_ctx = virgl_glx_create_context(context, &glx_params);
+   virgl_glx_make_context_current(context, virgl_ctx);
+
+   printf("%s", virgl_renderer_get_host_info());
+   virgl_glx_destroy_context(context, virgl_ctx);
+   virgl_glx_destroy(context);
+#else
+   fprintf(stderr, "GLX support not compiled in\n");
+#endif
+}
+
+static void print_egl_context_info(void)
+{
+#ifdef HAVE_EPOXY_EGL_H
+   struct virgl_gl_ctx_param glx_params = {2,0,false};
+   virgl_renderer_gl_context virgl_ctx;
+   struct virgl_egl *context;
+
+   context = virgl_egl_init();
+   virgl_ctx = virgl_egl_create_context(context, &glx_params);
+   virgl_egl_make_context_current(context, virgl_ctx);
+
+   printf("%s", virgl_renderer_get_host_info());
+
+   virgl_egl_destroy_context(context, virgl_ctx);
+   virgl_egl_destroy(context);
+#else
+   fprintf(stderr, "EGL support not compiled in\n");
+#endif
+
+}
+
+int main(int argc, const char *args[])
+{
+   if (argc == 2)
+      if (!strcmp(args[1], "egl"))
+         print_egl_context_info();
+      else if (!strcmp(args[1], "glx"))
+         print_glx_context_info();
+      else {
+         fprintf(stderr, "Error: Unknown parameter '%s' given\n",
+                 args[1]);
+         return 1;
+      }
+   else
+      fprintf(stderr, "Print information about host GL/Vrend\n\n"
+                      "Usage:\n  virgl-host-info <context = (glx|egl)>\n\n");
+   return 0;
+}
-- 
2.17.1



More information about the virglrenderer-devel mailing list