Skip to content

Commit

Permalink
vo_gpu_next: add a pass_colorspace override for drm
Browse files Browse the repository at this point in the history
The libplacebo colorspace hint api makes sense for things like vulkan,
but for other APIs like drm that are capable of directly handling
colorspaces and hdr metadata it's a nuisance. Add a pass_colorspace fns
that signals to vo_gpu_next that the backend doesn't need the color
information to be manipulated and can handle the metadata itself.
  • Loading branch information
Dudemanguy committed Nov 3, 2024
1 parent 8ab14fd commit 97acebd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
3 changes: 2 additions & 1 deletion video/out/drm_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,8 @@ 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;
drm->supported_colorspace = target_params_supported_by_display(drm);
bool use_sdr = !drm->supported_colorspace || 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;
Expand Down
1 change: 1 addition & 0 deletions video/out/drm_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ struct vo_drm_state {
const struct di_edid_chromaticity_coords *chromaticity;
const struct di_cta_hdr_static_metadata_block *hdr_static_metadata;
const struct di_cta_colorimetry_block *colorimetry;
bool supported_colorspace;

bool active;
bool paused;
Expand Down
4 changes: 4 additions & 0 deletions video/out/gpu/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ struct ra_ctx_fns {
// display size etc. are determined by it.
bool (*reconfig)(struct ra_ctx *ctx);

// Signal if the underlying context can use colorspace/hdr related functionality
// on its own.
bool (*pass_colorspace)(struct ra_ctx *ctx);

// This behaves exactly like vo_driver.control().
int (*control)(struct ra_ctx *ctx, int *events, int request, void *arg);

Expand Down
24 changes: 15 additions & 9 deletions video/out/opengl/context_drm_egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,11 @@ static bool drm_egl_reconfig(struct ra_ctx *ctx)
return true;
}

static bool drm_egl_pass_colorspace(struct ra_ctx *ctx)
{
return ctx->vo->drm->supported_colorspace;
}

static int drm_egl_control(struct ra_ctx *ctx, int *events, int request,
void *arg)
{
Expand All @@ -726,13 +731,14 @@ static void drm_egl_wakeup(struct ra_ctx *ctx)
}

const struct ra_ctx_fns ra_ctx_drm_egl = {
.type = "opengl",
.name = "drm",
.description = "DRM/EGL",
.reconfig = drm_egl_reconfig,
.control = drm_egl_control,
.init = drm_egl_init,
.uninit = drm_egl_uninit,
.wait_events = drm_egl_wait_events,
.wakeup = drm_egl_wakeup,
.type = "opengl",
.name = "drm",
.description = "DRM/EGL",
.reconfig = drm_egl_reconfig,
.pass_colorspace = drm_egl_pass_colorspace,
.control = drm_egl_control,
.init = drm_egl_init,
.uninit = drm_egl_uninit,
.wait_events = drm_egl_wait_events,
.wakeup = drm_egl_wakeup,
};
11 changes: 8 additions & 3 deletions video/out/vo_gpu_next.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,16 +990,21 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
p->last_id = id;
}

bool pass_colorspace = false;
struct pl_color_space hint;
if (p->next_opts->target_hint && frame->current) {
struct pl_color_space hint = frame->current->params.color;
hint = frame->current->params.color;
if (p->ra_ctx->fns->pass_colorspace && p->ra_ctx->fns->pass_colorspace(p->ra_ctx))
pass_colorspace = true;
if (opts->target_prim)
hint.primaries = opts->target_prim;
if (opts->target_trc)
hint.transfer = opts->target_trc;
if (opts->target_peak)
hint.hdr.max_luma = opts->target_peak;
apply_target_contrast(p, &hint);
pl_swapchain_colorspace_hint(p->sw, &hint);
if (!pass_colorspace)
pl_swapchain_colorspace_hint(p->sw, &hint);
} else if (!p->next_opts->target_hint) {
pl_swapchain_colorspace_hint(p->sw, NULL);
}
Expand Down Expand Up @@ -1142,7 +1147,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
? swframe.fbo->params.format->name : NULL,
.w = mp_rect_w(p->dst),
.h = mp_rect_h(p->dst),
.color = target.color,
.color = pass_colorspace ? hint : target.color,
.repr = target.repr,
.rotate = target.rotation,
};
Expand Down

0 comments on commit 97acebd

Please sign in to comment.