context_drm_egl: use target_csp to signal HDR

For the drm context, we can use the target_csp so vo_gpu_next knows what
colorspace to output to. We just need to be sure the monitor is able to
display bt2020. For now, all we detect on the EDID side is either pq or
hlg so ensure at least one of those works before we send back something
to vo_gpu_next to use for target_csp.
This commit is contained in:
Dudemanguy authored and Kacper Michajłow committed 2026-02-28 10:50:38 +01:00
1 parent 7dd06a6c0b
commit 2268297ac4
3 files changed
+55 -24

No files matched your search

+23 -24
View File
@@ -672,29 +672,6 @@ done:
drmModeFreePropertyBlob(blob);
}
static bool target_params_supported_by_display(struct vo_drm_state *drm)
{
if (!drm->chromaticity || !drm->colorimetry || !drm->hdr_static_metadata)
return false;
const struct di_cta_hdr_static_metadata_block *hdr_static_metadata = drm->hdr_static_metadata;
enum pl_color_transfer trc = drm->target_params.color.transfer;
if (!pl_color_transfer_is_hdr(trc) && !hdr_static_metadata->eotfs->traditional_sdr)
return false;
if (pl_color_transfer_is_hdr(trc) && !drm->colorimetry->bt2020_rgb)
return false;
if (trc == PL_COLOR_TRC_PQ && !hdr_static_metadata->eotfs->pq)
return false;
if (trc == PL_COLOR_TRC_HLG && !hdr_static_metadata->eotfs->hlg)
return false;
return true;
}
static bool all_digits(const char *str)
{
if (str == NULL || str[0] == '\0') {
@@ -1350,6 +1327,28 @@ static int drm_validate_mode_opt(struct mp_log *log, const struct m_option *opt,
}
/* Helpers */
bool vo_drm_color_supported_by_display(struct vo_drm_state *drm, struct pl_color_space color)
{
const struct di_cta_hdr_static_metadata_block *hdr_static_metadata = drm->hdr_static_metadata;
enum pl_color_transfer trc = color.transfer;
if (!pl_color_transfer_is_hdr(trc) && hdr_static_metadata && !hdr_static_metadata->eotfs->traditional_sdr)
return false;
if (pl_color_transfer_is_hdr(trc)) {
if (!drm->chromaticity || !drm->colorimetry || !hdr_static_metadata || !drm->colorimetry->bt2020_rgb)
return false;
if (trc == PL_COLOR_TRC_PQ && !hdr_static_metadata->eotfs->pq)
return false;
if (trc == PL_COLOR_TRC_HLG && !hdr_static_metadata->eotfs->hlg)
return false;
}
return true;
}
double vo_drm_get_display_fps(struct vo_drm_state *drm)
{
return mode_get_Hz(&drm->mode.mode);
@@ -1365,7 +1364,7 @@ bool vo_drm_set_hdr_metadata(struct vo *vo, bool force_sdr)
destroy_hdr_blob(drm);
drm->target_params = target_params;
bool use_sdr = !target_params_supported_by_display(drm) || force_sdr;
bool use_sdr = !vo_drm_color_supported_by_display(drm, drm->target_params.color) || force_sdr;
// For any HDR, the BT2020 drm colorspace is the only one that works in practice.
struct drm_atomic_context *atomic_ctx = drm->atomic_context;
+1
View File
@@ -156,6 +156,7 @@ struct vo_drm_state {
bool vo_drm_init(struct vo *vo);
int vo_drm_control(struct vo *vo, int *events, int request, void *arg);
bool vo_drm_color_supported_by_display(struct vo_drm_state *drm, struct pl_color_space color);
double vo_drm_get_display_fps(struct vo_drm_state *drm);
bool vo_drm_set_hdr_metadata(struct vo *vo, bool force_sdr);
void vo_drm_set_monitor_par(struct vo *vo);
+31
View File
@@ -516,6 +516,36 @@ static void drm_egl_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)
present_sync_get_info(drm->present, info);
}
static pl_color_space_t drm_egl_preferred_csp(struct ra_ctx *ctx)
{
struct vo_drm_state *drm = ctx->vo->drm;
pl_color_space_t bt2020 = {0};
// If the display supports either one of these colorspaces, return it as
// preferred.
if (vo_drm_color_supported_by_display(drm, pl_color_space_hdr10)) {
bt2020 = pl_color_space_hdr10;
} else if (vo_drm_color_supported_by_display(drm, pl_color_space_bt2020_hlg)) {
bt2020 = pl_color_space_bt2020_hlg;
}
if (bt2020.primaries != PL_COLOR_PRIM_UNKNOWN) {
bt2020.hdr.prim.red.x = drm->chromaticity->red_x;
bt2020.hdr.prim.red.y = drm->chromaticity->red_y;
bt2020.hdr.prim.green.x = drm->chromaticity->green_x;
bt2020.hdr.prim.green.y = drm->chromaticity->green_y;
bt2020.hdr.prim.blue.x = drm->chromaticity->blue_x;
bt2020.hdr.prim.blue.y = drm->chromaticity->blue_y;
bt2020.hdr.prim.white.x = drm->chromaticity->white_x;
bt2020.hdr.prim.white.y = drm->chromaticity->white_y;
bt2020.hdr.min_luma = drm->hdr_static_metadata->desired_content_min_luminance;
bt2020.hdr.max_luma = drm->hdr_static_metadata->desired_content_max_luminance;
return bt2020;
}
return pl_color_space_srgb;
}
static bool drm_egl_init(struct ra_ctx *ctx)
{
if (!vo_drm_init(ctx->vo))
@@ -630,6 +660,7 @@ static bool drm_egl_init(struct ra_ctx *ctx)
struct ra_ctx_params params = {
.get_vsync = drm_egl_get_vsync,
.preferred_csp = drm_egl_preferred_csp,
.swap_buffers = drm_egl_swap_buffers,
};
if (!ra_gl_ctx_init(ctx, &p->gl, params))