[RFC xserver v3 04/14] modesetting: Refactor xf86FindCrtcCoveringDrawable out of the driver

Louis-Francis Ratté-Boulianne lfrb at collabora.com
Wed Sep 27 05:19:03 UTC 2017


The functions will be needed outside of the driver.

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
---
 hw/xfree86/drivers/modesetting/dri2.c            |   8 +-
 hw/xfree86/drivers/modesetting/driver.h          |   4 -
 hw/xfree86/drivers/modesetting/drmmode_display.c |   9 ++
 hw/xfree86/drivers/modesetting/pageflip.c        |   2 +-
 hw/xfree86/drivers/modesetting/present.c         |   4 +-
 hw/xfree86/drivers/modesetting/vblank.c          | 122 ----------------------
 hw/xfree86/modes/xf86Crtc.c                      | 125 +++++++++++++++++++++++
 hw/xfree86/modes/xf86Crtc.h                      |  21 +++-
 8 files changed, 161 insertions(+), 134 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
index bfaea3b84..f60d337de 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -350,7 +350,7 @@ static int
 ms_dri2_get_msc(DrawablePtr draw, CARD64 *ust, CARD64 *msc)
 {
     int ret;
-    xf86CrtcPtr crtc = ms_dri2_crtc_covering_drawable(draw);
+    xf86CrtcPtr crtc = xf86FindCrtcCoveringDrawable(draw);
 
     /* Drawable not displayed, make up a *monotonic* value */
     if (crtc == NULL) {
@@ -546,7 +546,7 @@ can_exchange(ScrnInfoPtr scrn, DrawablePtr draw,
             return FALSE;
 #endif
 
-        if (ms_crtc_on(config->crtc[i]))
+        if (xf86CrtcIsEnabled(config->crtc[i]))
             num_crtcs_on++;
     }
 
@@ -699,7 +699,7 @@ ms_dri2_schedule_wait_msc(ClientPtr client, DrawablePtr draw, CARD64 target_msc,
     ms_dri2_frame_event_ptr wait_info;
     drmVBlank vbl;
     int ret;
-    xf86CrtcPtr crtc = ms_dri2_crtc_covering_drawable(draw);
+    xf86CrtcPtr crtc = xf86FindCrtcCoveringDrawable(draw);
     drmmode_crtc_private_ptr drmmode_crtc;
     CARD64 current_msc, current_ust, request_msc;
     uint32_t seq;
@@ -842,7 +842,7 @@ ms_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
     modesettingPtr ms = modesettingPTR(scrn);
     drmVBlank vbl;
     int ret, flip = 0;
-    xf86CrtcPtr crtc = ms_dri2_crtc_covering_drawable(draw);
+    xf86CrtcPtr crtc = xf86FindCrtcCoveringDrawable(draw);
     drmmode_crtc_private_ptr drmmode_crtc;
     ms_dri2_frame_event_ptr frame_info = NULL;
     uint64_t current_msc, current_ust;
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index bfdc66c89..2ffbc96b6 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -126,10 +126,6 @@ void ms_drm_abort(ScrnInfoPtr scrn,
                   void *match_data);
 void ms_drm_abort_seq(ScrnInfoPtr scrn, uint32_t seq);
 
-Bool ms_crtc_on(xf86CrtcPtr crtc);
-
-xf86CrtcPtr ms_dri2_crtc_covering_drawable(DrawablePtr pDraw);
-
 int ms_get_crtc_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc);
 
 uint32_t ms_crtc_msc_to_kernel_msc(xf86CrtcPtr crtc, uint64_t expect);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index fec7ac276..53188be78 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1098,6 +1098,14 @@ drmmode_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
     }
 }
 
+static Bool
+drmmode_crtc_is_enabled(xf86CrtcPtr crtc)
+{
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+    return crtc->enabled && drmmode_crtc->dpms_mode == DPMSModeOn;
+}
+
 static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
     .dpms = drmmode_crtc_dpms,
     .set_mode_major = drmmode_set_mode_major,
@@ -1113,6 +1121,7 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
     .shadow_allocate = drmmode_shadow_allocate,
     .shadow_create = drmmode_shadow_create,
     .shadow_destroy = drmmode_shadow_destroy,
+    .is_enabled = drmmode_crtc_is_enabled,
 };
 
 static uint32_t
diff --git a/hw/xfree86/drivers/modesetting/pageflip.c b/hw/xfree86/drivers/modesetting/pageflip.c
index d5fd0625b..427272a34 100644
--- a/hw/xfree86/drivers/modesetting/pageflip.c
+++ b/hw/xfree86/drivers/modesetting/pageflip.c
@@ -295,7 +295,7 @@ ms_do_pageflip(ScreenPtr screen,
     for (i = 0; i < config->num_crtc; i++) {
         xf86CrtcPtr crtc = config->crtc[i];
 
-        if (!ms_crtc_on(crtc))
+        if (!xf86CrtcIsEnabled(crtc))
             continue;
 
         if (!queue_flip_on_crtc(screen, crtc, flipdata,
diff --git a/hw/xfree86/drivers/modesetting/present.c b/hw/xfree86/drivers/modesetting/present.c
index fcff8ee16..b69415b2f 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -59,7 +59,7 @@ struct ms_present_vblank_event {
 static RRCrtcPtr
 ms_present_get_crtc(WindowPtr window)
 {
-    xf86CrtcPtr xf86_crtc = ms_dri2_crtc_covering_drawable(&window->drawable);
+    xf86CrtcPtr xf86_crtc = xf86FindCrtcCoveringDrawable(&window->drawable);
     return xf86_crtc ? xf86_crtc->randr_crtc : NULL;
 }
 
@@ -258,7 +258,7 @@ ms_present_check_flip(RRCrtcPtr crtc,
         if (drmmode_crtc->rotate_bo.gbm)
             return FALSE;
 
-        if (ms_crtc_on(config->crtc[i]))
+        if (xf86CrtcIsEnabled(config->crtc[i]))
             num_crtcs_on++;
     }
 
diff --git a/hw/xfree86/drivers/modesetting/vblank.c b/hw/xfree86/drivers/modesetting/vblank.c
index 8682f4d91..93ae41df9 100644
--- a/hw/xfree86/drivers/modesetting/vblank.c
+++ b/hw/xfree86/drivers/modesetting/vblank.c
@@ -49,128 +49,6 @@
 static struct xorg_list ms_drm_queue;
 static uint32_t ms_drm_seq;
 
-static void ms_box_intersect(BoxPtr dest, BoxPtr a, BoxPtr b)
-{
-    dest->x1 = a->x1 > b->x1 ? a->x1 : b->x1;
-    dest->x2 = a->x2 < b->x2 ? a->x2 : b->x2;
-    if (dest->x1 >= dest->x2) {
-        dest->x1 = dest->x2 = dest->y1 = dest->y2 = 0;
-        return;
-    }
-
-    dest->y1 = a->y1 > b->y1 ? a->y1 : b->y1;
-    dest->y2 = a->y2 < b->y2 ? a->y2 : b->y2;
-    if (dest->y1 >= dest->y2)
-        dest->x1 = dest->x2 = dest->y1 = dest->y2 = 0;
-}
-
-static void ms_crtc_box(xf86CrtcPtr crtc, BoxPtr crtc_box)
-{
-    if (crtc->enabled) {
-        crtc_box->x1 = crtc->x;
-        crtc_box->x2 =
-            crtc->x + xf86ModeWidth(&crtc->mode, crtc->rotation);
-        crtc_box->y1 = crtc->y;
-        crtc_box->y2 =
-            crtc->y + xf86ModeHeight(&crtc->mode, crtc->rotation);
-    } else
-        crtc_box->x1 = crtc_box->x2 = crtc_box->y1 = crtc_box->y2 = 0;
-}
-
-static int ms_box_area(BoxPtr box)
-{
-    return (int)(box->x2 - box->x1) * (int)(box->y2 - box->y1);
-}
-
-Bool
-ms_crtc_on(xf86CrtcPtr crtc)
-{
-    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-
-    return crtc->enabled && drmmode_crtc->dpms_mode == DPMSModeOn;
-}
-
-/*
- * Return the crtc covering 'box'. If two crtcs cover a portion of
- * 'box', then prefer the crtc with greater coverage.
- */
-
-static xf86CrtcPtr
-ms_covering_crtc(ScreenPtr pScreen, BoxPtr box, Bool screen_is_ms)
-{
-    ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
-    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
-    xf86CrtcPtr crtc, best_crtc;
-    int coverage, best_coverage;
-    int c;
-    BoxRec crtc_box, cover_box;
-    Bool crtc_on;
-
-    best_crtc = NULL;
-    best_coverage = 0;
-    for (c = 0; c < xf86_config->num_crtc; c++) {
-        crtc = xf86_config->crtc[c];
-
-        if (screen_is_ms)
-            crtc_on = ms_crtc_on(crtc);
-        else
-            crtc_on = crtc->enabled;
-
-        /* If the CRTC is off, treat it as not covering */
-        if (!crtc_on)
-            continue;
-
-        ms_crtc_box(crtc, &crtc_box);
-        ms_box_intersect(&cover_box, &crtc_box, box);
-        coverage = ms_box_area(&cover_box);
-        if (coverage > best_coverage) {
-            best_crtc = crtc;
-            best_coverage = coverage;
-        }
-    }
-
-    /* Fallback to primary crtc for drawable's on slave outputs */
-    if (best_crtc == NULL && !pScreen->isGPU) {
-        RROutputPtr primary_output = NULL;
-        ScreenPtr slave;
-
-        if (dixPrivateKeyRegistered(rrPrivKey))
-            primary_output = RRFirstOutput(scrn->pScreen);
-        if (!primary_output || !primary_output->crtc)
-            return NULL;
-
-        crtc = primary_output->crtc->devPrivate;
-        if (!ms_crtc_on(crtc))
-            return NULL;
-
-        xorg_list_for_each_entry(slave, &pScreen->slave_list, slave_head) {
-            if (!slave->is_output_slave)
-                continue;
-
-            if (ms_covering_crtc(slave, box, FALSE)) {
-                /* The drawable is on a slave output, return primary crtc */
-                return crtc;
-            }
-        }
-    }
-
-    return best_crtc;
-}
-
-xf86CrtcPtr
-ms_dri2_crtc_covering_drawable(DrawablePtr pDraw)
-{
-    ScreenPtr pScreen = pDraw->pScreen;
-    BoxRec box;
-
-    box.x1 = pDraw->x;
-    box.y1 = pDraw->y;
-    box.x2 = box.x1 + pDraw->width;
-    box.y2 = box.y1 + pDraw->height;
-
-    return ms_covering_crtc(pScreen, &box, TRUE);
-}
-
 static Bool
 ms_get_kernel_ust_msc(xf86CrtcPtr crtc,
                       uint32_t *msc, uint64_t *ust)
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index fa404d9d4..c322dceba 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -174,6 +174,131 @@ xf86CrtcInUse(xf86CrtcPtr crtc)
     return FALSE;
 }
 
+Bool
+xf86CrtcIsEnabled(xf86CrtcPtr crtc)
+{
+    if (crtc->funcs->is_enabled)
+        return crtc->funcs->is_enabled(crtc);
+    return crtc->enabled;
+}
+
+static void
+BoxIntersect(BoxPtr dest, BoxPtr a, BoxPtr b)
+{
+    dest->x1 = a->x1 > b->x1 ? a->x1 : b->x1;
+    dest->x2 = a->x2 < b->x2 ? a->x2 : b->x2;
+    if (dest->x1 >= dest->x2) {
+        dest->x1 = dest->x2 = dest->y1 = dest->y2 = 0;
+        return;
+    }
+
+    dest->y1 = a->y1 > b->y1 ? a->y1 : b->y1;
+    dest->y2 = a->y2 < b->y2 ? a->y2 : b->y2;
+    if (dest->y1 >= dest->y2)
+        dest->x1 = dest->x2 = dest->y1 = dest->y2 = 0;
+}
+
+static void
+xf86CrtcBox(xf86CrtcPtr crtc, BoxPtr crtc_box)
+{
+    if (crtc->enabled) {
+        crtc_box->x1 = crtc->x;
+        crtc_box->x2 =
+            crtc->x + xf86ModeWidth(&crtc->mode, crtc->rotation);
+        crtc_box->y1 = crtc->y;
+        crtc_box->y2 =
+            crtc->y + xf86ModeHeight(&crtc->mode, crtc->rotation);
+    } else
+        crtc_box->x1 = crtc_box->x2 = crtc_box->y1 = crtc_box->y2 = 0;
+}
+
+static int
+BoxArea(BoxPtr box)
+{
+    return (int)(box->x2 - box->x1) * (int)(box->y2 - box->y1);
+}
+
+static xf86CrtcPtr
+CoveringCrtc(ScreenPtr pScreen, BoxPtr box, Bool is_slave)
+{
+    ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    xf86CrtcPtr crtc, best_crtc;
+    int coverage, best_coverage;
+    int c;
+    BoxRec crtc_box, cover_box;
+    Bool crtc_on;
+
+    best_crtc = NULL;
+    best_coverage = 0;
+    for (c = 0; c < xf86_config->num_crtc; c++) {
+        crtc = xf86_config->crtc[c];
+
+        if (is_slave)
+            crtc_on = crtc->enabled;
+        else
+            crtc_on = xf86CrtcIsEnabled(crtc);
+
+        /* If the CRTC is off, treat it as not covering */
+        if (!crtc_on)
+            continue;
+
+        xf86CrtcBox(crtc, &crtc_box);
+        BoxIntersect(&cover_box, &crtc_box, box);
+        coverage = BoxArea(&cover_box);
+        if (coverage > best_coverage) {
+            best_crtc = crtc;
+            best_coverage = coverage;
+        }
+    }
+
+    /* Fallback to primary crtc for drawable's on slave outputs */
+    if (best_crtc == NULL && !pScreen->isGPU) {
+        RROutputPtr primary_output = NULL;
+        ScreenPtr slave;
+
+        if (dixPrivateKeyRegistered(rrPrivKey))
+            primary_output = RRFirstOutput(scrn->pScreen);
+        if (!primary_output || !primary_output->crtc)
+            return NULL;
+
+        crtc = primary_output->crtc->devPrivate;
+        if (!xf86CrtcIsEnabled(crtc))
+            return NULL;
+
+        xorg_list_for_each_entry(slave, &pScreen->slave_list, slave_head) {
+            if (!slave->is_output_slave)
+                continue;
+
+            if (CoveringCrtc(slave, box, TRUE)) {
+                /* The drawable is on a slave output, return primary crtc */
+                return crtc;
+            }
+        }
+    }
+
+    return best_crtc;
+}
+
+/**
+ * Return crtc covering the drawable area. If two crtcs cover a portion
+ * of the drawable, then prefer the crtc with greater coverage.
+ */
+
+xf86CrtcPtr
+xf86FindCrtcCoveringDrawable(DrawablePtr pDraw)
+{
+    ScreenPtr pScreen = pDraw->pScreen;
+    BoxRec box;
+
+    box.x1 = pDraw->x;
+    box.y1 = pDraw->y;
+    box.x2 = box.x1 + pDraw->width;
+    box.y2 = box.y1 + pDraw->height;
+
+    return CoveringCrtc(pScreen, &box, FALSE);
+}
+
 void
 xf86CrtcSetScreenSubpixelOrder(ScreenPtr pScreen)
 {
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 215eb2a04..3d7956af5 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -245,9 +245,16 @@ typedef struct _xf86CrtcFuncs {
     Bool
     (*set_scanout_pixmap)(xf86CrtcPtr crtc, PixmapPtr pixmap);
 
+    /*
+     * Returns whether the CRTC is enabled.
+     * Added in ABI version 8
+     */
+    Bool
+    (*is_enabled)(xf86CrtcPtr crtc);
+
 } xf86CrtcFuncsRec, *xf86CrtcFuncsPtr;
 
-#define XF86_CRTC_VERSION 7
+#define XF86_CRTC_VERSION 8
 
 struct _xf86Crtc {
     /**
@@ -859,6 +866,18 @@ extern _X_EXPORT void
 extern _X_EXPORT Bool
  xf86CrtcInUse(xf86CrtcPtr crtc);
 
+/**
+ * Return whether the crtc is enabled
+ */
+extern _X_EXPORT Bool
+ xf86CrtcIsEnabled(xf86CrtcPtr crtc);
+
+/**
+ * Return the crtc covering the drawable area.
+ */
+extern _X_EXPORT xf86CrtcPtr
+ xf86FindCrtcCoveringDrawable(DrawablePtr pDraw);
+
 /*
  * Output functions
  */
-- 
2.13.0



More information about the xorg-devel mailing list