All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qiang Yu <Qiang.Yu-5C7GfCeVMHo@public.gmane.org>
To: xorg-devel-go0+a7rfsptAfugRpC6u6w@public.gmane.org
Cc: Qiang Yu <Qiang.Yu-5C7GfCeVMHo@public.gmane.org>,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH xserver 5/6] modesetting: merge common page flip code for present and dri2
Date: Wed, 17 Aug 2016 18:29:10 +0800	[thread overview]
Message-ID: <1471429751-17269-6-git-send-email-Qiang.Yu@amd.com> (raw)
In-Reply-To: <1471429751-17269-1-git-send-email-Qiang.Yu-5C7GfCeVMHo@public.gmane.org>

Signed-off-by: Qiang Yu <Qiang.Yu@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

_______________________________________________
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

  parent reply	other threads:[~2016-08-17 10:29 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17 10:29 [PATCH xserver 0/6] modesetting: add DRI2 page flip support Qiang Yu
     [not found] ` <1471429751-17269-1-git-send-email-Qiang.Yu-5C7GfCeVMHo@public.gmane.org>
2016-08-17 10:29   ` [PATCH xserver 1/6] modesetting: make ms_do_pageflip generic for share with DRI2 Qiang Yu
     [not found]     ` <1471429751-17269-2-git-send-email-Qiang.Yu-5C7GfCeVMHo@public.gmane.org>
2016-08-18  7:48       ` Michel Dänzer
2016-08-17 10:29   ` [PATCH xserver 2/6] modesetting: move ms_do_pageflip to pageflip.c Qiang Yu
2016-08-17 10:29   ` [PATCH xserver 3/6] modesetting: add DRI2 page flip support Qiang Yu
     [not found]     ` <1471429751-17269-4-git-send-email-Qiang.Yu-5C7GfCeVMHo@public.gmane.org>
2016-08-18  8:12       ` Michel Dänzer
     [not found]         ` <7ae3a1a6-0e00-856b-885f-a8c39e7d5842-otUistvHUpPR7s880joybQ@public.gmane.org>
2016-08-19  7:06           ` Yu, Qiang
     [not found]             ` <DM5PR12MB120959145EBDFF1847B5FF1A8F160-2J9CzHegvk/Xl62ebUdyqgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2016-08-19  7:25               ` Michel Dänzer
     [not found]                 ` <1349a122-864e-2abd-9599-c7fa41e900c2-otUistvHUpPR7s880joybQ@public.gmane.org>
2016-08-19  7:48                   ` Yu, Qiang
     [not found]                     ` <MWHPR12MB12152F00C2A18FC6149473F18F160-Gy0DoCVfaSXDoeKT4XqzagdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2016-08-19  9:06                       ` Michel Dänzer
2016-08-17 10:29   ` [PATCH xserver 4/6] modesetting: exclude DRI2 and Present page flip Qiang Yu
2016-08-17 10:29   ` Qiang Yu [this message]
2016-08-17 10:29   ` [PATCH xserver 6/6] modesetting: remove redundent pixmap destroy Qiang Yu
2016-08-17 15:54   ` [PATCH xserver 0/6] modesetting: add DRI2 page flip support Martin Peres
2016-08-18  8:18   ` Michel Dänzer
     [not found]     ` <1b121a8c-a201-396e-426c-838c4abed8f3-otUistvHUpPR7s880joybQ@public.gmane.org>
2016-08-19  1:52       ` Yu, Qiang
2016-08-18 11:03   ` Emil Velikov
     [not found]     ` <CACvgo52vhzcyAS384uQdYy_XrA0LmKRdsRnLF0UB0OhV49A7uw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-08-19  2:02       ` Yu, Qiang
     [not found]         ` <MWHPR12MB121593BB7CA6C60D65B21E6B8F160-Gy0DoCVfaSXDoeKT4XqzagdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2016-08-19  2:09           ` Michel Dänzer
     [not found]             ` <09c2176a-6a7e-b28d-d7e1-6a4bb76dab58-otUistvHUpPR7s880joybQ@public.gmane.org>
2016-08-19  5:11               ` Keith Packard
2016-08-19  7:57               ` Emil Velikov
     [not found]                 ` <CACvgo51CgrEqe+pE-0-FOrhk3NhLSygLA54RU2U3aoFfHEvXGw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-08-19  9:09                   ` Michel Dänzer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471429751-17269-6-git-send-email-Qiang.Yu@amd.com \
    --to=qiang.yu-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=xorg-devel-go0+a7rfsptAfugRpC6u6w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.