xserver: Branch 'master' - 5 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Feb 18 15:37:26 UTC 2020


 present/present.c      |   95 ++++++++++++++++++++++++++++++++-----------------
 present/present_priv.h |   10 ++---
 present/present_scmd.c |   64 +++++++++++++++------------------
 present/present_wnmd.c |   41 +++++++++++----------
 4 files changed, 121 insertions(+), 89 deletions(-)

New commits:
commit 1e44861aba449eec81d69b1da3a6e6f88676e04f
Author: Roman Gilg <subdiff at gmail.com>
Date:   Mon May 27 23:01:53 2019 +0200

    present: Rename window_msc variable in present function
    
    The value is not the current msc of the window, but the target value
    the client sets independently of the window speicific msc offset. Make
    this clearer.
    
    Signed-off-by: Roman Gilg <subdiff at gmail.com>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/present/present_scmd.c b/present/present_scmd.c
index d47f2dba7..fa800e99c 100644
--- a/present/present_scmd.c
+++ b/present/present_scmd.c
@@ -648,7 +648,7 @@ present_scmd_pixmap(WindowPtr window,
                     SyncFence *wait_fence,
                     SyncFence *idle_fence,
                     uint32_t options,
-                    uint64_t window_msc,
+                    uint64_t target_window_msc,
                     uint64_t divisor,
                     uint64_t remainder,
                     present_notify_ptr notifies,
@@ -688,7 +688,7 @@ present_scmd_pixmap(WindowPtr window,
         window_priv->msc = crtc_msc;
     }
 
-    target_msc = present_get_target_msc(window_msc + window_priv->msc_offset,
+    target_msc = present_get_target_msc(target_window_msc + window_priv->msc_offset,
                                         crtc_msc,
                                         divisor,
                                         remainder,
diff --git a/present/present_wnmd.c b/present/present_wnmd.c
index 8894d99af..c9108e0e2 100644
--- a/present/present_wnmd.c
+++ b/present/present_wnmd.c
@@ -555,7 +555,7 @@ present_wnmd_pixmap(WindowPtr window,
                     SyncFence *wait_fence,
                     SyncFence *idle_fence,
                     uint32_t options,
-                    uint64_t window_msc,
+                    uint64_t target_window_msc,
                     uint64_t divisor,
                     uint64_t remainder,
                     present_notify_ptr notifies,
@@ -585,7 +585,7 @@ present_wnmd_pixmap(WindowPtr window,
         window_priv->msc = crtc_msc;
     }
 
-    target_msc = present_get_target_msc(window_msc + window_priv->msc_offset,
+    target_msc = present_get_target_msc(target_window_msc + window_priv->msc_offset,
                                         crtc_msc,
                                         divisor,
                                         remainder,
commit d3c1b223cec2b475c4f1661d7e5dc5238d08d8f6
Author: Roman Gilg <subdiff at gmail.com>
Date:   Mon May 27 22:58:49 2019 +0200

    present: Move scmd-update-window-crtc function
    
    Move the code portion down. That way it is at a similar position as in
    the window mode file.
    
    Signed-off-by: Roman Gilg <subdiff at gmail.com>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/present/present_scmd.c b/present/present_scmd.c
index cdbacec90..d47f2dba7 100644
--- a/present/present_scmd.c
+++ b/present/present_scmd.c
@@ -222,30 +222,6 @@ present_queue_vblank(ScreenPtr screen,
     return ret;
 }
 
-static void
-present_scmd_update_window_crtc(WindowPtr window, RRCrtcPtr crtc, uint64_t new_msc)
-{
-    present_window_priv_ptr window_priv = present_get_window_priv(window, TRUE);
-    uint64_t                old_ust, old_msc;
-
-    /* Crtc unchanged, no offset. */
-    if (crtc == window_priv->crtc)
-        return;
-
-    /* No crtc earlier to offset against, just set the crtc first time. */
-    if (window_priv->crtc == PresentCrtcNeverSet) {
-        window_priv->crtc = crtc;
-        return;
-    }
-
-    /* Crtc may have been turned off, just use whatever previous MSC we'd seen from this CRTC. */
-    if (present_get_ust_msc(window->drawable.pScreen, window_priv->crtc, &old_ust, &old_msc) != Success)
-        old_msc = window_priv->msc;
-
-    window_priv->msc_offset += new_msc - old_msc;
-    window_priv->crtc = crtc;
-}
-
 /*
  * When the wait fence or previous flip is completed, it's time
  * to re-try the request
@@ -636,6 +612,30 @@ present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
     present_execute_post(vblank, ust, crtc_msc);
 }
 
+static void
+present_scmd_update_window_crtc(WindowPtr window, RRCrtcPtr crtc, uint64_t new_msc)
+{
+    present_window_priv_ptr window_priv = present_get_window_priv(window, TRUE);
+    uint64_t                old_ust, old_msc;
+
+    /* Crtc unchanged, no offset. */
+    if (crtc == window_priv->crtc)
+        return;
+
+    /* No crtc earlier to offset against, just set the crtc. */
+    if (window_priv->crtc == PresentCrtcNeverSet) {
+        window_priv->crtc = crtc;
+        return;
+    }
+
+    /* Crtc may have been turned off, just use whatever previous MSC we'd seen from this CRTC. */
+    if (present_get_ust_msc(window->drawable.pScreen, window_priv->crtc, &old_ust, &old_msc) != Success)
+        old_msc = window_priv->msc;
+
+    window_priv->msc_offset += new_msc - old_msc;
+    window_priv->crtc = crtc;
+}
+
 static int
 present_scmd_pixmap(WindowPtr window,
                     PixmapPtr pixmap,
commit 8c2dcc5f800438d2b4545d21a515e013e6aac484
Author: Roman Gilg <subdiff at gmail.com>
Date:   Mon May 27 22:49:23 2019 +0200

    present: Code cleanup of window to crtc timings update
    
    Make the code more readable by going through some logical abort
    conditions. Also make the function only about updating the crtc
    msc value and not about also returning the next target msc.
    
    Signed-off-by: Roman Gilg <subdiff at gmail.com>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/present/present_scmd.c b/present/present_scmd.c
index 8bf8fc1d5..cdbacec90 100644
--- a/present/present_scmd.c
+++ b/present/present_scmd.c
@@ -222,30 +222,28 @@ present_queue_vblank(ScreenPtr screen,
     return ret;
 }
 
-static uint64_t
-present_window_to_crtc_msc(WindowPtr window, RRCrtcPtr crtc, uint64_t window_msc, uint64_t new_msc)
+static void
+present_scmd_update_window_crtc(WindowPtr window, RRCrtcPtr crtc, uint64_t new_msc)
 {
-    present_window_priv_ptr     window_priv = present_get_window_priv(window, TRUE);
-
-    if (crtc != window_priv->crtc) {
-        uint64_t        old_ust, old_msc;
-
-        if (window_priv->crtc == PresentCrtcNeverSet) {
-            window_priv->msc_offset = 0;
-        } else {
-            /* The old CRTC may have been turned off, in which case
-             * we'll just use whatever previous MSC we'd seen from this CRTC
-             */
+    present_window_priv_ptr window_priv = present_get_window_priv(window, TRUE);
+    uint64_t                old_ust, old_msc;
 
-            if (present_get_ust_msc(window->drawable.pScreen, window_priv->crtc, &old_ust, &old_msc) != Success)
-                old_msc = window_priv->msc;
+    /* Crtc unchanged, no offset. */
+    if (crtc == window_priv->crtc)
+        return;
 
-            window_priv->msc_offset += new_msc - old_msc;
-        }
+    /* No crtc earlier to offset against, just set the crtc first time. */
+    if (window_priv->crtc == PresentCrtcNeverSet) {
         window_priv->crtc = crtc;
+        return;
     }
 
-    return window_msc + window_priv->msc_offset;
+    /* Crtc may have been turned off, just use whatever previous MSC we'd seen from this CRTC. */
+    if (present_get_ust_msc(window->drawable.pScreen, window_priv->crtc, &old_ust, &old_msc) != Success)
+        old_msc = window_priv->msc;
+
+    window_priv->msc_offset += new_msc - old_msc;
+    window_priv->crtc = crtc;
 }
 
 /*
@@ -682,7 +680,7 @@ present_scmd_pixmap(WindowPtr window,
 
     ret = present_get_ust_msc(screen, target_crtc, &ust, &crtc_msc);
 
-    target_msc = present_window_to_crtc_msc(window, target_crtc, window_msc, crtc_msc);
+    present_scmd_update_window_crtc(window, target_crtc, crtc_msc);
 
     if (ret == Success) {
         /* Stash the current MSC away in case we need it later
@@ -690,7 +688,7 @@ present_scmd_pixmap(WindowPtr window,
         window_priv->msc = crtc_msc;
     }
 
-    target_msc = present_get_target_msc(target_msc,
+    target_msc = present_get_target_msc(window_msc + window_priv->msc_offset,
                                         crtc_msc,
                                         divisor,
                                         remainder,
diff --git a/present/present_wnmd.c b/present/present_wnmd.c
index 91aab985c..8894d99af 100644
--- a/present/present_wnmd.c
+++ b/present/present_wnmd.c
@@ -519,25 +519,28 @@ present_wnmd_queue_vblank(ScreenPtr screen,
     return (*screen_priv->wnmd_info->queue_vblank) (window, crtc, event_id, msc);
 }
 
-static uint64_t
-present_wnmd_window_to_crtc_msc(WindowPtr window, RRCrtcPtr crtc, uint64_t window_msc, uint64_t new_msc)
+static void
+present_wnmd_update_window_crtc(WindowPtr window, RRCrtcPtr crtc, uint64_t new_msc)
 {
     present_window_priv_ptr window_priv = present_get_window_priv(window, TRUE);
 
-    if (crtc != window_priv->crtc) {
-        if (window_priv->crtc == PresentCrtcNeverSet) {
-            window_priv->msc_offset = 0;
-        } else {
-            /* The old CRTC may have been turned off, in which case
-             * we'll just use whatever previous MSC we'd seen from this CRTC
-             */
+    /* Crtc unchanged, no offset. */
+    if (crtc == window_priv->crtc)
+        return;
 
-            window_priv->msc_offset += new_msc - window_priv->msc;
-        }
+    /* No crtc earlier to offset against, just set the crtc. */
+    if (window_priv->crtc == PresentCrtcNeverSet) {
+        window_priv->msc_offset = 0;
         window_priv->crtc = crtc;
+        return;
     }
 
-    return window_msc + window_priv->msc_offset;
+    /* In window-mode the last correct msc-offset is always kept
+     * in window-priv struct because msc is saved per window and
+     * not per crtc as in screen-mode.
+     */
+    window_priv->msc_offset += new_msc - window_priv->msc;
+    window_priv->crtc = crtc;
 }
 
 static int
@@ -574,7 +577,7 @@ present_wnmd_pixmap(WindowPtr window,
 
     ret = present_wnmd_get_ust_msc(screen, window, &ust, &crtc_msc);
 
-    target_msc = present_wnmd_window_to_crtc_msc(window, target_crtc, window_msc, crtc_msc);
+    present_wnmd_update_window_crtc(window, target_crtc, crtc_msc);
 
     if (ret == Success) {
         /* Stash the current MSC away in case we need it later
@@ -582,7 +585,7 @@ present_wnmd_pixmap(WindowPtr window,
         window_priv->msc = crtc_msc;
     }
 
-    target_msc = present_get_target_msc(target_msc,
+    target_msc = present_get_target_msc(window_msc + window_priv->msc_offset,
                                         crtc_msc,
                                         divisor,
                                         remainder,
commit 4d89ba0058457d51f2e1a132c0b7fc8a3ec5c76d
Author: Roman Gilg <subdiff at gmail.com>
Date:   Mon May 27 22:42:34 2019 +0200

    present: Unfold and annotate the target-msc getter
    
    Unfold and extensively annotate the target-msc adjustment function, to make
    it easier to understand what's happening and why.
    
    Signed-off-by: Roman Gilg <subdiff at gmail.com>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/present/present.c b/present/present.c
index 1a2163cdc..43581e378 100644
--- a/present/present.c
+++ b/present/present.c
@@ -27,17 +27,6 @@
 #include "present_priv.h"
 #include <gcstruct.h>
 
-/*
- * Returns:
- * TRUE if the first MSC value is equal to or after the second one
- * FALSE if the first MSC value is before the second one
- */
-static Bool
-msc_is_equal_or_after(uint64_t test, uint64_t reference)
-{
-    return (int64_t)(test - reference) >= 0;
-}
-
 uint32_t
 present_query_capabilities(RRCrtcPtr crtc)
 {
@@ -158,30 +147,71 @@ present_can_window_flip(WindowPtr window)
 }
 
 uint64_t
-present_get_target_msc(uint32_t options,
+present_get_target_msc(uint64_t target_msc_arg,
                        uint64_t crtc_msc,
-                       uint64_t target_msc,
                        uint64_t divisor,
-                       uint64_t remainder)
+                       uint64_t remainder,
+                       uint32_t options)
 {
-    /* Adjust target_msc to match modulus
+    const Bool  synced_flip = !(options & PresentOptionAsync);
+    uint64_t    target_msc;
+
+    /* If the specified target-msc lies in the future, then this
+     * defines the target-msc according to Present protocol.
+     */
+    if (msc_is_after(target_msc_arg, crtc_msc))
+        return target_msc_arg;
+
+    /* If no divisor is specified, the modulo is undefined
+     * and we do present instead asap.
      */
-    if (msc_is_equal_or_after(crtc_msc, target_msc)) {
-        if (divisor != 0) {
-            target_msc = crtc_msc - (crtc_msc % divisor) + remainder;
-            if (options & PresentOptionAsync) {
-                if (msc_is_after(crtc_msc, target_msc))
-                    target_msc += divisor;
-            } else {
-                if (msc_is_equal_or_after(crtc_msc, target_msc))
-                    target_msc += divisor;
-            }
-        } else {
-            target_msc = crtc_msc;
-            if (!(options & PresentOptionAsync))
-                (target_msc)++;
-        }
+    if (divisor == 0) {
+        target_msc = crtc_msc;
+
+        /* When no async presentation is forced, by default we sync the
+         * presentation with vblank. But in this case we can't target
+         * the current crtc-msc, which already has begun, but must aim
+         * for the upcoming one.
+         */
+        if (synced_flip)
+            target_msc++;
+
+        return target_msc;
     }
+
+    /* Calculate target-msc by the specified modulo parameters. According
+     * to Present protocol this is after the next field with:
+     *
+     *      field-msc % divisor == remainder.
+     *
+     * The following formula calculates a target_msc solving above equation
+     * and with |target_msc - crtc_msc| < divisor.
+     *
+     * Example with crtc_msc = 10, divisor = 4 and remainder = 3, 2, 1, 0:
+     *      11 = 10 - 2 + 3 = 10 - (10 % 4) + 3,
+     *      10 = 10 - 2 + 2 = 10 - (10 % 4) + 2,
+     *       9 = 10 - 2 + 1 = 10 - (10 % 4) + 1,
+     *       8 = 10 - 2 + 0 = 10 - (10 % 4) + 0.
+     */
+    target_msc = crtc_msc - (crtc_msc % divisor) + remainder;
+
+    /* Here we already found the correct field-msc. */
+    if (msc_is_after(target_msc, crtc_msc))
+        return target_msc;
+    /*
+     * Here either:
+     * a) target_msc == crtc_msc, i.e. crtc_msc actually solved
+     * above equation with crtc_msc % divisor == remainder.
+     *
+     * => This means we want to present at target_msc + divisor for a synced
+     *    flip or directly now for an async flip.
+     *
+     * b) target_msc < crtc_msc with target_msc + divisor > crtc_msc.
+     *
+     * => This means in any case we want to present at target_msc + divisor.
+     */
+    if (synced_flip || msc_is_after(crtc_msc, target_msc))
+        target_msc += divisor;
     return target_msc;
 }
 
diff --git a/present/present_priv.h b/present/present_priv.h
index 3205d033d..2bd6b4062 100644
--- a/present/present_priv.h
+++ b/present/present_priv.h
@@ -280,11 +280,11 @@ present_set_tree_pixmap(WindowPtr window,
                         PixmapPtr pixmap);
 
 uint64_t
-present_get_target_msc(uint32_t options,
+present_get_target_msc(uint64_t target_msc_arg,
                        uint64_t crtc_msc,
-                       uint64_t target_msc,
                        uint64_t divisor,
-                       uint64_t remainder);
+                       uint64_t remainder,
+                       uint32_t options);
 
 int
 present_pixmap(WindowPtr window,
diff --git a/present/present_scmd.c b/present/present_scmd.c
index 88c6ebbf7..8bf8fc1d5 100644
--- a/present/present_scmd.c
+++ b/present/present_scmd.c
@@ -690,11 +690,11 @@ present_scmd_pixmap(WindowPtr window,
         window_priv->msc = crtc_msc;
     }
 
-    target_msc = present_get_target_msc(options,
+    target_msc = present_get_target_msc(target_msc,
                                         crtc_msc,
-                                        target_msc,
                                         divisor,
-                                        remainder);
+                                        remainder,
+                                        options);
 
     /*
      * Look for a matching presentation already on the list and
diff --git a/present/present_wnmd.c b/present/present_wnmd.c
index f09e320aa..91aab985c 100644
--- a/present/present_wnmd.c
+++ b/present/present_wnmd.c
@@ -582,11 +582,11 @@ present_wnmd_pixmap(WindowPtr window,
         window_priv->msc = crtc_msc;
     }
 
-    target_msc = present_get_target_msc(options,
+    target_msc = present_get_target_msc(target_msc,
                                         crtc_msc,
-                                        target_msc,
                                         divisor,
-                                        remainder);
+                                        remainder,
+                                        options);
 
     /*
      * Look for a matching presentation already on the list...
commit 99e55f1b955e2db442184756fcd8b95791fd71de
Author: Roman Gilg <subdiff at gmail.com>
Date:   Mon May 27 22:32:22 2019 +0200

    present: Adjust timings with value arguments
    
    We can use value arguments instead of pointers when adjusting the timings
    by returning the adjusted value. This improves the readability.
    
    Signed-off-by: Roman Gilg <subdiff at gmail.com>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/present/present.c b/present/present.c
index 3eddb7434..1a2163cdc 100644
--- a/present/present.c
+++ b/present/present.c
@@ -157,31 +157,32 @@ present_can_window_flip(WindowPtr window)
     return screen_priv->can_window_flip(window);
 }
 
-void
-present_adjust_timings(uint32_t options,
-                       uint64_t *crtc_msc,
-                       uint64_t *target_msc,
+uint64_t
+present_get_target_msc(uint32_t options,
+                       uint64_t crtc_msc,
+                       uint64_t target_msc,
                        uint64_t divisor,
                        uint64_t remainder)
 {
     /* Adjust target_msc to match modulus
      */
-    if (msc_is_equal_or_after(*crtc_msc, *target_msc)) {
+    if (msc_is_equal_or_after(crtc_msc, target_msc)) {
         if (divisor != 0) {
-            *target_msc = *crtc_msc - (*crtc_msc % divisor) + remainder;
+            target_msc = crtc_msc - (crtc_msc % divisor) + remainder;
             if (options & PresentOptionAsync) {
-                if (msc_is_after(*crtc_msc, *target_msc))
-                    *target_msc += divisor;
+                if (msc_is_after(crtc_msc, target_msc))
+                    target_msc += divisor;
             } else {
-                if (msc_is_equal_or_after(*crtc_msc, *target_msc))
-                    *target_msc += divisor;
+                if (msc_is_equal_or_after(crtc_msc, target_msc))
+                    target_msc += divisor;
             }
         } else {
-            *target_msc = *crtc_msc;
+            target_msc = crtc_msc;
             if (!(options & PresentOptionAsync))
-                (*target_msc)++;
+                (target_msc)++;
         }
     }
+    return target_msc;
 }
 
 int
diff --git a/present/present_priv.h b/present/present_priv.h
index 5849b9e0b..3205d033d 100644
--- a/present/present_priv.h
+++ b/present/present_priv.h
@@ -279,10 +279,10 @@ present_set_tree_pixmap(WindowPtr window,
                         PixmapPtr expected,
                         PixmapPtr pixmap);
 
-void
-present_adjust_timings(uint32_t options,
-                       uint64_t *crtc_msc,
-                       uint64_t *target_msc,
+uint64_t
+present_get_target_msc(uint32_t options,
+                       uint64_t crtc_msc,
+                       uint64_t target_msc,
                        uint64_t divisor,
                        uint64_t remainder);
 
diff --git a/present/present_scmd.c b/present/present_scmd.c
index 8417d0925..88c6ebbf7 100644
--- a/present/present_scmd.c
+++ b/present/present_scmd.c
@@ -690,11 +690,11 @@ present_scmd_pixmap(WindowPtr window,
         window_priv->msc = crtc_msc;
     }
 
-    present_adjust_timings(options,
-                           &crtc_msc,
-                           &target_msc,
-                           divisor,
-                           remainder);
+    target_msc = present_get_target_msc(options,
+                                        crtc_msc,
+                                        target_msc,
+                                        divisor,
+                                        remainder);
 
     /*
      * Look for a matching presentation already on the list and
diff --git a/present/present_wnmd.c b/present/present_wnmd.c
index 82bae4022..f09e320aa 100644
--- a/present/present_wnmd.c
+++ b/present/present_wnmd.c
@@ -582,11 +582,11 @@ present_wnmd_pixmap(WindowPtr window,
         window_priv->msc = crtc_msc;
     }
 
-    present_adjust_timings(options,
-                           &crtc_msc,
-                           &target_msc,
-                           divisor,
-                           remainder);
+    target_msc = present_get_target_msc(options,
+                                        crtc_msc,
+                                        target_msc,
+                                        divisor,
+                                        remainder);
 
     /*
      * Look for a matching presentation already on the list...


More information about the xorg-commit mailing list