[mutter] crtc-mode-kms: Wrap MetaKmsMode instead of drmModeModeInfo
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] crtc-mode-kms: Wrap MetaKmsMode instead of drmModeModeInfo
- Date: Fri, 22 Jan 2021 17:08:26 +0000 (UTC)
commit abac217617a10ed1d3da7b79a68a720d2d97c867
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Thu Jul 2 15:47:32 2020 +0200
crtc-mode-kms: Wrap MetaKmsMode instead of drmModeModeInfo
We'll need to use the MetaKmsMode later on for state keeping.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1488>
src/backends/native/meta-crtc-kms.c | 5 ++-
src/backends/native/meta-crtc-mode-kms.c | 29 +++++---------
src/backends/native/meta-crtc-mode-kms.h | 7 ++--
src/backends/native/meta-gpu-kms.c | 69 ++++++--------------------------
src/backends/native/meta-gpu-kms.h | 4 +-
src/backends/native/meta-kms-mode.c | 48 ++++++++++++++++++++++
src/backends/native/meta-kms-mode.h | 5 +++
src/backends/native/meta-output-kms.c | 8 ++--
8 files changed, 89 insertions(+), 86 deletions(-)
---
diff --git a/src/backends/native/meta-crtc-kms.c b/src/backends/native/meta-crtc-kms.c
index 385e828ccf..02da381365 100644
--- a/src/backends/native/meta-crtc-kms.c
+++ b/src/backends/native/meta-crtc-kms.c
@@ -30,6 +30,7 @@
#include "backends/native/meta-gpu-kms.h"
#include "backends/native/meta-output-kms.h"
#include "backends/native/meta-kms-device.h"
+#include "backends/native/meta-kms-mode.h"
#include "backends/native/meta-kms-plane.h"
#include "backends/native/meta-kms-update.h"
@@ -183,8 +184,10 @@ meta_crtc_kms_set_mode (MetaCrtcKms *crtc_kms,
{
const MetaCrtcConfig *crtc_config = meta_crtc_get_config (crtc);
MetaCrtcModeKms *crtc_mode_kms = META_CRTC_MODE_KMS (crtc_config->mode);
+ MetaKmsMode *kms_mode;
- mode = meta_crtc_mode_kms_get_drm_mode (crtc_mode_kms);
+ kms_mode = meta_crtc_mode_kms_get_kms_mode (crtc_mode_kms);
+ mode = meta_kms_mode_get_drm_mode (kms_mode);
g_debug ("Setting CRTC (%" G_GUINT64_FORMAT ") mode to %s",
meta_crtc_get_id (crtc), mode->name);
diff --git a/src/backends/native/meta-crtc-mode-kms.c b/src/backends/native/meta-crtc-mode-kms.c
index 8e2cec2ab1..6f190edc4a 100644
--- a/src/backends/native/meta-crtc-mode-kms.c
+++ b/src/backends/native/meta-crtc-mode-kms.c
@@ -21,28 +21,30 @@
#include "backends/native/meta-crtc-mode-kms.h"
+#include "backends/native/meta-kms-mode.h"
#include "backends/native/meta-kms-utils.h"
struct _MetaCrtcModeKms
{
MetaCrtcMode parent;
- drmModeModeInfo *drm_mode;
+ MetaKmsMode *kms_mode;
};
G_DEFINE_TYPE (MetaCrtcModeKms, meta_crtc_mode_kms,
META_TYPE_CRTC_MODE)
-const drmModeModeInfo *
-meta_crtc_mode_kms_get_drm_mode (MetaCrtcModeKms *mode_kms)
+MetaKmsMode *
+meta_crtc_mode_kms_get_kms_mode (MetaCrtcModeKms *mode_kms)
{
- return mode_kms->drm_mode;
+ return mode_kms->kms_mode;
}
MetaCrtcModeKms *
-meta_crtc_mode_kms_new (const drmModeModeInfo *drm_mode,
- uint64_t id)
+meta_crtc_mode_kms_new (MetaKmsMode *kms_mode,
+ uint64_t id)
{
+ const drmModeModeInfo *drm_mode = meta_kms_mode_get_drm_mode (kms_mode);
g_autoptr (MetaCrtcModeInfo) crtc_mode_info = NULL;
g_autofree char *crtc_mode_name = NULL;
MetaCrtcModeKms *mode_kms;
@@ -61,21 +63,11 @@ meta_crtc_mode_kms_new (const drmModeModeInfo *drm_mode,
"info", crtc_mode_info,
NULL);
- mode_kms->drm_mode = g_slice_dup (drmModeModeInfo, drm_mode);
+ mode_kms->kms_mode = kms_mode;
return mode_kms;
}
-static void
-meta_crtc_mode_kms_finalize (GObject *object)
-{
- MetaCrtcModeKms *mode_kms = META_CRTC_MODE_KMS (object);
-
- g_slice_free (drmModeModeInfo, mode_kms->drm_mode);
-
- G_OBJECT_CLASS (meta_crtc_mode_kms_parent_class)->finalize (object);
-}
-
static void
meta_crtc_mode_kms_init (MetaCrtcModeKms *mode_kms)
{
@@ -84,7 +76,4 @@ meta_crtc_mode_kms_init (MetaCrtcModeKms *mode_kms)
static void
meta_crtc_mode_kms_class_init (MetaCrtcModeKmsClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = meta_crtc_mode_kms_finalize;
}
diff --git a/src/backends/native/meta-crtc-mode-kms.h b/src/backends/native/meta-crtc-mode-kms.h
index 220340add0..f392686124 100644
--- a/src/backends/native/meta-crtc-mode-kms.h
+++ b/src/backends/native/meta-crtc-mode-kms.h
@@ -24,15 +24,16 @@
#include <xf86drmMode.h>
#include "backends/meta-crtc-mode.h"
+#include "backends/native/meta-kms-types.h"
#define META_TYPE_CRTC_MODE_KMS (meta_crtc_mode_kms_get_type ())
G_DECLARE_FINAL_TYPE (MetaCrtcModeKms, meta_crtc_mode_kms,
META, CRTC_MODE_KMS,
MetaCrtcMode)
-const drmModeModeInfo * meta_crtc_mode_kms_get_drm_mode (MetaCrtcModeKms *crtc_mode_kms);
+MetaKmsMode * meta_crtc_mode_kms_get_kms_mode (MetaCrtcModeKms *mode_kms);
-MetaCrtcModeKms * meta_crtc_mode_kms_new (const drmModeModeInfo *drm_mode,
- uint64_t id);
+MetaCrtcModeKms * meta_crtc_mode_kms_new (MetaKmsMode *kms_mode,
+ uint64_t id);
#endif /* META_CRTC_MODE_KMS_H */
diff --git a/src/backends/native/meta-gpu-kms.c b/src/backends/native/meta-gpu-kms.c
index 9a76803d37..f156cb0561 100644
--- a/src/backends/native/meta-gpu-kms.c
+++ b/src/backends/native/meta-gpu-kms.c
@@ -286,50 +286,9 @@ compare_outputs (gconstpointer one,
return strcmp (output_info_one->name, output_info_two->name);
}
-gboolean
-meta_drm_mode_equal (const drmModeModeInfo *one,
- const drmModeModeInfo *two)
-{
- return (one->clock == two->clock &&
- one->hdisplay == two->hdisplay &&
- one->hsync_start == two->hsync_start &&
- one->hsync_end == two->hsync_end &&
- one->htotal == two->htotal &&
- one->hskew == two->hskew &&
- one->vdisplay == two->vdisplay &&
- one->vsync_start == two->vsync_start &&
- one->vsync_end == two->vsync_end &&
- one->vtotal == two->vtotal &&
- one->vscan == two->vscan &&
- one->vrefresh == two->vrefresh &&
- one->flags == two->flags &&
- one->type == two->type &&
- strncmp (one->name, two->name, DRM_DISPLAY_MODE_LEN) == 0);
-}
-
-static guint
-drm_mode_hash (gconstpointer ptr)
-{
- const drmModeModeInfo *mode = ptr;
- guint hash = 0;
-
- /*
- * We don't include the name in the hash because it's generally
- * derived from the other fields (hdisplay, vdisplay and flags)
- */
-
- hash ^= mode->clock;
- hash ^= mode->hdisplay ^ mode->hsync_start ^ mode->hsync_end;
- hash ^= mode->vdisplay ^ mode->vsync_start ^ mode->vsync_end;
- hash ^= mode->vrefresh;
- hash ^= mode->flags ^ mode->type;
-
- return hash;
-}
-
MetaCrtcMode *
-meta_gpu_kms_get_mode_from_drm_mode (MetaGpuKms *gpu_kms,
- const drmModeModeInfo *drm_mode)
+meta_gpu_kms_get_mode_from_kms_mode (MetaGpuKms *gpu_kms,
+ MetaKmsMode *kms_mode)
{
MetaGpu *gpu = META_GPU (gpu_kms);
GList *l;
@@ -338,8 +297,8 @@ meta_gpu_kms_get_mode_from_drm_mode (MetaGpuKms *gpu_kms,
{
MetaCrtcModeKms *crtc_mode_kms = l->data;
- if (meta_drm_mode_equal (drm_mode,
- meta_crtc_mode_kms_get_drm_mode (crtc_mode_kms)))
+ if (meta_kms_mode_equal (kms_mode,
+ meta_crtc_mode_kms_get_kms_mode (crtc_mode_kms)))
return META_CRTC_MODE (crtc_mode_kms);
}
@@ -398,14 +357,15 @@ init_modes (MetaGpuKms *gpu_kms)
GList *l;
GList *modes;
GHashTableIter iter;
- drmModeModeInfo *drm_mode;
+ gpointer value;
uint64_t mode_id;
/*
* Gather all modes on all connected connectors.
*/
- modes_table = g_hash_table_new (drm_mode_hash, (GEqualFunc) meta_drm_mode_equal);
- for (l = meta_kms_device_get_connectors (gpu_kms->kms_device); l; l = l->next)
+ modes_table = g_hash_table_new ((GHashFunc) meta_kms_mode_hash,
+ (GEqualFunc) meta_kms_mode_equal);
+ for (l = meta_kms_device_get_connectors (kms_device); l; l = l->next)
{
MetaKmsConnector *kms_connector = l->data;
const MetaKmsConnectorState *state;
@@ -418,31 +378,28 @@ init_modes (MetaGpuKms *gpu_kms)
for (l_mode = state->modes; l_mode; l_mode = l_mode->next)
{
MetaKmsMode *kms_mode = l_mode->data;
- const drmModeModeInfo *drm_mode =
- meta_kms_mode_get_drm_mode (kms_mode);
- g_hash_table_add (modes_table, (drmModeModeInfo *) drm_mode);
+ g_hash_table_add (modes_table, kms_mode);
}
}
for (l = meta_kms_device_get_fallback_modes (kms_device); l; l = l->next)
{
MetaKmsMode *fallback_mode = l->data;
- const drmModeModeInfo *drm_mode;
- drm_mode = meta_kms_mode_get_drm_mode (fallback_mode);
- g_hash_table_add (modes_table, (drmModeModeInfo *) drm_mode);
+ g_hash_table_add (modes_table, fallback_mode);
}
modes = NULL;
g_hash_table_iter_init (&iter, modes_table);
mode_id = 0;
- while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &drm_mode))
+ while (g_hash_table_iter_next (&iter, NULL, &value))
{
+ MetaKmsMode *kms_mode = value;
MetaCrtcModeKms *mode;
- mode = meta_crtc_mode_kms_new (drm_mode, mode_id);
+ mode = meta_crtc_mode_kms_new (kms_mode, mode_id);
modes = g_list_append (modes, mode);
mode_id++;
diff --git a/src/backends/native/meta-gpu-kms.h b/src/backends/native/meta-gpu-kms.h
index 9ca4d254a2..77aac47ec7 100644
--- a/src/backends/native/meta-gpu-kms.h
+++ b/src/backends/native/meta-gpu-kms.h
@@ -63,8 +63,8 @@ void meta_gpu_kms_set_power_save_mode (MetaGpuKms *gpu_kms,
uint64_t state,
MetaKmsUpdate *kms_update);
-MetaCrtcMode * meta_gpu_kms_get_mode_from_drm_mode (MetaGpuKms *gpu_kms,
- const drmModeModeInfo *drm_mode);
+MetaCrtcMode * meta_gpu_kms_get_mode_from_kms_mode (MetaGpuKms *gpu_kms,
+ MetaKmsMode *kms_mode);
gboolean meta_drm_mode_equal (const drmModeModeInfo *one,
const drmModeModeInfo *two);
diff --git a/src/backends/native/meta-kms-mode.c b/src/backends/native/meta-kms-mode.c
index 8b61e1f60b..cc726cff24 100644
--- a/src/backends/native/meta-kms-mode.c
+++ b/src/backends/native/meta-kms-mode.c
@@ -73,6 +73,54 @@ meta_kms_mode_get_drm_mode (MetaKmsMode *mode)
return &mode->drm_mode;
}
+static gboolean
+meta_drm_mode_equal (const drmModeModeInfo *one,
+ const drmModeModeInfo *two)
+{
+ return (one->clock == two->clock &&
+ one->hdisplay == two->hdisplay &&
+ one->hsync_start == two->hsync_start &&
+ one->hsync_end == two->hsync_end &&
+ one->htotal == two->htotal &&
+ one->hskew == two->hskew &&
+ one->vdisplay == two->vdisplay &&
+ one->vsync_start == two->vsync_start &&
+ one->vsync_end == two->vsync_end &&
+ one->vtotal == two->vtotal &&
+ one->vscan == two->vscan &&
+ one->vrefresh == two->vrefresh &&
+ one->flags == two->flags &&
+ one->type == two->type &&
+ strncmp (one->name, two->name, DRM_DISPLAY_MODE_LEN) == 0);
+}
+
+gboolean
+meta_kms_mode_equal (MetaKmsMode *mode,
+ MetaKmsMode *other_mode)
+{
+ return meta_drm_mode_equal (&mode->drm_mode, &other_mode->drm_mode);
+}
+
+unsigned int
+meta_kms_mode_hash (MetaKmsMode *mode)
+{
+ const drmModeModeInfo *drm_mode = &mode->drm_mode;
+ unsigned int hash = 0;
+
+ /*
+ * We don't include the name in the hash because it's generally
+ * derived from the other fields (hdisplay, vdisplay and flags)
+ */
+
+ hash ^= drm_mode->clock;
+ hash ^= drm_mode->hdisplay ^ drm_mode->hsync_start ^ drm_mode->hsync_end;
+ hash ^= drm_mode->vdisplay ^ drm_mode->vsync_start ^ drm_mode->vsync_end;
+ hash ^= drm_mode->vrefresh;
+ hash ^= drm_mode->flags ^ drm_mode->type;
+
+ return hash;
+}
+
void
meta_kms_mode_free (MetaKmsMode *mode)
{
diff --git a/src/backends/native/meta-kms-mode.h b/src/backends/native/meta-kms-mode.h
index 007638a593..40e844796a 100644
--- a/src/backends/native/meta-kms-mode.h
+++ b/src/backends/native/meta-kms-mode.h
@@ -39,4 +39,9 @@ MetaKmsModeFlag meta_kms_mode_get_flags (MetaKmsMode *mode);
const drmModeModeInfo * meta_kms_mode_get_drm_mode (MetaKmsMode *mode);
+gboolean meta_kms_mode_equal (MetaKmsMode *mode,
+ MetaKmsMode *other_mode);
+
+unsigned int meta_kms_mode_hash (MetaKmsMode *mode);
+
#endif /* META_KMS_MODE_H */
diff --git a/src/backends/native/meta-output-kms.c b/src/backends/native/meta-output-kms.c
index d581b79fd6..57e34bb245 100644
--- a/src/backends/native/meta-output-kms.c
+++ b/src/backends/native/meta-output-kms.c
@@ -143,7 +143,6 @@ static void
add_common_modes (MetaOutputInfo *output_info,
MetaGpuKms *gpu_kms)
{
- const drmModeModeInfo *drm_mode;
MetaCrtcMode *crtc_mode;
GPtrArray *array;
float refresh_rate;
@@ -159,8 +158,9 @@ add_common_modes (MetaOutputInfo *output_info,
{
MetaCrtcMode *crtc_mode = output_info->modes[i];
MetaCrtcModeKms *crtc_mode_kms = META_CRTC_MODE_KMS (crtc_mode);
+ MetaKmsMode *kms_mode = meta_crtc_mode_kms_get_kms_mode (crtc_mode_kms);
+ const drmModeModeInfo *drm_mode = meta_kms_mode_get_drm_mode (kms_mode);
- drm_mode = meta_crtc_mode_kms_get_drm_mode (crtc_mode_kms);
refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
max_hdisplay = MAX (max_hdisplay, drm_mode->hdisplay);
max_vdisplay = MAX (max_vdisplay, drm_mode->vdisplay);
@@ -194,7 +194,7 @@ add_common_modes (MetaOutputInfo *output_info,
refresh_rate > max_refresh_rate)
continue;
- crtc_mode = meta_gpu_kms_get_mode_from_drm_mode (gpu_kms, drm_mode);
+ crtc_mode = meta_gpu_kms_get_mode_from_kms_mode (gpu_kms, fallback_mode);
g_ptr_array_add (array, crtc_mode);
}
@@ -252,7 +252,7 @@ init_output_modes (MetaOutputInfo *output_info,
const drmModeModeInfo *drm_mode = meta_kms_mode_get_drm_mode (kms_mode);
MetaCrtcMode *crtc_mode;
- crtc_mode = meta_gpu_kms_get_mode_from_drm_mode (gpu_kms, drm_mode);
+ crtc_mode = meta_gpu_kms_get_mode_from_kms_mode (gpu_kms, kms_mode);
output_info->modes[i] = crtc_mode;
if (drm_mode->type & DRM_MODE_TYPE_PREFERRED)
output_info->preferred_mode = output_info->modes[i];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]