[gnome-flashback] monitor-normal: prefer modes with same flags as preferred mode
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] monitor-normal: prefer modes with same flags as preferred mode
- Date: Fri, 20 Oct 2017 16:38:10 +0000 (UTC)
commit 3121d921dda17f2a3d560e1a793fcfdbc1a199e0
Author: Jonas Ådahl <jadahl gmail com>
Date: Wed Oct 18 23:22:01 2017 +0800
monitor-normal: prefer modes with same flags as preferred mode
When generating GfMonitorMode's, prefer CRTC modes that has the same
set of flags as the preferred mode. This not only is probably a better
set of configurable modes, but it'll guarantee that the preferred mode
is added.
This fixes a crash when the preferred mode was not the first mode with
the same resolution, refresh rate and set of handled modes.
https://bugzilla.gnome.org/show_bug.cgi?id=789153
backends/gf-monitor-normal.c | 28 ++++++++++++++++++++--------
backends/gf-monitor-private.h | 3 ++-
backends/gf-monitor-tiled.c | 4 ++--
backends/gf-monitor.c | 15 +++++++++++----
4 files changed, 35 insertions(+), 15 deletions(-)
---
diff --git a/backends/gf-monitor-normal.c b/backends/gf-monitor-normal.c
index 6377c2d..b2cc170 100644
--- a/backends/gf-monitor-normal.c
+++ b/backends/gf-monitor-normal.c
@@ -36,15 +36,18 @@ generate_modes (GfMonitorNormal *normal)
{
GfMonitor *monitor;
GfOutput *output;
+ GfCrtcModeFlag preferred_mode_flags;
guint i;
monitor = GF_MONITOR (normal);
output = gf_monitor_get_main_output (monitor);
+ preferred_mode_flags = output->preferred_mode->flags;
for (i = 0; i < output->n_modes; i++)
{
GfCrtcMode *crtc_mode;
GfMonitorMode *mode;
+ gboolean replace;
crtc_mode = output->modes[i];
@@ -60,18 +63,27 @@ generate_modes (GfMonitorNormal *normal)
mode->crtc_modes[0].output = output;
mode->crtc_modes[0].crtc_mode = crtc_mode;
- if (gf_monitor_add_mode (monitor, mode))
- {
- if (crtc_mode == output->preferred_mode)
- gf_monitor_set_preferred_mode (monitor, mode);
+ /*
+ * We don't distinguish between all available mode flags, just the ones
+ * that are configurable. We still need to pick some mode though, so
+ * prefer ones that has the same set of flags as the preferred mode;
+ * otherwise take the first one in the list. This guarantees that the
+ * preferred mode is always added.
+ */
+ replace = crtc_mode->flags == preferred_mode_flags;
- if (output->crtc && crtc_mode == output->crtc->current_mode)
- gf_monitor_set_current_mode (monitor, mode);
- }
- else
+ if (!gf_monitor_add_mode (monitor, mode, replace))
{
+ g_assert (crtc_mode != output->preferred_mode);
gf_monitor_mode_free (mode);
+ continue;
}
+
+ if (crtc_mode == output->preferred_mode)
+ gf_monitor_set_preferred_mode (monitor, mode);
+
+ if (output->crtc && crtc_mode == output->crtc->current_mode)
+ gf_monitor_set_current_mode (monitor, mode);
}
}
diff --git a/backends/gf-monitor-private.h b/backends/gf-monitor-private.h
index 401ffbc..44538db 100644
--- a/backends/gf-monitor-private.h
+++ b/backends/gf-monitor-private.h
@@ -105,7 +105,8 @@ void gf_monitor_set_preferred_mode (GfMonitor
void gf_monitor_generate_spec (GfMonitor *monitor);
gboolean gf_monitor_add_mode (GfMonitor *monitor,
- GfMonitorMode *monitor_mode);
+ GfMonitorMode *monitor_mode,
+ gboolean replace);
void gf_monitor_mode_free (GfMonitorMode *monitor_mode);
diff --git a/backends/gf-monitor-tiled.c b/backends/gf-monitor-tiled.c
index ef9d1a3..61334be 100644
--- a/backends/gf-monitor-tiled.c
+++ b/backends/gf-monitor-tiled.c
@@ -268,7 +268,7 @@ generate_tiled_monitor_modes (GfMonitorTiled *tiled)
mode = l->data;
tiled_modes = g_list_remove_link (tiled_modes, l);
- if (!gf_monitor_add_mode (monitor, mode))
+ if (!gf_monitor_add_mode (monitor, mode, FALSE))
{
gf_monitor_mode_free (mode);
continue;
@@ -308,7 +308,7 @@ generate_untiled_monitor_modes (GfMonitorTiled *tiled)
if (!mode)
continue;
- if (!gf_monitor_add_mode (monitor, mode))
+ if (!gf_monitor_add_mode (monitor, mode, FALSE))
{
gf_monitor_mode_free (mode);
continue;
diff --git a/backends/gf-monitor.c b/backends/gf-monitor.c
index 3426fb4..aef8860 100644
--- a/backends/gf-monitor.c
+++ b/backends/gf-monitor.c
@@ -443,18 +443,25 @@ gf_monitor_generate_spec (GfMonitor *monitor)
gboolean
gf_monitor_add_mode (GfMonitor *monitor,
- GfMonitorMode *monitor_mode)
+ GfMonitorMode *monitor_mode,
+ gboolean replace)
{
GfMonitorPrivate *priv;
+ GfMonitorMode *existing_mode;
priv = gf_monitor_get_instance_private (monitor);
- if (g_hash_table_lookup (priv->mode_ids,
- gf_monitor_mode_get_id (monitor_mode)))
+ existing_mode = g_hash_table_lookup (priv->mode_ids,
+ gf_monitor_mode_get_id (monitor_mode));
+
+ if (existing_mode && !replace)
return FALSE;
+ if (existing_mode)
+ priv->modes = g_list_remove (priv->modes, existing_mode);
+
priv->modes = g_list_append (priv->modes, monitor_mode);
- g_hash_table_insert (priv->mode_ids, monitor_mode->id, monitor_mode);
+ g_hash_table_replace (priv->mode_ids, monitor_mode->id, monitor_mode);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]