Skip to content

Commit

Permalink
video/out/gpu/context: add target_csp callback to ra_swapchain
Browse files Browse the repository at this point in the history
This allows to get target display parameters.
  • Loading branch information
kasper93 committed Nov 23, 2024
1 parent 2f271a9 commit a132b46
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
45 changes: 45 additions & 0 deletions video/out/d3d11/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,50 @@ static int d3d11_color_depth(struct ra_swapchain *sw)
return MPMIN(ra_fmt->component_depth[0], desc1.BitsPerColor);
}

static struct pl_color_space d3d11_target_color_space(struct ra_swapchain *sw)
{
struct priv *p = sw->priv;

struct pl_color_space ret = {0};
DXGI_OUTPUT_DESC1 desc1;
if (!mp_get_dxgi_output_desc(p->swapchain, &desc1))
return ret;

ret.hdr.max_luma = desc1.MaxLuminance;
ret.hdr.min_luma = desc1.MinLuminance;
ret.hdr.prim.blue.x = desc1.BluePrimary[0];
ret.hdr.prim.blue.y = desc1.BluePrimary[1];
ret.hdr.prim.green.x = desc1.GreenPrimary[0];
ret.hdr.prim.green.y = desc1.GreenPrimary[1];
ret.hdr.prim.red.x = desc1.RedPrimary[0];
ret.hdr.prim.red.y = desc1.RedPrimary[1];

switch (desc1.ColorSpace) {
case DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709:
ret.primaries = PL_COLOR_PRIM_BT_709;
ret.transfer = PL_COLOR_TRC_SRGB;
break;
case DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709:
ret.primaries = PL_COLOR_PRIM_BT_709;
ret.transfer = PL_COLOR_TRC_LINEAR;
break;
case DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020:
ret.primaries = PL_COLOR_PRIM_BT_2020;
ret.transfer = PL_COLOR_TRC_PQ;
break;
case DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020:
ret.primaries = PL_COLOR_PRIM_BT_2020;
ret.transfer = PL_COLOR_TRC_SRGB;
break;
default:
ret.primaries = PL_COLOR_PRIM_UNKNOWN;
ret.transfer = PL_COLOR_TRC_UNKNOWN;
break;
}

return ret;
}

static bool d3d11_start_frame(struct ra_swapchain *sw, struct ra_fbo *out_fbo)
{
struct priv *p = sw->priv;
Expand Down Expand Up @@ -448,6 +492,7 @@ static void d3d11_uninit(struct ra_ctx *ctx)

static const struct ra_swapchain_fns d3d11_swapchain = {
.color_depth = d3d11_color_depth,
.target_csp = d3d11_target_color_space,
.start_frame = d3d11_start_frame,
.submit_frame = d3d11_submit_frame,
.swap_buffers = d3d11_swap_buffers,
Expand Down
7 changes: 7 additions & 0 deletions video/out/gpu/context.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <libplacebo/colorspace.h>

#include "video/out/vo.h"
#include "video/csputils.h"

Expand Down Expand Up @@ -78,10 +80,15 @@ struct ra_fbo {
struct pl_color_space color_space;
};

typedef struct pl_color_space pl_color_space_t;

struct ra_swapchain_fns {
// Gets the current framebuffer depth in bits (0 if unknown). Optional.
int (*color_depth)(struct ra_swapchain *sw);

// Target device color space. Optional.
pl_color_space_t (*target_csp)(struct ra_swapchain *sw);

// Called when rendering starts. Returns NULL on failure. This must be
// followed by submit_frame, to submit the rendered frame. This function
// can also fail sporadically, and such errors should be ignored unless
Expand Down

0 comments on commit a132b46

Please sign in to comment.