summaryrefslogtreecommitdiffstats
path: root/video/out/vo_drm.c
diff options
context:
space:
mode:
authorAnton Kindestam <antonki@kth.se>2019-07-29 19:32:29 +0200
committerJan Ekström <jeebjp@gmail.com>2019-09-28 14:10:01 +0300
commit9538fb5a7af951e220f26c87c80aaaa2a5cfbc67 (patch)
tree36a1c191a061a18ddfad7fe1926ad6de4993ee34 /video/out/vo_drm.c
parent77980c8184cdc62f964fd85fc6cbd3d79019ce7a (diff)
downloadmpv-9538fb5a7af951e220f26c87c80aaaa2a5cfbc67.tar.bz2
mpv-9538fb5a7af951e220f26c87c80aaaa2a5cfbc67.tar.xz
drm: refactor page_flipped callback
Avoid duplicating the same callback function in both context_drm_egl and vo_drm.
Diffstat (limited to 'video/out/vo_drm.c')
-rw-r--r--video/out/vo_drm.c61
1 files changed, 6 insertions, 55 deletions
diff --git a/video/out/vo_drm.c b/video/out/vo_drm.c
index 80757486c6..8e2ee9ae1b 100644
--- a/video/out/vo_drm.c
+++ b/video/out/vo_drm.c
@@ -21,7 +21,6 @@
#include <stdbool.h>
#include <sys/mman.h>
#include <poll.h>
-#include <time.h>
#include <unistd.h>
#include <libswscale/swscale.h>
@@ -65,11 +64,6 @@ struct kms_frame {
struct drm_vsync_tuple vsync;
};
-struct pflip_cb_closure {
- struct priv *priv;
- struct kms_frame *frame;
-};
-
struct priv {
char *connector_spec;
int mode_id;
@@ -202,50 +196,6 @@ static bool fb_setup_buffers(struct vo *vo)
return true;
}
-static void page_flipped(int fd, unsigned int msc, unsigned int sec,
- unsigned int usec, void *data)
-{
- struct pflip_cb_closure *closure = data;
- struct priv *p = closure->priv;
-
- // frame->vsync.ust is the timestamp of the pageflip that happened just before this flip was queued
- // frame->vsync.msc is the sequence number of the pageflip that happened just before this flip was queued
- // frame->vsync.sbc is the sequence number for the frame that was just flipped to screen
- struct kms_frame *frame = closure->frame;
-
- const bool ready =
- (p->vsync.msc != 0) &&
- (frame->vsync.ust != 0) && (frame->vsync.msc != 0);
-
- const uint64_t ust = (sec * 1000000LL) + usec;
-
- const unsigned int msc_since_last_flip = msc - p->vsync.msc;
-
- p->vsync.ust = ust;
- p->vsync.msc = msc;
-
- if (ready) {
- // Convert to mp_time
- struct timespec ts;
- if (clock_gettime(CLOCK_MONOTONIC, &ts))
- goto fail;
- const uint64_t now_monotonic = ts.tv_sec * 1000000LL + ts.tv_nsec / 1000;
- const uint64_t ust_mp_time = mp_time_us() - (now_monotonic - p->vsync.ust);
-
- const uint64_t ust_since_enqueue = p->vsync.ust - frame->vsync.ust;
- const unsigned int msc_since_enqueue = p->vsync.msc - frame->vsync.msc;
- const unsigned int sbc_since_enqueue = p->vsync.sbc - frame->vsync.sbc;
-
- p->vsync_info.vsync_duration = ust_since_enqueue / msc_since_enqueue;
- p->vsync_info.skipped_vsyncs = msc_since_last_flip - 1; // Valid iff swap_buffers is called every vsync
- p->vsync_info.last_queue_display_time = ust_mp_time + (sbc_since_enqueue * p->vsync_info.vsync_duration);
- }
-
-fail:
- p->waiting_for_flip = false;
- talloc_free(closure);
-}
-
static void get_vsync(struct vo *vo, struct vo_vsync_info *info)
{
struct priv *p = vo->priv;
@@ -538,9 +488,11 @@ static void queue_flip(struct vo *vo, struct kms_frame *frame)
p->cur_fb = frame->fb;
// Alloc and fill the data struct for the page flip callback
- struct pflip_cb_closure *data = talloc(p, struct pflip_cb_closure);
- data->priv = p;
- data->frame = frame;
+ struct drm_pflip_cb_closure *data = talloc(p, struct drm_pflip_cb_closure);
+ data->frame_vsync = &frame->vsync;
+ data->vsync = &p->vsync;
+ data->vsync_info = &p->vsync_info;
+ data->waiting_for_flip = &p->waiting_for_flip;
ret = drmModePageFlip(p->kms->fd, p->kms->crtc_id,
p->cur_fb->fb,
@@ -550,7 +502,6 @@ static void queue_flip(struct vo *vo, struct kms_frame *frame)
} else {
p->waiting_for_flip = true;
}
-
}
static void flip_page(struct vo *vo)
@@ -607,7 +558,7 @@ static int preinit(struct vo *vo)
struct priv *p = vo->priv;
p->sws = mp_sws_alloc(vo);
p->ev.version = DRM_EVENT_CONTEXT_VERSION;
- p->ev.page_flip_handler = page_flipped;
+ p->ev.page_flip_handler = &drm_pflip_cb;
p->vt_switcher_active = vt_switcher_init(&p->vt_switcher, vo->log);
if (p->vt_switcher_active) {