summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/context_drm_egl.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/opengl/context_drm_egl.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/opengl/context_drm_egl.c')
-rw-r--r--video/out/opengl/context_drm_egl.c60
1 files changed, 6 insertions, 54 deletions
diff --git a/video/out/opengl/context_drm_egl.c b/video/out/opengl/context_drm_egl.c
index 6962237123..fcc31df682 100644
--- a/video/out/opengl/context_drm_egl.c
+++ b/video/out/opengl/context_drm_egl.c
@@ -21,7 +21,6 @@
#include <signal.h>
#include <string.h>
#include <poll.h>
-#include <time.h>
#include <unistd.h>
#include <gbm.h>
@@ -106,11 +105,6 @@ struct priv {
struct mpv_opengl_drm_draw_surface_size draw_surface_size;
};
-struct pflip_cb_closure {
- struct priv *priv;
- struct gbm_frame *frame;
-};
-
// Not general. Limited to only the formats being used in this module
static const char *gbm_format_to_string(uint32_t format)
{
@@ -460,9 +454,11 @@ static void queue_flip(struct ra_ctx *ctx, struct gbm_frame *frame)
update_framebuffer_from_bo(ctx, frame->bo);
// Alloc and fill the data struct for the page flip callback
- struct pflip_cb_closure *data = talloc(ctx, struct pflip_cb_closure);
- data->priv = p;
- data->frame = frame;
+ struct drm_pflip_cb_closure *data = talloc(ctx, 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;
if (atomic_ctx) {
drm_object_set_property(atomic_ctx->request, atomic_ctx->draw_plane, "FB_ID", p->fb->id);
@@ -715,50 +711,6 @@ static bool probe_gbm_format(struct ra_ctx *ctx, uint32_t argb_format, uint32_t
return result;
}
-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 gbm_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 drm_egl_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)
{
struct priv *p = ctx->priv;
@@ -774,7 +726,7 @@ static bool drm_egl_init(struct ra_ctx *ctx)
struct priv *p = ctx->priv = talloc_zero(ctx, struct priv);
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, ctx->vo->log);
if (p->vt_switcher_active) {