[PATCH xserver] glamor: Restore glamor_fd_from_pixmap and glamor_pixmap_from_fd
Michel Dänzer
michel at daenzer.net
Tue Mar 6 09:53:19 UTC 2018
From: Michel Dänzer <michel.daenzer at amd.com>
They're part of the 1.20 RC1 ABI, and actually used by external drivers.
Also, requiring drivers which don't support the new functionality in
DRI3 1.2 to switch to the new interfaces seems unreasonable.
Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
glamor/glamor.c | 35 +++++++++++++++++++++++------------
glamor/glamor.h | 35 +++++++++++++++++++++++++++++++++++
glamor/glamor_egl.c | 22 ++++++++++++++++++++++
3 files changed, 80 insertions(+), 12 deletions(-)
diff --git a/glamor/glamor.c b/glamor/glamor.c
index c7077dd84..acc7de940 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -845,26 +845,18 @@ glamor_fds_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, int *fds,
}
_X_EXPORT int
-glamor_shareable_fd_from_pixmap(ScreenPtr screen,
- PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
+glamor_fd_from_pixmap(ScreenPtr screen,
+ PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
{
- unsigned orig_usage_hint = pixmap->usage_hint;
int ret;
int fds[4];
uint32_t strides[4], offsets[4];
uint64_t modifier;
- /*
- * The actual difference between a sharable and non sharable buffer
- * is decided 4 call levels deep in glamor_make_pixmap_exportable()
- * based on pixmap->usage_hint == CREATE_PIXMAP_USAGE_SHARED
- * 2 of those calls are also exported API, so we cannot just add a flag.
- */
- pixmap->usage_hint = CREATE_PIXMAP_USAGE_SHARED;
ret = glamor_fds_from_pixmap(screen, pixmap, fds, strides, offsets,
&modifier);
- /* Pixmaps with multi-planes/modifier are not shareable */
+ /* Pixmaps with multi-planes/modifier are not supported in this interface */
if (ret > 1) {
while (ret > 0)
close(fds[--ret]);
@@ -875,8 +867,27 @@ glamor_shareable_fd_from_pixmap(ScreenPtr screen,
*stride = strides[0];
*size = pixmap->drawable.height * *stride;
- pixmap->usage_hint = orig_usage_hint;
+ return ret;
+}
+
+_X_EXPORT int
+glamor_shareable_fd_from_pixmap(ScreenPtr screen,
+ PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
+{
+ unsigned orig_usage_hint = pixmap->usage_hint;
+ int ret;
+ /*
+ * The actual difference between a sharable and non sharable buffer
+ * is decided 4 call levels deep in glamor_make_pixmap_exportable()
+ * based on pixmap->usage_hint == CREATE_PIXMAP_USAGE_SHARED
+ * 2 of those calls are also exported API, so we cannot just add a flag.
+ */
+ pixmap->usage_hint = CREATE_PIXMAP_USAGE_SHARED;
+
+ ret = glamor_fd_from_pixmap(screen, pixmap, stride, size);
+
+ pixmap->usage_hint = orig_usage_hint;
return ret;
}
diff --git a/glamor/glamor.h b/glamor/glamor.h
index 5475aedbb..7b5676226 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -183,6 +183,21 @@ extern _X_EXPORT int glamor_fds_from_pixmap(ScreenPtr screen,
uint32_t *strides, uint32_t *offsets,
uint64_t *modifier);
+/* @glamor_fd_from_pixmap: Get a dma-buf fd from a pixmap.
+ *
+ * @screen: Current screen pointer.
+ * @pixmap: The pixmap from which we want the fd.
+ * @stride, @size: Pointers to fill the stride and size of the
+ * buffer associated to the fd.
+ *
+ * the pixmap and the buffer associated by the fd will share the same
+ * content.
+ * Returns the fd on success, -1 on error.
+ * */
+extern _X_EXPORT int glamor_fd_from_pixmap(ScreenPtr screen,
+ PixmapPtr pixmap,
+ CARD16 *stride, CARD32 *size);
+
/* @glamor_shareable_fd_from_pixmap: Get a dma-buf fd suitable for sharing
* with other GPUs from a pixmap.
*
@@ -258,6 +273,26 @@ extern _X_EXPORT PixmapPtr glamor_pixmap_from_fds(ScreenPtr screen,
CARD8 bpp,
uint64_t modifier);
+/* @glamor_pixmap_from_fd: Creates a pixmap to wrap a dma-buf fd.
+ *
+ * @screen: Current screen pointer.
+ * @fd: The dma-buf fd to import.
+ * @width: The width of the buffer.
+ * @height: The height of the buffer.
+ * @stride: The stride of the buffer.
+ * @depth: The depth of the buffer.
+ * @bpp: The bpp of the buffer.
+ *
+ * Returns a valid pixmap if the import succeeded, else NULL.
+ * */
+extern _X_EXPORT PixmapPtr glamor_pixmap_from_fd(ScreenPtr screen,
+ int fd,
+ CARD16 width,
+ CARD16 height,
+ CARD16 stride,
+ CARD8 depth,
+ CARD8 bpp);
+
/* @glamor_back_pixmap_from_fd: Backs an existing pixmap with a dma-buf fd.
*
* @pixmap: Pixmap to change backing for
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index ca368c15c..8389d5f29 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -525,6 +525,28 @@ glamor_pixmap_from_fds(ScreenPtr screen,
return pixmap;
}
+_X_EXPORT PixmapPtr
+glamor_pixmap_from_fd(ScreenPtr screen,
+ int fd,
+ CARD16 width,
+ CARD16 height,
+ CARD16 stride, CARD8 depth, CARD8 bpp)
+{
+ PixmapPtr pixmap;
+ Bool ret;
+
+ pixmap = screen->CreatePixmap(screen, 0, 0, depth, 0);
+
+ ret = glamor_back_pixmap_from_fd(pixmap, fd, width, height,
+ stride, depth, bpp);
+
+ if (ret == FALSE) {
+ screen->DestroyPixmap(pixmap);
+ return NULL;
+ }
+ return pixmap;
+}
+
_X_EXPORT Bool
glamor_get_formats(ScreenPtr screen,
CARD32 *num_formats, CARD32 **formats)
--
2.16.2
More information about the xorg-devel
mailing list