<div dir="ltr"><div>Hi Roman,<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 3, 2018 at 1:13 AM, Roman Gilg <span dir="ltr"><<a href="mailto:subdiff@gmail.com" target="_blank">subdiff@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">For backwards compatibility a driver supporting window flip mode still must<br>
calculate msc values per CRTC.<br>
<br>
It is important that the driver returns the msc for the CRTC that Present<br>
requests the msc for or return an error if this is not possible.<br>
<br>
This way Present can calculate the offset correctly in<br>
present_wnmd_window_to_crtc_<wbr>msc.<br>
<br>
Signed-off-by: Roman Gilg <<a href="mailto:subdiff@gmail.com">subdiff@gmail.com</a>><br>
---<br>
 hw/xwayland/xwayland-present.c | 10 +++++++++-<br>
 present/present.h              |  2 +-<br>
 present/present_wnmd.c         | 14 +++++++++-----<br>
 3 files changed, 19 insertions(+), 7 deletions(-)<br>
<br>
diff --git a/hw/xwayland/xwayland-<wbr>present.c b/hw/xwayland/xwayland-<wbr>present.c<br>
index 66bfaae..adc3a68 100644<br>
--- a/hw/xwayland/xwayland-<wbr>present.c<br>
+++ b/hw/xwayland/xwayland-<wbr>present.c<br>
@@ -258,11 +258,19 @@ xwl_present_get_crtc(WindowPtr present_window)<br>
 }<br>
<br>
 static int<br>
-xwl_present_get_ust_msc(<wbr>WindowPtr present_window, uint64_t *ust, uint64_t *msc)<br>
+xwl_present_get_ust_msc(<wbr>WindowPtr present_window, RRCrtcPtr crtc, uint64_t *ust, uint64_t *msc)<br>
 {<br>
     struct xwl_window *xwl_window = xwl_window_from_window(<wbr>present_window);<br>
     if (!xwl_window)<br>
         return BadAlloc;<br>
+<br>
+    if (xwl_window->present_crtc_fake != crtc) {<br>
+        /* the crtc changed between the last call and this one,<br>
+         * falls back to using the saved window msc in Present<br>
+         */<br>
+        return BadMatch;<br>
+    }<br>
+<br>
     *ust = xwl_window->present_ust;<br>
     *msc = xwl_window->present_msc;<br>
<br>
diff --git a/present/present.h b/present/present.h<br>
index 3d0b972..0a3682c 100644<br>
--- a/present/present.h<br>
+++ b/present/present.h<br>
@@ -41,7 +41,7 @@ typedef RRCrtcPtr (*present_get_crtc_ptr) (WindowPtr window);<br>
 /* Return the current ust/msc for 'crtc'<br>
  */<br>
 typedef int (*present_get_ust_msc_ptr) (RRCrtcPtr crtc, uint64_t *ust, uint64_t *msc);<br>
-typedef int (*present_wnmd_get_ust_msc_<wbr>ptr) (WindowPtr window, uint64_t *ust, uint64_t *msc);<br>
+typedef int (*present_wnmd_get_ust_msc_<wbr>ptr) (WindowPtr window, RRCrtcPtr crtc, uint64_t *ust, uint64_t *msc);<br></blockquote><div><br><br></div><div>Unfortunately, this is an API/ABI change, I am not sure this is possible at this point in time wrt the release even though present_wnmd*() is presumably used only by Xwayland at the moment if I understand correctly. I'll leave that to Adam to decide.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

 /* Queue callback on 'crtc' for time 'msc'. Call present_event_notify with 'event_id'<br>
  * at or after 'msc'. Return false if it didn't happen (which might occur if 'crtc'<br>
diff --git a/present/present_wnmd.c b/present/present_wnmd.c<br>
index 80ffb01..c95bc92 100644<br>
--- a/present/present_wnmd.c<br>
+++ b/present/present_wnmd.c<br>
@@ -61,10 +61,10 @@ present_wnmd_get_crtc(present_<wbr>screen_priv_ptr screen_priv, WindowPtr window)<br>
 }<br>
<br>
 static int<br>
-present_wnmd_get_ust_msc(<wbr>ScreenPtr screen, WindowPtr window, uint64_t *ust, uint64_t *msc)<br>
+present_wnmd_get_ust_msc(<wbr>ScreenPtr screen, WindowPtr window, RRCrtcPtr crtc, uint64_t *ust, uint64_t *msc)<br>
 {<br>
     present_screen_priv_ptr screen_priv = present_screen_priv(screen);<br>
-    return (*screen_priv->wnmd_info->get_<wbr>ust_msc)(window, ust, msc);<br>
+    return (*screen_priv->wnmd_info->get_<wbr>ust_msc)(window, crtc, ust, msc);<br>
 }<br>
<br>
 /*<br>
@@ -76,7 +76,7 @@ present_wnmd_re_execute(<wbr>present_vblank_ptr vblank)<br>
 {<br>
     uint64_t ust = 0, crtc_msc = 0;<br>
<br>
-    (void) present_wnmd_get_ust_msc(<wbr>vblank->screen, vblank->window, &ust, &crtc_msc);<br>
+    (void) present_wnmd_get_ust_msc(<wbr>vblank->screen, vblank->window, vblank->crtc, &ust, &crtc_msc);<br>
     present_wnmd_execute(vblank, ust, crtc_msc);<br>
 }<br>
<br>
@@ -518,6 +518,7 @@ present_wnmd_window_to_crtc_<wbr>msc(WindowPtr window, RRCrtcPtr crtc, uint64_t windo<br>
     present_window_priv_ptr window_priv = present_get_window_priv(<wbr>window, TRUE);<br>
<br>
     if (crtc != window_priv->crtc) {<br>
+        uint64_t old_ust, old_msc;<br>
         if (window_priv->crtc == PresentCrtcNeverSet) {<br>
             window_priv->msc_offset = 0;<br>
         } else {<br>
@@ -525,7 +526,10 @@ present_wnmd_window_to_crtc_<wbr>msc(WindowPtr window, RRCrtcPtr crtc, uint64_t windo<br>
              * we'll just use whatever previous MSC we'd seen from this CRTC<br>
              */<br>
<br>
-            window_priv->msc_offset += new_msc - window_priv->msc;<br>
+            if (present_wnmd_get_ust_msc(<wbr>window->drawable.pScreen, window, window_priv->crtc, &old_ust, &old_msc) != Success)<br>
+                old_msc = window_priv->msc;<br>
+<br>
+            window_priv->msc_offset += new_msc - old_msc;<br>
         }<br>
         window_priv->crtc = crtc;<br>
     }<br>
@@ -565,7 +569,7 @@ present_wnmd_pixmap(WindowPtr window,<br>
<br>
     target_crtc = present_wnmd_get_crtc(screen_<wbr>priv, window);<br>
<br>
-    ret = present_wnmd_get_ust_msc(<wbr>screen, window, &ust, &crtc_msc);<br>
+    ret = present_wnmd_get_ust_msc(<wbr>screen, window, target_crtc, &ust, &crtc_msc);<br>
<br>
     target_msc = present_wnmd_window_to_crtc_<wbr>msc(window, target_crtc, window_msc, crtc_msc);<br>
<span class="HOEnZb"><font color="#888888"> <br>
-- <br>
2.7.4<br>
<br>
______________________________<wbr>_________________<br>
<a href="mailto:xorg-devel@lists.x.org">xorg-devel@lists.x.org</a>: X.Org development<br>
Archives: <a href="http://lists.x.org/archives/xorg-devel" rel="noreferrer" target="_blank">http://lists.x.org/archives/<wbr>xorg-devel</a><br>
Info: <a href="https://lists.x.org/mailman/listinfo/xorg-devel" rel="noreferrer" target="_blank">https://lists.x.org/mailman/<wbr>listinfo/xorg-devel</a></font></span></blockquote><div><br></div><div>Regardless of the API/ABI change, this patch fixes the issue in the reproducer, so:<br><br></div><div>Tested-by: Olivier Fourdan <<a href="mailto:ofourdan@redhat.com">ofourdan@redhat.com</a>><br><br></div><div>Cheers,<br></div><div>Olivier<br></div></div><br></div></div>