From 2ebd43cba95eea4d515a6cdb36353961dfda074c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 25 Feb 2020 10:39:56 +0100 Subject: [PATCH] crtc: Move MetaGpu field to instance-private Users either set during construction, or get via the helper. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1287 --- src/backends/meta-crtc.c | 74 ++++++++++++++++++++++- src/backends/meta-crtc.h | 3 +- src/backends/meta-monitor-manager-dummy.c | 9 ++- src/backends/native/meta-crtc-kms.c | 5 +- src/backends/x11/meta-crtc-xrandr.c | 7 ++- src/tests/headless-start-test.c | 6 +- src/tests/meta-monitor-manager-test.c | 2 - src/tests/monitor-test-utils.c | 11 +++- src/tests/monitor-test-utils.h | 2 + 9 files changed, 103 insertions(+), 16 deletions(-) diff --git a/src/backends/meta-crtc.c b/src/backends/meta-crtc.c index 7a38f5692..bef657774 100644 --- a/src/backends/meta-crtc.c +++ b/src/backends/meta-crtc.c @@ -21,14 +21,34 @@ #include "backends/meta-crtc.h" -G_DEFINE_TYPE (MetaCrtc, meta_crtc, G_TYPE_OBJECT) +#include "backends/meta-gpu.h" + +enum +{ + PROP_0, + + PROP_GPU, + + N_PROPS +}; + +static GParamSpec *obj_props[N_PROPS]; + +typedef struct _MetaCrtcPrivate +{ + MetaGpu *gpu; +} MetaCrtcPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE (MetaCrtc, meta_crtc, G_TYPE_OBJECT) G_DEFINE_TYPE (MetaCrtcMode, meta_crtc_mode, G_TYPE_OBJECT) MetaGpu * meta_crtc_get_gpu (MetaCrtc *crtc) { - return crtc->gpu; + MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc); + + return priv->gpu; } void @@ -55,6 +75,44 @@ meta_crtc_unset_config (MetaCrtc *crtc) g_clear_pointer (&crtc->config, g_free); } +static void +meta_crtc_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MetaCrtc *crtc = META_CRTC (object); + MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc); + + switch (prop_id) + { + case PROP_GPU: + priv->gpu = g_value_get_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +meta_crtc_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MetaCrtc *crtc = META_CRTC (object); + MetaCrtcPrivate *priv = meta_crtc_get_instance_private (crtc); + + switch (prop_id) + { + case PROP_GPU: + g_value_set_object (value, priv->gpu); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + static void meta_crtc_finalize (GObject *object) { @@ -78,7 +136,19 @@ meta_crtc_class_init (MetaCrtcClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->set_property = meta_crtc_set_property; + object_class->get_property = meta_crtc_get_property; object_class->finalize = meta_crtc_finalize; + + obj_props[PROP_GPU] = + g_param_spec_object ("gpu", + "gpu", + "MetaGpu", + META_TYPE_GPU, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, N_PROPS, obj_props); } static void diff --git a/src/backends/meta-crtc.h b/src/backends/meta-crtc.h index d9a47dc89..abc75be42 100644 --- a/src/backends/meta-crtc.h +++ b/src/backends/meta-crtc.h @@ -60,8 +60,6 @@ struct _MetaCrtc { GObject parent; - MetaGpu *gpu; - glong crtc_id; unsigned int all_transforms; @@ -97,6 +95,7 @@ META_EXPORT_TEST G_DECLARE_FINAL_TYPE (MetaCrtc, meta_crtc, META, CRTC, GObject) #define META_TYPE_CRTC_MODE (meta_crtc_mode_get_type ()) META_EXPORT_TEST G_DECLARE_FINAL_TYPE (MetaCrtcMode, meta_crtc_mode, META, CRTC_MODE, GObject) +META_EXPORT_TEST MetaGpu * meta_crtc_get_gpu (MetaCrtc *crtc); META_EXPORT_TEST diff --git a/src/backends/meta-monitor-manager-dummy.c b/src/backends/meta-monitor-manager-dummy.c index 2ddd826a8..71bf8a232 100644 --- a/src/backends/meta-monitor-manager-dummy.c +++ b/src/backends/meta-monitor-manager-dummy.c @@ -198,7 +198,9 @@ append_monitor (MetaMonitorManager *manager, } *modes = g_list_concat (*modes, new_modes); - crtc = g_object_new (META_TYPE_CRTC, NULL); + crtc = g_object_new (META_TYPE_CRTC, + "gpu", gpu, + NULL); crtc->crtc_id = g_list_length (*crtcs) + 1; crtc->all_transforms = ALL_TRANSFORMS; *crtcs = g_list_append (*crtcs, crtc); @@ -289,8 +291,9 @@ append_tiled_monitor (MetaMonitorManager *manager, { MetaCrtc *crtc; - crtc = g_object_new (META_TYPE_CRTC, NULL); - crtc->gpu = gpu; + crtc = g_object_new (META_TYPE_CRTC, + "gpu", gpu, + NULL); crtc->crtc_id = g_list_length (*crtcs) + i + 1; crtc->all_transforms = ALL_TRANSFORMS; new_crtcs = g_list_append (new_crtcs, crtc); diff --git a/src/backends/native/meta-crtc-kms.c b/src/backends/native/meta-crtc-kms.c index 3bff4e2b5..a7e839233 100644 --- a/src/backends/native/meta-crtc-kms.c +++ b/src/backends/native/meta-crtc-kms.c @@ -296,8 +296,9 @@ meta_create_kms_crtc (MetaGpuKms *gpu_kms, kms_device = meta_gpu_kms_get_kms_device (gpu_kms); primary_plane = meta_kms_device_get_primary_plane_for (kms_device, kms_crtc); - crtc = g_object_new (META_TYPE_CRTC, NULL); - crtc->gpu = gpu; + crtc = g_object_new (META_TYPE_CRTC, + "gpu", gpu, + NULL); crtc->crtc_id = meta_kms_crtc_get_id (kms_crtc); crtc->is_dirty = FALSE; crtc->all_transforms = ALL_TRANSFORMS_MASK; diff --git a/src/backends/x11/meta-crtc-xrandr.c b/src/backends/x11/meta-crtc-xrandr.c index 89115ca52..d1d2bbf6d 100644 --- a/src/backends/x11/meta-crtc-xrandr.c +++ b/src/backends/x11/meta-crtc-xrandr.c @@ -248,7 +248,9 @@ meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr, unsigned int i; GList *modes; - crtc = g_object_new (META_TYPE_CRTC, NULL); + crtc = g_object_new (META_TYPE_CRTC, + "gpu", gpu, + NULL); crtc_xrandr = g_new0 (MetaCrtcXrandr, 1); crtc_xrandr->transform = @@ -256,7 +258,6 @@ meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr, crtc->driver_private = crtc_xrandr; crtc->driver_notify = (GDestroyNotify) meta_crtc_destroy_notify; - crtc->gpu = META_GPU (gpu_xrandr); crtc->crtc_id = crtc_id; panning = XRRGetPanning (xdisplay, resources, crtc_id); @@ -283,7 +284,7 @@ meta_create_xrandr_crtc (MetaGpuXrandr *gpu_xrandr, crtc->all_transforms = meta_monitor_transform_from_xrandr_all (xrandr_crtc->rotations); - modes = meta_gpu_get_modes (crtc->gpu); + modes = meta_gpu_get_modes (gpu); for (i = 0; i < (unsigned int) resources->nmode; i++) { if (resources->modes[i].id == xrandr_crtc->mode) diff --git a/src/tests/headless-start-test.c b/src/tests/headless-start-test.c index 16a7fd471..2b49c3646 100644 --- a/src/tests/headless-start-test.c +++ b/src/tests/headless-start-test.c @@ -121,6 +121,7 @@ meta_test_headless_monitor_connect (void) MetaMonitorTestSetup *test_setup; MetaCrtcMode **modes; MetaCrtcMode *crtc_mode; + MetaGpu *gpu; MetaCrtc *crtc; MetaCrtc **possible_crtcs; MetaOutput *output; @@ -136,7 +137,10 @@ meta_test_headless_monitor_connect (void) crtc_mode->refresh_rate = 60.0; test_setup->modes = g_list_append (NULL, crtc_mode); - crtc = g_object_new (META_TYPE_CRTC, NULL); + gpu = META_GPU (meta_backend_get_gpus (meta_get_backend ())->data); + crtc = g_object_new (META_TYPE_CRTC, + "gpu", gpu, + NULL); crtc->crtc_id = 1; crtc->all_transforms = ALL_TRANSFORMS; test_setup->crtcs = g_list_append (NULL, crtc); diff --git a/src/tests/meta-monitor-manager-test.c b/src/tests/meta-monitor-manager-test.c index 4bfbb8da1..3717af42b 100644 --- a/src/tests/meta-monitor-manager-test.c +++ b/src/tests/meta-monitor-manager-test.c @@ -94,8 +94,6 @@ meta_monitor_manager_test_read_current (MetaMonitorManager *manager) for (l = manager_test->test_setup->outputs; l; l = l->next) META_OUTPUT (l->data)->gpu = gpu; - for (l = manager_test->test_setup->crtcs; l; l = l->next) - META_CRTC (l->data)->gpu = gpu; meta_gpu_take_modes (gpu, manager_test->test_setup->modes); meta_gpu_take_crtcs (gpu, manager_test->test_setup->crtcs); diff --git a/src/tests/monitor-test-utils.c b/src/tests/monitor-test-utils.c index 6de2682bb..7b36122d6 100644 --- a/src/tests/monitor-test-utils.c +++ b/src/tests/monitor-test-utils.c @@ -27,8 +27,15 @@ #include "backends/meta-monitor-config-manager.h" #include "backends/meta-monitor-config-store.h" #include "backends/meta-output.h" +#include "tests/test-utils.h" #include "meta-backend-test.h" +MetaGpu * +test_get_gpu (void) +{ + return META_GPU (meta_backend_get_gpus (meta_get_backend ())->data); +} + void set_custom_monitor_config (const char *filename) { @@ -565,7 +572,9 @@ create_monitor_test_setup (MonitorTestCaseSetup *setup, { MetaCrtc *crtc; - crtc = g_object_new (META_TYPE_CRTC, NULL); + crtc = g_object_new (META_TYPE_CRTC, + "gpu", test_get_gpu (), + NULL); crtc->crtc_id = i + 1; crtc->all_transforms = ALL_TRANSFORMS; diff --git a/src/tests/monitor-test-utils.h b/src/tests/monitor-test-utils.h index ef6330665..f3b71a915 100644 --- a/src/tests/monitor-test-utils.h +++ b/src/tests/monitor-test-utils.h @@ -191,6 +191,8 @@ struct _MonitorTestCase MonitorTestCaseExpect expect; }; +MetaGpu * test_get_gpu (void); + void set_custom_monitor_config (const char *filename); char * read_file (const char *file_path);