From: Rob Clark <robcl...@freedesktop.org>

Like xa_surface_from_handle(), but takes a handle type, rather than
hard-coding 'shared' handle.  This is needed to fix bugs seen with
xf86-video-freedreno with xrandr rotation, for example.  The root issue
is that doing a GEM_OPEN ioctl on a bo that already has a GEM handle
associated with the drm_file will result in two unique handles for the
same bo.  Which causes all sorts of follow-on fail.

Cc: "10.5 10.6" <mesa-sta...@lists.freedesktop.org>
Signed-off-by: Rob Clark <robcl...@freedesktop.org>
---
Note: it would be good to get this in stable too, since I have a patch
for xf86-video-freedreno which will depend on this.

 src/gallium/state_trackers/xa/xa_tracker.c | 40 +++++++++++++++++++++++-------
 src/gallium/state_trackers/xa/xa_tracker.h |  8 ++++++
 src/gallium/targets/xa/xa.sym              |  1 +
 3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/src/gallium/state_trackers/xa/xa_tracker.c 
b/src/gallium/state_trackers/xa/xa_tracker.c
index 59e8108..d1d3951 100644
--- a/src/gallium/state_trackers/xa/xa_tracker.c
+++ b/src/gallium/state_trackers/xa/xa_tracker.c
@@ -298,6 +298,18 @@ xa_format_check_supported(struct xa_tracker *xa,
     return XA_ERR_NONE;
 }
 
+static unsigned
+handle_type(enum xa_handle_type type)
+{
+    switch (type) {
+    case xa_handle_type_kms:
+       return DRM_API_HANDLE_TYPE_KMS;
+    case xa_handle_type_shared:
+    default:
+       return DRM_API_HANDLE_TYPE_SHARED;
+    }
+}
+
 static struct xa_surface *
 surface_create(struct xa_tracker *xa,
                  int width,
@@ -388,6 +400,24 @@ xa_surface_from_handle(struct xa_tracker *xa,
     return surface_create(xa, width, height, depth, stype, xa_format, flags, 
&whandle);
 }
 
+XA_EXPORT struct xa_surface *
+xa_surface_from_handle2(struct xa_tracker *xa,
+                 int width,
+                 int height,
+                 int depth,
+                 enum xa_surface_type stype,
+                 enum xa_formats xa_format, unsigned int flags,
+                 enum xa_handle_type type,
+                 uint32_t handle, uint32_t stride)
+{
+    struct winsys_handle whandle;
+    memset(&whandle, 0, sizeof(whandle));
+    whandle.type = handle_type(type);
+    whandle.handle = handle;
+    whandle.stride = stride;
+    return surface_create(xa, width, height, depth, stype, xa_format, flags, 
&whandle);
+}
+
 XA_EXPORT int
 xa_surface_redefine(struct xa_surface *srf,
                    int width,
@@ -511,15 +541,7 @@ xa_surface_handle(struct xa_surface *srf,
     boolean res;
 
     memset(&whandle, 0, sizeof(whandle));
-    switch (type) {
-    case xa_handle_type_kms:
-       whandle.type = DRM_API_HANDLE_TYPE_KMS;
-       break;
-    case xa_handle_type_shared:
-    default:
-       whandle.type = DRM_API_HANDLE_TYPE_SHARED;
-       break;
-    }
+    whandle.type = handle_type(type);
     res = screen->resource_get_handle(screen, srf->tex, &whandle);
     if (!res)
        return -XA_ERR_INVAL;
diff --git a/src/gallium/state_trackers/xa/xa_tracker.h 
b/src/gallium/state_trackers/xa/xa_tracker.h
index 5c6435e..8afebb6 100644
--- a/src/gallium/state_trackers/xa/xa_tracker.h
+++ b/src/gallium/state_trackers/xa/xa_tracker.h
@@ -177,6 +177,14 @@ extern struct xa_surface * xa_surface_from_handle(struct 
xa_tracker *xa,
                                            enum xa_formats pform,
                                            unsigned int flags,
                                            uint32_t handle, uint32_t stride);
+extern struct xa_surface * xa_surface_from_handle2(struct xa_tracker *xa,
+                                           int width,
+                                           int height,
+                                           int depth,
+                                           enum xa_surface_type stype,
+                                           enum xa_formats xa_format, unsigned 
int flags,
+                                           enum xa_handle_type type,
+                                           uint32_t handle, uint32_t stride);
 
 enum xa_formats xa_surface_format(const struct xa_surface *srf);
 
diff --git a/src/gallium/targets/xa/xa.sym b/src/gallium/targets/xa/xa.sym
index 9c7f422..50ccc99 100644
--- a/src/gallium/targets/xa/xa.sym
+++ b/src/gallium/targets/xa/xa.sym
@@ -23,6 +23,7 @@
                xa_surface_dma;
                xa_surface_format;
                xa_surface_from_handle;
+               xa_surface_from_handle2;
                xa_surface_handle;
                xa_surface_map;
                xa_surface_redefine;
-- 
2.4.3

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to