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
This commit is contained in:
Jonas Ådahl 2020-02-25 10:39:56 +01:00 committed by Georges Basile Stavracas Neto
parent 2724f36527
commit 2ebd43cba9
9 changed files with 103 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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);