llvmpipe: use global llvm context for PIPE_SUBSYSTEM_EMBEDDED
[mesa.git] / src / gallium / state_trackers / gbm / gbm_drm.c
index 8490480652ff83ea44758517ba69870eba6d79f2..da6d7241ae717a3267ba577f48ab185964b3d713 100644 (file)
@@ -28,6 +28,7 @@
 #include "util/u_memory.h"
 #include "util/u_inlines.h"
 
+#include "pipe-loader/pipe_loader.h"
 #include "state_tracker/drm_driver.h"
 
 #include <unistd.h>
@@ -45,9 +46,9 @@ gbm_format_to_gallium(enum gbm_bo_format format)
 {
    switch (format) {
    case GBM_BO_FORMAT_XRGB8888:
-      return PIPE_FORMAT_B8G8R8X8_UNORM;
+      return PIPE_FORMAT_BGRX8888_UNORM;
    case GBM_BO_FORMAT_ARGB8888:
-      return PIPE_FORMAT_B8G8R8A8_UNORM;
+      return PIPE_FORMAT_BGRA8888_UNORM;
    default:
       return PIPE_FORMAT_NONE;
    }
@@ -66,7 +67,7 @@ gbm_usage_to_gallium(uint usage)
    if (usage & GBM_BO_USE_RENDERING)
       resource_usage |= PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
 
-   if (usage & GBM_BO_USE_CURSOR_64X64)
+   if (usage & GBM_BO_USE_CURSOR)
       resource_usage |= PIPE_BIND_CURSOR;
 
    return resource_usage;
@@ -84,7 +85,7 @@ gbm_gallium_drm_is_format_supported(struct gbm_device *gbm,
    if (pf == PIPE_FORMAT_NONE)
       return 0;
 
-   if (!gdrm->screen->is_format_supported(gdrm->screen, PIPE_TEXTURE_2D, pf, 0,
+   if (!gdrm->screen->is_format_supported(gdrm->screen, pf, PIPE_TEXTURE_2D, 0,
                                           gbm_usage_to_gallium(usage)))
       return 0;
 
@@ -145,10 +146,10 @@ gbm_gallium_drm_bo_import(struct gbm_device *gbm,
    bo->base.base.height = resource->height0;
 
    switch (resource->format) {
-   case PIPE_FORMAT_B8G8R8X8_UNORM:
+   case PIPE_FORMAT_BGRX8888_UNORM:
       bo->base.base.format = GBM_BO_FORMAT_XRGB8888;
       break;
-   case PIPE_FORMAT_B8G8R8A8_UNORM:
+   case PIPE_FORMAT_BGRA8888_UNORM:
       bo->base.base.format = GBM_BO_FORMAT_ARGB8888;
       break;
    default:
@@ -223,17 +224,40 @@ gbm_gallium_drm_destroy(struct gbm_device *gbm)
 {
    struct gbm_gallium_drm_device *gdrm = gbm_gallium_drm_device(gbm);
 
-   gallium_screen_destroy(gdrm);
-   FREE(gdrm);
+   free(gdrm->base.driver_name);
+   gdrm->screen->destroy(gdrm->screen);
+#if !GALLIUM_STATIC_TARGETS
+   pipe_loader_release(&gdrm->dev, 1);
+#endif
+   free(gdrm);
 }
 
-struct gbm_device *
+#if !GALLIUM_STATIC_TARGETS
+#ifdef HAVE_PIPE_LOADER_DRM
+static const char *
+get_library_search_path(void)
+{
+   const char *search_path = NULL;
+
+   /* don't allow setuid apps to use GBM_BACKENDS_PATH */
+   if (geteuid() == getuid())
+      search_path = getenv("GBM_BACKENDS_PATH");
+   if (search_path == NULL)
+      search_path = PIPE_SEARCH_DIR;
+
+   return search_path;
+}
+#endif
+#endif
+
+static struct gbm_device *
 gbm_gallium_drm_device_create(int fd)
 {
    struct gbm_gallium_drm_device *gdrm;
-   int ret;
 
    gdrm = calloc(1, sizeof *gdrm);
+   if (!gdrm)
+      return NULL;
 
    gdrm->base.base.fd = fd;
    gdrm->base.base.bo_create = gbm_gallium_drm_bo_create;
@@ -245,11 +269,40 @@ gbm_gallium_drm_device_create(int fd)
    gdrm->base.type = GBM_DRM_DRIVER_TYPE_GALLIUM;
    gdrm->base.base.name = "drm";
 
-   ret = gallium_screen_create(gdrm);
-   if (ret) {
-      free(gdrm);
-      return NULL;
-   }
+#if GALLIUM_STATIC_TARGETS
+   gdrm->screen = dd_create_screen(gdrm->base.base.fd);
+#else
+#ifdef HAVE_PIPE_LOADER_DRM
+   if (pipe_loader_drm_probe_fd(&gdrm->dev, gdrm->base.base.fd, false))
+      gdrm->screen = pipe_loader_create_screen(gdrm->dev,
+                                               get_library_search_path());
+#endif /* HAVE_PIPE_LOADER_DRM */
+#endif
 
+   if (gdrm->screen == NULL)
+      goto out_no_screen;
+
+#if GALLIUM_STATIC_TARGETS
+   gdrm->base.driver_name = strdup(dd_driver_name());
+#else
+#ifdef HAVE_PIPE_LOADER_DRM
+   gdrm->base.driver_name = strdup(gdrm->dev->driver_name);
+#endif /* HAVE_PIPE_LOADER_DRM */
+#endif
    return &gdrm->base.base;
+
+out_no_screen:
+   debug_printf("failed to load gallium_gbm\n");
+#if !GALLIUM_STATIC_TARGETS
+   if (gdrm->dev)
+      pipe_loader_release(&gdrm->dev, 1);
+#endif
+   free(gdrm);
+   return NULL;
 }
+
+
+GBM_EXPORT struct gbm_backend gbm_backend = {
+   .backend_name = "gallium_drm",
+   .create_device = gbm_gallium_drm_device_create,
+};