[PATCH xserver 5/6] modesetting: merge common page flip code for present and dri2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Qiang Yu <Qiang.Yu at amd.com>
---
 hw/xfree86/drivers/modesetting/dri2.c     |  72 ++++++--------------
 hw/xfree86/drivers/modesetting/driver.h   |  33 +---------
 hw/xfree86/drivers/modesetting/pageflip.c | 105 ++++++++++++++++++++++++++++--
 hw/xfree86/drivers/modesetting/present.c  |  72 ++++----------------
 4 files changed, 134 insertions(+), 148 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
index 1abf98c..4cf638e 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -408,65 +408,31 @@ struct ms_dri2_vblank_event {
 };
 
 static void
-ms_dri2_flip_free(struct ms_crtc_pageflip *flip)
+ms_dri2_flip_abort(modesettingPtr ms, void *data)
 {
-    struct ms_flipdata *flipdata = flip->flipdata;
+    struct ms_present_vblank_event *event = data;
 
-    free(flip);
-    if (--flipdata->flip_count > 0)
-        return;
-    free(flipdata);
-}
-
-static void
-ms_dri2_flip_abort(void *data)
-{
-    struct ms_crtc_pageflip *flip = data;
-    struct ms_flipdata *flipdata = flip->flipdata;
-    ScreenPtr screen = flipdata->screen;
-    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
-    modesettingPtr ms = modesettingPTR(scrn);
-
-    if (flipdata->flip_count == 1) {
-            ms->drmmode.dri2_flipping = FALSE;
-            free(flipdata->event);
-    }
-
-    ms_dri2_flip_free(flip);
+    ms->drmmode.dri2_flipping = FALSE;
+    free(event);
 }
 
 static void
-ms_dri2_flip_handler(uint64_t msc, uint64_t ust, void *data)
+ms_dri2_flip_handler(modesettingPtr ms, uint64_t msc, 
+                     uint64_t ust, void *data)
 {
-    struct ms_crtc_pageflip *flip = data;
-    ScreenPtr screen = flip->flipdata->screen;
-    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
-    modesettingPtr ms = modesettingPTR(scrn);
-    struct ms_flipdata *flipdata = flip->flipdata;
-    struct ms_dri2_vblank_event *event = flipdata->event;
-
-    if (flip->on_reference_crtc) {
-        flipdata->fe_msc = msc;
-        flipdata->fe_usec = ust;
-    }
-
-    if (flipdata->flip_count == 1) {
-        uint32_t frame = flipdata->fe_msc;
-        uint32_t tv_sec = flipdata->fe_usec / 1000000;
-        uint32_t tv_usec = flipdata->fe_usec % 1000000;
-        DrawablePtr drawable;
-        int status;
-
-        status = dixLookupDrawable(&drawable, event->drawable_id, serverClient,
-                                   M_ANY, DixWriteAccess);
-        if (status == Success)
-            DRI2SwapComplete(event->client, drawable, frame, tv_sec, tv_usec,
-                             DRI2_FLIP_COMPLETE, event->event_complete,
-                             event->event_data);
-        drmModeRmFB(ms->fd, flipdata->old_fb_id);
-    }
-
-    ms_dri2_flip_free(flip);
+    struct ms_dri2_vblank_event *event = data;
+    uint32_t frame = msc;
+    uint32_t tv_sec = ust / 1000000;
+    uint32_t tv_usec = ust % 1000000;
+    DrawablePtr drawable;
+    int status;
+
+    status = dixLookupDrawable(&drawable, event->drawable_id, serverClient,
+                               M_ANY, DixWriteAccess);
+    if (status == Success)
+        DRI2SwapComplete(event->client, drawable, frame, tv_sec, tv_usec,
+                         DRI2_FLIP_COMPLETE, event->event_complete,
+                         event->event_data);
 }
 
 static Bool
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index c0d80a8..761490a 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -156,39 +156,12 @@ Bool ms_present_screen_init(ScreenPtr screen);
 
 #ifdef GLAMOR
 
-/*
- * Event data for an in progress flip.
- * This contains a pointer to the vblank event,
- * and information about the flip in progress.
- * a reference to this is stored in the per-crtc
- * flips.
- */
-struct ms_flipdata {
-    ScreenPtr screen;
-    void *event;
-    /* number of CRTC events referencing this */
-    int flip_count;
-    uint64_t fe_msc;
-    uint64_t fe_usec;
-    uint32_t old_fb_id;
-};
-
-/*
- * Per crtc pageflipping infomation,
- * These are submitted to the queuing code
- * one of them per crtc per flip.
- */
-struct ms_crtc_pageflip {
-    Bool on_reference_crtc;
-    /* reference to the ms_flipdata */
-    struct ms_flipdata *flipdata;
-};
-
-typedef void (*ms_pageflip_handler_proc)(uint64_t frame,
+typedef void (*ms_pageflip_handler_proc)(modesettingPtr ms,
+                                         uint64_t frame,
                                          uint64_t usec,
                                          void *data);
 
-typedef void (*ms_pageflip_abort_proc)(void *data);
+typedef void (*ms_pageflip_abort_proc)(modesettingPtr ms, void *data);
 
 int ms_flush_drm_events(ScreenPtr screen);
 
diff --git a/hw/xfree86/drivers/modesetting/pageflip.c b/hw/xfree86/drivers/modesetting/pageflip.c
index 4549792..a82e0d6 100644
--- a/hw/xfree86/drivers/modesetting/pageflip.c
+++ b/hw/xfree86/drivers/modesetting/pageflip.c
@@ -32,6 +32,100 @@
 #ifdef GLAMOR
 
 /*
+ * Event data for an in progress flip.
+ * This contains a pointer to the vblank event,
+ * and information about the flip in progress.
+ * a reference to this is stored in the per-crtc
+ * flips.
+ */
+struct ms_flipdata {
+    ScreenPtr screen;
+    void *event;
+    ms_pageflip_handler_proc event_handler;
+    ms_pageflip_abort_proc abort_handler;
+    /* number of CRTC events referencing this */
+    int flip_count;
+    uint64_t fe_msc;
+    uint64_t fe_usec;
+    uint32_t old_fb_id;
+};
+
+/*
+ * Per crtc pageflipping infomation,
+ * These are submitted to the queuing code
+ * one of them per crtc per flip.
+ */
+struct ms_crtc_pageflip {
+    Bool on_reference_crtc;
+    /* reference to the ms_flipdata */
+    struct ms_flipdata *flipdata;
+};
+
+/**
+ * Free an ms_crtc_pageflip.
+ *
+ * Drops the reference count on the flipdata.
+ */
+static void
+ms_pageflip_free(struct ms_crtc_pageflip *flip)
+{
+    struct ms_flipdata *flipdata = flip->flipdata;
+
+    free(flip);
+    if (--flipdata->flip_count > 0)
+        return;
+    free(flipdata);
+}
+
+/**
+ * Callback for the DRM event queue when a single flip has completed
+ *
+ * Once the flip has been completed on all pipes, notify the
+ * extension code telling it when that happened
+ */
+static void
+ms_pageflip_handler(uint64_t msc, uint64_t ust, void *data)
+{
+    struct ms_crtc_pageflip *flip = data;
+    struct ms_flipdata *flipdata = flip->flipdata;
+    ScreenPtr screen = flipdata->screen;
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    modesettingPtr ms = modesettingPTR(scrn);
+
+    if (flip->on_reference_crtc) {
+        flipdata->fe_msc = msc;
+        flipdata->fe_usec = ust;
+    }
+
+    if (flipdata->flip_count == 1) {
+        flipdata->event_handler(ms, flipdata->fe_msc,
+                                flipdata->fe_usec,
+                                flipdata->event);
+
+        drmModeRmFB(ms->fd, flipdata->old_fb_id);
+    }
+    ms_pageflip_free(flip);
+}
+
+/*
+ * Callback for the DRM queue abort code.  A flip has been aborted.
+ */
+static void
+ms_pageflip_abort(void *data)
+{
+    struct ms_crtc_pageflip *flip = data;
+    struct ms_flipdata *flipdata = flip->flipdata;
+    ScreenPtr screen = flipdata->screen;
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    modesettingPtr ms = modesettingPTR(scrn);
+
+    if (flipdata->flip_count == 1)
+        flipdata->abort_handler(ms, flipdata->event);
+
+    ms_pageflip_free(flip);
+}
+
+/*
  * Flush the DRM event queue when full; makes space for new events.
  *
  * Returns a negative value on error, 0 if there was nothing to process,
@@ -68,9 +162,7 @@ ms_flush_drm_events(ScreenPtr screen)
 static Bool
 queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
                    struct ms_flipdata *flipdata,
-                   int ref_crtc_vblank_pipe, uint32_t flags,
-                   ms_pageflip_handler_proc pageflip_handler,
-                   ms_pageflip_abort_proc pageflip_abort)
+                   int ref_crtc_vblank_pipe, uint32_t flags)
 {
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     modesettingPtr ms = modesettingPTR(scrn);
@@ -92,7 +184,7 @@ queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
     flip->on_reference_crtc = (drmmode_crtc->vblank_pipe == ref_crtc_vblank_pipe);
     flip->flipdata = flipdata;
 
-    seq = ms_drm_queue_alloc(crtc, flip, pageflip_handler, pageflip_abort);
+    seq = ms_drm_queue_alloc(crtc, flip, ms_pageflip_handler, ms_pageflip_abort);
     if (!seq) {
         free(flip);
         return FALSE;
@@ -164,6 +256,8 @@ ms_do_pageflip(ScreenPtr screen,
 
     flipdata->event = event;
     flipdata->screen = screen;
+    flipdata->event_handler = pageflip_handler;
+    flipdata->abort_handler = pageflip_abort;
 
     /*
      * Take a local reference on flipdata.
@@ -206,8 +300,7 @@ ms_do_pageflip(ScreenPtr screen,
 
         if (!queue_flip_on_crtc(screen, crtc, flipdata,
                                 ref_crtc_vblank_pipe,
-                                flags, pageflip_handler,
-                                pageflip_abort)) {
+                                flags)) {
             goto error_undo;
         }
     }
diff --git a/hw/xfree86/drivers/modesetting/present.c b/hw/xfree86/drivers/modesetting/present.c
index d10c674..1101808 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -193,80 +193,34 @@ ms_present_flush(WindowPtr window)
 #ifdef GLAMOR
 
 /**
- * Free an ms_crtc_pageflip.
- *
- * Drops the reference count on the flipdata.
- */
-static void
-ms_present_flip_free(struct ms_crtc_pageflip *flip)
-{
-    struct ms_flipdata *flipdata = flip->flipdata;
-
-    free(flip);
-    if (--flipdata->flip_count > 0)
-        return;
-    free(flipdata);
-}
-
-/**
- * Callback for the DRM event queue when a single flip has completed
- *
- * Once the flip has been completed on all pipes, notify the
+ * Callback for the flip has been completed on all pipes, notify the
  * extension code telling it when that happened
  */
 static void
-ms_present_flip_handler(uint64_t msc, uint64_t ust, void *data)
+ms_present_flip_handler(modesettingPtr ms, uint64_t msc, 
+                        uint64_t ust, void *data)
 {
-    struct ms_crtc_pageflip *flip = data;
-    ScreenPtr screen = flip->flipdata->screen;
-    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
-    modesettingPtr ms = modesettingPTR(scrn);
-    struct ms_flipdata *flipdata = flip->flipdata;
-    struct ms_present_vblank_event *event = flipdata->event;
+    struct ms_present_vblank_event *event = data;
 
-    DebugPresent(("\t\tms:fh %lld c %d msc %llu ust %llu\n",
-                  (long long) flipdata->event->event_id,
-                  flipdata->flip_count,
+    DebugPresent(("\t\tms:fc %lld msc %llu ust %llu\n",
+                  (long long) event->event_id,
                   (long long) msc, (long long) ust));
 
-    if (flip->on_reference_crtc) {
-        flipdata->fe_msc = msc;
-        flipdata->fe_usec = ust;
-    }
-
-    if (flipdata->flip_count == 1) {
-        DebugPresent(("\t\tms:fc %lld c %d msc %llu ust %llu\n",
-                      (long long) flipdata->event->event_id,
-                      flipdata->flip_count,
-                      (long long) flipdata->fe_msc, (long long) flipdata->fe_usec));
-
-        if (event->unflip)
-            ms->drmmode.present_flipping = FALSE;
-
-        ms_present_vblank_handler(flipdata->fe_msc,
-                                  flipdata->fe_usec,
-                                  flipdata->event);
+    if (event->unflip)
+        ms->drmmode.present_flipping = FALSE;
 
-        drmModeRmFB(ms->fd, flipdata->old_fb_id);
-    }
-    ms_present_flip_free(flip);
+    ms_present_vblank_handler(msc, ust, event);
 }
 
 /*
- * Callback for the DRM queue abort code.  A flip has been aborted.
+ * Callback for the flip has been aborted.
  */
 static void
-ms_present_flip_abort(void *data)
+ms_present_flip_abort(modesettingPtr ms, void *data)
 {
-    struct ms_crtc_pageflip *flip = data;
-    struct ms_flipdata *flipdata = flip->flipdata;
-
-    DebugPresent(("\t\tms:fa %lld c %d\n", (long long) flipdata->event->event_id, flipdata->flip_count));
-
-    if (flipdata->flip_count == 1)
-        free(flipdata->event);
+    struct ms_present_vblank_event *event = data;
 
-    ms_present_flip_free(flip);
+    free(event);
 }
 
 /*
-- 
2.7.4



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux