[Mesa-dev] [PATCH 4/4] st/omx: add headless support

Leo Liu leo.liu at amd.com
Thu Nov 5 10:47:12 PST 2015


This will allow dec/enc/transcode without X

Signed-off-by: Leo Liu <leo.liu at amd.com>
---
 src/gallium/state_trackers/omx/entrypoint.c | 39 +++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/src/gallium/state_trackers/omx/entrypoint.c b/src/gallium/state_trackers/omx/entrypoint.c
index a765666..a6a1279 100644
--- a/src/gallium/state_trackers/omx/entrypoint.c
+++ b/src/gallium/state_trackers/omx/entrypoint.c
@@ -33,6 +33,7 @@
 
 #include <assert.h>
 #include <string.h>
+#include <fcntl.h>
 
 #include <X11/Xlib.h>
 
@@ -47,6 +48,7 @@ pipe_static_mutex(omx_lock);
 static Display *omx_display = NULL;
 static struct vl_screen *omx_screen = NULL;
 static unsigned omx_usecount = 0;
+static const char *omx_render_node = NULL;
 
 int omx_component_library_Setup(stLoaderComponentType **stComponents)
 {
@@ -73,33 +75,50 @@ struct vl_screen *omx_get_screen(void)
    pipe_mutex_lock(omx_lock);
 
    if (!omx_display) {
+      omx_render_node = debug_get_option("OMX_DRM_RENDER_NODES", NULL);
       omx_display = XOpenDisplay(NULL);
       if (!omx_display) {
-         pipe_mutex_unlock(omx_lock);
-         return NULL;
-      }
+         if (!omx_render_node)
+            goto error;
+      } else
+         omx_render_node = NULL;
    }
 
    if (!omx_screen) {
-      omx_screen = vl_screen_create(omx_display, 0);
-      if (!omx_screen) {
-         pipe_mutex_unlock(omx_lock);
-         return NULL;
-      }
+      if (omx_render_node) {
+         int fd = open(omx_render_node, O_RDWR);
+         if (fd < 0)
+            goto error;
+         omx_screen = vl_drm_screen_create(fd);
+      } else
+         omx_screen = vl_screen_create(omx_display, 0);
+
+      if (!omx_screen)
+         goto error;
    }
 
    ++omx_usecount;
 
    pipe_mutex_unlock(omx_lock);
    return omx_screen;
+
+error:
+   if (omx_display)
+      XCloseDisplay(omx_display);
+   pipe_mutex_unlock(omx_lock);
+   return NULL;
 }
 
 void omx_put_screen(void)
 {
    pipe_mutex_lock(omx_lock);
    if ((--omx_usecount) == 0) {
-      vl_screen_destroy(omx_screen);
-      XCloseDisplay(omx_display);
+      if (!omx_render_node) {
+         vl_screen_destroy(omx_screen);
+         if (omx_display)
+            XCloseDisplay(omx_display);
+      } else
+         vl_drm_screen_destroy(omx_screen);
       omx_screen = NULL;
       omx_display = NULL;
    }
-- 
1.9.1



More information about the mesa-dev mailing list