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

backends: make GfCrtc a GObject

Based on mutter commit:
mutter@f64fab1d
parent 1673742f
......@@ -30,6 +30,7 @@ libbackends_la_SOURCES = \
gf-backend.c \
gf-backend.h \
gf-crtc-private.h \
gf-crtc.c \
gf-direction.h \
gf-display-config-shared.h \
gf-edid-parse.c \
......
......@@ -25,6 +25,8 @@
#ifndef GF_CRTC_MODE_PRIVATE_H
#define GF_CRTC_MODE_PRIVATE_H
#include <glib-object.h>
#include "gf-monitor-manager-enums-private.h"
#include "gf-monitor-manager-types-private.h"
#include "gf-rectangle.h"
......@@ -33,6 +35,8 @@ G_BEGIN_DECLS
struct _GfCrtc
{
GObject parent;
glong crtc_id;
GfRectangle rect;
GfCrtcMode *current_mode;
......@@ -76,6 +80,10 @@ typedef struct
GPtrArray *outputs;
} GfCrtcInfo;
#define GF_TYPE_CRTC (gf_crtc_get_type ())
G_DECLARE_FINAL_TYPE (GfCrtc, gf_crtc, GF, CRTC, GObject)
G_END_DECLS
#endif
/*
* Copyright (C) 2017 Red Hat
* Copyright (C) 2018 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/>.
*/
#include "config.h"
#include "gf-crtc-private.h"
G_DEFINE_TYPE (GfCrtc, gf_crtc, G_TYPE_OBJECT)
static void
gf_crtc_finalize (GObject *object)
{
GfCrtc *crtc;
crtc = GF_CRTC (object);
if (crtc->driver_notify)
crtc->driver_notify (crtc);
G_OBJECT_CLASS (gf_crtc_parent_class)->finalize (object);
}
static void
gf_crtc_class_init (GfCrtcClass *crtc_class)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (crtc_class);
object_class->finalize = gf_crtc_finalize;
}
static void
gf_crtc_init (GfCrtc *crtc)
{
}
......@@ -65,13 +65,11 @@ struct _GfMonitorManager
* while logical_monitors refer to logical ones.
*/
GList *outputs;
GList *crtcs;
GfCrtcMode *modes;
guint n_modes;
GfCrtc *crtcs;
guint n_crtcs;
GList *monitors;
GList *logical_monitors;
......@@ -176,6 +174,8 @@ GList *gf_monitor_manager_get_monitors (GfM
GList *gf_monitor_manager_get_outputs (GfMonitorManager *manager);
GList *gf_monitor_manager_get_crtcs (GfMonitorManager *manager);
gboolean gf_monitor_manager_has_hotplug_mode_update (GfMonitorManager *manager);
void gf_monitor_manager_read_current_state (GfMonitorManager *manager);
void gf_monitor_manager_on_hotplug (GfMonitorManager *manager);
......@@ -229,8 +229,6 @@ GfMonitorConfigManager *gf_monitor_manager_get_config_manager (GfM
void gf_monitor_manager_clear_mode (GfCrtcMode *mode);
void gf_monitor_manager_clear_crtc (GfCrtc *crtc);
static inline gboolean
gf_monitor_transform_is_rotated (GfMonitorTransform transform)
{
......
......@@ -382,12 +382,11 @@ is_assignments_changed (GfMonitorManager *manager,
GfOutputInfo **output_infos,
guint n_output_infos)
{
guint i;
GList *l;
for (i = 0; i < manager->n_crtcs; i++)
for (l = manager->crtcs; l; l = l->next)
{
GfCrtc *crtc = &manager->crtcs[i];
GfCrtc *crtc = l->data;
if (is_crtc_assignment_changed (crtc, crtc_infos, n_crtc_infos))
return TRUE;
......@@ -895,19 +894,22 @@ output_get_crtcs (GfMonitorManager *manager,
GfOutput *output,
XRROutputInfo *xrandr_output)
{
guint j, k;
guint j;
guint n_actual_crtcs;
GList *l;
output->possible_crtcs = g_new0 (GfCrtc *, xrandr_output->ncrtc);
n_actual_crtcs = 0;
for (j = 0; j < (guint) xrandr_output->ncrtc; j++)
{
for (k = 0; k < manager->n_crtcs; k++)
for (l = manager->crtcs; l; l = l->next)
{
if ((XID) manager->crtcs[k].crtc_id == xrandr_output->crtcs[j])
GfCrtc *crtc = l->data;
if ((XID) crtc->crtc_id == xrandr_output->crtcs[j])
{
output->possible_crtcs[n_actual_crtcs] = &manager->crtcs[k];
output->possible_crtcs[n_actual_crtcs] = crtc;
n_actual_crtcs += 1;
break;
}
......@@ -916,11 +918,13 @@ output_get_crtcs (GfMonitorManager *manager,
output->n_possible_crtcs = n_actual_crtcs;
output->crtc = NULL;
for (j = 0; j < manager->n_crtcs; j++)
for (l = manager->crtcs; l; l = l->next)
{
if ((XID) manager->crtcs[j].crtc_id == xrandr_output->crtc)
GfCrtc *crtc = l->data;
if ((XID) crtc->crtc_id == xrandr_output->crtc)
{
output->crtc = &manager->crtcs[j];
output->crtc = crtc;
break;
}
}
......@@ -1206,9 +1210,9 @@ apply_crtc_assignments (GfMonitorManager *manager,
}
/* Disable CRTCs not mentioned in the list */
for (i = 0; i < manager->n_crtcs; i++)
for (l = manager->crtcs; l; l = l->next)
{
GfCrtc *crtc = &manager->crtcs[i];
GfCrtc *crtc = l->data;
if (crtc->is_dirty)
{
......@@ -1586,11 +1590,10 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
return;
xrandr->resources = resources;
manager->n_crtcs = resources->ncrtc;
manager->n_modes = resources->nmode;
manager->outputs = NULL;
manager->modes = g_new0 (GfCrtcMode, manager->n_modes);
manager->crtcs = g_new0 (GfCrtc, manager->n_crtcs);
manager->crtcs = NULL;
for (i = 0; i < (guint) resources->nmode; i++)
{
......@@ -1614,7 +1617,7 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
GfCrtc *crtc;
xrandr_crtc = XRRGetCrtcInfo (xrandr->xdisplay, resources, resources->crtcs[i]);
crtc = &manager->crtcs[i];
crtc = g_object_new (GF_TYPE_CRTC, NULL);
crtc->crtc_id = resources->crtcs[i];
crtc->rect.x = xrandr_crtc->x;
......@@ -1634,6 +1637,7 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
}
}
manager->crtcs = g_list_append (manager->crtcs, crtc);
XRRFreeCrtcInfo (xrandr_crtc);
}
......
......@@ -1103,18 +1103,6 @@ free_mode_array (GfCrtcMode *old_modes,
g_free (old_modes);
}
static void
free_crtc_array (GfCrtc *old_crtcs,
gint n_old_crtcs)
{
gint i;
for (i = 0; i < n_old_crtcs; i++)
gf_monitor_manager_clear_crtc (&old_crtcs[i]);
g_free (old_crtcs);
}
static gboolean
gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
GDBusMethodInvocation *invocation)
......@@ -1136,9 +1124,9 @@ gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
g_variant_builder_init (&output_builder, G_VARIANT_TYPE ("a(uxiausauaua{sv})"));
g_variant_builder_init (&mode_builder, G_VARIANT_TYPE ("a(uxuudu)"));
for (i = 0; i < manager->n_crtcs; i++)
for (l = manager->crtcs, i = 0; l; l = l->next, i++)
{
GfCrtc *crtc = &manager->crtcs[i];
GfCrtc *crtc = l->data;
GVariantBuilder transforms;
g_variant_builder_init (&transforms, G_VARIANT_TYPE ("au"));
......@@ -1165,11 +1153,19 @@ gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
GVariantBuilder crtcs, modes, clones, properties;
GBytes *edid;
gchar *edid_file;
gint crtc_index;
g_variant_builder_init (&crtcs, G_VARIANT_TYPE ("au"));
for (j = 0; j < output->n_possible_crtcs; j++)
g_variant_builder_add (&crtcs, "u",
(guint) (output->possible_crtcs[j] - manager->crtcs));
{
GfCrtc *possible_crtc;
guint possible_crtc_index;
possible_crtc = output->possible_crtcs[j];
possible_crtc_index = g_list_index (manager->crtcs, possible_crtc);
g_variant_builder_add (&crtcs, "u", possible_crtc_index);
}
g_variant_builder_init (&modes, G_VARIANT_TYPE ("au"));
for (j = 0; j < output->n_modes; j++)
......@@ -1249,10 +1245,12 @@ gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
output->tile_info.tile_h));
}
crtc_index = output->crtc ? g_list_index (manager->crtcs, output->crtc) : -1;
g_variant_builder_add (&output_builder, "(uxiausauaua{sv})",
i, /* ID */
(gint64) output->winsys_id,
(gint) (output->crtc ? output->crtc - manager->crtcs : -1),
crtc_index,
&crtcs,
output->name,
&modes,
......@@ -1379,7 +1377,7 @@ gf_monitor_manager_handle_get_crtc_gamma (GfDBusDisplayConfig *skeleton,
return TRUE;
}
if (crtc_id >= manager->n_crtcs)
if (crtc_id >= g_list_length (manager->crtcs))
{
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_INVALID_ARGS,
......@@ -1387,7 +1385,7 @@ gf_monitor_manager_handle_get_crtc_gamma (GfDBusDisplayConfig *skeleton,
return TRUE;
}
crtc = &manager->crtcs[crtc_id];
crtc = g_list_nth_data (manager->crtcs, crtc_id);
if (manager_class->get_crtc_gamma)
{
......@@ -1448,7 +1446,7 @@ gf_monitor_manager_handle_set_crtc_gamma (GfDBusDisplayConfig *skeleton,
return TRUE;
}
if (crtc_id >= manager->n_crtcs)
if (crtc_id >= g_list_length (manager->crtcs))
{
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
G_DBUS_ERROR_INVALID_ARGS,
......@@ -1456,7 +1454,7 @@ gf_monitor_manager_handle_set_crtc_gamma (GfDBusDisplayConfig *skeleton,
return TRUE;
}
crtc = &manager->crtcs[crtc_id];
crtc = g_list_nth_data (manager->crtcs, crtc_id);
red_bytes = g_variant_get_data_as_bytes (red_v);
green_bytes = g_variant_get_data_as_bytes (green_v);
......@@ -2015,7 +2013,7 @@ gf_monitor_manager_finalize (GObject *object)
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);
g_list_free_full (manager->crtcs, g_object_unref);
g_list_free_full (manager->logical_monitors, g_object_unref);
......@@ -2205,6 +2203,12 @@ gf_monitor_manager_get_outputs (GfMonitorManager *manager)
return manager->outputs;
}
GList *
gf_monitor_manager_get_crtcs (GfMonitorManager *manager)
{
return manager->crtcs;
}
gboolean
gf_monitor_manager_has_hotplug_mode_update (GfMonitorManager *manager)
{
......@@ -2225,9 +2229,8 @@ void
gf_monitor_manager_read_current_state (GfMonitorManager *manager)
{
GList *old_outputs;
GfCrtc *old_crtcs;
GList *old_crtcs;
GfCrtcMode *old_modes;
guint n_old_crtcs;
guint n_old_modes;
/* Some implementations of read_current use the existing information
......@@ -2236,7 +2239,6 @@ gf_monitor_manager_read_current_state (GfMonitorManager *manager)
*/
old_outputs = manager->outputs;
old_crtcs = manager->crtcs;
n_old_crtcs = manager->n_crtcs;
old_modes = manager->modes;
n_old_modes = manager->n_modes;
......@@ -2247,7 +2249,7 @@ gf_monitor_manager_read_current_state (GfMonitorManager *manager)
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);
g_list_free_full (old_crtcs, g_object_unref);
}
void
......@@ -2559,15 +2561,6 @@ gf_monitor_manager_clear_mode (GfCrtcMode *mode)
memset (mode, 0, sizeof (*mode));
}
void
gf_monitor_manager_clear_crtc (GfCrtc *crtc)
{
if (crtc->driver_notify)
crtc->driver_notify (crtc);
memset (crtc, 0, sizeof (*crtc));
}
gint
gf_monitor_manager_get_monitor_for_output (GfMonitorManager *manager,
guint id)
......
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