st/xorg: Get new connection status from kernel
authorJakob Bornecrantz <jakob@vmware.com>
Thu, 22 Apr 2010 09:48:28 +0000 (10:48 +0100)
committerJakob Bornecrantz <jakob@vmware.com>
Thu, 29 Apr 2010 13:27:34 +0000 (14:27 +0100)
src/gallium/state_trackers/xorg/xorg_crtc.c
src/gallium/state_trackers/xorg/xorg_output.c
src/gallium/state_trackers/xorg/xorg_tracker.h

index 669bd9edcf01de0b76828aca82e1e1bbbaead75a..f9022a9f934bdb33cc93957ee06bd5aca5847bb2 100644 (file)
@@ -90,11 +90,10 @@ crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     xf86OutputPtr output = NULL;
-    drmModeConnectorPtr drm_connector;
     struct crtc_private *crtcp = crtc->driver_private;
     drmModeCrtcPtr drm_crtc = crtcp->drm_crtc;
     drmModeModeInfo drm_mode;
-    int i, ret;
+    int i, ret, connector_id;
 
     for (i = 0; i < config->num_output; output = NULL, i++) {
        output = config->output[i];
@@ -106,7 +105,7 @@ crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
     if (!output)
        return FALSE;
 
-    drm_connector = output->driver_private;
+    connector_id = xorg_output_get_id(output);
 
     drm_mode.clock = mode->Clock;
     drm_mode.hdisplay = mode->HDisplay;
@@ -127,7 +126,7 @@ crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
     drm_mode.name[DRM_DISPLAY_MODE_LEN - 1] = '\0';
 
     ret = drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
-                        &drm_connector->connector_id, 1, &drm_mode);
+                        &connector_id, 1, &drm_mode);
 
     if (ret)
        return FALSE;
index 13c3fb97e3bd8b1581b5ce290cbd15e781f5e6f3..056098f76b41f815807cf10ffdc72efc75fdce51 100644 (file)
 
 #include "xorg_tracker.h"
 
+struct output_private
+{
+    drmModeConnectorPtr drm_connector;
+
+    int c;
+};
+
 static char *output_enum_list[] = {
     "Unknown",
     "VGA",
@@ -82,22 +89,38 @@ output_dpms(xf86OutputPtr output, int mode)
 static xf86OutputStatus
 output_detect(xf86OutputPtr output)
 {
-    drmModeConnectorPtr drm_connector = output->driver_private;
+    modesettingPtr ms = modesettingPTR(output->scrn);
+    struct output_private *priv = output->driver_private;
+    drmModeConnectorPtr drm_connector;
+    xf86OutputStatus status;
+
+    drm_connector = drmModeGetConnector(ms->fd, priv->drm_connector->connector_id);
+    if (drm_connector) {
+       drmModeFreeConnector(priv->drm_connector);
+       priv->drm_connector = drm_connector;
+    } else {
+       drm_connector = priv->drm_connector;
+    }
 
     switch (drm_connector->connection) {
     case DRM_MODE_CONNECTED:
-       return XF86OutputStatusConnected;
+       status = XF86OutputStatusConnected;
+       break;
     case DRM_MODE_DISCONNECTED:
-       return XF86OutputStatusDisconnected;
+       status = XF86OutputStatusDisconnected;
+       break;
     default:
-       return XF86OutputStatusUnknown;
+       status = XF86OutputStatusUnknown;
     }
+
+    return status;
 }
 
 static DisplayModePtr
 output_get_modes(xf86OutputPtr output)
 {
-    drmModeConnectorPtr drm_connector = output->driver_private;
+    struct output_private *priv = output->driver_private;
+    drmModeConnectorPtr drm_connector = priv->drm_connector;
     drmModeModeInfoPtr drm_mode = NULL;
     DisplayModePtr modes = NULL, mode = NULL;
     int i;
@@ -161,7 +184,10 @@ output_get_property(xf86OutputPtr output, Atom property)
 static void
 output_destroy(xf86OutputPtr output)
 {
-    drmModeFreeConnector(output->driver_private);
+    struct output_private *priv = output->driver_private;
+    drmModeFreeConnector(priv->drm_connector);
+    xfree(priv);
+    output->driver_private = NULL;
 }
 
 static const xf86OutputFuncsRec output_funcs = {
@@ -188,6 +214,7 @@ xorg_output_init(ScrnInfoPtr pScrn)
     drmModeResPtr res;
     drmModeConnectorPtr drm_connector = NULL;
     drmModeEncoderPtr drm_encoder = NULL;
+    struct output_private *priv;
     char name[32];
     int c, v, p;
 
@@ -226,9 +253,16 @@ xorg_output_init(ScrnInfoPtr pScrn)
                 drm_connector->connector_type_id);
 
 
+       priv = xcalloc(sizeof(*priv), 1);
+       if (!priv) {
+           continue;
+       }
+
        output = xf86OutputCreate(pScrn, &output_funcs, name);
-       if (!output)
+       if (!output) {
+           xfree(priv);
            continue;
+       }
 
        drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]);
        if (drm_encoder) {
@@ -238,7 +272,9 @@ xorg_output_init(ScrnInfoPtr pScrn)
            output->possible_crtcs = 0;
            output->possible_clones = 0;
        }
-       output->driver_private = drm_connector;
+       priv->c = c;
+       priv->drm_connector = drm_connector;
+       output->driver_private = priv;
        output->subpixel_order = SubPixelHorizontalRGB;
        output->interlaceAllowed = FALSE;
        output->doubleScanAllowed = FALSE;
@@ -248,4 +284,11 @@ xorg_output_init(ScrnInfoPtr pScrn)
     drmModeFreeResources(res);
 }
 
+unsigned
+xorg_output_get_id(xf86OutputPtr output)
+{
+    struct output_private *priv = output->driver_private;
+    return priv->drm_connector->connector_id;
+}
+
 /* vim: set sw=4 ts=8 sts=4: */
index cb6773424a827e7a0819057b19657cdccb2c685d..8d9c2a097ed2a898384e8e27d7c8b9844b442819 100644 (file)
@@ -192,6 +192,9 @@ xorg_crtc_cursor_destroy(xf86CrtcPtr crtc);
 void
 xorg_output_init(ScrnInfoPtr pScrn);
 
+unsigned
+xorg_output_get_id(xf86OutputPtr output);
+
 
 /***********************************************************************
  * xorg_xv.c