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).
This commit is contained in:
Anton Kindestam 2018-02-24 21:34:32 +01:00 committed by Kevin Mitchell
parent fe23715876
commit 0874e4e461
1 changed files with 5 additions and 2 deletions

View File

@ -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;