From eb66449ab72f5dcb77e926c2abaa8f494a2c4f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 4 Jun 2020 17:20:36 +0200 Subject: [PATCH] kms/mode: Add API to create blob IDs for modes on demand Will be used by the atomic KMS backend. Part-of: --- src/backends/native/meta-kms-mode-private.h | 3 ++ src/backends/native/meta-kms-mode.c | 34 +++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/backends/native/meta-kms-mode-private.h b/src/backends/native/meta-kms-mode-private.h index 3af6e2cd2..5694db07a 100644 --- a/src/backends/native/meta-kms-mode-private.h +++ b/src/backends/native/meta-kms-mode-private.h @@ -22,6 +22,9 @@ #include "backends/native/meta-kms-mode.h" +uint32_t meta_kms_mode_ensure_blob_id (MetaKmsMode *mode, + GError **error); + void meta_kms_mode_free (MetaKmsMode *mode); MetaKmsMode * meta_kms_mode_new (MetaKmsImplDevice *impl_device, diff --git a/src/backends/native/meta-kms-mode.c b/src/backends/native/meta-kms-mode.c index 68b5dc07f..07c793f39 100644 --- a/src/backends/native/meta-kms-mode.c +++ b/src/backends/native/meta-kms-mode.c @@ -27,8 +27,33 @@ struct _MetaKmsMode { MetaKmsImplDevice *impl_device; drmModeModeInfo drm_mode; + uint32_t blob_id; }; +uint32_t +meta_kms_mode_ensure_blob_id (MetaKmsMode *mode, + GError **error) +{ + int fd; + int ret; + + fd = meta_kms_impl_device_get_fd (mode->impl_device); + + ret = drmModeCreatePropertyBlob (fd, + &mode->drm_mode, + sizeof (mode->drm_mode), + &mode->blob_id); + if (ret < 0) + { + g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret), + "drmModeCreatePropertyBlob: %s", + g_strerror (-ret)); + return 0; + } + + return mode->blob_id; +} + const drmModeModeInfo * meta_kms_mode_get_drm_mode (MetaKmsMode *mode) { @@ -38,6 +63,15 @@ meta_kms_mode_get_drm_mode (MetaKmsMode *mode) void meta_kms_mode_free (MetaKmsMode *mode) { + if (mode->blob_id) + { + int fd; + + fd = meta_kms_impl_device_get_fd (mode->impl_device); + + drmModeDestroyPropertyBlob (fd, mode->blob_id); + } + g_free (mode); }