diff --git a/src/backends/meta-crtc-mode.c b/src/backends/meta-crtc-mode.c index 6d2de4b74..748145747 100644 --- a/src/backends/meta-crtc-mode.c +++ b/src/backends/meta-crtc-mode.c @@ -152,6 +152,9 @@ meta_crtc_mode_finalize (GObject *object) MetaCrtcMode *crtc_mode = META_CRTC_MODE (object); MetaCrtcModePrivate *priv = meta_crtc_mode_get_instance_private (crtc_mode); + if (crtc_mode->driver_notify) + crtc_mode->driver_notify (crtc_mode); + g_clear_pointer (&priv->name, g_free); g_clear_pointer (&priv->info, meta_crtc_mode_info_unref); diff --git a/src/backends/meta-crtc-mode.h b/src/backends/meta-crtc-mode.h index 87778b866..b7165265e 100644 --- a/src/backends/meta-crtc-mode.h +++ b/src/backends/meta-crtc-mode.h @@ -57,16 +57,19 @@ typedef struct _MetaCrtcModeInfo MetaCrtcModeFlag flags; } MetaCrtcModeInfo; +struct _MetaCrtcMode +{ + GObject parent; + + gpointer driver_private; + GDestroyNotify driver_notify; +}; + #define META_TYPE_CRTC_MODE (meta_crtc_mode_get_type ()) META_EXPORT_TEST -G_DECLARE_DERIVABLE_TYPE (MetaCrtcMode, meta_crtc_mode, - META, CRTC_MODE, - GObject) - -struct _MetaCrtcModeClass -{ - GObjectClass parent_class; -}; +G_DECLARE_FINAL_TYPE (MetaCrtcMode, meta_crtc_mode, + META, CRTC_MODE, + GObject) #define META_TYPE_CRTC_MODE_INFO (meta_crtc_mode_info_get_type ()) GType meta_crtc_mode_info_get_type (void); diff --git a/src/backends/native/meta-crtc-kms.c b/src/backends/native/meta-crtc-kms.c index 89d6f40a8..5860f42a2 100644 --- a/src/backends/native/meta-crtc-kms.c +++ b/src/backends/native/meta-crtc-kms.c @@ -26,7 +26,6 @@ #include "backends/meta-backend-private.h" #include "backends/meta-logical-monitor.h" -#include "backends/native/meta-crtc-mode-kms.h" #include "backends/native/meta-gpu-kms.h" #include "backends/native/meta-output-kms.h" #include "backends/native/meta-kms-device.h" @@ -173,16 +172,15 @@ meta_crtc_kms_set_mode (MetaCrtcKms *crtc_kms, MetaCrtc *crtc = META_CRTC (crtc_kms); MetaGpu *gpu = meta_crtc_get_gpu (crtc); GList *connectors; - const drmModeModeInfo *mode; + drmModeModeInfo *mode; connectors = generate_crtc_connector_list (gpu, crtc); if (connectors) { const MetaCrtcConfig *crtc_config = meta_crtc_get_config (crtc); - MetaCrtcModeKms *crtc_mode_kms = META_CRTC_MODE_KMS (crtc_config->mode); - mode = meta_crtc_mode_kms_get_drm_mode (crtc_mode_kms); + mode = crtc_config->mode->driver_private; g_debug ("Setting CRTC (%ld) 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 deleted file mode 100644 index 76dc5774d..000000000 --- a/src/backends/native/meta-crtc-mode-kms.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2017-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-crtc-mode-kms.h" - -#include "backends/native/meta-kms-utils.h" - -struct _MetaCrtcModeKms -{ - drmModeModeInfo *drm_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) -{ - return mode_kms->drm_mode; -} - -MetaCrtcModeKms * -meta_crtc_mode_kms_new (const drmModeModeInfo *drm_mode, - uint64_t id) -{ - g_autoptr (MetaCrtcModeInfo) crtc_mode_info = NULL; - g_autofree char *crtc_mode_name = NULL; - MetaCrtcModeKms *mode_kms; - - crtc_mode_info = meta_crtc_mode_info_new (); - crtc_mode_info->width = drm_mode->hdisplay; - crtc_mode_info->height = drm_mode->vdisplay; - crtc_mode_info->flags = drm_mode->flags; - crtc_mode_info->refresh_rate = - meta_calculate_drm_mode_refresh_rate (drm_mode); - - crtc_mode_name = g_strndup (drm_mode->name, DRM_DISPLAY_MODE_LEN); - mode_kms = g_object_new (META_TYPE_CRTC_MODE_KMS, - "id", id, - "name", crtc_mode_name, - "info", crtc_mode_info, - NULL); - - mode_kms->drm_mode = g_slice_dup (drmModeModeInfo, drm_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) -{ -} - -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 deleted file mode 100644 index 220340add..000000000 --- a/src/backends/native/meta-crtc-mode-kms.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2017-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_CRTC_MODE_KMS_H -#define META_CRTC_MODE_KMS_H - -#include -#include - -#include "backends/meta-crtc-mode.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); - -MetaCrtcModeKms * meta_crtc_mode_kms_new (const drmModeModeInfo *drm_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 f587c2d0f..18f7d8036 100644 --- a/src/backends/native/meta-gpu-kms.c +++ b/src/backends/native/meta-gpu-kms.c @@ -38,7 +38,6 @@ #include "backends/meta-output.h" #include "backends/native/meta-backend-native.h" #include "backends/native/meta-crtc-kms.h" -#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-update.h" @@ -274,6 +273,12 @@ compare_outputs (gconstpointer one, return strcmp (output_info_one->name, output_info_two->name); } +static void +meta_crtc_mode_destroy_notify (MetaCrtcMode *mode) +{ + g_slice_free (drmModeModeInfo, mode->driver_private); +} + gboolean meta_drm_mode_equal (const drmModeModeInfo *one, const drmModeModeInfo *two) @@ -324,11 +329,10 @@ meta_gpu_kms_get_mode_from_drm_mode (MetaGpuKms *gpu_kms, for (l = meta_gpu_get_modes (gpu); l; l = l->next) { - MetaCrtcModeKms *crtc_mode_kms = l->data; + MetaCrtcMode *mode = l->data; - if (meta_drm_mode_equal (drm_mode, - meta_crtc_mode_kms_get_drm_mode (crtc_mode_kms))) - return META_CRTC_MODE (crtc_mode_kms); + if (meta_drm_mode_equal (drm_mode, mode->driver_private)) + return mode; } g_assert_not_reached (); @@ -357,6 +361,9 @@ create_mode (const drmModeModeInfo *drm_mode, "info", crtc_mode_info, NULL); + mode->driver_private = g_slice_dup (drmModeModeInfo, drm_mode); + mode->driver_notify = (GDestroyNotify) meta_crtc_mode_destroy_notify; + return mode; } diff --git a/src/backends/native/meta-kms-update.c b/src/backends/native/meta-kms-update.c index d1092b43f..5ace83021 100644 --- a/src/backends/native/meta-kms-update.c +++ b/src/backends/native/meta-kms-update.c @@ -208,10 +208,10 @@ meta_kms_update_unassign_plane (MetaKmsUpdate *update, } void -meta_kms_update_mode_set (MetaKmsUpdate *update, - MetaKmsCrtc *crtc, - GList *connectors, - const drmModeModeInfo *drm_mode) +meta_kms_update_mode_set (MetaKmsUpdate *update, + MetaKmsCrtc *crtc, + GList *connectors, + drmModeModeInfo *drm_mode) { MetaKmsModeSet *mode_set; diff --git a/src/backends/native/meta-kms-update.h b/src/backends/native/meta-kms-update.h index 1727c1974..13dff16dd 100644 --- a/src/backends/native/meta-kms-update.h +++ b/src/backends/native/meta-kms-update.h @@ -79,10 +79,10 @@ MetaKmsUpdate * meta_kms_update_new (void); void meta_kms_update_free (MetaKmsUpdate *update); -void meta_kms_update_mode_set (MetaKmsUpdate *update, - MetaKmsCrtc *crtc, - GList *connectors, - const drmModeModeInfo *drm_mode); +void meta_kms_update_mode_set (MetaKmsUpdate *update, + MetaKmsCrtc *crtc, + GList *connectors, + drmModeModeInfo *drm_mode); MetaKmsPlaneAssignment * meta_kms_update_assign_plane (MetaKmsUpdate *update, MetaKmsCrtc *crtc, diff --git a/src/backends/native/meta-output-kms.c b/src/backends/native/meta-output-kms.c index 2f27029ce..906833a15 100644 --- a/src/backends/native/meta-output-kms.c +++ b/src/backends/native/meta-output-kms.c @@ -32,7 +32,6 @@ #include "backends/native/meta-kms-connector.h" #include "backends/native/meta-kms-utils.h" #include "backends/native/meta-crtc-kms.h" -#include "backends/native/meta-crtc-mode-kms.h" #include "meta-default-modes.h" @@ -154,10 +153,7 @@ add_common_modes (MetaOutputInfo *output_info, for (i = 0; i < output_info->n_modes; i++) { - MetaCrtcMode *crtc_mode = output_info->modes[i]; - MetaCrtcModeKms *crtc_mode_kms = META_CRTC_MODE_KMS (crtc_mode); - - drm_mode = meta_crtc_mode_kms_get_drm_mode (crtc_mode_kms); + drm_mode = output_info->modes[i]->driver_private; 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); diff --git a/src/meson.build b/src/meson.build index ae286526e..56c47faa2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -632,8 +632,6 @@ if have_native_backend 'backends/native/meta-clutter-backend-native.h', 'backends/native/meta-crtc-kms.c', 'backends/native/meta-crtc-kms.h', - 'backends/native/meta-crtc-mode-kms.c', - 'backends/native/meta-crtc-mode-kms.h', 'backends/native/meta-cursor-renderer-native.c', 'backends/native/meta-cursor-renderer-native.h', 'backends/native/meta-drm-buffer-dumb.c',