From f092b6c78c6fd7ce919c1467ad92733e7f1fc871 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Thu, 2 Mar 2023 02:04:12 +0100 Subject: [PATCH] backends/native: Add color space and HDR metadata updates Allows to prepare KMS updates to set the color space and HDR Static Metadata on the output. For some reason we need ALLOW_MODESET on commits which change the HDR Static Metadata InfoFrame on AMDGPU. There is no technical reason why one needs to mode set to send an InfoFrame and the driver should just manage without ALLOW_MODESET. Until this is resolved in the kernel we just prepare KMS updates which might mode set. Part-of: --- src/backends/native/meta-kms-update-private.h | 11 +++++ src/backends/native/meta-kms-update.c | 45 +++++++++++++++++++ src/backends/native/meta-kms-update.h | 9 ++++ 3 files changed, 65 insertions(+) diff --git a/src/backends/native/meta-kms-update-private.h b/src/backends/native/meta-kms-update-private.h index 98a1b55d1..ab4ad1395 100644 --- a/src/backends/native/meta-kms-update-private.h +++ b/src/backends/native/meta-kms-update-private.h @@ -23,6 +23,7 @@ #include #include +#include "backends/meta-output.h" #include "backends/native/meta-kms-crtc.h" #include "backends/native/meta-kms-plane-private.h" #include "backends/native/meta-kms-types.h" @@ -101,6 +102,16 @@ typedef struct _MetaKmsConnectorUpdate gboolean has_update; uint64_t value; } max_bpc; + + struct { + gboolean has_update; + MetaOutputColorspace value; + } colorspace; + + struct { + gboolean has_update; + MetaOutputHdrMetadata value; + } hdr; } MetaKmsConnectorUpdate; typedef struct _MetaKmsPageFlipListener diff --git a/src/backends/native/meta-kms-update.c b/src/backends/native/meta-kms-update.c index 4a4a3d692..ceb298a80 100644 --- a/src/backends/native/meta-kms-update.c +++ b/src/backends/native/meta-kms-update.c @@ -407,6 +407,40 @@ meta_kms_update_set_max_bpc (MetaKmsUpdate *update, connector_update->max_bpc.has_update = TRUE; } +void +meta_kms_update_set_color_space (MetaKmsUpdate *update, + MetaKmsConnector *connector, + MetaOutputColorspace color_space) +{ + MetaKmsConnectorUpdate *connector_update; + + g_assert (meta_kms_connector_get_device (connector) == update->device); + g_return_if_fail (meta_kms_connector_is_color_space_supported (connector, + color_space)); + + connector_update = ensure_connector_update (update, connector); + connector_update->colorspace.has_update = TRUE; + connector_update->colorspace.value = color_space; +} + +void +meta_kms_update_set_hdr_metadata (MetaKmsUpdate *update, + MetaKmsConnector *connector, + MetaOutputHdrMetadata *metadata) +{ + MetaKmsConnectorUpdate *connector_update; + + g_assert (meta_kms_connector_get_device (connector) == update->device); + g_return_if_fail (meta_kms_connector_is_hdr_metadata_supported (connector)); + + connector_update = ensure_connector_update (update, connector); + connector_update->hdr.has_update = TRUE; + connector_update->hdr.value = *metadata; + + /* Currently required on AMDGPU but should in general not require mode sets */ + update->needs_modeset = TRUE; +} + static MetaKmsCrtcColorUpdate * ensure_color_update (MetaKmsUpdate *update, MetaKmsCrtc *crtc) @@ -898,6 +932,17 @@ merge_connector_updates_from (MetaKmsUpdate *update, connector_update->max_bpc = other_connector_update->max_bpc; } + + if (other_connector_update->colorspace.has_update) + { + connector_update->colorspace = + other_connector_update->colorspace; + } + + if (other_connector_update->hdr.has_update) + { + connector_update->hdr = other_connector_update->hdr; + } } else { diff --git a/src/backends/native/meta-kms-update.h b/src/backends/native/meta-kms-update.h index 627d5f274..26da6ca27 100644 --- a/src/backends/native/meta-kms-update.h +++ b/src/backends/native/meta-kms-update.h @@ -26,6 +26,7 @@ #include #include "backends/meta-monitor-transform.h" +#include "backends/meta-output.h" #include "backends/native/meta-drm-buffer.h" #include "backends/native/meta-kms-types.h" #include "meta/boxes.h" @@ -123,6 +124,14 @@ void meta_kms_update_set_max_bpc (MetaKmsUpdate *update, MetaKmsConnector *connector, uint64_t max_bpc); +void meta_kms_update_set_color_space (MetaKmsUpdate *update, + MetaKmsConnector *connector, + MetaOutputColorspace color_space); + +void meta_kms_update_set_hdr_metadata (MetaKmsUpdate *update, + MetaKmsConnector *connector, + MetaOutputHdrMetadata *metadata); + META_EXPORT_TEST void meta_kms_update_set_power_save (MetaKmsUpdate *update);