Commit 5c500ad4 authored by Jonas Ådahl's avatar Jonas Ådahl Committed by Georges Basile Stavracas Neto

backend: Move GPU ownership from the monitor manager to the backend

Lets work towards making MetaMonitorManager about managing monitors, and
not about managing GPUs. This changes other units to keep a pointer to
the backend instead of a monitor manager, in case their ownership
changed, or their main usage of the monitor manager was to look up GPUs.

#548
!525
parent e7fd068a
......@@ -181,4 +181,11 @@ void meta_backend_notify_keymap_layout_group_changed (MetaBackend *backend,
void meta_backend_notify_ui_scaling_factor_changed (MetaBackend *backend);
META_EXPORT_TEST
void meta_backend_add_gpu (MetaBackend *backend,
MetaGpu *gpu);
META_EXPORT_TEST
GList * meta_backend_get_gpus (MetaBackend *backend);
#endif /* META_BACKEND_PRIVATE_H */
......@@ -89,6 +89,7 @@ enum
KEYMAP_LAYOUT_GROUP_CHANGED,
LAST_DEVICE_CHANGED,
LID_IS_CLOSED_CHANGED,
GPU_ADDED,
N_SIGNALS
};
......@@ -138,6 +139,8 @@ struct _MetaBackendPrivate
ClutterBackend *clutter_backend;
ClutterActor *stage;
GList *gpus;
gboolean is_pointer_position_initialized;
guint device_update_idle_id;
......@@ -175,6 +178,8 @@ meta_backend_finalize (GObject *object)
MetaBackend *backend = META_BACKEND (object);
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
g_list_free_full (priv->gpus, g_object_unref);
g_clear_object (&priv->monitor_manager);
g_clear_object (&priv->orientation_manager);
g_clear_object (&priv->input_settings);
......@@ -752,6 +757,18 @@ meta_backend_class_init (MetaBackendClass *klass)
0,
NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
/**
* MetaBackend::gpu-added: (skip)
* @backend: the #MetaBackend
* @gpu: the #MetaGpu
*/
signals[GPU_ADDED] =
g_signal_new ("gpu-added",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 1, META_TYPE_GPU);
mutter_stage_views = g_getenv ("MUTTER_STAGE_VIEWS");
stage_views_disabled = g_strcmp0 (mutter_stage_views, "0") == 0;
......@@ -1399,3 +1416,22 @@ meta_backend_notify_keymap_layout_group_changed (MetaBackend *backend,
g_signal_emit (backend, signals[KEYMAP_LAYOUT_GROUP_CHANGED], 0,
locked_group);
}
void
meta_backend_add_gpu (MetaBackend *backend,
MetaGpu *gpu)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
priv->gpus = g_list_append (priv->gpus, gpu);
g_signal_emit (backend, signals[GPU_ADDED], 0, gpu);
}
GList *
meta_backend_get_gpus (MetaBackend *backend)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
return priv->gpus;
}
......@@ -23,13 +23,14 @@
#include "backends/meta-gpu.h"
#include "backends/meta-backend-private.h"
#include "backends/meta-output.h"
enum
{
PROP_0,
PROP_MONITOR_MANAGER,
PROP_BACKEND,
PROP_LAST
};
......@@ -38,7 +39,7 @@ static GParamSpec *obj_props[PROP_LAST];
typedef struct _MetaGpuPrivate
{
MetaMonitorManager *monitor_manager;
MetaBackend *backend;
GList *outputs;
GList *crtcs;
......@@ -88,12 +89,12 @@ meta_gpu_read_current (MetaGpu *gpu,
return ret;
}
MetaMonitorManager *
meta_gpu_get_monitor_manager (MetaGpu *gpu)
MetaBackend *
meta_gpu_get_backend (MetaGpu *gpu)
{
MetaGpuPrivate *priv = meta_gpu_get_instance_private (gpu);
return priv->monitor_manager;
return priv->backend;
}
GList *
......@@ -158,8 +159,8 @@ meta_gpu_set_property (GObject *object,
switch (prop_id)
{
case PROP_MONITOR_MANAGER:
priv->monitor_manager = g_value_get_object (value);
case PROP_BACKEND:
priv->backend = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -177,8 +178,8 @@ meta_gpu_get_property (GObject *object,
switch (prop_id)
{
case PROP_MONITOR_MANAGER:
g_value_set_object (value, priv->monitor_manager);
case PROP_BACKEND:
g_value_set_object (value, priv->backend);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -212,11 +213,11 @@ meta_gpu_class_init (MetaGpuClass *klass)
object_class->get_property = meta_gpu_get_property;
object_class->finalize = meta_gpu_finalize;
obj_props[PROP_MONITOR_MANAGER] =
g_param_spec_object ("monitor-manager",
"monitor-manager",
"MetaMonitorManager",
META_TYPE_MONITOR_MANAGER,
obj_props[PROP_BACKEND] =
g_param_spec_object ("backend",
"backend",
"MetaBackend",
META_TYPE_BACKEND,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
......
......@@ -46,7 +46,7 @@ META_EXPORT_TEST
gboolean meta_gpu_has_hotplug_mode_update (MetaGpu *gpu);
META_EXPORT_TEST
MetaMonitorManager * meta_gpu_get_monitor_manager (MetaGpu *gpu);
MetaBackend * meta_gpu_get_backend (MetaGpu *gpu);
META_EXPORT_TEST
GList * meta_gpu_get_outputs (MetaGpu *gpu);
......
......@@ -47,8 +47,6 @@ struct _MetaMonitorManagerDummy
{
MetaMonitorManager parent_instance;
MetaGpu *gpu;
gboolean is_transform_handled;
};
......@@ -98,6 +96,14 @@ create_mode (CrtcModeSpec *spec,
return mode;
}
static MetaGpu *
get_gpu (MetaMonitorManager *manager)
{
MetaBackend *backend = meta_monitor_manager_get_backend (manager);
return META_GPU (meta_backend_get_gpus (backend)->data);
}
static void
append_monitor (MetaMonitorManager *manager,
GList **modes,
......@@ -105,8 +111,7 @@ append_monitor (MetaMonitorManager *manager,
GList **outputs,
float scale)
{
MetaMonitorManagerDummy *manager_dummy = META_MONITOR_MANAGER_DUMMY (manager);
MetaGpu *gpu = manager_dummy->gpu;
MetaGpu *gpu = get_gpu (manager);
CrtcModeSpec default_specs[] = {
{
.width = 800,
......@@ -246,8 +251,7 @@ append_tiled_monitor (MetaMonitorManager *manager,
GList **outputs,
int scale)
{
MetaMonitorManagerDummy *manager_dummy = META_MONITOR_MANAGER_DUMMY (manager);
MetaGpu *gpu = manager_dummy->gpu;
MetaGpu *gpu = get_gpu (manager);
CrtcModeSpec mode_specs[] = {
{
.width = 800,
......@@ -371,8 +375,7 @@ meta_output_dummy_notify_destroy (MetaOutput *output)
static void
meta_monitor_manager_dummy_read_current (MetaMonitorManager *manager)
{
MetaMonitorManagerDummy *manager_dummy = META_MONITOR_MANAGER_DUMMY (manager);
MetaGpu *gpu = manager_dummy->gpu;
MetaGpu *gpu = get_gpu (manager);
unsigned int num_monitors = 1;
float *monitor_scales = NULL;
const char *num_monitors_str;
......@@ -495,7 +498,6 @@ apply_crtc_assignments (MetaMonitorManager *manager,
MetaOutputInfo **outputs,
unsigned int n_outputs)
{
MetaMonitorManagerDummy *manager_dummy = META_MONITOR_MANAGER_DUMMY (manager);
GList *l;
unsigned i;
......@@ -560,7 +562,7 @@ apply_crtc_assignments (MetaMonitorManager *manager,
}
/* Disable CRTCs not mentioned in the list */
for (l = meta_gpu_get_crtcs (manager_dummy->gpu); l; l = l->next)
for (l = meta_gpu_get_crtcs (get_gpu (manager)); l; l = l->next)
{
MetaCrtc *crtc = l->data;
......@@ -580,7 +582,7 @@ apply_crtc_assignments (MetaMonitorManager *manager,
}
/* Disable outputs not mentioned in the list */
for (l = meta_gpu_get_outputs (manager_dummy->gpu); l; l = l->next)
for (l = meta_gpu_get_outputs (get_gpu (manager)); l; l = l->next)
{
MetaOutput *output = l->data;
......@@ -772,11 +774,32 @@ meta_monitor_manager_dummy_get_default_layout_mode (MetaMonitorManager *manager)
return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
}
static void
meta_monitor_manager_dummy_constructed (GObject *object)
{
MetaMonitorManagerDummy *manager_dummy = META_MONITOR_MANAGER_DUMMY (object);
const char *nested_offscreen_transform;
GObjectClass *parent_object_class =
G_OBJECT_CLASS (meta_monitor_manager_dummy_parent_class);
parent_object_class->constructed (object);
nested_offscreen_transform =
g_getenv ("MUTTER_DEBUG_NESTED_OFFSCREEN_TRANSFORM");
if (g_strcmp0 (nested_offscreen_transform, "1") == 0)
manager_dummy->is_transform_handled = FALSE;
else
manager_dummy->is_transform_handled = TRUE;
}
static void
meta_monitor_manager_dummy_class_init (MetaMonitorManagerDummyClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_CLASS (klass);
object_class->constructed = meta_monitor_manager_dummy_constructed;
manager_class->ensure_initial_config = meta_monitor_manager_dummy_ensure_initial_config;
manager_class->apply_monitors_config = meta_monitor_manager_dummy_apply_monitors_config;
manager_class->is_transform_handled = meta_monitor_manager_dummy_is_transform_handled;
......@@ -790,27 +813,14 @@ meta_monitor_manager_dummy_class_init (MetaMonitorManagerDummyClass *klass)
static void
meta_monitor_manager_dummy_init (MetaMonitorManagerDummy *manager_dummy)
{
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_dummy);
const char *nested_offscreen_transform;
nested_offscreen_transform =
g_getenv ("MUTTER_DEBUG_NESTED_OFFSCREEN_TRANSFORM");
if (g_strcmp0 (nested_offscreen_transform, "1") == 0)
manager_dummy->is_transform_handled = FALSE;
else
manager_dummy->is_transform_handled = TRUE;
manager_dummy->gpu = g_object_new (META_TYPE_GPU_DUMMY,
"monitor-manager", manager,
NULL);
meta_monitor_manager_add_gpu (manager, manager_dummy->gpu);
}
static gboolean
meta_gpu_dummy_read_current (MetaGpu *gpu,
GError **error)
{
MetaMonitorManager *manager = meta_gpu_get_monitor_manager (gpu);
MetaBackend *backend = meta_gpu_get_backend (gpu);
MetaMonitorManager *manager = meta_backend_get_monitor_manager (backend);
meta_monitor_manager_dummy_read_current (manager);
......
......@@ -121,8 +121,6 @@ struct _MetaMonitorManager
int screen_width;
int screen_height;
GList *gpus;
GList *monitors;
GList *logical_monitors;
......@@ -248,6 +246,7 @@ struct _MetaMonitorManagerClass
MetaLogicalMonitorLayoutMode (*get_default_layout_mode) (MetaMonitorManager *);
};
META_EXPORT_TEST
MetaBackend * meta_monitor_manager_get_backend (MetaMonitorManager *manager);
void meta_monitor_manager_setup (MetaMonitorManager *manager);
......@@ -295,12 +294,6 @@ MetaMonitor * meta_monitor_manager_get_monitor_from_connector (MetaMonitor
META_EXPORT_TEST
GList * meta_monitor_manager_get_monitors (MetaMonitorManager *manager);
META_EXPORT_TEST
void meta_monitor_manager_add_gpu (MetaMonitorManager *manager,
MetaGpu *gpu);
META_EXPORT_TEST
GList * meta_monitor_manager_get_gpus (MetaMonitorManager *manager);
void meta_monitor_manager_get_screen_size (MetaMonitorManager *manager,
int *width,
int *height);
......
......@@ -511,9 +511,11 @@ meta_monitor_manager_apply_monitors_config (MetaMonitorManager *manager,
gboolean
meta_monitor_manager_has_hotplug_mode_update (MetaMonitorManager *manager)
{
GList *gpus;
GList *l;
for (l = manager->gpus; l; l = l->next)
gpus = meta_backend_get_gpus (manager->backend);
for (l = gpus; l; l = l->next)
{
MetaGpu *gpu = l->data;
......@@ -794,7 +796,6 @@ meta_monitor_manager_finalize (GObject *object)
{
MetaMonitorManager *manager = META_MONITOR_MANAGER (object);
g_list_free_full (manager->gpus, g_object_unref);
g_list_free_full (manager->logical_monitors, g_object_unref);
g_signal_handler_disconnect (manager->backend,
......@@ -1063,10 +1064,12 @@ static GList *
combine_gpu_lists (MetaMonitorManager *manager,
GList * (*list_getter) (MetaGpu *gpu))
{
GList *gpus;
GList *list = NULL;
GList *l;
for (l = manager->gpus; l; l = l->next)
gpus = meta_backend_get_gpus (manager->backend);
for (l = gpus; l; l = l->next)
{
MetaGpu *gpu = l->data;
......@@ -2676,26 +2679,6 @@ meta_monitor_manager_get_monitors (MetaMonitorManager *manager)
return manager->monitors;
}
/**
* meta_monitor_manager_add_gpu:
* @manager: A #MetaMonitorManager object
*
* Should only be called by subclasses. Adds a #MetaGpu to the internal list of
* GPU's.
*/
void
meta_monitor_manager_add_gpu (MetaMonitorManager *manager,
MetaGpu *gpu)
{
manager->gpus = g_list_append (manager->gpus, gpu);
}
GList *
meta_monitor_manager_get_gpus (MetaMonitorManager *manager)
{
return manager->gpus;
}
void
meta_monitor_manager_get_screen_size (MetaMonitorManager *manager,
int *width,
......@@ -2717,6 +2700,7 @@ meta_monitor_manager_get_power_save_mode (MetaMonitorManager *manager)
static void
rebuild_monitors (MetaMonitorManager *manager)
{
GList *gpus;
GList *l;
if (manager->monitors)
......@@ -2725,7 +2709,8 @@ rebuild_monitors (MetaMonitorManager *manager)
manager->monitors = NULL;
}
for (l = manager->gpus; l; l = l->next)
gpus = meta_backend_get_gpus (manager->backend);
for (l = gpus; l; l = l->next)
{
MetaGpu *gpu = l->data;
GList *k;
......@@ -2740,7 +2725,7 @@ rebuild_monitors (MetaMonitorManager *manager)
{
MetaMonitorTiled *monitor_tiled;
monitor_tiled = meta_monitor_tiled_new (gpu, output);
monitor_tiled = meta_monitor_tiled_new (gpu, manager, output);
manager->monitors = g_list_append (manager->monitors,
monitor_tiled);
}
......@@ -2797,7 +2782,7 @@ meta_monitor_manager_real_read_current_state (MetaMonitorManager *manager)
manager->serial++;
for (l = manager->gpus; l; l = l->next)
for (l = meta_backend_get_gpus (manager->backend); l; l = l->next)
{
MetaGpu *gpu = l->data;
GError *error = NULL;
......
......@@ -90,6 +90,8 @@ struct _MetaMonitorTiled
{
MetaMonitor parent;
MetaMonitorManager *monitor_manager;
uint32_t tile_group_id;
/* The tile (0, 0) output. */
......@@ -1176,10 +1178,10 @@ meta_monitor_tiled_generate_modes (MetaMonitorTiled *monitor_tiled)
}
MetaMonitorTiled *
meta_monitor_tiled_new (MetaGpu *gpu,
MetaOutput *output)
meta_monitor_tiled_new (MetaGpu *gpu,
MetaMonitorManager *monitor_manager,
MetaOutput *output)
{
MetaMonitorManager *monitor_manager;
MetaMonitorTiled *monitor_tiled;
MetaMonitor *monitor;
MetaMonitorPrivate *monitor_priv;
......@@ -1200,7 +1202,7 @@ meta_monitor_tiled_new (MetaGpu *gpu,
meta_monitor_generate_spec (monitor);
monitor_manager = meta_gpu_get_monitor_manager (gpu);
monitor_tiled->monitor_manager = monitor_manager;
meta_monitor_manager_tiled_monitor_added (monitor_manager,
META_MONITOR (monitor_tiled));
......@@ -1286,14 +1288,10 @@ meta_monitor_tiled_calculate_crtc_pos (MetaMonitor *monitor,
static void
meta_monitor_tiled_finalize (GObject *object)
{
MetaMonitor *monitor = META_MONITOR (object);
MetaMonitorPrivate *monitor_priv =
meta_monitor_get_instance_private (monitor);
MetaMonitorManager *monitor_manager;
MetaMonitorTiled *monitor_tiled = META_MONITOR_TILED (object);
monitor_manager = meta_gpu_get_monitor_manager (monitor_priv->gpu);
meta_monitor_manager_tiled_monitor_removed (monitor_manager,
monitor);
meta_monitor_manager_tiled_monitor_removed (monitor_tiled->monitor_manager,
META_MONITOR (monitor_tiled));
G_OBJECT_CLASS (meta_monitor_tiled_parent_class)->finalize (object);
}
......
......@@ -96,8 +96,9 @@ G_DECLARE_FINAL_TYPE (MetaMonitorTiled, meta_monitor_tiled,
MetaMonitor)
META_EXPORT_TEST
MetaMonitorTiled * meta_monitor_tiled_new (MetaGpu *gpu,
MetaOutput *output);
MetaMonitorTiled * meta_monitor_tiled_new (MetaGpu *gpu,
MetaMonitorManager *monitor_manager,
MetaOutput *output);
META_EXPORT_TEST
MetaMonitorNormal * meta_monitor_normal_new (MetaGpu *gpu,
......
......@@ -113,7 +113,9 @@ meta_screen_cast_monitor_stream_new (MetaScreenCastSession *session,
GError **error)
{
MetaGpu *gpu = meta_monitor_get_gpu (monitor);
MetaMonitorManager *monitor_manager = meta_gpu_get_monitor_manager (gpu);
MetaBackend *backend = meta_gpu_get_backend (gpu);
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaScreenCastMonitorStream *monitor_stream;
if (!meta_monitor_is_active (monitor))
......
......@@ -66,6 +66,8 @@ struct _MetaBackendNative
MetaLauncher *launcher;
MetaUdev *udev;
MetaBarrierManagerNative *barrier_manager;
guint udev_device_added_handler_id;
};
static GInitableIface *initable_parent_iface;
......@@ -77,11 +79,17 @@ G_DEFINE_TYPE_WITH_CODE (MetaBackendNative, meta_backend_native, META_TYPE_BACKE
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
initable_iface_init))
static void
disconnect_udev_device_added_handler (MetaBackendNative *native);
static void
meta_backend_native_finalize (GObject *object)
{
MetaBackendNative *native = META_BACKEND_NATIVE (object);
if (native->udev_device_added_handler_id)
disconnect_udev_device_added_handler (native);
g_clear_object (&native->udev);
meta_launcher_free (native->launcher);
......@@ -370,13 +378,10 @@ static MetaRenderer *
meta_backend_native_create_renderer (MetaBackend *backend,
GError **error)
{
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaMonitorManagerKms *monitor_manager_kms =
META_MONITOR_MANAGER_KMS (monitor_manager);
MetaBackendNative *native = META_BACKEND_NATIVE (backend);
MetaRendererNative *renderer_native;
renderer_native = meta_renderer_native_new (monitor_manager_kms, error);
renderer_native = meta_renderer_native_new (native, error);
if (!renderer_native)
return NULL;
......@@ -513,6 +518,128 @@ meta_backend_native_update_screen_size (MetaBackend *backend,
clutter_actor_set_size (stage, width, height);
}
static MetaGpuKms *
create_gpu_from_udev_device (MetaBackendNative *native,
GUdevDevice *device,
GError **error)
{
MetaGpuKmsFlag flags = META_GPU_KMS_FLAG_NONE;
const char *device_path;
if (meta_is_udev_device_platform_device (device))
flags |= META_GPU_KMS_FLAG_PLATFORM_DEVICE;
if (meta_is_udev_device_boot_vga (device))
flags |= META_GPU_KMS_FLAG_BOOT_VGA;
device_path = g_udev_device_get_device_file (device);
return meta_gpu_kms_new (native, device_path, flags, error);
}
static void
on_udev_device_added (MetaUdev *udev,
GUdevDevice *device,
MetaBackendNative *native)
{
MetaBackend *backend = META_BACKEND (native);
g_autoptr (GError) error = NULL;
const char *device_path;
MetaGpuKms *new_gpu_kms;
GList *gpus, *l;
if (!meta_udev_is_drm_device (udev, device))
return;
device_path = g_udev_device_get_device_file (device);
gpus = meta_backend_get_gpus (backend);;
for (l = gpus; l; l = l->next)
{
MetaGpuKms *gpu_kms = l->data;
if (!g_strcmp0 (device_path, meta_gpu_kms_get_file_path (gpu_kms)))
{
g_warning ("Failed to hotplug secondary gpu '%s': %s",
device_path, "device already present");
return;
}
}
new_gpu_kms = create_gpu_from_udev_device (native, device, &error);
if (!new_gpu_kms)
{
g_warning ("Failed to hotplug secondary gpu '%s': %s",
device_path, error->message);
g_error_free (error);
return;
}
meta_backend_add_gpu (backend, META_GPU (new_gpu_kms));
}
static void
connect_udev_device_added_handler (MetaBackendNative *native)
{
native->udev_device_added_handler_id =
g_signal_connect (native->udev, "device-added",
G_CALLBACK (on_udev_device_added), native);
}
static void
disconnect_udev_device_added_handler (MetaBackendNative *native)
{
g_signal_handler_disconnect (native->udev,
native->udev_device_added_handler_id);
native->udev_device_added_handler_id = 0;
}
static gboolean
init_gpus (MetaBackendNative *native,
GError **error)
{
MetaBackend *backend = META_BACKEND (native);
MetaUdev *udev = meta_backend_native_get_udev (native);
GList *devices;
GList *l;
devices = meta_udev_list_drm_devices (udev, error);