summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorAnton Kindestam <antonki@kth.se>2018-02-24 21:34:32 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-02-26 23:56:13 -0800
commit0874e4e461e3ade9e3bf1f537732c5f849a15b5e (patch)
treef156c6025efdfbb3827f8560cecd1bfed12c14ae /video
parentfe23715876282215aa3d7cca26722ada4396d425 (diff)
downloadmpv-0874e4e461e3ade9e3bf1f537732c5f849a15b5e.tar.bz2
mpv-0874e4e461e3ade9e3bf1f537732c5f849a15b5e.tar.xz
vo_drm: Fix pageflip errors on VT switch
crtc_setup gets called on VT reacquire as well as during normal setup. When called during VT reacquire p->front_buf might not be 0, so the maths was wrong, and could cause array OOB errors. Use mathematically correct (for negative numbers) modulo to always pick the farthest away buffer (should work even for larger values of BUF_COUNT).
Diffstat (limited to 'video')
-rw-r--r--video/out/vo_drm.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/video/out/vo_drm.c b/video/out/vo_drm.c
index 2cf88ad862..b25f036256 100644
--- a/video/out/vo_drm.c
+++ b/video/out/vo_drm.c
@@ -41,6 +41,9 @@
#define USE_MASTER 0
#define BUF_COUNT 2
+// Modulo that works correctly for negative numbers
+#define MOD(a,b) ((((a)%(b))+(b))%(b))
+
struct framebuffer {
uint32_t width;
uint32_t height;
@@ -181,7 +184,7 @@ static bool crtc_setup(struct vo *vo)
return true;
p->old_crtc = drmModeGetCrtc(p->kms->fd, p->kms->crtc_id);
int ret = drmModeSetCrtc(p->kms->fd, p->kms->crtc_id,
- p->bufs[p->front_buf + BUF_COUNT - 1].fb,
+ p->bufs[MOD(p->front_buf - 1, BUF_COUNT)].fb,
0, 0, &p->kms->connector->connector_id, 1,
&p->kms->mode);
p->active = true;
@@ -356,7 +359,7 @@ static void flip_page(struct vo *vo)
p->bufs[p->front_buf].fb,
DRM_MODE_PAGE_FLIP_EVENT, p);
if (ret) {
- MP_WARN(vo, "Cannot flip page for connector\n");
+ MP_WARN(vo, "Failed to queue page flip: %s\n", mp_strerror(errno));
} else {
p->front_buf++;
p->front_buf %= BUF_COUNT;