[PATCH v6 04/11] modesetting: Internal storage of scanout pixmaps

Alex Goins agoins at nvidia.com
Sat Jun 11 00:20:58 UTC 2016


modesetting relied on randr_crtc->scanout_pixmap being consistent with
calls to SetScanoutPixmap, which is very fragile and makes a lot of
assumptions about the caller's behavior.

For example, RRReplaceScanoutPixmap(), when dropping off with !size_fits,
will set randr_crtc->scanout_pixmap = NULL and then call SetScanoutPixmap.
Without this patch, drmmode_set_scanout_pixmap_(cpu/gpu) will think that
there is no scanout pixmap to tear down, because it's already been set to
NULL.

By keeping track of the scanout pixmap in its internal state, modesetting
can avoid these types of bugs and reduce constraints on calling
conventions.

v1: N/A
v2: N/A
v3: N/A
v4: N/A
v5: Initial commit
v6: Rebase onto ToT

Signed-off-by: Alex Goins <agoins at nvidia.com>
---
 hw/xfree86/drivers/modesetting/driver.c          |  9 +++++----
 hw/xfree86/drivers/modesetting/drmmode_display.c | 22 ++++++++++++++--------
 hw/xfree86/drivers/modesetting/drmmode_display.h |  3 +++
 3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 1604044..0059e56 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -532,10 +532,10 @@ static void
 dispatch_dirty_crtc(ScrnInfoPtr scrn, xf86CrtcPtr crtc)
 {
     modesettingPtr ms = modesettingPTR(scrn);
-    PixmapPtr pixmap = crtc->randr_crtc->scanout_pixmap;
-    msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, pixmap);
     drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    PixmapPtr pixmap = drmmode_crtc->prime_pixmap;
     DamagePtr damage = drmmode_crtc->slave_damage;
+    msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, pixmap);
     int fb_id = ppriv->fb_id;
     int ret;
 
@@ -554,10 +554,11 @@ dispatch_slave_dirty(ScreenPtr pScreen)
 
     for (c = 0; c < xf86_config->num_crtc; c++) {
         xf86CrtcPtr crtc = xf86_config->crtc[c];
+        drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 
-        if (!crtc->randr_crtc)
+        if (!drmmode_crtc)
             continue;
-        if (!crtc->randr_crtc->scanout_pixmap)
+        if (!drmmode_crtc->prime_pixmap)
             continue;
 
         dispatch_dirty_crtc(scrn, crtc);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index d192d05..e92d1e2 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -470,10 +470,10 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
         drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
 
         fb_id = drmmode->fb_id;
-        if (crtc->randr_crtc->scanout_pixmap) {
+        if (drmmode_crtc->prime_pixmap) {
             if (!drmmode->reverse_prime_offload_mode) {
                 msPixmapPrivPtr ppriv =
-                    msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
+                    msGetPixmapPriv(drmmode, drmmode_crtc->prime_pixmap);
                 fb_id = ppriv->fb_id;
                 x = 0;
             } else
@@ -638,8 +638,8 @@ drmmode_set_scanout_pixmap_gpu(xf86CrtcPtr crtc, PixmapPtr ppix)
     int c, total_width = 0, max_height = 0, this_x = 0;
 
     if (!ppix) {
-        if (crtc->randr_crtc->scanout_pixmap)
-            PixmapStopDirtyTracking(crtc->randr_crtc->scanout_pixmap, screenpix);
+        if (drmmode_crtc->prime_pixmap)
+            PixmapStopDirtyTracking(drmmode_crtc->prime_pixmap, screenpix);
         drmmode_crtc->prime_pixmap_x = 0;
         return TRUE;
     }
@@ -684,8 +684,8 @@ drmmode_set_scanout_pixmap_cpu(xf86CrtcPtr crtc, PixmapPtr ppix)
     void *ptr;
 
     if (!ppix) {
-        if (crtc->randr_crtc->scanout_pixmap) {
-            ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
+        if (drmmode_crtc->prime_pixmap) {
+            ppriv = msGetPixmapPriv(drmmode, drmmode_crtc->prime_pixmap);
             drmModeRmFB(drmmode->fd, ppriv->fb_id);
         }
         if (drmmode_crtc->slave_damage) {
@@ -720,13 +720,19 @@ drmmode_set_scanout_pixmap_cpu(xf86CrtcPtr crtc, PixmapPtr ppix)
 static Bool
 drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 {
+    Bool ret;
     drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
     drmmode_ptr drmmode = drmmode_crtc->drmmode;
 
     if (drmmode->reverse_prime_offload_mode)
-        return drmmode_set_scanout_pixmap_gpu(crtc, ppix);
+        ret = drmmode_set_scanout_pixmap_gpu(crtc, ppix);
     else
-        return drmmode_set_scanout_pixmap_cpu(crtc, ppix);
+        ret = drmmode_set_scanout_pixmap_cpu(crtc, ppix);
+
+    if (ret)
+        drmmode_crtc->prime_pixmap = ppix;
+
+    return ret;
 }
 
 static void *
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 6b94641..36c6e91 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -103,7 +103,10 @@ typedef struct {
 
     drmmode_bo rotate_bo;
     unsigned rotate_fb_id;
+
+    PixmapPtr prime_pixmap;
     unsigned prime_pixmap_x;
+
     /**
      * @{ MSC (vblank count) handling for the PRESENT extension.
      *
-- 
1.9.1



More information about the xorg-devel mailing list