From 9186b6d6b099cf5ef5319bd3a82799751e1cc3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 25 Feb 2020 16:54:20 +0100 Subject: [PATCH] monitor-manager: Remove is_dirty from MetaCrtc and MetaOutput It was used during configuration to ensure that we always dealt with every output and CRTC. Do this without polluting the MetaOutput and MetaCrtc structs with intermediate variables not used by the corresponding types themself. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1287 --- src/backends/meta-crtc.h | 3 - src/backends/meta-monitor-manager-dummy.c | 27 ++++---- src/backends/meta-output.h | 3 - src/backends/native/meta-crtc-kms.c | 1 - .../native/meta-monitor-manager-kms.c | 66 ++++++++----------- src/backends/x11/meta-crtc-xrandr.c | 1 - .../x11/meta-monitor-manager-xrandr.c | 28 ++++---- src/tests/meta-monitor-manager-test.c | 27 ++++---- 8 files changed, 62 insertions(+), 94 deletions(-) diff --git a/src/backends/meta-crtc.h b/src/backends/meta-crtc.h index 0853a6537..12c46951c 100644 --- a/src/backends/meta-crtc.h +++ b/src/backends/meta-crtc.h @@ -64,9 +64,6 @@ struct _MetaCrtc MetaCrtcConfig *config; - /* Used when changing configuration */ - gboolean is_dirty; - gpointer driver_private; GDestroyNotify driver_notify; }; diff --git a/src/backends/meta-monitor-manager-dummy.c b/src/backends/meta-monitor-manager-dummy.c index ebcdc21bb..ff96df749 100644 --- a/src/backends/meta-monitor-manager-dummy.c +++ b/src/backends/meta-monitor-manager-dummy.c @@ -506,14 +506,20 @@ apply_crtc_assignments (MetaMonitorManager *manager, MetaOutputInfo **outputs, unsigned int n_outputs) { + g_autoptr (GList) to_configure_outputs = NULL; + g_autoptr (GList) to_configure_crtcs = NULL; GList *l; unsigned i; + to_configure_outputs = g_list_copy (meta_gpu_get_outputs (get_gpu (manager))); + to_configure_crtcs = g_list_copy (meta_gpu_get_crtcs (get_gpu (manager))); + for (i = 0; i < n_crtcs; i++) { MetaCrtcInfo *crtc_info = crtcs[i]; MetaCrtc *crtc = crtc_info->crtc; - crtc->is_dirty = TRUE; + + to_configure_crtcs = g_list_remove (to_configure_crtcs, crtc); if (crtc_info->mode == NULL) { @@ -533,7 +539,8 @@ apply_crtc_assignments (MetaMonitorManager *manager, { output = ((MetaOutput**)crtc_info->outputs->pdata)[j]; - output->is_dirty = TRUE; + to_configure_outputs = g_list_remove (to_configure_outputs, + output); meta_output_assign_crtc (output, crtc); } } @@ -549,30 +556,18 @@ apply_crtc_assignments (MetaMonitorManager *manager, } /* Disable CRTCs not mentioned in the list */ - for (l = meta_gpu_get_crtcs (get_gpu (manager)); l; l = l->next) + for (l = to_configure_crtcs; l; l = l->next) { MetaCrtc *crtc = l->data; - if (crtc->is_dirty) - { - crtc->is_dirty = FALSE; - continue; - } - meta_crtc_unset_config (crtc); } /* Disable outputs not mentioned in the list */ - for (l = meta_gpu_get_outputs (get_gpu (manager)); l; l = l->next) + for (l = to_configure_outputs; l; l = l->next) { MetaOutput *output = l->data; - if (output->is_dirty) - { - output->is_dirty = FALSE; - continue; - } - meta_output_unassign_crtc (output); output->is_primary = FALSE; } diff --git a/src/backends/meta-output.h b/src/backends/meta-output.h index 6e940509f..18850baf9 100644 --- a/src/backends/meta-output.h +++ b/src/backends/meta-output.h @@ -89,9 +89,6 @@ struct _MetaOutput int backlight_min; int backlight_max; - /* Used when changing configuration */ - gboolean is_dirty; - gboolean is_primary; gboolean is_presentation; diff --git a/src/backends/native/meta-crtc-kms.c b/src/backends/native/meta-crtc-kms.c index cb343bebb..372a4dac4 100644 --- a/src/backends/native/meta-crtc-kms.c +++ b/src/backends/native/meta-crtc-kms.c @@ -302,7 +302,6 @@ meta_create_kms_crtc (MetaGpuKms *gpu_kms, "id", meta_kms_crtc_get_id (kms_crtc), "gpu", gpu, NULL); - crtc->is_dirty = FALSE; crtc->all_transforms = ALL_TRANSFORMS_MASK; crtc_kms = g_new0 (MetaCrtcKms, 1); diff --git a/src/backends/native/meta-monitor-manager-kms.c b/src/backends/native/meta-monitor-manager-kms.c index 2607bc0e4..4d1ca7e21 100644 --- a/src/backends/native/meta-monitor-manager-kms.c +++ b/src/backends/native/meta-monitor-manager-kms.c @@ -176,16 +176,32 @@ apply_crtc_assignments (MetaMonitorManager *manager, unsigned int n_outputs) { MetaBackend *backend = meta_monitor_manager_get_backend (manager); + g_autoptr (GList) to_configure_outputs = NULL; + g_autoptr (GList) to_configure_crtcs = NULL; unsigned i; GList *gpus; GList *l; + gpus = meta_backend_get_gpus (backend); + for (l = gpus; l; l = l->next) + { + MetaGpu *gpu = l->data; + GList *crtcs; + GList *outputs; + + outputs = g_list_copy (meta_gpu_get_outputs (gpu)); + to_configure_outputs = g_list_concat (to_configure_outputs, outputs); + + crtcs = g_list_copy (meta_gpu_get_crtcs (gpu)); + to_configure_crtcs = g_list_concat (to_configure_crtcs, crtcs); + } + for (i = 0; i < n_crtcs; i++) { MetaCrtcInfo *crtc_info = crtcs[i]; MetaCrtc *crtc = crtc_info->crtc; - crtc->is_dirty = TRUE; + to_configure_crtcs = g_list_remove (to_configure_crtcs, crtc); if (crtc_info->mode == NULL) { @@ -204,31 +220,19 @@ apply_crtc_assignments (MetaMonitorManager *manager, { MetaOutput *output = g_ptr_array_index (crtc_info->outputs, j); - output->is_dirty = TRUE; + to_configure_outputs = g_list_remove (to_configure_outputs, + output); meta_output_assign_crtc (output, crtc); } } } - /* Disable CRTCs not mentioned in the list (they have is_dirty == FALSE, - because they weren't seen in the first loop) */ - gpus = meta_backend_get_gpus (backend); - for (l = gpus; l; l = l->next) + + /* Disable CRTCs yet to be configured. */ + for (l = to_configure_crtcs; l; l = l->next) { - MetaGpu *gpu = l->data; - GList *k; + MetaCrtc *crtc = l->data; - for (k = meta_gpu_get_crtcs (gpu); k; k = k->next) - { - MetaCrtc *crtc = k->data; - - if (crtc->is_dirty) - { - crtc->is_dirty = FALSE; - continue; - } - - meta_crtc_unset_config (crtc); - } + meta_crtc_unset_config (crtc); } for (i = 0; i < n_outputs; i++) @@ -241,25 +245,13 @@ apply_crtc_assignments (MetaMonitorManager *manager, output->is_underscanning = output_info->is_underscanning; } - /* Disable outputs not mentioned in the list */ - for (l = gpus; l; l = l->next) + /* Disable outputs yet to be configured. */ + for (l = to_configure_outputs; l; l = l->next) { - MetaGpu *gpu = l->data; - GList *k; + MetaOutput *output = l->data; - for (k = meta_gpu_get_outputs (gpu); k; k = k->next) - { - MetaOutput *output = k->data; - - if (output->is_dirty) - { - output->is_dirty = FALSE; - continue; - } - - meta_output_unassign_crtc (output); - output->is_primary = FALSE; - } + meta_output_unassign_crtc (output); + output->is_primary = FALSE; } } diff --git a/src/backends/x11/meta-crtc-xrandr.c b/src/backends/x11/meta-crtc-xrandr.c index fa24b95c8..bee536406 100644 --- a/src/backends/x11/meta-crtc-xrandr.c +++ b/src/backends/x11/meta-crtc-xrandr.c @@ -280,7 +280,6 @@ meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr, }; } - crtc->is_dirty = FALSE; crtc->all_transforms = meta_monitor_transform_from_xrandr_all (xrandr_crtc->rotations); diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c index 8e074604a..d06f7daff 100644 --- a/src/backends/x11/meta-monitor-manager-xrandr.c +++ b/src/backends/x11/meta-monitor-manager-xrandr.c @@ -368,10 +368,15 @@ apply_crtc_assignments (MetaMonitorManager *manager, { MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager); MetaGpu *gpu = meta_monitor_manager_xrandr_get_gpu (manager_xrandr); + g_autoptr (GList) to_configure_outputs = NULL; + g_autoptr (GList) to_disable_crtcs = NULL; unsigned i; GList *l; int width, height, width_mm, height_mm; + to_configure_outputs = g_list_copy (meta_gpu_get_outputs (gpu)); + to_disable_crtcs = g_list_copy (meta_gpu_get_crtcs (gpu)); + XGrabServer (manager_xrandr->xdisplay); /* First compute the new size of the screen (framebuffer) */ @@ -380,11 +385,12 @@ apply_crtc_assignments (MetaMonitorManager *manager, { MetaCrtcInfo *crtc_info = crtcs[i]; MetaCrtc *crtc = crtc_info->crtc; - crtc->is_dirty = TRUE; if (crtc_info->mode == NULL) continue; + to_disable_crtcs = g_list_remove (to_disable_crtcs, crtc); + width = MAX (width, (int) roundf (crtc_info->layout.origin.x + crtc_info->layout.size.width)); height = MAX (height, (int) roundf (crtc_info->layout.origin.y + @@ -427,17 +433,10 @@ apply_crtc_assignments (MetaMonitorManager *manager, } } - /* Disable CRTCs not mentioned in the list */ - for (l = meta_gpu_get_crtcs (gpu); l; l = l->next) + for (l = to_disable_crtcs; l; l = l->next) { MetaCrtc *crtc = l->data; - if (crtc->is_dirty) - { - crtc->is_dirty = FALSE; - continue; - } - if (!crtc->config) continue; @@ -488,7 +487,8 @@ apply_crtc_assignments (MetaMonitorManager *manager, output = ((MetaOutput**)crtc_info->outputs->pdata)[j]; - output->is_dirty = TRUE; + to_configure_outputs = g_list_remove (to_configure_outputs, + output); meta_output_assign_crtc (output, crtc); output_ids[j] = meta_output_get_id (output); @@ -536,16 +536,10 @@ apply_crtc_assignments (MetaMonitorManager *manager, } /* Disable outputs not mentioned in the list */ - for (l = meta_gpu_get_outputs (gpu); l; l = l->next) + for (l = to_configure_outputs; l; l = l->next) { MetaOutput *output = l->data; - if (output->is_dirty) - { - output->is_dirty = FALSE; - continue; - } - meta_output_unassign_crtc (output); output->is_primary = FALSE; } diff --git a/src/tests/meta-monitor-manager-test.c b/src/tests/meta-monitor-manager-test.c index 71fffda29..d76ada57a 100644 --- a/src/tests/meta-monitor-manager-test.c +++ b/src/tests/meta-monitor-manager-test.c @@ -123,14 +123,20 @@ apply_crtc_assignments (MetaMonitorManager *manager, MetaBackend *backend = meta_monitor_manager_get_backend (manager); MetaBackendTest *backend_test = META_BACKEND_TEST (backend); MetaGpu *gpu = meta_backend_test_get_gpu (backend_test); + g_autoptr (GList) to_configure_outputs = NULL; + g_autoptr (GList) to_configure_crtcs = NULL; GList *l; unsigned int i; + to_configure_outputs = g_list_copy (meta_gpu_get_outputs (gpu)); + to_configure_crtcs = g_list_copy (meta_gpu_get_crtcs (gpu)); + for (i = 0; i < n_crtcs; i++) { MetaCrtcInfo *crtc_info = crtcs[i]; MetaCrtc *crtc = crtc_info->crtc; - crtc->is_dirty = TRUE; + + to_configure_crtcs = g_list_remove (to_configure_crtcs, crtc); if (crtc_info->mode == NULL) { @@ -150,7 +156,8 @@ apply_crtc_assignments (MetaMonitorManager *manager, { output = ((MetaOutput**)crtc_info->outputs->pdata)[j]; - output->is_dirty = TRUE; + to_configure_outputs = g_list_remove (to_configure_outputs, + output); meta_output_assign_crtc (output, crtc); } } @@ -167,30 +174,18 @@ apply_crtc_assignments (MetaMonitorManager *manager, } /* Disable CRTCs not mentioned in the list */ - for (l = meta_gpu_get_crtcs (gpu); l; l = l->next) + for (l = to_configure_crtcs; l; l = l->next) { MetaCrtc *crtc = l->data; - if (crtc->is_dirty) - { - crtc->is_dirty = FALSE; - continue; - } - meta_crtc_unset_config (crtc); } /* Disable outputs not mentioned in the list */ - for (l = meta_gpu_get_outputs (gpu); l; l = l->next) + for (l = to_configure_outputs; l; l = l->next) { MetaOutput *output = l->data; - if (output->is_dirty) - { - output->is_dirty = FALSE; - continue; - } - meta_output_unassign_crtc (output); output->is_primary = FALSE; }