[mutter] kms: Add MetaKmsMode abstraction
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] kms: Add MetaKmsMode abstraction
- Date: Fri, 22 Jan 2021 17:08:25 +0000 (UTC)
commit f0d3201dabe5bd154f2aeb295b0508b30ffc8dda
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Thu Jun 4 17:12:34 2020 +0200
kms: Add MetaKmsMode abstraction
This contains a copy of a drmModeModeInfo, describing a mode. It also
has an unused pointer to the impl device it is associated with. It'll
later be used to get a blob ID for the mode.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1488>
src/backends/native/meta-gpu-kms.c | 12 +++++--
src/backends/native/meta-kms-connector.c | 20 +++++++----
src/backends/native/meta-kms-connector.h | 3 +-
src/backends/native/meta-kms-mode-private.h | 30 ++++++++++++++++
src/backends/native/meta-kms-mode.c | 55 +++++++++++++++++++++++++++++
src/backends/native/meta-kms-mode.h | 31 ++++++++++++++++
src/backends/native/meta-kms-types.h | 2 ++
src/backends/native/meta-kms.c | 6 ++++
src/backends/native/meta-output-kms.c | 9 +++--
src/meson.build | 2 ++
10 files changed, 157 insertions(+), 13 deletions(-)
---
diff --git a/src/backends/native/meta-gpu-kms.c b/src/backends/native/meta-gpu-kms.c
index 819bd2c9a3..0100d532cd 100644
--- a/src/backends/native/meta-gpu-kms.c
+++ b/src/backends/native/meta-gpu-kms.c
@@ -41,6 +41,7 @@
#include "backends/native/meta-crtc-mode-kms.h"
#include "backends/native/meta-kms-connector.h"
#include "backends/native/meta-kms-device.h"
+#include "backends/native/meta-kms-mode.h"
#include "backends/native/meta-kms-update.h"
#include "backends/native/meta-kms-utils.h"
#include "backends/native/meta-kms.h"
@@ -410,13 +411,20 @@ init_modes (MetaGpuKms *gpu_kms)
{
MetaKmsConnector *kms_connector = l->data;
const MetaKmsConnectorState *state;
+ GList *l_mode;
state = meta_kms_connector_get_current_state (kms_connector);
if (!state)
continue;
- for (i = 0; i < state->n_modes; i++)
- g_hash_table_add (modes_table, &state->modes[i]);
+ 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);
+ }
}
modes = NULL;
diff --git a/src/backends/native/meta-kms-connector.c b/src/backends/native/meta-kms-connector.c
index 4eee7522e6..e019651888 100644
--- a/src/backends/native/meta-kms-connector.c
+++ b/src/backends/native/meta-kms-connector.c
@@ -27,6 +27,7 @@
#include "backends/native/meta-kms-crtc.h"
#include "backends/native/meta-kms-device-private.h"
#include "backends/native/meta-kms-impl-device.h"
+#include "backends/native/meta-kms-mode-private.h"
#include "backends/native/meta-kms-update-private.h"
struct _MetaKmsConnector
@@ -354,12 +355,19 @@ state_set_physical_dimensions (MetaKmsConnectorState *state,
static void
state_set_modes (MetaKmsConnectorState *state,
+ MetaKmsImplDevice *impl_device,
drmModeConnector *drm_connector)
{
- state->modes =
- g_memdup (drm_connector->modes,
- drm_connector->count_modes * sizeof (drmModeModeInfo));
- state->n_modes = drm_connector->count_modes;
+ int i;
+
+ for (i = 0; i < drm_connector->count_modes; i++)
+ {
+ MetaKmsMode *mode;
+
+ mode = meta_kms_mode_new (impl_device, &drm_connector->modes[i]);
+ state->modes = g_list_prepend (state->modes, mode);
+ }
+ state->modes = g_list_reverse (state->modes);
}
static void
@@ -452,7 +460,7 @@ static void
meta_kms_connector_state_free (MetaKmsConnectorState *state)
{
g_clear_pointer (&state->edid_data, g_bytes_unref);
- g_free (state->modes);
+ g_list_free_full (state->modes, (GDestroyNotify) meta_kms_mode_free);
g_free (state);
}
@@ -480,7 +488,7 @@ meta_kms_connector_read_state (MetaKmsConnector *connector,
state_set_physical_dimensions (state, drm_connector);
- state_set_modes (state, drm_connector);
+ state_set_modes (state, impl_device, drm_connector);
state_set_crtc_state (state, drm_connector, impl_device, drm_resources);
diff --git a/src/backends/native/meta-kms-connector.h b/src/backends/native/meta-kms-connector.h
index 2547dc16d3..b2a0fa9b49 100644
--- a/src/backends/native/meta-kms-connector.h
+++ b/src/backends/native/meta-kms-connector.h
@@ -39,8 +39,7 @@ typedef struct _MetaKmsConnectorState
uint32_t common_possible_clones;
uint32_t encoder_device_idxs;
- drmModeModeInfo *modes;
- int n_modes;
+ GList *modes;
uint32_t width_mm;
uint32_t height_mm;
diff --git a/src/backends/native/meta-kms-mode-private.h b/src/backends/native/meta-kms-mode-private.h
new file mode 100644
index 0000000000..3af6e2cd2b
--- /dev/null
+++ b/src/backends/native/meta-kms-mode-private.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2020 Red Hat
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef META_KMS_MODE_PRIVATE_H
+#define META_KMS_MODE_PRIVATE_H
+
+#include "backends/native/meta-kms-mode.h"
+
+void meta_kms_mode_free (MetaKmsMode *mode);
+
+MetaKmsMode * meta_kms_mode_new (MetaKmsImplDevice *impl_device,
+ const drmModeModeInfo *drm_mode);
+
+#endif /* META_KMS_MODE_PRIVATE_H */
diff --git a/src/backends/native/meta-kms-mode.c b/src/backends/native/meta-kms-mode.c
new file mode 100644
index 0000000000..68b5dc07f8
--- /dev/null
+++ b/src/backends/native/meta-kms-mode.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2020 Red Hat
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "backends/native/meta-kms-mode-private.h"
+
+#include "backends/native/meta-kms-impl-device.h"
+
+struct _MetaKmsMode
+{
+ MetaKmsImplDevice *impl_device;
+ drmModeModeInfo drm_mode;
+};
+
+const drmModeModeInfo *
+meta_kms_mode_get_drm_mode (MetaKmsMode *mode)
+{
+ return &mode->drm_mode;
+}
+
+void
+meta_kms_mode_free (MetaKmsMode *mode)
+{
+ g_free (mode);
+}
+
+MetaKmsMode *
+meta_kms_mode_new (MetaKmsImplDevice *impl_device,
+ const drmModeModeInfo *drm_mode)
+{
+ MetaKmsMode *mode;
+
+ mode = g_new0 (MetaKmsMode, 1);
+ mode->impl_device = impl_device;
+ mode->drm_mode = *drm_mode;
+
+ return mode;
+}
diff --git a/src/backends/native/meta-kms-mode.h b/src/backends/native/meta-kms-mode.h
new file mode 100644
index 0000000000..91458f5c3f
--- /dev/null
+++ b/src/backends/native/meta-kms-mode.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2020 Red Hat
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef META_KMS_MODE_H
+#define META_KMS_MODE_H
+
+#include <glib.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include "backends/native/meta-kms-types.h"
+
+const drmModeModeInfo * meta_kms_mode_get_drm_mode (MetaKmsMode *mode);
+
+#endif /* META_KMS_MODE_H */
diff --git a/src/backends/native/meta-kms-types.h b/src/backends/native/meta-kms-types.h
index 1d59025053..4d3950a2bf 100644
--- a/src/backends/native/meta-kms-types.h
+++ b/src/backends/native/meta-kms-types.h
@@ -33,6 +33,8 @@ typedef struct _MetaKmsUpdate MetaKmsUpdate;
typedef struct _MetaKmsPlaneAssignment MetaKmsPlaneAssignment;
typedef struct _MetaKmsModeSet MetaKmsModeSet;
+typedef struct _MetaKmsMode MetaKmsMode;
+
typedef struct _MetaKmsFeedback MetaKmsFeedback;
typedef struct _MetaKmsPageFlipFeedback MetaKmsPageFlipFeedback;
diff --git a/src/backends/native/meta-kms.c b/src/backends/native/meta-kms.c
index a14b69f405..957cc274e6 100644
--- a/src/backends/native/meta-kms.c
+++ b/src/backends/native/meta-kms.c
@@ -83,6 +83,12 @@
* should be presented on a CRTC. Planes can either be primary planes, used as
* a backdrop for CRTCs, overlay planes, and cursor planes.
*
+ * #MetaKmsMode:
+ *
+ * Represents a mode a CRTC and connector can be configured with.
+ * Represents both modes directly derived from the devices, as well as
+ * fall back modes when the CRTC supports scaling.
+ *
* #MetaKmsUpdate:
*
* A KMS transaction object, meant to be processed potentially atomically when
diff --git a/src/backends/native/meta-output-kms.c b/src/backends/native/meta-output-kms.c
index 2f27029ce8..2d5e444b1c 100644
--- a/src/backends/native/meta-output-kms.c
+++ b/src/backends/native/meta-output-kms.c
@@ -30,6 +30,7 @@
#include "backends/meta-crtc.h"
#include "backends/native/meta-kms-connector.h"
+#include "backends/native/meta-kms-mode.h"
#include "backends/native/meta-kms-utils.h"
#include "backends/native/meta-crtc-kms.h"
#include "backends/native/meta-crtc-mode-kms.h"
@@ -240,17 +241,19 @@ init_output_modes (MetaOutputInfo *output_info,
GError **error)
{
const MetaKmsConnectorState *connector_state;
+ GList *l;
int i;
connector_state = meta_kms_connector_get_current_state (kms_connector);
output_info->preferred_mode = NULL;
- output_info->n_modes = connector_state->n_modes;
+ output_info->n_modes = g_list_length (connector_state->modes);
output_info->modes = g_new0 (MetaCrtcMode *, output_info->n_modes);
- for (i = 0; i < connector_state->n_modes; i++)
+ for (l = connector_state->modes, i = 0; l; l = l->next, i++)
{
- drmModeModeInfo *drm_mode = &connector_state->modes[i];
+ MetaKmsMode *kms_mode = l->data;
+ 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);
diff --git a/src/meson.build b/src/meson.build
index ef0b28702d..097c73984b 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -684,6 +684,8 @@ if have_native_backend
'backends/native/meta-kms-impl-simple.h',
'backends/native/meta-kms-impl.c',
'backends/native/meta-kms-impl.h',
+ 'backends/native/meta-kms-mode.c',
+ 'backends/native/meta-kms-mode.h',
'backends/native/meta-kms-page-flip.c',
'backends/native/meta-kms-page-flip-private.h',
'backends/native/meta-kms-plane.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]