r600: document some of the missing shader constants.
[mesa.git] / src / gallium / state_trackers / omx / entrypoint.c
index a7656660e8c52a4a36d42ab6c87d9d2b36d05491..251cc7d65d52fba8cf38c8f7e7e494dc470016bb 100644 (file)
 
 #include <assert.h>
 #include <string.h>
+#include <stdbool.h>
 
+#if defined(HAVE_X11_PLATFORM)
 #include <X11/Xlib.h>
+#else
+#define XOpenDisplay(x) NULL
+#define XCloseDisplay(x)
+#define Display void
+#endif
 
 #include "os/os_thread.h"
 #include "util/u_memory.h"
+#include "loader/loader.h"
 
 #include "entrypoint.h"
 #include "vid_dec.h"
 #include "vid_enc.h"
 
-pipe_static_mutex(omx_lock);
+static mtx_t omx_lock = _MTX_INITIALIZER_NP;
 static Display *omx_display = NULL;
 static struct vl_screen *omx_screen = NULL;
 static unsigned omx_usecount = 0;
+static const char *omx_render_node = NULL;
+static int drm_fd;
 
 int omx_component_library_Setup(stLoaderComponentType **stComponents)
 {
@@ -70,40 +80,62 @@ int omx_component_library_Setup(stLoaderComponentType **stComponents)
 
 struct vl_screen *omx_get_screen(void)
 {
-   pipe_mutex_lock(omx_lock);
-
-   if (!omx_display) {
-      omx_display = XOpenDisplay(NULL);
-      if (!omx_display) {
-         pipe_mutex_unlock(omx_lock);
-         return NULL;
-      }
-   }
+   static bool first_time = true;
+   mtx_lock(&omx_lock);
 
    if (!omx_screen) {
-      omx_screen = vl_screen_create(omx_display, 0);
-      if (!omx_screen) {
-         pipe_mutex_unlock(omx_lock);
-         return NULL;
+      if (first_time) {
+         omx_render_node = debug_get_option("OMX_RENDER_NODE", NULL);
+         first_time = false;
+      }
+      if (omx_render_node) {
+         drm_fd = loader_open_device(omx_render_node);
+         if (drm_fd < 0)
+            goto error;
+
+         omx_screen = vl_drm_screen_create(drm_fd);
+         if (!omx_screen) {
+            close(drm_fd);
+            goto error;
+         }
+      } else {
+         omx_display = XOpenDisplay(NULL);
+         if (!omx_display)
+            goto error;
+
+         omx_screen = vl_dri3_screen_create(omx_display, 0);
+         if (!omx_screen)
+            omx_screen = vl_dri2_screen_create(omx_display, 0);
+         if (!omx_screen) {
+            XCloseDisplay(omx_display);
+            goto error;
+         }
       }
    }
 
    ++omx_usecount;
 
-   pipe_mutex_unlock(omx_lock);
+   mtx_unlock(&omx_lock);
    return omx_screen;
+
+error:
+   mtx_unlock(&omx_lock);
+   return NULL;
 }
 
 void omx_put_screen(void)
 {
-   pipe_mutex_lock(omx_lock);
+   mtx_lock(&omx_lock);
    if ((--omx_usecount) == 0) {
-      vl_screen_destroy(omx_screen);
-      XCloseDisplay(omx_display);
+      omx_screen->destroy(omx_screen);
       omx_screen = NULL;
-      omx_display = NULL;
+
+      if (omx_render_node)
+         close(drm_fd);
+      else
+         XCloseDisplay(omx_display);
    }
-   pipe_mutex_unlock(omx_lock);
+   mtx_unlock(&omx_lock);
 }
 
 OMX_ERRORTYPE omx_workaround_Destructor(OMX_COMPONENTTYPE *comp)
@@ -113,7 +145,7 @@ OMX_ERRORTYPE omx_workaround_Destructor(OMX_COMPONENTTYPE *comp)
    priv->state = OMX_StateInvalid;
    tsem_up(priv->messageSem);
 
-   /* wait for thread to exit */;
+   /* wait for thread to exit */
    pthread_join(priv->messageHandlerThread, NULL);
 
    return omx_base_component_Destructor(comp);