st/xorg: attach EDID to outputs
authorLucas Stach <dev@lynxeye.de>
Wed, 18 Jul 2012 14:07:29 +0000 (16:07 +0200)
committerMichel Dänzer <michel.daenzer@amd.com>
Wed, 18 Jul 2012 15:19:16 +0000 (17:19 +0200)
Allows tools like GNOME's monitor configuration to show meaningful names.

v2: fix resource leak

Signed-off-by: Lucas Stach <dev@lynxeye.de>
src/gallium/state_trackers/xorg/xorg_output.c

index 5555b51131cdb1f30847ecc1dc5ab0c6473d87db..b183cdf9dc1df8ca2085f0a3cd32d4f97b8d328c 100644 (file)
@@ -32,6 +32,7 @@
 #include <xf86.h>
 #include <xf86i2c.h>
 #include <xf86Crtc.h>
+#include <xf86DDC.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -54,7 +55,8 @@
 struct output_private
 {
     drmModeConnectorPtr drm_connector;
-
+    drmModePropertyBlobPtr edid_blob;
+    int fd;
     int c;
 };
 
@@ -122,9 +124,39 @@ output_get_modes(xf86OutputPtr output)
     struct output_private *priv = output->driver_private;
     drmModeConnectorPtr drm_connector = priv->drm_connector;
     drmModeModeInfoPtr drm_mode = NULL;
+    drmModePropertyPtr props = NULL;
+    xf86MonPtr ddc_mon = NULL;
     DisplayModePtr modes = NULL, mode = NULL;
     int i;
 
+       for (i = 0; i < drm_connector->count_props; i++) {
+               props = drmModeGetProperty(priv->fd, drm_connector->props[i]);
+               if (!props)
+                       continue;
+
+               if (!(props->flags & DRM_MODE_PROP_BLOB))
+                       goto out_free;
+
+               if (!strcmp(props->name, "EDID")) {
+                       if (priv->edid_blob)
+                               drmModeFreePropertyBlob(priv->edid_blob);
+                       priv->edid_blob = drmModeGetPropertyBlob(priv->fd,
+                                                         drm_connector->prop_values[i]);
+               }
+
+               out_free:
+               drmModeFreeProperty(props);
+       }
+
+       if (priv->edid_blob) {
+               ddc_mon = xf86InterpretEDID(output->scrn->scrnIndex,
+                                                                       priv->edid_blob->data);
+
+               if (ddc_mon && priv->edid_blob->length > 128)
+                       ddc_mon->flags |= MONITOR_EDID_COMPLETE_RAWDATA;
+       }
+       xf86OutputSetEDID(output, ddc_mon);
+
     for (i = 0; i < drm_connector->count_modes; i++) {
        drm_mode = &drm_connector->modes[i];
        if (drm_mode) {
@@ -194,6 +226,8 @@ static void
 output_destroy(xf86OutputPtr output)
 {
     struct output_private *priv = output->driver_private;
+    if (priv->edid_blob)
+               drmModeFreePropertyBlob(priv->edid_blob);
     drmModeFreeConnector(priv->drm_connector);
     free(priv);
     output->driver_private = NULL;
@@ -283,6 +317,7 @@ xorg_output_init(ScrnInfoPtr pScrn)
        }
        priv->c = c;
        priv->drm_connector = drm_connector;
+       priv->fd = ms->fd;
        output->driver_private = priv;
        output->subpixel_order = SubPixelHorizontalRGB;
        output->interlaceAllowed = FALSE;