Commit 63163777 authored by Alberts Muktupāvels's avatar Alberts Muktupāvels
Browse files

backends: make GfOutput a GObject

Based on mutter commit:
mutter@9817a6aa
parent 8196b5bd
......@@ -64,8 +64,7 @@ struct _GfMonitorManager
* (like encoders, but less tied to the HW),
* while logical_monitors refer to logical ones.
*/
GfOutput *outputs;
guint n_outputs;
GList *outputs;
GfCrtcMode *modes;
guint n_modes;
......@@ -175,8 +174,7 @@ GfMonitor *gf_monitor_manager_get_monitor_from_spec (GfM
GList *gf_monitor_manager_get_monitors (GfMonitorManager *manager);
GfOutput *gf_monitor_manager_get_outputs (GfMonitorManager *manager,
guint *n_outputs);
GList *gf_monitor_manager_get_outputs (GfMonitorManager *manager);
gboolean gf_monitor_manager_has_hotplug_mode_update (GfMonitorManager *manager);
void gf_monitor_manager_read_current_state (GfMonitorManager *manager);
......@@ -229,8 +227,6 @@ GfLogicalMonitorLayoutMode gf_monitor_manager_get_default_layout_mode (GfM
GfMonitorConfigManager *gf_monitor_manager_get_config_manager (GfMonitorManager *manager);
void gf_monitor_manager_clear_output (GfOutput *output);
void gf_monitor_manager_clear_mode (GfCrtcMode *mode);
void gf_monitor_manager_clear_crtc (GfCrtc *crtc);
......
......@@ -383,6 +383,7 @@ is_assignments_changed (GfMonitorManager *manager,
guint n_output_infos)
{
guint i;
GList *l;
for (i = 0; i < manager->n_crtcs; i++)
{
......@@ -392,9 +393,9 @@ is_assignments_changed (GfMonitorManager *manager,
return TRUE;
}
for (i = 0; i < manager->n_outputs; i++)
for (l = manager->outputs; l; l = l->next)
{
GfOutput *output = &manager->outputs[i];
GfOutput *output = l->data;
if (is_output_assignment_changed (output,
crtc_infos,
......@@ -1144,6 +1145,7 @@ apply_crtc_assignments (GfMonitorManager *manager,
GfMonitorManagerXrandr *xrandr;
gint width, height, width_mm, height_mm;
guint i;
GList *l;
xrandr = GF_MONITOR_MANAGER_XRANDR (manager);
......@@ -1338,9 +1340,9 @@ apply_crtc_assignments (GfMonitorManager *manager,
}
/* Disable outputs not mentioned in the list */
for (i = 0; i < manager->n_outputs; i++)
for (l = manager->outputs; l; l = l->next)
{
GfOutput *output = &manager->outputs[i];
GfOutput *output = l->data;
if (output->is_dirty)
{
......@@ -1529,9 +1531,9 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
gint min_width;
gint min_height;
Screen *screen;
guint i, j, k;
guint i, j;
GList *l;
RROutput primary_output;
guint n_actual_outputs;
xrandr = GF_MONITOR_MANAGER_XRANDR (manager);
......@@ -1584,10 +1586,9 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
return;
xrandr->resources = resources;
manager->n_outputs = resources->noutput;
manager->n_crtcs = resources->ncrtc;
manager->n_modes = resources->nmode;
manager->outputs = g_new0 (GfOutput, manager->n_outputs);
manager->outputs = NULL;
manager->modes = g_new0 (GfCrtcMode, manager->n_modes);
manager->crtcs = g_new0 (GfCrtc, manager->n_crtcs);
......@@ -1638,7 +1639,6 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
primary_output = XRRGetOutputPrimary (xrandr->xdisplay, xrandr->xroot);
n_actual_outputs = 0;
for (i = 0; i < (guint) resources->noutput; i++)
{
XRROutputInfo *xrandr_output;
......@@ -1650,12 +1650,12 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
if (!xrandr_output)
continue;
output = &manager->outputs[n_actual_outputs];
if (xrandr_output->connection != RR_Disconnected)
{
GBytes *edid;
output = g_object_new (GF_TYPE_OUTPUT, NULL);
output->winsys_id = resources->outputs[i];
output->name = g_strdup (xrandr_output->name);
......@@ -1699,35 +1699,36 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
output->backlight = -1;
if (output->n_modes == 0 || output->n_possible_crtcs == 0)
gf_monitor_manager_clear_output (output);
g_object_unref (output);
else
n_actual_outputs++;
manager->outputs = g_list_prepend (manager->outputs, output);
}
XRRFreeOutputInfo (xrandr_output);
}
manager->n_outputs = n_actual_outputs;
/* Sort the outputs for easier handling in GfMonitorConfig */
qsort (manager->outputs, manager->n_outputs, sizeof (GfOutput), compare_outputs);
manager->outputs = g_list_sort (manager->outputs, compare_outputs);
/* Now fix the clones */
for (i = 0; i < manager->n_outputs; i++)
for (l = manager->outputs; l; l = l->next)
{
GfOutput *output;
GList *k;
output = &manager->outputs[i];
output = l->data;
for (j = 0; j < output->n_possible_clones; j++)
{
RROutput clone = GPOINTER_TO_INT (output->possible_clones[j]);
for (k = 0; k < manager->n_outputs; k++)
for (k = manager->outputs; k; k = k->next)
{
if (clone == (XID) manager->outputs[k].winsys_id)
GfOutput *possible_clone = k->data;
if (clone == (XID) possible_clone->winsys_id)
{
output->possible_clones[j] = &manager->outputs[k];
output->possible_clones[j] = possible_clone;
break;
}
}
......
......@@ -1059,7 +1059,7 @@ is_main_tiled_monitor_output (GfOutput *output)
static void
rebuild_monitors (GfMonitorManager *manager)
{
guint i;
GList *l;
if (manager->monitors)
{
......@@ -1067,9 +1067,9 @@ rebuild_monitors (GfMonitorManager *manager)
manager->monitors = NULL;
}
for (i = 0; i < manager->n_outputs; i++)
for (l = manager->outputs; l; l = l->next)
{
GfOutput *output = &manager->outputs[i];
GfOutput *output = l->data;
if (output->tile_info.group_id)
{
......@@ -1091,18 +1091,6 @@ rebuild_monitors (GfMonitorManager *manager)
}
}
static void
free_output_array (GfOutput *old_outputs,
gint n_old_outputs)
{
gint i;
for (i = 0; i < n_old_outputs; i++)
gf_monitor_manager_clear_output (&old_outputs[i]);
g_free (old_outputs);
}
static void
free_mode_array (GfCrtcMode *old_modes,
gint n_old_modes)
......@@ -1136,6 +1124,7 @@ gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
GVariantBuilder crtc_builder;
GVariantBuilder output_builder;
GVariantBuilder mode_builder;
GList *l;
guint i, j;
gint max_screen_width;
gint max_screen_height;
......@@ -1170,9 +1159,9 @@ gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
NULL /* properties */);
}
for (i = 0; i < manager->n_outputs; i++)
for (l = manager->outputs; l; l = l->next)
{
GfOutput *output = &manager->outputs[i];
GfOutput *output = l->data;
GVariantBuilder crtcs, modes, clones, properties;
GBytes *edid;
gchar *edid_file;
......@@ -1189,8 +1178,14 @@ gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
g_variant_builder_init (&clones, G_VARIANT_TYPE ("au"));
for (j = 0; j < output->n_possible_clones; j++)
g_variant_builder_add (&clones, "u",
(guint) (output->possible_clones[j] - manager->outputs));
{
guint possible_clone_index;
possible_clone_index = g_list_index (manager->outputs,
output->possible_clones[j]);
g_variant_builder_add (&clones, "u", possible_clone_index);
}
g_variant_builder_init (&properties, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&properties, "{sv}", "vendor",
......@@ -1318,7 +1313,7 @@ gf_monitor_manager_handle_change_backlight (GfDBusDisplayConfig *skeleton,
return TRUE;
}
if (output_index >= manager->n_outputs)
if (output_index >= g_list_length (manager->outputs))
{
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_INVALID_ARGS,
......@@ -1326,7 +1321,7 @@ gf_monitor_manager_handle_change_backlight (GfDBusDisplayConfig *skeleton,
return TRUE;
}
output = &manager->outputs[output_index];
output = g_list_nth_data (manager->outputs, output_index);
if (value < 0 || value > 100)
{
......@@ -2018,7 +2013,7 @@ gf_monitor_manager_finalize (GObject *object)
manager = GF_MONITOR_MANAGER (object);
free_output_array (manager->outputs, manager->n_outputs);
g_list_free_full (manager->outputs, g_object_unref);
free_mode_array (manager->modes, manager->n_modes);
free_crtc_array (manager->crtcs, manager->n_crtcs);
......@@ -2204,22 +2199,20 @@ gf_monitor_manager_get_monitors (GfMonitorManager *manager)
return manager->monitors;
}
GfOutput *
gf_monitor_manager_get_outputs (GfMonitorManager *manager,
guint *n_outputs)
GList *
gf_monitor_manager_get_outputs (GfMonitorManager *manager)
{
*n_outputs = manager->n_outputs;
return manager->outputs;
}
gboolean
gf_monitor_manager_has_hotplug_mode_update (GfMonitorManager *manager)
{
guint i;
GList *l;
for (i = 0; i < manager->n_outputs; i++)
for (l = manager->outputs; l; l = l->next)
{
GfOutput *output = &manager->outputs[i];
GfOutput *output = l->data;
if (output->hotplug_mode_update)
return TRUE;
......@@ -2231,10 +2224,9 @@ gf_monitor_manager_has_hotplug_mode_update (GfMonitorManager *manager)
void
gf_monitor_manager_read_current_state (GfMonitorManager *manager)
{
GfOutput *old_outputs;
GList *old_outputs;
GfCrtc *old_crtcs;
GfCrtcMode *old_modes;
guint n_old_outputs;
guint n_old_crtcs;
guint n_old_modes;
......@@ -2243,7 +2235,6 @@ gf_monitor_manager_read_current_state (GfMonitorManager *manager)
* read_current finishes.
*/
old_outputs = manager->outputs;
n_old_outputs = manager->n_outputs;
old_crtcs = manager->crtcs;
n_old_crtcs = manager->n_crtcs;
old_modes = manager->modes;
......@@ -2254,7 +2245,7 @@ gf_monitor_manager_read_current_state (GfMonitorManager *manager)
rebuild_monitors (manager);
free_output_array (old_outputs, n_old_outputs);
g_list_free_full (old_outputs, g_object_unref);
free_mode_array (old_modes, n_old_modes);
free_crtc_array (old_crtcs, n_old_crtcs);
}
......@@ -2557,23 +2548,6 @@ gf_monitor_manager_get_config_manager (GfMonitorManager *manager)
return manager->config_manager;
}
void
gf_monitor_manager_clear_output (GfOutput *output)
{
g_free (output->name);
g_free (output->vendor);
g_free (output->product);
g_free (output->serial);
g_free (output->modes);
g_free (output->possible_crtcs);
g_free (output->possible_clones);
if (output->driver_notify)
output->driver_notify (output);
memset (output, 0, sizeof (*output));
}
void
gf_monitor_manager_clear_mode (GfCrtcMode *mode)
{
......@@ -2602,9 +2576,9 @@ gf_monitor_manager_get_monitor_for_output (GfMonitorManager *manager,
GList *l;
g_return_val_if_fail (GF_IS_MONITOR_MANAGER (manager), -1);
g_return_val_if_fail (id < manager->n_outputs, -1);
g_return_val_if_fail (id < g_list_length (manager->outputs), -1);
output = &manager->outputs[id];
output = g_list_nth_data (manager->outputs, id);
if (!output || !output->crtc)
return -1;
......
......@@ -498,15 +498,17 @@ add_tiled_monitor_outputs (GfMonitorManager *monitor_manager,
GfMonitorTiled *tiled)
{
GfMonitor *monitor;
guint i;
GList *outputs;
GList *l;
monitor = GF_MONITOR (tiled);
for (i = 0; i < monitor_manager->n_outputs; i++)
outputs = monitor_manager->outputs;
for (l = outputs; l; l = l->next)
{
GfOutput *output;
output = &monitor_manager->outputs[i];
output = l->data;
if (output->tile_info.group_id != tiled->tile_group_id)
continue;
......
......@@ -25,6 +25,8 @@
#ifndef GF_OUTPUT_PRIVATE_H
#define GF_OUTPUT_PRIVATE_H
#include <glib-object.h>
#include "gf-monitor-manager-enums-private.h"
#include "gf-monitor-manager-types-private.h"
......@@ -52,6 +54,8 @@ typedef struct
struct _GfOutput
{
GObject parent;
/* The CRTC driving this output, NULL if the output is not enabled */
GfCrtc *crtc;
......@@ -102,6 +106,9 @@ struct _GfOutput
GfTileInfo tile_info;
};
#define GF_TYPE_OUTPUT (gf_output_get_type ())
G_DECLARE_FINAL_TYPE (GfOutput, gf_output, GF, OUTPUT, GObject)
void gf_output_parse_edid (GfOutput *output,
GBytes *edid);
......
......@@ -7,6 +7,7 @@
* Copyright (C) 2004-2006 Elijah Newren
* Copyright (C) 2013 Red Hat Inc.
* Copyright (C) 2017 Alberts Muktupāvels
* Copyright (C) 2017 Red Hat
*
* 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
......@@ -29,6 +30,44 @@
#include "gf-edid-private.h"
#include "gf-output-private.h"
G_DEFINE_TYPE (GfOutput, gf_output, G_TYPE_OBJECT)
static void
gf_output_finalize (GObject *object)
{
GfOutput *output;
output = GF_OUTPUT (object);
g_free (output->name);
g_free (output->vendor);
g_free (output->product);
g_free (output->serial);
g_free (output->modes);
g_free (output->possible_crtcs);
g_free (output->possible_clones);
if (output->driver_notify)
output->driver_notify (output);
G_OBJECT_CLASS (gf_output_parent_class)->finalize (object);
}
static void
gf_output_class_init (GfOutputClass *output_class)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (output_class);
object_class->finalize = gf_output_finalize;
}
static void
gf_output_init (GfOutput *output)
{
}
void
gf_output_parse_edid (GfOutput *output,
GBytes *edid)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment