gallium/winsys/drm: Prepare for passing prime fds in winsys_handle
authorChristopher James Halse Rogers <raof@ubuntu.com>
Thu, 21 Nov 2013 04:11:39 +0000 (15:11 +1100)
committerMaarten Lankhorst <maarten.lankhorst@canonical.com>
Tue, 10 Dec 2013 08:46:05 +0000 (09:46 +0100)
Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
src/gallium/drivers/freedreno/freedreno_screen.c
src/gallium/drivers/nouveau/nouveau_screen.c
src/gallium/include/state_tracker/drm_driver.h
src/gallium/state_trackers/dri/drm/dri2.c
src/gallium/state_trackers/egl/common/native_helper.c
src/gallium/state_trackers/egl/x11/native_dri2.c
src/gallium/winsys/i915/drm/i915_drm_buffer.c
src/gallium/winsys/radeon/drm/radeon_drm_bo.c
src/gallium/winsys/svga/drm/vmw_screen_dri.c

index d07cc0b323e09f92c9bc5b4c9103de9f00337e5a..319e29f3adae82db9343a699d934470b946a3a7b 100644 (file)
@@ -361,6 +361,11 @@ fd_screen_bo_from_handle(struct pipe_screen *pscreen,
        struct fd_screen *screen = fd_screen(pscreen);
        struct fd_bo *bo;
 
+       if (whandle->type != DRM_API_HANDLE_TYPE_SHARED) {
+               DBG("Attempt to import unsupported handle type %d", whandle->type);
+               return NULL;
+       }
+
        bo = fd_bo_from_name(screen->dev, whandle->handle);
        if (!bo) {
                DBG("ref name 0x%08x failed", whandle->handle);
index 5b35ee47c126cb02dcc299044c16c775b5a30438..248d1641c5a03fa3b5346a09b97fbccf29a4d8af 100644 (file)
@@ -86,6 +86,12 @@ nouveau_screen_bo_from_handle(struct pipe_screen *pscreen,
        struct nouveau_bo *bo = 0;
        int ret;
 
+       if (whandle->type != DRM_API_HANDLE_TYPE_SHARED) {
+               debug_printf("%s: attempt to import unsupported handle type %d\n",
+                            __FUNCTION__, whandle->type);
+               return NULL;
+       }
+
        ret = nouveau_bo_name_ref(dev, whandle->handle, &bo);
        if (ret) {
                debug_printf("%s: ref name 0x%08x failed with %d\n",
index f9bd2220e98fac4d22d80d3d12fb06e3ab76a6cf..5b76d87a69f63870a9f16be0fbbfb9a0ba247403 100644 (file)
@@ -10,6 +10,8 @@ struct pipe_resource;
 
 #define DRM_API_HANDLE_TYPE_SHARED 0
 #define DRM_API_HANDLE_TYPE_KMS    1
+#define DRM_API_HANDLE_TYPE_FD     2
+
 
 /**
  * For use with pipe_screen::{texture_from_handle|texture_get_handle}.
@@ -17,9 +19,10 @@ struct pipe_resource;
 struct winsys_handle
 {
    /**
-    * Unused for texture_from_handle, always
-    * DRM_API_HANDLE_TYPE_SHARED.  Input to texture_get_handle,
-    * use TEXTURE_USAGE to select handle for kms or ipc.
+    * Input for texture_from_handle, valid values are
+    * DRM_API_HANDLE_TYPE_SHARED or DRM_API_HANDLE_TYPE_FD.
+    * Input to texture_get_handle,
+    * to select handle for kms, flink, or prime.
     */
    unsigned type;
    /**
index 27f214780fc3b7ab2d30f5c498a66f3d2f283f52..2a2f8ac74982d4178617a339baa32fc9fd109eb4 100644 (file)
@@ -265,6 +265,7 @@ dri2_drawable_process_buffers(struct dri_context *ctx,
 
       templ.format = format;
       templ.bind = bind;
+      whandle.type = DRM_API_HANDLE_TYPE_SHARED;
       whandle.handle = buf->name;
       whandle.stride = buf->pitch;
 
@@ -578,6 +579,7 @@ dri2_create_image_from_name(__DRIscreen *_screen,
 
    memset(&whandle, 0, sizeof(whandle));
    whandle.handle = name;
+   whandle.type = DRM_API_HANDLE_TYPE_SHARED;
    whandle.stride = pitch * util_format_get_blocksize(pf);
 
    img->texture = screen->base.screen->resource_from_handle(screen->base.screen,
index b578a8afe967452101c968233cda2481c828df97..d1e1acdab4c488d0fed813443f1b0cbdd3d3ed32 100644 (file)
@@ -427,6 +427,7 @@ drm_display_import_native_buffer(struct native_display *ndpy,
 
          memset(&wsh, 0, sizeof(wsh));
          wsh.handle = nbuf->u.drm.name;
+         wsh.type = DRM_API_HANDLE_TYPE_SHARED;
          wsh.stride = nbuf->u.drm.stride;
 
          res = screen->resource_from_handle(screen, &nbuf->u.drm.templ, &wsh);
index 3c58979e29549213bf5157c79c2db40ded274168..bbd962d6962cc7be25d901a3e3ec3bcc1d3bb807 100644 (file)
@@ -173,6 +173,7 @@ dri2_surface_process_drawable_buffers(struct native_surface *nsurf,
       }
 
       memset(&whandle, 0, sizeof(whandle));
+      whandle.type = DRM_API_HANDLE_TYPE_SHARED;
       whandle.stride = xbuf->pitch;
       whandle.handle = xbuf->name;
       dri2surf->textures[natt] = dri2dpy->base.screen->resource_from_handle(
index ac66af333dfd84000171d16bdd3fc5d6851ac131..38e06193c61f3b82079e76d07f2c62afcd995612 100644 (file)
@@ -95,9 +95,13 @@ i915_drm_buffer_from_handle(struct i915_winsys *iws,
                             unsigned *stride)
 {
    struct i915_drm_winsys *idws = i915_drm_winsys(iws);
-   struct i915_drm_buffer *buf = CALLOC_STRUCT(i915_drm_buffer);
+   struct i915_drm_buffer *buf;
    uint32_t tile = 0, swizzle = 0;
 
+   if (whandle->type != DRM_API_HANDLE_TYPE_SHARED)
+      return NULL;
+
+   buf = CALLOC_STRUCT(i915_drm_buffer);
    if (!buf)
       return NULL;
 
index 3019a525cf81ec3fc3741a27ca7a1df0e0dd8ec6..744df1b745eae81ee317c3fe128dbb8cc00fc6fe 100644 (file)
@@ -877,6 +877,9 @@ static struct pb_buffer *radeon_winsys_bo_from_handle(struct radeon_winsys *rws,
 
     memset(&open_arg, 0, sizeof(open_arg));
 
+    if (whandle->type != DRM_API_HANDLE_TYPE_SHARED)
+        return NULL;
+
     /* We must maintain a list of pairs <handle, bo>, so that we always return
      * the same BO for one particular handle. If we didn't do that and created
      * more than one BO for the same handle and then relocated them in a CS,
@@ -991,6 +994,9 @@ static boolean radeon_winsys_bo_get_handle(struct pb_buffer *buffer,
         whandle->handle = bo->flink;
     } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
         whandle->handle = bo->handle;
+    } else if (whandle->type == DRM_API_HANDLE_TYPE_FD) {
+        /* TODO: Implement */
+        return FALSE;
     }
 
     whandle->stride = stride;
index 511cca73aea37b23a759c774df2b807e0d5c9e9a..6323a8ae2c46a00b18aa11276718222df4f9e0b6 100644 (file)
@@ -163,6 +163,12 @@ vmw_drm_surface_from_handle(struct svga_winsys_screen *sws,
     int ret;
     int i;
 
+    if (whandle->type != DRM_API_HANDLE_TYPE_SHARED) {
+        vmw_error("Attempt to import unknown handle type %d\n",
+                  whandle->type);
+        return NULL;
+    }
+
     /**
      * The vmware device specific handle is the hardware SID.
      * FIXME: We probably want to move this to the ioctl implementations.