[vlc-commits] xcb/shm: revector
Rémi Denis-Courmont
git at videolan.org
Sat May 26 10:04:47 CEST 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri May 25 22:39:22 2018 +0300| [fa8328923927433cad40c490c6ec1de285a5e8fa] | committer: Rémi Denis-Courmont
xcb/shm: revector
(also fix alignment when not using SHM)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fa8328923927433cad40c490c6ec1de285a5e8fa
---
modules/video_output/xcb/pictures.c | 49 +++++++++++++++++++++++++------------
1 file changed, 34 insertions(+), 15 deletions(-)
diff --git a/modules/video_output/xcb/pictures.c b/modules/video_output/xcb/pictures.c
index 547e41e15e..92ff76db93 100644
--- a/modules/video_output/xcb/pictures.c
+++ b/modules/video_output/xcb/pictures.c
@@ -68,25 +68,20 @@ bool XCB_shm_Check (vlc_object_t *obj, xcb_connection_t *conn)
return false;
}
+#ifdef HAVE_SYS_SHM_H
/**
* Release picture private data: detach the shared memory segment.
*/
-static void XCB_picture_Destroy (picture_t *pic)
+static void XCB_picture_SysV_Destroy (picture_t *pic)
{
shmdt (pic->p[0].p_pixels);
free (pic);
}
-/**
- * Initialize a picture buffer as shared memory, according to the video output
- * format. If a attach is true, the segment is attached to
- * the X server (MIT-SHM extension).
- */
-int XCB_picture_Alloc (vout_display_t *vd, picture_resource_t *res,
- size_t size, xcb_connection_t *conn,
- xcb_shm_seg_t segment)
+static int XCB_picture_SysV_Alloc(vout_display_t *vd, picture_resource_t *res,
+ size_t size, xcb_connection_t *conn,
+ xcb_shm_seg_t segment)
{
-#ifdef HAVE_SYS_SHM_H
/* Allocate shared memory segment */
int id = shmget (IPC_PRIVATE, size, IPC_CREAT | S_IRWXU);
if (id == -1)
@@ -135,15 +130,39 @@ int XCB_picture_Alloc (vout_display_t *vd, picture_resource_t *res,
}
shmctl (id, IPC_RMID, NULL);
+
+ res->p_sys = (void *)(uintptr_t)segment;
+ res->pf_destroy = XCB_picture_SysV_Destroy;
+ res->p[0].p_pixels = shm;
+ return 0;
+}
#else
- assert (segment == 0);
+# define XCB_picture_SysV_Alloc(...) (-1)
+#endif
- /* XXX: align on 32 bytes for VLC chroma filters */
- void *shm = malloc (size);
+static void XCB_picture_Destroy(picture_t *pic)
+{
+ free(pic->p[0].p_pixels);
+ free(pic);
+}
+
+/**
+ * Initialize a picture buffer as shared memory, according to the video output
+ * format. If a attach is true, the segment is attached to
+ * the X server (MIT-SHM extension).
+ */
+int XCB_picture_Alloc (vout_display_t *vd, picture_resource_t *res,
+ size_t size, xcb_connection_t *conn,
+ xcb_shm_seg_t segment)
+{
+ if (XCB_picture_SysV_Alloc(vd, res, size, conn, segment) == 0)
+ return 0;
+
+ void *shm = aligned_alloc(32, (size + 31) & ~31);
if (unlikely(shm == NULL))
return -1;
-#endif
- res->p_sys = (void *)(uintptr_t)segment;
+
+ res->p_sys = NULL;
res->pf_destroy = XCB_picture_Destroy;
res->p[0].p_pixels = shm;
return 0;
More information about the vlc-commits
mailing list