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>
This commit is contained in:
Jonas Ådahl 2020-07-02 15:47:32 +02:00 committed by Marge Bot
parent e15bb68d8f
commit abac217617
8 changed files with 89 additions and 86 deletions

View File

@ -30,6 +30,7 @@
#include "backends/native/meta-gpu-kms.h" #include "backends/native/meta-gpu-kms.h"
#include "backends/native/meta-output-kms.h" #include "backends/native/meta-output-kms.h"
#include "backends/native/meta-kms-device.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-plane.h"
#include "backends/native/meta-kms-update.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); const MetaCrtcConfig *crtc_config = meta_crtc_get_config (crtc);
MetaCrtcModeKms *crtc_mode_kms = META_CRTC_MODE_KMS (crtc_config->mode); 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", g_debug ("Setting CRTC (%" G_GUINT64_FORMAT ") mode to %s",
meta_crtc_get_id (crtc), mode->name); meta_crtc_get_id (crtc), mode->name);

View File

@ -21,28 +21,30 @@
#include "backends/native/meta-crtc-mode-kms.h" #include "backends/native/meta-crtc-mode-kms.h"
#include "backends/native/meta-kms-mode.h"
#include "backends/native/meta-kms-utils.h" #include "backends/native/meta-kms-utils.h"
struct _MetaCrtcModeKms struct _MetaCrtcModeKms
{ {
MetaCrtcMode parent; MetaCrtcMode parent;
drmModeModeInfo *drm_mode; MetaKmsMode *kms_mode;
}; };
G_DEFINE_TYPE (MetaCrtcModeKms, meta_crtc_mode_kms, G_DEFINE_TYPE (MetaCrtcModeKms, meta_crtc_mode_kms,
META_TYPE_CRTC_MODE) META_TYPE_CRTC_MODE)
const drmModeModeInfo * MetaKmsMode *
meta_crtc_mode_kms_get_drm_mode (MetaCrtcModeKms *mode_kms) meta_crtc_mode_kms_get_kms_mode (MetaCrtcModeKms *mode_kms)
{ {
return mode_kms->drm_mode; return mode_kms->kms_mode;
} }
MetaCrtcModeKms * MetaCrtcModeKms *
meta_crtc_mode_kms_new (const drmModeModeInfo *drm_mode, meta_crtc_mode_kms_new (MetaKmsMode *kms_mode,
uint64_t id) uint64_t id)
{ {
const drmModeModeInfo *drm_mode = meta_kms_mode_get_drm_mode (kms_mode);
g_autoptr (MetaCrtcModeInfo) crtc_mode_info = NULL; g_autoptr (MetaCrtcModeInfo) crtc_mode_info = NULL;
g_autofree char *crtc_mode_name = NULL; g_autofree char *crtc_mode_name = NULL;
MetaCrtcModeKms *mode_kms; MetaCrtcModeKms *mode_kms;
@ -61,21 +63,11 @@ meta_crtc_mode_kms_new (const drmModeModeInfo *drm_mode,
"info", crtc_mode_info, "info", crtc_mode_info,
NULL); NULL);
mode_kms->drm_mode = g_slice_dup (drmModeModeInfo, drm_mode); mode_kms->kms_mode = kms_mode;
return mode_kms; 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 static void
meta_crtc_mode_kms_init (MetaCrtcModeKms *mode_kms) meta_crtc_mode_kms_init (MetaCrtcModeKms *mode_kms)
{ {
@ -84,7 +76,4 @@ meta_crtc_mode_kms_init (MetaCrtcModeKms *mode_kms)
static void static void
meta_crtc_mode_kms_class_init (MetaCrtcModeKmsClass *klass) meta_crtc_mode_kms_class_init (MetaCrtcModeKmsClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = meta_crtc_mode_kms_finalize;
} }

View File

@ -24,15 +24,16 @@
#include <xf86drmMode.h> #include <xf86drmMode.h>
#include "backends/meta-crtc-mode.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 ()) #define META_TYPE_CRTC_MODE_KMS (meta_crtc_mode_kms_get_type ())
G_DECLARE_FINAL_TYPE (MetaCrtcModeKms, meta_crtc_mode_kms, G_DECLARE_FINAL_TYPE (MetaCrtcModeKms, meta_crtc_mode_kms,
META, CRTC_MODE_KMS, META, CRTC_MODE_KMS,
MetaCrtcMode) 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, MetaCrtcModeKms * meta_crtc_mode_kms_new (MetaKmsMode *kms_mode,
uint64_t id); uint64_t id);
#endif /* META_CRTC_MODE_KMS_H */ #endif /* META_CRTC_MODE_KMS_H */

View File

@ -286,50 +286,9 @@ compare_outputs (gconstpointer one,
return strcmp (output_info_one->name, output_info_two->name); 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 * MetaCrtcMode *
meta_gpu_kms_get_mode_from_drm_mode (MetaGpuKms *gpu_kms, meta_gpu_kms_get_mode_from_kms_mode (MetaGpuKms *gpu_kms,
const drmModeModeInfo *drm_mode) MetaKmsMode *kms_mode)
{ {
MetaGpu *gpu = META_GPU (gpu_kms); MetaGpu *gpu = META_GPU (gpu_kms);
GList *l; GList *l;
@ -338,8 +297,8 @@ meta_gpu_kms_get_mode_from_drm_mode (MetaGpuKms *gpu_kms,
{ {
MetaCrtcModeKms *crtc_mode_kms = l->data; MetaCrtcModeKms *crtc_mode_kms = l->data;
if (meta_drm_mode_equal (drm_mode, if (meta_kms_mode_equal (kms_mode,
meta_crtc_mode_kms_get_drm_mode (crtc_mode_kms))) meta_crtc_mode_kms_get_kms_mode (crtc_mode_kms)))
return META_CRTC_MODE (crtc_mode_kms); return META_CRTC_MODE (crtc_mode_kms);
} }
@ -398,14 +357,15 @@ init_modes (MetaGpuKms *gpu_kms)
GList *l; GList *l;
GList *modes; GList *modes;
GHashTableIter iter; GHashTableIter iter;
drmModeModeInfo *drm_mode; gpointer value;
uint64_t mode_id; uint64_t mode_id;
/* /*
* Gather all modes on all connected connectors. * Gather all modes on all connected connectors.
*/ */
modes_table = g_hash_table_new (drm_mode_hash, (GEqualFunc) meta_drm_mode_equal); modes_table = g_hash_table_new ((GHashFunc) meta_kms_mode_hash,
for (l = meta_kms_device_get_connectors (gpu_kms->kms_device); l; l = l->next) (GEqualFunc) meta_kms_mode_equal);
for (l = meta_kms_device_get_connectors (kms_device); l; l = l->next)
{ {
MetaKmsConnector *kms_connector = l->data; MetaKmsConnector *kms_connector = l->data;
const MetaKmsConnectorState *state; const MetaKmsConnectorState *state;
@ -418,31 +378,28 @@ init_modes (MetaGpuKms *gpu_kms)
for (l_mode = state->modes; l_mode; l_mode = l_mode->next) for (l_mode = state->modes; l_mode; l_mode = l_mode->next)
{ {
MetaKmsMode *kms_mode = l_mode->data; 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) for (l = meta_kms_device_get_fallback_modes (kms_device); l; l = l->next)
{ {
MetaKmsMode *fallback_mode = l->data; 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, fallback_mode);
g_hash_table_add (modes_table, (drmModeModeInfo *) drm_mode);
} }
modes = NULL; modes = NULL;
g_hash_table_iter_init (&iter, modes_table); g_hash_table_iter_init (&iter, modes_table);
mode_id = 0; 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; 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); modes = g_list_append (modes, mode);
mode_id++; mode_id++;

View File

@ -63,8 +63,8 @@ void meta_gpu_kms_set_power_save_mode (MetaGpuKms *gpu_kms,
uint64_t state, uint64_t state,
MetaKmsUpdate *kms_update); MetaKmsUpdate *kms_update);
MetaCrtcMode * meta_gpu_kms_get_mode_from_drm_mode (MetaGpuKms *gpu_kms, MetaCrtcMode * meta_gpu_kms_get_mode_from_kms_mode (MetaGpuKms *gpu_kms,
const drmModeModeInfo *drm_mode); MetaKmsMode *kms_mode);
gboolean meta_drm_mode_equal (const drmModeModeInfo *one, gboolean meta_drm_mode_equal (const drmModeModeInfo *one,
const drmModeModeInfo *two); const drmModeModeInfo *two);

View File

@ -73,6 +73,54 @@ meta_kms_mode_get_drm_mode (MetaKmsMode *mode)
return &mode->drm_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 void
meta_kms_mode_free (MetaKmsMode *mode) meta_kms_mode_free (MetaKmsMode *mode)
{ {

View File

@ -39,4 +39,9 @@ MetaKmsModeFlag meta_kms_mode_get_flags (MetaKmsMode *mode);
const drmModeModeInfo * meta_kms_mode_get_drm_mode (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 */ #endif /* META_KMS_MODE_H */

View File

@ -143,7 +143,6 @@ static void
add_common_modes (MetaOutputInfo *output_info, add_common_modes (MetaOutputInfo *output_info,
MetaGpuKms *gpu_kms) MetaGpuKms *gpu_kms)
{ {
const drmModeModeInfo *drm_mode;
MetaCrtcMode *crtc_mode; MetaCrtcMode *crtc_mode;
GPtrArray *array; GPtrArray *array;
float refresh_rate; float refresh_rate;
@ -159,8 +158,9 @@ add_common_modes (MetaOutputInfo *output_info,
{ {
MetaCrtcMode *crtc_mode = output_info->modes[i]; MetaCrtcMode *crtc_mode = output_info->modes[i];
MetaCrtcModeKms *crtc_mode_kms = META_CRTC_MODE_KMS (crtc_mode); 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); refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
max_hdisplay = MAX (max_hdisplay, drm_mode->hdisplay); max_hdisplay = MAX (max_hdisplay, drm_mode->hdisplay);
max_vdisplay = MAX (max_vdisplay, drm_mode->vdisplay); max_vdisplay = MAX (max_vdisplay, drm_mode->vdisplay);
@ -194,7 +194,7 @@ add_common_modes (MetaOutputInfo *output_info,
refresh_rate > max_refresh_rate) refresh_rate > max_refresh_rate)
continue; 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); 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); const drmModeModeInfo *drm_mode = meta_kms_mode_get_drm_mode (kms_mode);
MetaCrtcMode *crtc_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; output_info->modes[i] = crtc_mode;
if (drm_mode->type & DRM_MODE_TYPE_PREFERRED) if (drm_mode->type & DRM_MODE_TYPE_PREFERRED)
output_info->preferred_mode = output_info->modes[i]; output_info->preferred_mode = output_info->modes[i];