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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2879>
This commit is contained in:
Sebastian Wick 2023-03-02 02:11:34 +01:00 committed by Marge Bot
parent 650d30c7bf
commit a8d73e669a
2 changed files with 110 additions and 0 deletions

View File

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

View File

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