kms/mode: Add API to create blob IDs for modes on demand

Will be used by the atomic KMS backend.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1488>
This commit is contained in:
Jonas Ådahl 2020-06-04 17:20:36 +02:00 committed by Marge Bot
parent f0d3201dab
commit eb66449ab7
2 changed files with 37 additions and 0 deletions

View File

@ -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,

View File

@ -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);
}