[gnome-flashback] backends: add GfOutput



commit 1cb2cb03e10d908be11a0e25fdb159a61077cb8a
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Sep 10 19:54:31 2017 +0300

    backends: add GfOutput

 backends/Makefile.am                        |    2 +
 backends/gf-monitor-manager-enums-private.h |   22 +++++
 backends/gf-monitor-manager-types-private.h |    1 +
 backends/gf-output-private.h                |  112 +++++++++++++++++++++++++++
 backends/gf-output.c                        |  110 ++++++++++++++++++++++++++
 5 files changed, 247 insertions(+), 0 deletions(-)
---
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 5f57955..5c38819 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -48,6 +48,8 @@ libbackends_la_SOURCES = \
        gf-monitor-spec.c \
        gf-orientation-manager-private.h \
        gf-orientation-manager.c \
+       gf-output-private.h \
+       gf-output.c \
        gf-rectangle.h \
        gf-settings-private.h \
        gf-settings.c \
diff --git a/backends/gf-monitor-manager-enums-private.h b/backends/gf-monitor-manager-enums-private.h
index 0efeeb4..c88492e 100644
--- a/backends/gf-monitor-manager-enums-private.h
+++ b/backends/gf-monitor-manager-enums-private.h
@@ -41,6 +41,28 @@ typedef enum
   GF_MONITOR_TRANSFORM_FLIPPED_270,
 } GfMonitorTransform;
 
+/* This matches the values in drm_mode.h */
+typedef enum
+{
+  GF_CONNECTOR_TYPE_Unknown = 0,
+  GF_CONNECTOR_TYPE_VGA = 1,
+  GF_CONNECTOR_TYPE_DVII = 2,
+  GF_CONNECTOR_TYPE_DVID = 3,
+  GF_CONNECTOR_TYPE_DVIA = 4,
+  GF_CONNECTOR_TYPE_Composite = 5,
+  GF_CONNECTOR_TYPE_SVIDEO = 6,
+  GF_CONNECTOR_TYPE_LVDS = 7,
+  GF_CONNECTOR_TYPE_Component = 8,
+  GF_CONNECTOR_TYPE_9PinDIN = 9,
+  GF_CONNECTOR_TYPE_DisplayPort = 10,
+  GF_CONNECTOR_TYPE_HDMIA = 11,
+  GF_CONNECTOR_TYPE_HDMIB = 12,
+  GF_CONNECTOR_TYPE_TV = 13,
+  GF_CONNECTOR_TYPE_eDP = 14,
+  GF_CONNECTOR_TYPE_VIRTUAL = 15,
+  GF_CONNECTOR_TYPE_DSI = 16
+} GfConnectorType;
+
 /* Same as KMS mode flags and X11 randr flags */
 typedef enum
 {
diff --git a/backends/gf-monitor-manager-types-private.h b/backends/gf-monitor-manager-types-private.h
index f2b769b..0518404 100644
--- a/backends/gf-monitor-manager-types-private.h
+++ b/backends/gf-monitor-manager-types-private.h
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
 typedef struct _GfLogicalMonitor GfLogicalMonitor;
 
 typedef struct _GfCrtc GfCrtc;
+typedef struct _GfOutput GfOutput;
 typedef struct _GfCrtcMode GfCrtcMode;
 
 G_END_DECLS
diff --git a/backends/gf-output-private.h b/backends/gf-output-private.h
new file mode 100644
index 0000000..ed55d1e
--- /dev/null
+++ b/backends/gf-output-private.h
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2001 Havoc Pennington
+ * Copyright (C) 2003 Rob Adams
+ * Copyright (C) 2004-2006 Elijah Newren
+ * Copyright (C) 2013 Red Hat Inc.
+ * Copyright (C) 2017 Alberts Muktupāvels
+ *
+ * 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 3 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 details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Adapted from mutter:
+ * - src/backends/meta-monitor-manager-private.h
+ */
+
+#ifndef GF_OUTPUT_PRIVATE_H
+#define GF_OUTPUT_PRIVATE_H
+
+#include "gf-monitor-manager-enums-private.h"
+#include "gf-monitor-manager-types-private.h"
+
+G_BEGIN_DECLS
+
+typedef struct
+{
+  guint32 group_id;
+  guint32 flags;
+  guint32 max_h_tiles;
+  guint32 max_v_tiles;
+  guint32 loc_h_tile;
+  guint32 loc_v_tile;
+  guint32 tile_w;
+  guint32 tile_h;
+} GfTileInfo;
+
+typedef struct
+{
+  GfOutput *output;
+  gboolean  is_primary;
+  gboolean  is_presentation;
+  gboolean  is_underscanning;
+} GfOutputInfo;
+
+struct _GfOutput
+{
+  /* The CRTC driving this output, NULL if the output is not enabled */
+  GfCrtc           *crtc;
+
+  /* The low-level ID of this output, used to apply back configuration */
+  glong             winsys_id;
+  gchar            *name;
+  gchar            *vendor;
+  gchar            *product;
+  gchar            *serial;
+  gint              width_mm;
+  gint              height_mm;
+
+  GfConnectorType   connector_type;
+
+  GfCrtcMode       *preferred_mode;
+  GfCrtcMode      **modes;
+  guint             n_modes;
+
+  GfCrtc          **possible_crtcs;
+  guint             n_possible_crtcs;
+
+  GfOutput        **possible_clones;
+  guint             n_possible_clones;
+
+  gint              backlight;
+  gint              backlight_min;
+  gint              backlight_max;
+
+  /* Used when changing configuration */
+  gboolean          is_dirty;
+
+  /* The low-level bits used to build the high-level info in GfLogicalMonitor */
+  gboolean          is_primary;
+  gboolean          is_presentation;
+  gboolean          is_underscanning;
+  gboolean          supports_underscanning;
+
+  gpointer          driver_private;
+  GDestroyNotify    driver_notify;
+
+  /* Get a new preferred mode on hotplug events, to handle
+   * dynamic guest resizing
+   */
+  gboolean          hotplug_mode_update;
+  gint              suggested_x;
+  gint              suggested_y;
+
+  GfTileInfo        tile_info;
+};
+
+void     gf_output_parse_edid (GfOutput *output,
+                               GBytes   *edid);
+
+gboolean gf_output_is_laptop  (GfOutput *output);
+
+G_END_DECLS
+
+#endif
diff --git a/backends/gf-output.c b/backends/gf-output.c
new file mode 100644
index 0000000..6332606
--- /dev/null
+++ b/backends/gf-output.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2001, 2002 Havoc Pennington
+ * Copyright (C) 2002, 2003 Red Hat Inc.
+ * Some ICCCM manager selection code derived from fvwm2,
+ * Copyright (C) 2001 Dominik Vogt, Matthias Clasen, and fvwm2 team
+ * Copyright (C) 2003 Rob Adams
+ * Copyright (C) 2004-2006 Elijah Newren
+ * Copyright (C) 2013 Red Hat Inc.
+ * Copyright (C) 2017 Alberts Muktupāvels
+ *
+ * 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 3 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 details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Adapted from mutter:
+ * - src/backends/meta-monitor-manager.c
+ */
+
+#include "config.h"
+#include "gf-edid-private.h"
+#include "gf-output-private.h"
+
+void
+gf_output_parse_edid (GfOutput *output,
+                      GBytes   *edid)
+{
+  MonitorInfo *parsed_edid;
+  gsize len;
+
+  if (!edid)
+    {
+      output->vendor = g_strdup ("unknown");
+      output->product = g_strdup ("unknown");
+      output->serial = g_strdup ("unknown");
+      return;
+    }
+
+  parsed_edid = decode_edid (g_bytes_get_data (edid, &len));
+  if (parsed_edid)
+    {
+      output->vendor = g_strndup (parsed_edid->manufacturer_code, 4);
+      if (!g_utf8_validate (output->vendor, -1, NULL))
+        g_clear_pointer (&output->vendor, g_free);
+
+      output->product = g_strndup (parsed_edid->dsc_product_name, 14);
+      if (!g_utf8_validate (output->product, -1, NULL) || output->product[0] == '\0')
+        {
+          g_clear_pointer (&output->product, g_free);
+          output->product = g_strdup_printf ("0x%04x", (unsigned) parsed_edid->product_code);
+        }
+
+      output->serial = g_strndup (parsed_edid->dsc_serial_number, 14);
+      if (!g_utf8_validate (output->serial, -1, NULL) || output->serial[0] == '\0')
+        {
+          g_clear_pointer (&output->serial, g_free);
+          output->serial = g_strdup_printf ("0x%08x", parsed_edid->serial_number);
+        }
+
+      g_free (parsed_edid);
+    }
+
+  if (!output->vendor)
+    output->vendor = g_strdup ("unknown");
+
+  if (!output->product)
+    output->product = g_strdup ("unknown");
+
+  if (!output->serial)
+    output->serial = g_strdup ("unknown");
+}
+
+gboolean
+gf_output_is_laptop (GfOutput *output)
+{
+  switch (output->connector_type)
+    {
+      case GF_CONNECTOR_TYPE_LVDS:
+      case GF_CONNECTOR_TYPE_eDP:
+      case GF_CONNECTOR_TYPE_DSI:
+        return TRUE;
+
+      case GF_CONNECTOR_TYPE_Unknown:
+      case GF_CONNECTOR_TYPE_VGA:
+      case GF_CONNECTOR_TYPE_DVII:
+      case GF_CONNECTOR_TYPE_DVID:
+      case GF_CONNECTOR_TYPE_DVIA:
+      case GF_CONNECTOR_TYPE_Composite:
+      case GF_CONNECTOR_TYPE_SVIDEO:
+      case GF_CONNECTOR_TYPE_Component:
+      case GF_CONNECTOR_TYPE_9PinDIN:
+      case GF_CONNECTOR_TYPE_DisplayPort:
+      case GF_CONNECTOR_TYPE_HDMIA:
+      case GF_CONNECTOR_TYPE_HDMIB:
+      case GF_CONNECTOR_TYPE_TV:
+      case GF_CONNECTOR_TYPE_VIRTUAL:
+      default:
+        break;
+    }
+
+  return FALSE;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]