kms: Only update a device state if it contains the changed crtc/connector

On hotplug events we may receive a "CRTC" or "CONNECTOR" property that
indicates which crtc/connector property ID has changed.

In such case, instead of update data for all the devices, only update the
device containing the relative connector.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1964>
This commit is contained in:
Marco Trevisan (Treviño) 2020-08-04 19:25:37 +02:00 committed by Marge Bot
parent 3d3668a389
commit 91ed95ab6f

View File

@ -565,8 +565,16 @@ meta_kms_is_waiting_for_impl_task (MetaKms *kms)
return kms->waiting_for_impl_task; return kms->waiting_for_impl_task;
} }
typedef struct _UpdateStatesData
{
const char *device_path;
uint32_t crtc_id;
uint32_t connector_id;
} UpdateStatesData;
static MetaKmsUpdateChanges static MetaKmsUpdateChanges
meta_kms_update_states_in_impl (MetaKms *kms) meta_kms_update_states_in_impl (MetaKms *kms,
UpdateStatesData *update_data)
{ {
MetaKmsUpdateChanges changes = META_KMS_UPDATE_CHANGE_NONE; MetaKmsUpdateChanges changes = META_KMS_UPDATE_CHANGE_NONE;
GList *l; GList *l;
@ -582,6 +590,20 @@ meta_kms_update_states_in_impl (MetaKms *kms)
for (l = kms->devices; l; l = l->next) for (l = kms->devices; l; l = l->next)
{ {
MetaKmsDevice *kms_device = META_KMS_DEVICE (l->data); MetaKmsDevice *kms_device = META_KMS_DEVICE (l->data);
const char *kms_device_path = meta_kms_device_get_path (kms_device);
if (update_data->device_path &&
g_strcmp0 (kms_device_path, update_data->device_path) != 0)
continue;
if (update_data->crtc_id > 0 &&
!meta_kms_device_find_crtc_in_impl (kms_device, update_data->crtc_id))
continue;
if (update_data->connector_id > 0 &&
!meta_kms_device_find_connector_in_impl (kms_device,
update_data->connector_id))
continue;
changes |= meta_kms_device_update_states_in_impl (kms_device); changes |= meta_kms_device_update_states_in_impl (kms_device);
} }
@ -594,26 +616,42 @@ update_states_in_impl (MetaKmsImpl *impl,
gpointer user_data, gpointer user_data,
GError **error) GError **error)
{ {
UpdateStatesData *data = user_data;
MetaKms *kms = meta_kms_impl_get_kms (impl); MetaKms *kms = meta_kms_impl_get_kms (impl);
return GUINT_TO_POINTER (meta_kms_update_states_in_impl (kms)); return GUINT_TO_POINTER (meta_kms_update_states_in_impl (kms, data));
} }
static MetaKmsUpdateChanges static MetaKmsUpdateChanges
meta_kms_update_states_sync (MetaKms *kms) meta_kms_update_states_sync (MetaKms *kms,
GUdevDevice *udev_device)
{ {
UpdateStatesData data = {};
gpointer ret; gpointer ret;
ret = meta_kms_run_impl_task_sync (kms, update_states_in_impl, NULL, NULL); if (udev_device)
{
data.device_path = g_udev_device_get_device_file (udev_device);
data.crtc_id =
CLAMP (g_udev_device_get_property_as_int (udev_device, "CRTC"),
0, UINT32_MAX);
data.connector_id =
CLAMP (g_udev_device_get_property_as_int (udev_device, "CONNECTOR"),
0, UINT32_MAX);
}
ret = meta_kms_run_impl_task_sync (kms, update_states_in_impl, &data, NULL);
return GPOINTER_TO_UINT (ret); return GPOINTER_TO_UINT (ret);
} }
static void static void
handle_hotplug_event (MetaKms *kms) handle_hotplug_event (MetaKms *kms,
GUdevDevice *udev_device)
{ {
MetaKmsUpdateChanges changes; MetaKmsUpdateChanges changes;
changes = meta_kms_update_states_sync (kms); changes = meta_kms_update_states_sync (kms, udev_device);
if (changes != META_KMS_UPDATE_CHANGE_NONE) if (changes != META_KMS_UPDATE_CHANGE_NONE)
g_signal_emit (kms, signals[RESOURCES_CHANGED], 0, changes); g_signal_emit (kms, signals[RESOURCES_CHANGED], 0, changes);
@ -622,7 +660,7 @@ handle_hotplug_event (MetaKms *kms)
void void
meta_kms_resume (MetaKms *kms) meta_kms_resume (MetaKms *kms)
{ {
handle_hotplug_event (kms); handle_hotplug_event (kms, NULL);
} }
static void static void
@ -630,7 +668,7 @@ on_udev_hotplug (MetaUdev *udev,
GUdevDevice *udev_device, GUdevDevice *udev_device,
MetaKms *kms) MetaKms *kms)
{ {
handle_hotplug_event (kms); handle_hotplug_event (kms, udev_device);
} }
static void static void
@ -638,7 +676,7 @@ on_udev_device_removed (MetaUdev *udev,
GUdevDevice *device, GUdevDevice *device,
MetaKms *kms) MetaKms *kms)
{ {
handle_hotplug_event (kms); handle_hotplug_event (kms, NULL);
} }
MetaBackend * MetaBackend *