[gnome-color-manager] Split the EDID functionality into it's own object
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Split the EDID functionality into it's own object
- Date: Thu, 29 Oct 2009 22:40:55 +0000 (UTC)
commit c6bb9b6a71cfa60b3dae13529c3e45426ec2d704
Author: Richard Hughes <richard hughsie com>
Date: Thu Oct 29 15:41:20 2009 +0000
Split the EDID functionality into it's own object
src/Makefile.am | 2 +
src/gcm-edid.c | 255 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gcm-edid.h | 66 ++++++++++++++
src/gcm-utils.c | 80 +++++------------
4 files changed, 346 insertions(+), 57 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 91be2bc..a090040 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,6 +22,8 @@ libgcmshared_a_SOURCES = \
gcm-utils.h \
gcm-clut.c \
gcm-clut.h \
+ gcm-edid.c \
+ gcm-edid.h \
gcm-profile.c \
gcm-profile.h
diff --git a/src/gcm-edid.c b/src/gcm-edid.c
new file mode 100644
index 0000000..c217828
--- /dev/null
+++ b/src/gcm-edid.c
@@ -0,0 +1,255 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more edid.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * SECTION:gcm-edid
+ * @short_description: EDID parsing object
+ *
+ * This object parses EDID data blocks.
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+#include <math.h>
+#include <string.h>
+#include <gio/gio.h>
+#include <stdlib.h>
+
+#include "gcm-edid.h"
+
+#include "egg-debug.h"
+
+static void gcm_edid_finalize (GObject *object);
+
+#define GCM_EDID_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_EDID, GcmEdidPrivate))
+
+/**
+ * GcmEdidPrivate:
+ *
+ * Private #GcmEdid data
+ **/
+struct _GcmEdidPrivate
+{
+ gchar *monitor_name;
+ gchar *serial_number;
+ gchar *ascii_string;
+};
+
+enum {
+ PROP_0,
+ PROP_MONITOR_NAME,
+ PROP_SERIAL_NUMBER,
+ PROP_ASCII_STRING,
+ PROP_LAST
+};
+
+G_DEFINE_TYPE (GcmEdid, gcm_edid, G_TYPE_OBJECT)
+
+/**
+ * gcm_edid_parse:
+ **/
+gboolean
+gcm_edid_parse (GcmEdid *edid, const guint8 *data, GError **error)
+{
+ gboolean ret = TRUE;
+ guint i;
+ GcmEdidPrivate *priv = edid->priv;
+
+ g_return_val_if_fail (GCM_IS_EDID (edid), FALSE);
+
+ /* chekc header */
+ if (data[0] != 0x00 || data[1] != 0xff) {
+ if (error != NULL)
+ *error = g_error_new (1, 0, "failed to parse header");
+ ret = FALSE;
+ goto out;
+ }
+
+ /* free old data */
+ g_free (priv->monitor_name);
+ g_free (priv->serial_number);
+ g_free (priv->ascii_string);
+ priv->monitor_name = NULL;
+ priv->serial_number = NULL;
+ priv->ascii_string = NULL;
+
+ /* parse EDID data */
+ for (i=54; i <= 108; i+=18) {
+ /* ignore pixel clock data */
+ if (data[i] != 0)
+ continue;
+ if (data[i+2] != 0)
+ continue;
+
+ /* any useful blocks? */
+ if (data[i+3] == 0xfc)
+ priv->monitor_name = g_strdup (&data[i+5]);
+ else if (data[i+3] == 0xff)
+ priv->serial_number = g_strdup (&data[i+5]);
+ else if (data[i+3] == 0xfe)
+ priv->ascii_string = g_strdup (&data[i+5]);
+ }
+
+ /* remove embedded newlines */
+ if (priv->monitor_name != NULL)
+ g_strdelimit (priv->monitor_name, "\n", '\0');
+ if (priv->serial_number != NULL)
+ g_strdelimit (priv->serial_number, "\n", '\0');
+ if (priv->ascii_string != NULL)
+ g_strdelimit (priv->ascii_string, "\n", '\0');
+out:
+ return ret;
+}
+
+/**
+ * gcm_edid_get_property:
+ **/
+static void
+gcm_edid_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ GcmEdid *edid = GCM_EDID (object);
+ GcmEdidPrivate *priv = edid->priv;
+
+ switch (prop_id) {
+ case PROP_MONITOR_NAME:
+ g_value_set_string (value, priv->monitor_name);
+ break;
+ case PROP_SERIAL_NUMBER:
+ g_value_set_string (value, priv->serial_number);
+ break;
+ case PROP_ASCII_STRING:
+ g_value_set_string (value, priv->ascii_string);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+/**
+ * gcm_edid_set_property:
+ **/
+static void
+gcm_edid_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ GcmEdid *edid = GCM_EDID (object);
+ GcmEdidPrivate *priv = edid->priv;
+
+ switch (prop_id) {
+ case PROP_MONITOR_NAME:
+ g_free (priv->monitor_name);
+ priv->monitor_name = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_SERIAL_NUMBER:
+ g_free (priv->serial_number);
+ priv->serial_number = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_ASCII_STRING:
+ g_free (priv->ascii_string);
+ priv->ascii_string = g_strdup (g_value_get_string (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+/**
+ * gcm_edid_class_init:
+ **/
+static void
+gcm_edid_class_init (GcmEdidClass *klass)
+{
+ GParamSpec *pspec;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = gcm_edid_finalize;
+ object_class->get_property = gcm_edid_get_property;
+ object_class->set_property = gcm_edid_set_property;
+
+ /**
+ * GcmEdid:monitor-name:
+ */
+ pspec = g_param_spec_string ("monitor-name", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_MONITOR_NAME, pspec);
+
+ /**
+ * GcmEdid:serial-number:
+ */
+ pspec = g_param_spec_string ("serial-number", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_SERIAL_NUMBER, pspec);
+
+ /**
+ * GcmEdid:ascii-string:
+ */
+ pspec = g_param_spec_string ("ascii-string", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_ASCII_STRING, pspec);
+
+ g_type_class_add_private (klass, sizeof (GcmEdidPrivate));
+}
+
+/**
+ * gcm_edid_init:
+ **/
+static void
+gcm_edid_init (GcmEdid *edid)
+{
+ edid->priv = GCM_EDID_GET_PRIVATE (edid);
+ edid->priv->monitor_name = NULL;
+ edid->priv->serial_number = NULL;
+ edid->priv->ascii_string = NULL;
+}
+
+/**
+ * gcm_edid_finalize:
+ **/
+static void
+gcm_edid_finalize (GObject *object)
+{
+ GcmEdid *edid = GCM_EDID (object);
+ GcmEdidPrivate *priv = edid->priv;
+
+ g_free (priv->monitor_name);
+ g_free (priv->serial_number);
+ g_free (priv->ascii_string);
+
+ G_OBJECT_CLASS (gcm_edid_parent_class)->finalize (object);
+}
+
+/**
+ * gcm_edid_new:
+ *
+ * Return value: a new GcmEdid object.
+ **/
+GcmEdid *
+gcm_edid_new (void)
+{
+ GcmEdid *edid;
+ edid = g_object_new (GCM_TYPE_EDID, NULL);
+ return GCM_EDID (edid);
+}
+
diff --git a/src/gcm-edid.h b/src/gcm-edid.h
new file mode 100644
index 0000000..0385b1f
--- /dev/null
+++ b/src/gcm-edid.h
@@ -0,0 +1,66 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more edid.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GCM_EDID_H
+#define __GCM_EDID_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GCM_TYPE_EDID (gcm_edid_get_type ())
+#define GCM_EDID(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_EDID, GcmEdid))
+#define GCM_EDID_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_EDID, GcmEdidClass))
+#define GCM_IS_EDID(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_EDID))
+#define GCM_IS_EDID_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_EDID))
+#define GCM_EDID_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_EDID, GcmEdidClass))
+
+typedef struct _GcmEdidPrivate GcmEdidPrivate;
+typedef struct _GcmEdid GcmEdid;
+typedef struct _GcmEdidClass GcmEdidClass;
+
+struct _GcmEdid
+{
+ GObject parent;
+ GcmEdidPrivate *priv;
+};
+
+struct _GcmEdidClass
+{
+ GObjectClass parent_class;
+ /* padding for future expansion */
+ void (*_gcm_reserved1) (void);
+ void (*_gcm_reserved2) (void);
+ void (*_gcm_reserved3) (void);
+ void (*_gcm_reserved4) (void);
+ void (*_gcm_reserved5) (void);
+};
+
+GType gcm_edid_get_type (void);
+GcmEdid *gcm_edid_new (void);
+gboolean gcm_edid_parse (GcmEdid *edid,
+ const guint8 *data,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __GCM_EDID_H */
+
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index a98b583..6493d90 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -26,59 +26,10 @@
#include <gdk/gdkx.h>
#include "gcm-utils.h"
+#include "gcm-edid.h"
#include "egg-debug.h"
/**
- * gcm_utils_get_edid_name:
- *
- * Return value: the output name, free with g_free().
- **/
-static gchar *
-gcm_utils_get_edid_name (const guint8 *edid)
-{
- guint i;
- gchar *monitor = NULL;
- gchar *serial = NULL;
- gchar *string = NULL;
- gchar *retval = NULL;
-
- /* parse EDID data */
- for (i=54; i <= 108; i+=18) {
- /* ignore pixel clock data */
- if (edid[i] != 0)
- continue;
- if (edid[i+2] != 0)
- continue;
-
- /* any useful blocks? */
- if (edid[i+3] == 0xfc)
- monitor = g_strdup (&edid[i+5]);
- else if (edid[i+3] == 0xff)
- serial = g_strdup (&edid[i+5]);
- else if (edid[i+3] == 0xfe)
- string = g_strdup (&edid[i+5]);
- }
-
- /* find the best option */
- if (monitor != NULL)
- retval = g_strdup (monitor);
- else if (serial != NULL)
- retval = g_strdup (serial);
- else if (string != NULL)
- retval = g_strdup (string);
- g_free (monitor);
- g_free (serial);
- g_free (string);
-
- /* replace invalid chars */
- if (retval != NULL) {
- g_strdelimit (retval, "-", '_');
- g_strdelimit (retval, "\n", '\0');
- }
- return retval;
-}
-
-/**
* gcm_utils_get_output_name:
*
* Return value: the output name, free with g_free().
@@ -86,15 +37,30 @@ gcm_utils_get_edid_name (const guint8 *edid)
gchar *
gcm_utils_get_output_name (GnomeRROutput *output)
{
- const guint8 *edid;
+ const guint8 *data;
guint i, j;
const gchar *output_name;
- gchar *name;
+ gchar *name = NULL;
+ GcmEdid *edid;
+ gboolean ret;
+
+ /* parse the EDID to get a crtc-specific name, not an output specific name */
+ data = gnome_rr_output_get_edid_data (output);
+ edid = gcm_edid_new ();
+ ret = gcm_edid_parse (edid, data, NULL);
+ if (!ret) {
+ egg_warning ("failed to parse edid");
+ goto out;
+ }
- /* TODO: need to parse the EDID to get a crtc-specific name, not an output specific name */
- edid = gnome_rr_output_get_edid_data (output);
- name = gcm_utils_get_edid_name (edid);
+ /* find the best option */
+ g_object_get (edid, "monitor-name", &name, NULL);
+ if (name == NULL)
+ g_object_get (edid, "ascii-string", &name, NULL);
+ if (name == NULL)
+ g_object_get (edid, "serial-number", &name, NULL);
+out:
/* fallback to the output name */
if (name == NULL) {
output_name = gnome_rr_output_get_name (output);
@@ -103,7 +69,7 @@ gcm_utils_get_output_name (GnomeRROutput *output)
name = g_strdup (output_name);
}
- /* for now, use the output name */
+ g_object_unref (edid);
return name;
}
@@ -174,7 +140,7 @@ gcm_utils_set_crtc_gamma (GnomeRRCrtc *crtc, GcmClut *clut, GError **error)
gamma->green[i] = data->green;
gamma->blue[i] = data->blue;
}
-
+
/* get id that X recognises */
id = gnome_rr_crtc_get_id (crtc);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]