From a8d73e669ac3c7ec1149d8d38a60d6d7094c7593 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Thu, 2 Mar 2023 02:11:34 +0100 Subject: [PATCH] backends/native: Wire up color space and HDR metadata Announce support for color spaces and HDR metadata in OutputKms and prepare KMS update in OnscreenNative. Part-of: --- src/backends/native/meta-onscreen-native.c | 82 ++++++++++++++++++++++ src/backends/native/meta-output-kms.c | 28 ++++++++ 2 files changed, 110 insertions(+) diff --git a/src/backends/native/meta-onscreen-native.c b/src/backends/native/meta-onscreen-native.c index 734648320..3311b64b1 100644 --- a/src/backends/native/meta-onscreen-native.c +++ b/src/backends/native/meta-onscreen-native.c @@ -109,9 +109,13 @@ struct _MetaOnscreenNative gboolean is_gamma_lut_invalid; gboolean is_privacy_screen_invalid; + gboolean is_color_space_invalid; + gboolean is_hdr_metadata_invalid; gulong gamma_lut_changed_handler_id; gulong privacy_screen_changed_handler_id; + gulong color_space_changed_handler_id; + gulong hdr_metadata_changed_handler_id; }; G_DEFINE_TYPE (MetaOnscreenNative, meta_onscreen_native, @@ -217,6 +221,8 @@ notify_view_crtc_presented (MetaRendererView *view, onscreen_native->is_gamma_lut_invalid = FALSE; onscreen_native->is_privacy_screen_invalid = FALSE; + onscreen_native->is_color_space_invalid = FALSE; + onscreen_native->is_hdr_metadata_invalid = FALSE; crtc = META_CRTC (meta_crtc_kms_from_kms_crtc (kms_crtc)); maybe_update_frame_info (crtc, frame_info, time_us, flags, sequence); @@ -1489,6 +1495,34 @@ meta_onscreen_native_prepare_frame (CoglOnscreen *onscreen, enabled = meta_output_is_privacy_screen_enabled (onscreen_native->output); meta_kms_update_set_privacy_screen (kms_update, kms_connector, enabled); } + + if (onscreen_native->is_color_space_invalid) + { + MetaKmsConnector *kms_connector = + meta_output_kms_get_kms_connector (output_kms); + MetaKmsUpdate *kms_update; + MetaOutputColorspace color_space; + + kms_update = meta_frame_native_ensure_kms_update (frame_native, + kms_device); + + color_space = meta_output_peek_color_space (onscreen_native->output); + meta_kms_update_set_color_space (kms_update, kms_connector, color_space); + } + + if (onscreen_native->is_hdr_metadata_invalid) + { + MetaKmsConnector *kms_connector = + meta_output_kms_get_kms_connector (output_kms); + MetaKmsUpdate *kms_update; + MetaOutputHdrMetadata *metadata; + + kms_update = meta_frame_native_ensure_kms_update (frame_native, + kms_device); + + metadata = meta_output_peek_hdr_metadata (onscreen_native->output); + meta_kms_update_set_hdr_metadata (kms_update, kms_connector, metadata); + } } void @@ -2204,6 +2238,11 @@ meta_onscreen_native_invalidate (MetaOnscreenNative *onscreen_native) onscreen_native->is_gamma_lut_invalid = TRUE; if (meta_output_is_privacy_screen_supported (onscreen_native->output)) onscreen_native->is_privacy_screen_invalid = TRUE; + if (meta_output_is_color_space_supported (onscreen_native->output, + META_OUTPUT_COLORSPACE_DEFAULT)) + onscreen_native->is_color_space_invalid = TRUE; + if (meta_output_is_hdr_metadata_supported (onscreen_native->output)) + onscreen_native->is_hdr_metadata_invalid = TRUE; } static void @@ -2227,6 +2266,26 @@ on_privacy_screen_enabled_changed (MetaOutput *output, clutter_stage_view_schedule_update (stage_view); } +static void +on_color_space_changed (MetaOutput *output, + MetaOnscreenNative *onscreen_native) +{ + ClutterStageView *stage_view = CLUTTER_STAGE_VIEW (onscreen_native->view); + + onscreen_native->is_color_space_invalid = TRUE; + clutter_stage_view_schedule_update (stage_view); +} + +static void +on_hdr_metadata_changed (MetaOutput *output, + MetaOnscreenNative *onscreen_native) +{ + ClutterStageView *stage_view = CLUTTER_STAGE_VIEW (onscreen_native->view); + + onscreen_native->is_hdr_metadata_invalid = TRUE; + clutter_stage_view_schedule_update (stage_view); +} + MetaOnscreenNative * meta_onscreen_native_new (MetaRendererNative *renderer_native, MetaGpuKms *render_gpu, @@ -2273,6 +2332,25 @@ meta_onscreen_native_new (MetaRendererNative *renderer_native, onscreen_native); } + if (meta_output_is_color_space_supported (output, + META_OUTPUT_COLORSPACE_DEFAULT)) + { + onscreen_native->is_color_space_invalid = TRUE; + onscreen_native->color_space_changed_handler_id = + g_signal_connect (output, "color-space-changed", + G_CALLBACK (on_color_space_changed), + onscreen_native); + } + + if (meta_output_is_hdr_metadata_supported (output)) + { + onscreen_native->is_hdr_metadata_invalid = TRUE; + onscreen_native->hdr_metadata_changed_handler_id = + g_signal_connect (output, "hdr-metadata-changed", + G_CALLBACK (on_hdr_metadata_changed), + onscreen_native); + } + return onscreen_native; } @@ -2283,6 +2361,10 @@ clear_invalidation_handlers (MetaOnscreenNative *onscreen_native) onscreen_native->crtc); g_clear_signal_handler (&onscreen_native->privacy_screen_changed_handler_id, onscreen_native->output); + g_clear_signal_handler (&onscreen_native->color_space_changed_handler_id, + onscreen_native->output); + g_clear_signal_handler (&onscreen_native->hdr_metadata_changed_handler_id, + onscreen_native->output); } static void diff --git a/src/backends/native/meta-output-kms.c b/src/backends/native/meta-output-kms.c index e6ba57c1f..5107dd069 100644 --- a/src/backends/native/meta-output-kms.c +++ b/src/backends/native/meta-output-kms.c @@ -139,6 +139,30 @@ meta_output_kms_get_privacy_screen_state (MetaOutput *output) return connector_state->privacy_screen_state; } +static uint64_t +meta_output_kms_get_supported_color_spaces (MetaOutput *output) +{ + MetaOutputKms *output_kms = META_OUTPUT_KMS (output); + const MetaKmsConnectorState *connector_state; + + connector_state = + meta_kms_connector_get_current_state (output_kms->kms_connector); + + return connector_state->colorspace.supported; +} + +static gboolean +meta_output_kms_is_hdr_metadata_supported (MetaOutput *output) +{ + MetaOutputKms *output_kms = META_OUTPUT_KMS (output); + const MetaKmsConnectorState *connector_state; + + connector_state = + meta_kms_connector_get_current_state (output_kms->kms_connector); + + return connector_state->hdr.supported; +} + uint32_t meta_output_kms_get_connector_id (MetaOutputKms *output_kms) { @@ -511,6 +535,10 @@ meta_output_kms_class_init (MetaOutputKmsClass *klass) output_class->get_privacy_screen_state = meta_output_kms_get_privacy_screen_state; + output_class->get_supported_color_spaces = + meta_output_kms_get_supported_color_spaces; + output_class->is_hdr_metadata_supported = + meta_output_kms_is_hdr_metadata_supported; output_native_class->read_edid = meta_output_kms_read_edid; }