[Openchrome-devel] xf86-video-openchrome: src/via_kms.c

James Simmons jsimmons at kemper.freedesktop.org
Sun May 19 12:41:02 PDT 2013


 src/via_kms.c |  131 +++++++++++++++++++---------------------------------------
 1 file changed, 45 insertions(+), 86 deletions(-)

New commits:
commit 42d7ac70e3e9735619690a86482954827936d169
Author: James Simmons <jsimmons at infradead.org>
Date:   Sun May 19 15:13:28 2013 -0400

    In our driver in order to support both KMS and UMS we can't call drmmode_set_mode_major directly but instead
    call xf86CrtcSetMode or alike functions. All those xorg methods are wrappers around xf86CrtcSetModeTransform
    which does the handling of restoring the mode in failure cases. If you look at drmmode_set_mode_major it also
    does the the same error handling because the was copied from drivers that directly called it. Since this is
    not the case for us we can make drmmode_set_mode_major much simpler and depend on xf86CrtcSetModeTransform to
    handle failures for us.

diff --git a/src/via_kms.c b/src/via_kms.c
index c0e8b52..9547d5d 100644
--- a/src/via_kms.c
+++ b/src/via_kms.c
@@ -160,120 +160,79 @@ static Bool
 drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
                         Rotation rotation, int x, int y)
 {
-    ScrnInfoPtr pScrn = crtc->scrn;
-    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
     drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
     drmmode_ptr drmmode = drmmode_crtc->drmmode;
-    int saved_x, saved_y;
-    Rotation saved_rotation;
-    DisplayModeRec saved_mode;
-    uint32_t *output_ids;
-    int output_count = 0;
-    Bool ret = TRUE;
-    int i;
-    int fb_id;
+    ScrnInfoPtr pScrn = crtc->scrn;
+    int output_count = 0, ret, i;
+    uint32_t *output_ids = NULL;
     drmModeModeInfo kmode;
-    int height;
 
-    height = pScrn->virtualY;
+    if (!mode || !xf86CrtcRotate(crtc))
+        return FALSE;
+
+    output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
+    if (!output_ids)
+        return FALSE;
+
+    for (i = 0; i < xf86_config->num_output; i++) {
+        xf86OutputPtr output = xf86_config->output[i];
+        drmmode_output_private_ptr drmmode_output;
+
+        if (output->crtc != crtc)
+            continue;
+
+        drmmode_output = output->driver_private;
+        output_ids[output_count] = drmmode_output->mode_output->connector_id;
+        output_count++;
+    }
+
+    xf86SetModeDefaultName(mode);
+    drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
 
     if (drmmode->fb_id == 0) {
-        ret = drmModeAddFB(drmmode->fd, pScrn->virtualX, height,
+        ret = drmModeAddFB(drmmode->fd, pScrn->virtualX, pScrn->virtualY,
                             pScrn->depth, pScrn->bitsPerPixel,
                             drmmode->front_bo->pitch,
                             drmmode->front_bo->handle,
                             &drmmode->fb_id);
         if (ret < 0) {
             ErrorF("failed to add fb %d\n", ret);
-            return FALSE;
+            goto done;
         }
     }
 
-    saved_mode = crtc->mode;
-    saved_x = crtc->x;
-    saved_y = crtc->y;
-    saved_rotation = crtc->rotation;
-
-    if (mode) {
-        crtc->mode = *mode;
-        crtc->x = x;
-        crtc->y = y;
-        crtc->rotation = rotation;
-#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,5,99,0,0)
-        crtc->transformPresent = FALSE;
-#endif
-    }
-
-    output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
-    if (!output_ids) {
-        ret = FALSE;
+    ret = drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+                         drmmode->fb_id, x, y, output_ids, output_count, &kmode);
+    if (ret) {
+        xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR, "failed to set mode: %s",
+                   strerror(-ret));
         goto done;
     }
 
-    if (mode) {
-        for (i = 0; i < xf86_config->num_output; i++) {
-            xf86OutputPtr output = xf86_config->output[i];
-            drmmode_output_private_ptr drmmode_output;
+    if (crtc->scrn->pScreen)
+        xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
 
-            if (output->crtc != crtc)
-                continue;
+    /* go through all the outputs and force DPMS them back on? */
+    for (i = 0; i < xf86_config->num_output; i++) {
+        xf86OutputPtr output = xf86_config->output[i];
 
-            drmmode_output = output->driver_private;
-            output_ids[output_count] = drmmode_output->mode_output->connector_id;
-            output_count++;
-        }
+        if (output->crtc != crtc)
+            continue;
 
-        if (!xf86CrtcRotate(crtc)) {
-            goto done;
-        }
+        output->funcs->dpms(output, DPMSModeOn);
+    }
 
 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,7,0,0,0)
-        crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
-                                crtc->gamma_blue, crtc->gamma_size);
+    crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
+                           crtc->gamma_blue, crtc->gamma_size);
 #endif
-        drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
-
-        fb_id = drmmode->fb_id;
-        if (drmmode_crtc->rotate_fb_id) {
-            fb_id = drmmode_crtc->rotate_fb_id;
-            x = y = 0;
-        }
-        ret = drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
-                            fb_id, x, y, output_ids, output_count, &kmode);
-        if (ret)
-            xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR, "failed to set mode: %s",
-                        strerror(-ret));
-        else
-            ret = TRUE;
-
-        if (crtc->scrn->pScreen)
-            xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
-
-        /* go through all the outputs and force DPMS them back on? */
-        for (i = 0; i < xf86_config->num_output; i++) {
-            xf86OutputPtr output = xf86_config->output[i];
-
-            if (output->crtc != crtc)
-			    continue;
-
-            output->funcs->dpms(output, DPMSModeOn);
-        }
-    }
 
     if (pScrn->pScreen && drmmode->hwcursor)
         xf86_reload_cursors(pScrn->pScreen);
 done:
-    if (!ret) {
-        crtc->x = saved_x;
-        crtc->y = saved_y;
-        crtc->rotation = saved_rotation;
-        crtc->mode = saved_mode;
-    }
-#if defined(XF86_CRTC_VERSION) && XF86_CRTC_VERSION >= 3
-    else
-        crtc->active = TRUE;
-#endif
-	return ret;
+    free(output_ids);
+    return (ret < 0 ? FALSE : TRUE);
 }
 
 static void


More information about the Openchrome-devel mailing list