2015-04-15 16:14:14 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2015-04-15 16:14:14 +00:00
|
|
|
*
|
|
|
|
* mpv is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2016-01-19 17:36:34 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2015-11-07 22:22:38 +00:00
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2015-04-15 16:14:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdbool.h>
|
2015-04-19 07:09:37 +00:00
|
|
|
#include <sys/mman.h>
|
2017-01-09 15:21:28 +00:00
|
|
|
#include <poll.h>
|
2015-04-17 17:59:31 +00:00
|
|
|
#include <unistd.h>
|
2015-04-19 07:09:37 +00:00
|
|
|
|
2019-12-07 18:17:21 +00:00
|
|
|
#include <drm_fourcc.h>
|
2015-04-15 16:14:14 +00:00
|
|
|
|
|
|
|
#include "common/msg.h"
|
2023-01-05 03:34:26 +00:00
|
|
|
#include "drm_atomic.h"
|
|
|
|
#include "drm_common.h"
|
2015-04-19 07:39:58 +00:00
|
|
|
#include "osdep/timer.h"
|
2015-04-15 16:14:14 +00:00
|
|
|
#include "sub/osd.h"
|
|
|
|
#include "video/fmt-conversion.h"
|
|
|
|
#include "video/mp_image.h"
|
2023-11-02 20:54:01 +00:00
|
|
|
#include "video/out/present_sync.h"
|
2015-04-15 16:14:14 +00:00
|
|
|
#include "video/sws_utils.h"
|
|
|
|
#include "vo.h"
|
|
|
|
|
2018-02-19 18:23:44 +00:00
|
|
|
#define IMGFMT_XRGB8888 IMGFMT_BGR0
|
2024-03-10 19:44:37 +00:00
|
|
|
#define IMGFMT_XBGR8888 IMGFMT_RGB0
|
2024-03-10 19:30:04 +00:00
|
|
|
#define IMGFMT_XRGB2101010 \
|
|
|
|
pixfmt2imgfmt(MP_SELECT_LE_BE(AV_PIX_FMT_X2RGB10LE, AV_PIX_FMT_X2RGB10BE))
|
2024-03-10 19:44:37 +00:00
|
|
|
#define IMGFMT_XBGR2101010 \
|
|
|
|
pixfmt2imgfmt(MP_SELECT_LE_BE(AV_PIX_FMT_X2BGR10LE, AV_PIX_FMT_X2BGR10BE))
|
2024-03-11 19:46:00 +00:00
|
|
|
#define IMGFMT_YUYV pixfmt2imgfmt(AV_PIX_FMT_YUYV422)
|
2018-02-19 18:23:44 +00:00
|
|
|
|
2015-05-29 15:49:51 +00:00
|
|
|
#define BYTES_PER_PIXEL 4
|
|
|
|
#define BITS_PER_PIXEL 32
|
2015-04-15 16:14:14 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
struct drm_frame {
|
2019-04-11 21:26:06 +00:00
|
|
|
struct framebuffer *fb;
|
|
|
|
};
|
|
|
|
|
2015-04-15 16:14:14 +00:00
|
|
|
struct priv {
|
2023-01-05 03:34:26 +00:00
|
|
|
struct drm_frame **fb_queue;
|
2019-04-11 21:26:06 +00:00
|
|
|
unsigned int fb_queue_len;
|
2015-04-15 16:14:14 +00:00
|
|
|
|
2019-12-07 18:17:21 +00:00
|
|
|
uint32_t drm_format;
|
2018-02-19 18:23:44 +00:00
|
|
|
enum mp_imgfmt imgfmt;
|
|
|
|
|
2015-04-15 16:14:14 +00:00
|
|
|
struct mp_image *last_input;
|
|
|
|
struct mp_image *cur_frame;
|
vo_drm: make the osd as large as the screen
Before this commit, the drm vo drew the osd over the scaled image, and
then copied the result onto the framebuffer, shifted. This made the
frame centered, but forced the osd to be only as large as the image.
This was inconsistent with other vo's, covered the image with the
progress indicator even when a black band was at the top of the screen,
made the progress indicator wrap on narrow videos, etc.
The change is to always use an image as large as the screen. The frame
is copied scaled and shifted to it, and the osd drawn over it. The
result is finally copied to the framebuffer without any shift, since it
is already as large as it.
Technically, cur_frame is an image as large as the screen and
cur_frame_cropped is a dummy reference to it, cropped to the size of
the scaled video. This way, copying the scaled image to
cur_frame_cropped positions the image in the right place in cur_frame,
which can then have the osd added to it and copied to the framebuffer.
2018-01-24 13:19:40 +00:00
|
|
|
struct mp_image *cur_frame_cropped;
|
2015-04-15 16:14:14 +00:00
|
|
|
struct mp_rect src;
|
|
|
|
struct mp_rect dst;
|
|
|
|
struct mp_osd_res osd;
|
|
|
|
struct mp_sws_context *sws;
|
2019-04-11 21:26:06 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
struct framebuffer **bufs;
|
|
|
|
int front_buf;
|
|
|
|
int buf_count;
|
2015-04-15 16:14:14 +00:00
|
|
|
};
|
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
static void destroy_framebuffer(int fd, struct framebuffer *fb)
|
2015-04-15 16:14:14 +00:00
|
|
|
{
|
2023-01-05 03:34:26 +00:00
|
|
|
if (!fb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fb->map) {
|
|
|
|
munmap(fb->map, fb->size);
|
2015-04-15 16:14:14 +00:00
|
|
|
}
|
2023-01-05 03:34:26 +00:00
|
|
|
if (fb->id) {
|
|
|
|
drmModeRmFB(fd, fb->id);
|
2015-04-15 16:14:14 +00:00
|
|
|
}
|
2023-01-05 03:34:26 +00:00
|
|
|
if (fb->handle) {
|
2015-04-15 16:14:14 +00:00
|
|
|
struct drm_mode_destroy_dumb dreq = {
|
2023-01-05 03:34:26 +00:00
|
|
|
.handle = fb->handle,
|
2015-04-15 16:14:14 +00:00
|
|
|
};
|
|
|
|
drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &dreq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
static struct framebuffer *setup_framebuffer(struct vo *vo)
|
2015-04-15 16:14:14 +00:00
|
|
|
{
|
2018-02-19 18:23:44 +00:00
|
|
|
struct priv *p = vo->priv;
|
2023-01-05 03:34:26 +00:00
|
|
|
struct vo_drm_state *drm = vo->drm;
|
2018-02-19 18:23:44 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
struct framebuffer *fb = talloc_zero(drm, struct framebuffer);
|
|
|
|
fb->width = drm->mode.mode.hdisplay;
|
|
|
|
fb->height = drm->mode.mode.vdisplay;
|
|
|
|
fb->fd = drm->fd;
|
|
|
|
fb->handle = 0;
|
2015-04-15 16:14:14 +00:00
|
|
|
|
|
|
|
// create dumb buffer
|
|
|
|
struct drm_mode_create_dumb creq = {
|
2023-01-05 03:34:26 +00:00
|
|
|
.width = fb->width,
|
|
|
|
.height = fb->height,
|
2015-05-29 15:49:51 +00:00
|
|
|
.bpp = BITS_PER_PIXEL,
|
2015-04-15 16:14:14 +00:00
|
|
|
};
|
2023-01-05 03:34:26 +00:00
|
|
|
|
|
|
|
if (drmIoctl(drm->fd, DRM_IOCTL_MODE_CREATE_DUMB, &creq) < 0) {
|
2015-04-15 16:14:14 +00:00
|
|
|
MP_ERR(vo, "Cannot create dumb buffer: %s\n", mp_strerror(errno));
|
2015-11-07 20:11:04 +00:00
|
|
|
goto err;
|
2015-04-15 16:14:14 +00:00
|
|
|
}
|
2023-01-05 03:34:26 +00:00
|
|
|
|
|
|
|
fb->stride = creq.pitch;
|
|
|
|
fb->size = creq.size;
|
|
|
|
fb->handle = creq.handle;
|
|
|
|
|
|
|
|
// select format
|
2024-03-10 19:44:37 +00:00
|
|
|
switch (drm->opts->drm_format) {
|
|
|
|
case DRM_OPTS_FORMAT_XRGB2101010:
|
2023-01-05 03:34:26 +00:00
|
|
|
p->drm_format = DRM_FORMAT_XRGB2101010;
|
|
|
|
p->imgfmt = IMGFMT_XRGB2101010;
|
2024-03-10 19:44:37 +00:00
|
|
|
break;
|
|
|
|
case DRM_OPTS_FORMAT_XBGR2101010:
|
|
|
|
p->drm_format = DRM_FORMAT_XRGB2101010;
|
|
|
|
p->imgfmt = IMGFMT_XRGB2101010;
|
|
|
|
break;
|
|
|
|
case DRM_OPTS_FORMAT_XBGR8888:
|
|
|
|
p->drm_format = DRM_FORMAT_XBGR8888;
|
|
|
|
p->imgfmt = IMGFMT_XBGR8888;
|
|
|
|
break;
|
2024-03-11 19:46:00 +00:00
|
|
|
case DRM_OPTS_FORMAT_YUYV:
|
|
|
|
p->drm_format = DRM_FORMAT_YUYV;
|
|
|
|
p->imgfmt = IMGFMT_YUYV;
|
|
|
|
break;
|
2024-03-10 19:44:37 +00:00
|
|
|
default:
|
|
|
|
if (drm->opts->drm_format != DRM_OPTS_FORMAT_XRGB8888) {
|
|
|
|
MP_VERBOSE(vo, "Requested format not supported by VO, "
|
|
|
|
"falling back to xrgb8888\n");
|
|
|
|
}
|
|
|
|
p->drm_format = DRM_FORMAT_XRGB8888;
|
2023-01-05 03:34:26 +00:00
|
|
|
p->imgfmt = IMGFMT_XRGB8888;
|
2024-03-10 19:44:37 +00:00
|
|
|
break;
|
2023-01-05 03:34:26 +00:00
|
|
|
}
|
2015-04-15 16:14:14 +00:00
|
|
|
|
|
|
|
// create framebuffer object for the dumb-buffer
|
2023-01-05 03:34:26 +00:00
|
|
|
int ret = drmModeAddFB2(fb->fd, fb->width, fb->height,
|
2019-12-07 18:17:21 +00:00
|
|
|
p->drm_format,
|
2023-01-05 03:34:26 +00:00
|
|
|
(uint32_t[4]){fb->handle, 0, 0, 0},
|
|
|
|
(uint32_t[4]){fb->stride, 0, 0, 0},
|
2019-12-07 18:17:21 +00:00
|
|
|
(uint32_t[4]){0, 0, 0, 0},
|
2023-01-05 03:34:26 +00:00
|
|
|
&fb->id, 0);
|
2019-12-07 18:17:21 +00:00
|
|
|
if (ret) {
|
2015-04-15 16:14:14 +00:00
|
|
|
MP_ERR(vo, "Cannot create framebuffer: %s\n", mp_strerror(errno));
|
2015-11-07 20:11:04 +00:00
|
|
|
goto err;
|
2015-04-15 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// prepare buffer for memory mapping
|
|
|
|
struct drm_mode_map_dumb mreq = {
|
2023-01-05 03:34:26 +00:00
|
|
|
.handle = fb->handle,
|
2015-04-15 16:14:14 +00:00
|
|
|
};
|
2023-01-05 03:34:26 +00:00
|
|
|
if (drmIoctl(drm->fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq)) {
|
2015-04-15 16:14:14 +00:00
|
|
|
MP_ERR(vo, "Cannot map dumb buffer: %s\n", mp_strerror(errno));
|
2015-11-07 20:11:04 +00:00
|
|
|
goto err;
|
2015-04-15 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// perform actual memory mapping
|
2023-01-05 03:34:26 +00:00
|
|
|
fb->map = mmap(0, fb->size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
|
|
|
drm->fd, mreq.offset);
|
|
|
|
if (fb->map == MAP_FAILED) {
|
2015-04-15 16:14:14 +00:00
|
|
|
MP_ERR(vo, "Cannot map dumb buffer: %s\n", mp_strerror(errno));
|
2015-11-07 20:11:04 +00:00
|
|
|
goto err;
|
2015-04-15 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
memset(fb->map, 0, fb->size);
|
|
|
|
return fb;
|
2015-04-15 16:14:14 +00:00
|
|
|
|
2015-11-07 20:11:04 +00:00
|
|
|
err:
|
2023-01-05 03:34:26 +00:00
|
|
|
destroy_framebuffer(drm->fd, fb);
|
|
|
|
return NULL;
|
2015-04-17 17:59:31 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 16:20:16 +00:00
|
|
|
static int reconfig(struct vo *vo, struct mp_image_params *params)
|
2015-04-15 16:14:14 +00:00
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
2023-01-05 03:34:26 +00:00
|
|
|
struct vo_drm_state *drm = vo->drm;
|
2015-04-15 16:14:14 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
vo->dwidth =drm->fb->width;
|
|
|
|
vo->dheight = drm->fb->height;
|
2015-04-15 16:14:14 +00:00
|
|
|
vo_get_src_dst_rects(vo, &p->src, &p->dst, &p->osd);
|
|
|
|
|
2024-03-11 19:46:00 +00:00
|
|
|
struct mp_imgfmt_desc fmt = mp_imgfmt_get_desc(p->imgfmt);
|
|
|
|
p->dst.x0 = MP_ALIGN_DOWN(p->dst.x0, fmt.align_x);
|
|
|
|
p->dst.y0 = MP_ALIGN_DOWN(p->dst.y0, fmt.align_y);
|
2015-04-15 16:14:14 +00:00
|
|
|
|
|
|
|
p->sws->src = *params;
|
|
|
|
p->sws->dst = (struct mp_image_params) {
|
2018-02-19 18:23:44 +00:00
|
|
|
.imgfmt = p->imgfmt,
|
2024-03-11 19:46:00 +00:00
|
|
|
.w = mp_rect_w(p->dst),
|
|
|
|
.h = mp_rect_h(p->dst),
|
2015-12-19 19:04:31 +00:00
|
|
|
.p_w = 1,
|
|
|
|
.p_h = 1,
|
2015-04-15 16:14:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
talloc_free(p->cur_frame);
|
2023-01-05 03:34:26 +00:00
|
|
|
p->cur_frame = mp_image_alloc(p->imgfmt, drm->fb->width, drm->fb->height);
|
2015-04-15 16:14:14 +00:00
|
|
|
mp_image_params_guess_csp(&p->sws->dst);
|
|
|
|
mp_image_set_params(p->cur_frame, &p->sws->dst);
|
2023-01-05 03:34:26 +00:00
|
|
|
mp_image_set_size(p->cur_frame, drm->fb->width, drm->fb->height);
|
vo_drm: make the osd as large as the screen
Before this commit, the drm vo drew the osd over the scaled image, and
then copied the result onto the framebuffer, shifted. This made the
frame centered, but forced the osd to be only as large as the image.
This was inconsistent with other vo's, covered the image with the
progress indicator even when a black band was at the top of the screen,
made the progress indicator wrap on narrow videos, etc.
The change is to always use an image as large as the screen. The frame
is copied scaled and shifted to it, and the osd drawn over it. The
result is finally copied to the framebuffer without any shift, since it
is already as large as it.
Technically, cur_frame is an image as large as the screen and
cur_frame_cropped is a dummy reference to it, cropped to the size of
the scaled video. This way, copying the scaled image to
cur_frame_cropped positions the image in the right place in cur_frame,
which can then have the osd added to it and copied to the framebuffer.
2018-01-24 13:19:40 +00:00
|
|
|
|
|
|
|
talloc_free(p->cur_frame_cropped);
|
|
|
|
p->cur_frame_cropped = mp_image_new_dummy_ref(p->cur_frame);
|
|
|
|
mp_image_crop_rc(p->cur_frame_cropped, p->dst);
|
2015-04-15 16:14:14 +00:00
|
|
|
|
2018-02-08 10:55:22 +00:00
|
|
|
talloc_free(p->last_input);
|
|
|
|
p->last_input = NULL;
|
|
|
|
|
2015-04-15 16:14:14 +00:00
|
|
|
if (mp_sws_reinit(p->sws) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2024-03-11 19:40:24 +00:00
|
|
|
mp_mutex_lock(&vo->params_mutex);
|
|
|
|
vo->target_params = &p->sws->dst; // essentially constant, so this is okay
|
|
|
|
mp_mutex_unlock(&vo->params_mutex);
|
2015-04-15 16:14:14 +00:00
|
|
|
vo->want_redraw = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-11 21:26:06 +00:00
|
|
|
static struct framebuffer *get_new_fb(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
|
|
|
|
|
|
|
p->front_buf++;
|
2019-09-28 09:17:48 +00:00
|
|
|
p->front_buf %= p->buf_count;
|
2019-04-11 21:26:06 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
return p->bufs[p->front_buf];
|
2019-04-11 21:26:06 +00:00
|
|
|
}
|
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
static void draw_image(struct vo *vo, mp_image_t *mpi, struct framebuffer *buf)
|
2019-04-11 21:26:06 +00:00
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
2023-01-05 03:34:26 +00:00
|
|
|
struct vo_drm_state *drm = vo->drm;
|
2019-04-11 21:26:06 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
if (drm->active && buf != NULL) {
|
2015-10-29 11:42:24 +00:00
|
|
|
if (mpi) {
|
|
|
|
struct mp_image src = *mpi;
|
|
|
|
struct mp_rect src_rc = p->src;
|
|
|
|
src_rc.x0 = MP_ALIGN_DOWN(src_rc.x0, mpi->fmt.align_x);
|
|
|
|
src_rc.y0 = MP_ALIGN_DOWN(src_rc.y0, mpi->fmt.align_y);
|
|
|
|
mp_image_crop_rc(&src, src_rc);
|
vo_drm: make the osd as large as the screen
Before this commit, the drm vo drew the osd over the scaled image, and
then copied the result onto the framebuffer, shifted. This made the
frame centered, but forced the osd to be only as large as the image.
This was inconsistent with other vo's, covered the image with the
progress indicator even when a black band was at the top of the screen,
made the progress indicator wrap on narrow videos, etc.
The change is to always use an image as large as the screen. The frame
is copied scaled and shifted to it, and the osd drawn over it. The
result is finally copied to the framebuffer without any shift, since it
is already as large as it.
Technically, cur_frame is an image as large as the screen and
cur_frame_cropped is a dummy reference to it, cropped to the size of
the scaled video. This way, copying the scaled image to
cur_frame_cropped positions the image in the right place in cur_frame,
which can then have the osd added to it and copied to the framebuffer.
2018-01-24 13:19:40 +00:00
|
|
|
|
|
|
|
mp_image_clear(p->cur_frame, 0, 0, p->cur_frame->w, p->dst.y0);
|
|
|
|
mp_image_clear(p->cur_frame, 0, p->dst.y1, p->cur_frame->w, p->cur_frame->h);
|
|
|
|
mp_image_clear(p->cur_frame, 0, p->dst.y0, p->dst.x0, p->dst.y1);
|
|
|
|
mp_image_clear(p->cur_frame, p->dst.x1, p->dst.y0, p->cur_frame->w, p->dst.y1);
|
|
|
|
|
|
|
|
mp_sws_scale(p->sws, p->cur_frame_cropped, &src);
|
2015-10-29 11:42:24 +00:00
|
|
|
osd_draw_on_image(vo->osd, p->osd, src.pts, 0, p->cur_frame);
|
|
|
|
} else {
|
|
|
|
mp_image_clear(p->cur_frame, 0, 0, p->cur_frame->w, p->cur_frame->h);
|
|
|
|
osd_draw_on_image(vo->osd, p->osd, 0, 0, p->cur_frame);
|
|
|
|
}
|
2015-04-17 17:59:31 +00:00
|
|
|
|
2024-03-10 19:30:04 +00:00
|
|
|
memcpy_pic(buf->map, p->cur_frame->planes[0],
|
|
|
|
p->cur_frame->w * BYTES_PER_PIXEL, p->cur_frame->h,
|
|
|
|
buf->stride,
|
|
|
|
p->cur_frame->stride[0]);
|
2015-04-17 17:59:31 +00:00
|
|
|
}
|
2015-04-15 16:14:14 +00:00
|
|
|
|
|
|
|
if (mpi != p->last_input) {
|
|
|
|
talloc_free(p->last_input);
|
|
|
|
p->last_input = mpi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-11 21:26:06 +00:00
|
|
|
static void enqueue_frame(struct vo *vo, struct framebuffer *fb)
|
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
struct drm_frame *new_frame = talloc(p, struct drm_frame);
|
2019-04-11 21:26:06 +00:00
|
|
|
new_frame->fb = fb;
|
|
|
|
MP_TARRAY_APPEND(p, p->fb_queue, p->fb_queue_len, new_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dequeue_frame(struct vo *vo)
|
2015-04-15 16:14:14 +00:00
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
2019-04-11 21:26:06 +00:00
|
|
|
|
|
|
|
talloc_free(p->fb_queue[0]);
|
|
|
|
MP_TARRAY_REMOVE_AT(p->fb_queue, p->fb_queue_len, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void swapchain_step(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
|
|
|
|
|
|
|
if (p->fb_queue_len > 0) {
|
|
|
|
dequeue_frame(vo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_frame(struct vo *vo, struct vo_frame *frame)
|
|
|
|
{
|
2023-01-05 03:34:26 +00:00
|
|
|
struct vo_drm_state *drm = vo->drm;
|
2019-04-11 21:26:06 +00:00
|
|
|
struct priv *p = vo->priv;
|
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
if (!drm->active)
|
2015-04-21 09:50:44 +00:00
|
|
|
return;
|
2015-04-15 16:14:14 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
drm->still = frame->still;
|
2019-04-11 21:26:06 +00:00
|
|
|
|
|
|
|
// we redraw the entire image when OSD needs to be redrawn
|
2023-01-05 03:34:26 +00:00
|
|
|
struct framebuffer *fb = p->bufs[p->front_buf];
|
2019-04-11 21:26:06 +00:00
|
|
|
const bool repeat = frame->repeat && !frame->redraw;
|
|
|
|
if (!repeat) {
|
|
|
|
fb = get_new_fb(vo);
|
|
|
|
draw_image(vo, mp_image_new_ref(frame->current), fb);
|
|
|
|
}
|
|
|
|
|
|
|
|
enqueue_frame(vo, fb);
|
|
|
|
}
|
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
static void queue_flip(struct vo *vo, struct drm_frame *frame)
|
2019-04-11 21:26:06 +00:00
|
|
|
{
|
2023-01-05 03:34:26 +00:00
|
|
|
struct vo_drm_state *drm = vo->drm;
|
2019-04-11 21:26:06 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
drm->fb = frame->fb;
|
2019-04-11 21:26:06 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
int ret = drmModePageFlip(drm->fd, drm->crtc_id,
|
2023-11-02 20:54:01 +00:00
|
|
|
drm->fb->id, DRM_MODE_PAGE_FLIP_EVENT, drm);
|
|
|
|
if (ret)
|
2018-02-24 20:34:32 +00:00
|
|
|
MP_WARN(vo, "Failed to queue page flip: %s\n", mp_strerror(errno));
|
2023-01-05 03:34:26 +00:00
|
|
|
drm->waiting_for_flip = !ret;
|
2019-04-11 21:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void flip_page(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
2023-01-05 03:34:26 +00:00
|
|
|
struct vo_drm_state *drm = vo->drm;
|
|
|
|
const bool drain = drm->paused || drm->still;
|
2019-04-11 21:26:06 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
if (!drm->active)
|
2019-04-11 21:26:06 +00:00
|
|
|
return;
|
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
while (drain || p->fb_queue_len > vo->opts->swapchain_depth) {
|
|
|
|
if (drm->waiting_for_flip) {
|
|
|
|
vo_drm_wait_on_flip(vo->drm);
|
2019-04-11 21:26:06 +00:00
|
|
|
swapchain_step(vo);
|
2015-04-20 16:57:24 +00:00
|
|
|
}
|
2019-04-11 21:26:06 +00:00
|
|
|
if (p->fb_queue_len <= 1)
|
|
|
|
break;
|
|
|
|
if (!p->fb_queue[1] || !p->fb_queue[1]->fb) {
|
|
|
|
MP_ERR(vo, "Hole in swapchain?\n");
|
|
|
|
swapchain_step(vo);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
queue_flip(vo, p->fb_queue[1]);
|
2015-04-15 16:14:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-02 20:54:01 +00:00
|
|
|
static void get_vsync(struct vo *vo, struct vo_vsync_info *info)
|
|
|
|
{
|
|
|
|
struct vo_drm_state *drm = vo->drm;
|
|
|
|
present_sync_get_info(drm->present, info);
|
|
|
|
}
|
|
|
|
|
2015-04-17 17:59:31 +00:00
|
|
|
static void uninit(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
vo_drm_uninit(vo);
|
2015-11-07 12:41:40 +00:00
|
|
|
|
2019-04-11 21:26:06 +00:00
|
|
|
while (p->fb_queue_len > 0) {
|
|
|
|
swapchain_step(vo);
|
|
|
|
}
|
|
|
|
|
2015-04-17 17:59:31 +00:00
|
|
|
talloc_free(p->last_input);
|
|
|
|
talloc_free(p->cur_frame);
|
vo_drm: make the osd as large as the screen
Before this commit, the drm vo drew the osd over the scaled image, and
then copied the result onto the framebuffer, shifted. This made the
frame centered, but forced the osd to be only as large as the image.
This was inconsistent with other vo's, covered the image with the
progress indicator even when a black band was at the top of the screen,
made the progress indicator wrap on narrow videos, etc.
The change is to always use an image as large as the screen. The frame
is copied scaled and shifted to it, and the osd drawn over it. The
result is finally copied to the framebuffer without any shift, since it
is already as large as it.
Technically, cur_frame is an image as large as the screen and
cur_frame_cropped is a dummy reference to it, cropped to the size of
the scaled video. This way, copying the scaled image to
cur_frame_cropped positions the image in the right place in cur_frame,
which can then have the osd added to it and copied to the framebuffer.
2018-01-24 13:19:40 +00:00
|
|
|
talloc_free(p->cur_frame_cropped);
|
2015-04-17 17:59:31 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 16:14:14 +00:00
|
|
|
static int preinit(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
2015-04-19 07:39:58 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
if (!vo_drm_init(vo))
|
2015-11-07 12:41:40 +00:00
|
|
|
goto err;
|
2018-02-19 18:23:44 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
struct vo_drm_state *drm = vo->drm;
|
|
|
|
p->buf_count = vo->opts->swapchain_depth + 1;
|
|
|
|
p->bufs = talloc_zero_array(p, struct framebuffer *, p->buf_count);
|
2015-04-15 16:14:14 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
p->front_buf = 0;
|
|
|
|
for (int i = 0; i < p->buf_count; i++) {
|
|
|
|
p->bufs[i] = setup_framebuffer(vo);
|
|
|
|
if (!p->bufs[i])
|
|
|
|
goto err;
|
2015-11-07 12:41:40 +00:00
|
|
|
}
|
2023-01-05 03:34:26 +00:00
|
|
|
drm->fb = p->bufs[0];
|
2015-04-15 16:14:14 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
vo->drm->width = vo->drm->fb->width;
|
|
|
|
vo->drm->height = vo->drm->fb->height;
|
2015-04-15 16:14:14 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
if (!vo_drm_acquire_crtc(vo->drm)) {
|
|
|
|
MP_ERR(vo, "Failed to set CRTC for connector %u: %s\n",
|
|
|
|
vo->drm->connector->connector_id, mp_strerror(errno));
|
2015-04-17 17:59:31 +00:00
|
|
|
goto err;
|
2015-04-15 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
vo_drm_set_monitor_par(vo);
|
|
|
|
p->sws = mp_sws_alloc(vo);
|
|
|
|
p->sws->log = vo->log;
|
|
|
|
mp_sws_enable_cmdline_opts(p->sws, vo->global);
|
2015-04-15 16:14:14 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-04-17 17:59:31 +00:00
|
|
|
err:
|
|
|
|
uninit(vo);
|
|
|
|
return -1;
|
2015-04-15 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int query_format(struct vo *vo, int format)
|
|
|
|
{
|
2024-03-11 20:13:39 +00:00
|
|
|
struct priv *p = vo->priv;
|
|
|
|
return mp_sws_supports_formats(p->sws, p->imgfmt, format) ? 1 : 0;
|
2015-04-15 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-24 12:59:31 +00:00
|
|
|
static int control(struct vo *vo, uint32_t request, void *arg)
|
2015-04-15 16:14:14 +00:00
|
|
|
{
|
|
|
|
switch (request) {
|
2015-05-08 20:37:45 +00:00
|
|
|
case VOCTRL_SET_PANSCAN:
|
|
|
|
if (vo->config_ok)
|
2015-10-03 16:20:16 +00:00
|
|
|
reconfig(vo, vo->params);
|
2015-05-08 20:37:45 +00:00
|
|
|
return VO_TRUE;
|
2016-09-24 12:59:31 +00:00
|
|
|
}
|
2015-04-15 16:14:14 +00:00
|
|
|
|
2023-01-05 03:34:26 +00:00
|
|
|
int events = 0;
|
|
|
|
int ret = vo_drm_control(vo, &events, request, arg);
|
|
|
|
vo_event(vo, events);
|
|
|
|
return ret;
|
|
|
|
}
|
2015-04-15 16:14:14 +00:00
|
|
|
|
|
|
|
const struct vo_driver video_out_drm = {
|
|
|
|
.name = "drm",
|
2020-02-11 20:45:16 +00:00
|
|
|
.description = "Direct Rendering Manager (software scaling)",
|
2015-04-15 16:14:14 +00:00
|
|
|
.preinit = preinit,
|
|
|
|
.query_format = query_format,
|
|
|
|
.reconfig = reconfig,
|
|
|
|
.control = control,
|
2019-04-11 21:26:06 +00:00
|
|
|
.draw_frame = draw_frame,
|
2015-04-15 16:14:14 +00:00
|
|
|
.flip_page = flip_page,
|
2023-11-02 20:54:01 +00:00
|
|
|
.get_vsync = get_vsync,
|
2015-04-15 16:14:14 +00:00
|
|
|
.uninit = uninit,
|
2023-01-05 03:34:26 +00:00
|
|
|
.wait_events = vo_drm_wait_events,
|
|
|
|
.wakeup = vo_drm_wakeup,
|
2015-04-15 16:14:14 +00:00
|
|
|
.priv_size = sizeof(struct priv),
|
|
|
|
};
|