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

backends: make GfCrtcMode a GObject

Based on mutter commit:
mutter@2db55052
parent 2c0bd78c
......@@ -29,6 +29,7 @@ libbackends_la_SOURCES = \
gf-backend-x11.c \
gf-backend.c \
gf-backend.h \
gf-crtc-mode.c \
gf-crtc-private.h \
gf-crtc.c \
gf-direction.h \
......
/*
* 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 (GfCrtcMode, gf_crtc_mode, G_TYPE_OBJECT)
static void
gf_crtc_mode_finalize (GObject *object)
{
GfCrtcMode *crtc_mode;
crtc_mode = GF_CRTC_MODE (object);
if (crtc_mode->driver_notify)
crtc_mode->driver_notify (crtc_mode);
G_OBJECT_CLASS (gf_crtc_mode_parent_class)->finalize (object);
}
static void
gf_crtc_mode_class_init (GfCrtcModeClass *crtc_mode_class)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (crtc_mode_class);
object_class->finalize = gf_crtc_mode_finalize;
}
static void
gf_crtc_mode_init (GfCrtcMode *crtc_mode)
{
}
......@@ -57,6 +57,8 @@ struct _GfCrtc
struct _GfCrtcMode
{
GObject parent;
/* The low-level ID of this mode, used to apply back configuration */
glong mode_id;
gchar *name;
......@@ -80,10 +82,12 @@ typedef struct
GPtrArray *outputs;
} GfCrtcInfo;
#define GF_TYPE_CRTC (gf_crtc_get_type ())
G_DECLARE_FINAL_TYPE (GfCrtc, gf_crtc, GF, CRTC, GObject)
#define GF_TYPE_CRTC_MODE (gf_crtc_mode_get_type ())
G_DECLARE_FINAL_TYPE (GfCrtcMode, gf_crtc_mode, GF, CRTC_MODE, GObject)
G_END_DECLS
#endif
......@@ -66,9 +66,7 @@ struct _GfMonitorManager
*/
GList *outputs;
GList *crtcs;
GfCrtcMode *modes;
guint n_modes;
GList *modes;
GList *monitors;
......@@ -227,8 +225,6 @@ GfLogicalMonitorLayoutMode gf_monitor_manager_get_default_layout_mode (GfM
GfMonitorConfigManager *gf_monitor_manager_get_config_manager (GfMonitorManager *manager);
void gf_monitor_manager_clear_mode (GfCrtcMode *mode);
static inline gboolean
gf_monitor_transform_is_rotated (GfMonitorTransform transform)
{
......
......@@ -865,7 +865,7 @@ output_get_modes (GfMonitorManager *manager,
GfOutput *output,
XRROutputInfo *xrandr_output)
{
guint j, k;
guint j;
guint n_actual_modes;
output->modes = g_new0 (GfCrtcMode *, xrandr_output->nmode);
......@@ -873,11 +873,15 @@ output_get_modes (GfMonitorManager *manager,
n_actual_modes = 0;
for (j = 0; j < (guint) xrandr_output->nmode; j++)
{
for (k = 0; k < manager->n_modes; k++)
GList *l;
for (l = manager->modes; l; l = l->next)
{
if (xrandr_output->modes[j] == (XID) manager->modes[k].mode_id)
GfCrtcMode *mode = l->data;
if (xrandr_output->modes[j] == (XID) mode->mode_id)
{
output->modes[n_actual_modes] = &manager->modes[k];
output->modes[n_actual_modes] = mode;
n_actual_modes += 1;
break;
}
......@@ -1590,9 +1594,8 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
return;
xrandr->resources = resources;
manager->n_modes = resources->nmode;
manager->outputs = NULL;
manager->modes = g_new0 (GfCrtcMode, manager->n_modes);
manager->modes = NULL;
manager->crtcs = NULL;
for (i = 0; i < (guint) resources->nmode; i++)
......@@ -1601,7 +1604,7 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
GfCrtcMode *mode;
xmode = &resources->modes[i];
mode = &manager->modes[i];
mode = g_object_new (GF_TYPE_CRTC_MODE, NULL);
mode->mode_id = xmode->id;
mode->width = xmode->width;
......@@ -1609,6 +1612,8 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
mode->refresh_rate = (xmode->dotClock / ((gfloat) xmode->hTotal * xmode->vTotal));
mode->flags = xmode->modeFlags;
mode->name = g_strdup_printf ("%dx%d", xmode->width, xmode->height);
manager->modes = g_list_append (manager->modes, mode);
}
for (i = 0; i < (guint) resources->ncrtc; i++)
......@@ -1632,7 +1637,7 @@ gf_monitor_manager_xrandr_read_current (GfMonitorManager *manager)
{
if (resources->modes[j].id == xrandr_crtc->mode)
{
crtc->current_mode = &manager->modes[j];
crtc->current_mode = g_list_nth_data (manager->modes, j);
break;
}
}
......
......@@ -1091,18 +1091,6 @@ rebuild_monitors (GfMonitorManager *manager)
}
}
static void
free_mode_array (GfCrtcMode *old_modes,
gint n_old_modes)
{
gint i;
for (i = 0; i < n_old_modes; i++)
gf_monitor_manager_clear_mode (&old_modes[i]);
g_free (old_modes);
}
static gboolean
gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
GDBusMethodInvocation *invocation)
......@@ -1128,12 +1116,18 @@ gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
{
GfCrtc *crtc = l->data;
GVariantBuilder transforms;
gint current_mode_index;
g_variant_builder_init (&transforms, G_VARIANT_TYPE ("au"));
for (j = 0; j <= GF_MONITOR_TRANSFORM_FLIPPED_270; j++)
if (crtc->all_transforms & (1 << j))
g_variant_builder_add (&transforms, "u", j);
if (crtc->current_mode)
current_mode_index = g_list_index (manager->modes, crtc->current_mode);
else
current_mode_index = -1;
g_variant_builder_add (&crtc_builder, "(uxiiiiiuaua{sv})",
i, /* ID */
(gint64) crtc->crtc_id,
......@@ -1141,7 +1135,7 @@ gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
(gint) crtc->rect.y,
(gint) crtc->rect.width,
(gint) crtc->rect.height,
(gint) (crtc->current_mode ? crtc->current_mode - manager->modes : -1),
current_mode_index,
(guint32) crtc->transform,
&transforms,
NULL /* properties */);
......@@ -1169,8 +1163,13 @@ gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
g_variant_builder_init (&modes, G_VARIANT_TYPE ("au"));
for (j = 0; j < output->n_modes; j++)
g_variant_builder_add (&modes, "u",
(guint) (output->modes[j] - manager->modes));
{
guint mode_index;
mode_index = g_list_index (manager->modes, output->modes[j]);
g_variant_builder_add (&modes, "u", mode_index);
}
g_variant_builder_init (&clones, G_VARIANT_TYPE ("au"));
for (j = 0; j < output->n_possible_clones; j++)
......@@ -1258,9 +1257,9 @@ gf_monitor_manager_handle_get_resources (GfDBusDisplayConfig *skeleton,
&properties);
}
for (i = 0; i < manager->n_modes; i++)
for (l = manager->modes, i = 0; l; l = l->next, i++)
{
GfCrtcMode *mode = &manager->modes[i];
GfCrtcMode *mode = l->data;
g_variant_builder_add (&mode_builder, "(uxuudu)",
i, /* ID */
......@@ -2012,7 +2011,7 @@ gf_monitor_manager_finalize (GObject *object)
manager = GF_MONITOR_MANAGER (object);
g_list_free_full (manager->outputs, g_object_unref);
free_mode_array (manager->modes, manager->n_modes);
g_list_free_full (manager->modes, g_object_unref);
g_list_free_full (manager->crtcs, g_object_unref);
g_list_free_full (manager->logical_monitors, g_object_unref);
......@@ -2230,8 +2229,7 @@ gf_monitor_manager_read_current_state (GfMonitorManager *manager)
{
GList *old_outputs;
GList *old_crtcs;
GfCrtcMode *old_modes;
guint n_old_modes;
GList *old_modes;
/* Some implementations of read_current use the existing information
* we have available, so don't free the old configuration until after
......@@ -2240,7 +2238,6 @@ gf_monitor_manager_read_current_state (GfMonitorManager *manager)
old_outputs = manager->outputs;
old_crtcs = manager->crtcs;
old_modes = manager->modes;
n_old_modes = manager->n_modes;
manager->serial++;
GF_MONITOR_MANAGER_GET_CLASS (manager)->read_current (manager);
......@@ -2248,7 +2245,7 @@ gf_monitor_manager_read_current_state (GfMonitorManager *manager)
rebuild_monitors (manager);
g_list_free_full (old_outputs, g_object_unref);
free_mode_array (old_modes, n_old_modes);
g_list_free_full (old_modes, g_object_unref);
g_list_free_full (old_crtcs, g_object_unref);
}
......@@ -2550,17 +2547,6 @@ gf_monitor_manager_get_config_manager (GfMonitorManager *manager)
return manager->config_manager;
}
void
gf_monitor_manager_clear_mode (GfCrtcMode *mode)
{
g_free (mode->name);
if (mode->driver_notify)
mode->driver_notify (mode);
memset (mode, 0, sizeof (*mode));
}
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