From b2b15d4e6e1d92290d0d7e772b9a5468ddea8a81 Mon Sep 17 00:00:00 2001 From: Anton Kindestam Date: Sat, 7 Dec 2019 19:17:21 +0100 Subject: [PATCH] vo_drm: replace drmModeAddFB usage with drmModeAddFB2 drmModeAddFB is legacy, and might not pick the pixel format you expect, depending on your driver. Use drmModeAddFB2 which specifies this explicitly using a fourcc. --- video/out/vo_drm.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/video/out/vo_drm.c b/video/out/vo_drm.c index 7eee6c66c1..96286bd30a 100644 --- a/video/out/vo_drm.c +++ b/video/out/vo_drm.c @@ -23,6 +23,7 @@ #include #include +#include #include #include "drm_common.h" @@ -85,7 +86,7 @@ struct priv { unsigned int fb_queue_len; struct framebuffer *cur_fb; - uint32_t depth; + uint32_t drm_format; enum mp_imgfmt imgfmt; int32_t screen_w; @@ -139,8 +140,13 @@ static bool fb_setup_single(struct vo *vo, int fd, struct framebuffer *buf) buf->handle = creq.handle; // create framebuffer object for the dumb-buffer - if (drmModeAddFB(fd, buf->width, buf->height, p->depth, creq.bpp, buf->stride, - buf->handle, &buf->fb)) { + int ret = drmModeAddFB2(fd, buf->width, buf->height, + p->drm_format, + (uint32_t[4]){buf->handle, 0, 0, 0}, + (uint32_t[4]){buf->stride, 0, 0, 0}, + (uint32_t[4]){0, 0, 0, 0}, + &buf->fb, 0); + if (ret) { MP_ERR(vo, "Cannot create framebuffer: %s\n", mp_strerror(errno)); goto err; } @@ -390,7 +396,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi, struct framebuffer *front osd_draw_on_image(vo->osd, p->osd, 0, 0, p->cur_frame); } - if (p->depth == 30) { + if (p->drm_format == DRM_FORMAT_XRGB2101010) { // Pack GBRP10 image into XRGB2101010 for DRM const int w = p->cur_frame->w; const int h = p->cur_frame->h; @@ -413,7 +419,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi, struct framebuffer *front r_ptr += r_padding; fbuf_ptr += fbuf_padding; } - } else { + } else { // p->drm_format == DRM_FORMAT_XRGB8888 memcpy_pic(front_buf->map, p->cur_frame->planes[0], p->cur_frame->w * BYTES_PER_PIXEL, p->cur_frame->h, front_buf->stride, @@ -577,10 +583,10 @@ static int preinit(struct vo *vo) } if (vo->opts->drm_opts->drm_format == DRM_OPTS_FORMAT_XRGB2101010) { - p->depth = 30; + p->drm_format = DRM_FORMAT_XRGB2101010; p->imgfmt = IMGFMT_XRGB2101010; } else { - p->depth = 24; + p->drm_format = DRM_FORMAT_XRGB8888;; p->imgfmt = IMGFMT_XRGB8888; }