1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 07:12:39 +00:00

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.
This commit is contained in:
Anton Kindestam 2019-12-07 19:17:21 +01:00
parent d5cabf7348
commit b2b15d4e6e

View File

@ -23,6 +23,7 @@
#include <poll.h>
#include <unistd.h>
#include <drm_fourcc.h>
#include <libswscale/swscale.h>
#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;
}