Synchronize swapchain and pl_frame colorspace values

This commit is contained in:
Cameron Gutman 2023-12-16 17:36:02 -06:00
parent 9497657c83
commit c939537c5c
2 changed files with 8 additions and 38 deletions

View file

@ -427,6 +427,13 @@ void PlVkRenderer::renderFrame(AVFrame *frame)
return;
}
// Adjust the swapchain if the colorspace of incoming frames has changed
if (!pl_color_space_equal(&mappedFrame.color, &m_LastColorspace)) {
m_LastColorspace = mappedFrame.color;
SDL_assert(pl_color_space_equal(&mappedFrame.color, &m_LastColorspace));
pl_swapchain_colorspace_hint(m_Swapchain, &mappedFrame.color);
}
// Reserve enough space to avoid allocating under the overlay lock
pl_overlay_part overlayParts[Overlay::OverlayMax] = {};
std::vector<pl_tex> texturesToDestroy;
@ -649,43 +656,6 @@ void PlVkRenderer::notifyOverlayUpdated(Overlay::OverlayType type)
SDL_AtomicUnlock(&m_OverlayLock);
}
void PlVkRenderer::setHdrMode(bool enabled)
{
pl_color_space csp = {};
if (enabled) {
csp.primaries = PL_COLOR_PRIM_BT_2020;
csp.transfer = PL_COLOR_TRC_PQ;
// Use the host's provided HDR metadata if present
SS_HDR_METADATA hdrMetadata;
if (LiGetHdrMetadata(&hdrMetadata)) {
csp.hdr.prim.red.x = hdrMetadata.displayPrimaries[0].x / 50000.f;
csp.hdr.prim.red.y = hdrMetadata.displayPrimaries[0].y / 50000.f;
csp.hdr.prim.green.x = hdrMetadata.displayPrimaries[1].x / 50000.f;
csp.hdr.prim.green.y = hdrMetadata.displayPrimaries[1].y / 50000.f;
csp.hdr.prim.blue.x = hdrMetadata.displayPrimaries[2].x / 50000.f;
csp.hdr.prim.blue.y = hdrMetadata.displayPrimaries[2].y / 50000.f;
csp.hdr.prim.white.x = hdrMetadata.whitePoint.x / 50000.f;
csp.hdr.prim.white.y = hdrMetadata.whitePoint.y / 50000.f;
csp.hdr.min_luma = hdrMetadata.minDisplayLuminance / 10000.f;
csp.hdr.max_luma = hdrMetadata.maxDisplayLuminance;
csp.hdr.max_cll = hdrMetadata.maxContentLightLevel;
csp.hdr.max_fall = hdrMetadata.maxFrameAverageLightLevel;
}
else {
// Use the generic HDR10 metadata if the host doesn't provide HDR metadata
csp.hdr = pl_hdr_metadata_hdr10;
}
}
else {
csp.primaries = PL_COLOR_PRIM_UNKNOWN;
csp.transfer = PL_COLOR_TRC_UNKNOWN;
}
pl_swapchain_colorspace_hint(m_Swapchain, &csp);
}
int PlVkRenderer::getRendererAttributes()
{
int attributes = 0;

View file

@ -15,7 +15,6 @@ public:
virtual void renderFrame(AVFrame* frame) override;
virtual bool testRenderFrame(AVFrame* frame) override;
virtual void notifyOverlayUpdated(Overlay::OverlayType) override;
virtual void setHdrMode(bool enabled) override;
virtual int getRendererAttributes() override;
virtual int getDecoderCapabilities() override;
virtual bool needsTestFrame() override;
@ -44,6 +43,7 @@ private:
pl_swapchain m_Swapchain = nullptr;
pl_renderer m_Renderer = nullptr;
pl_tex m_Textures[PL_MAX_PLANES] = {};
pl_color_space m_LastColorspace = {};
// Overlay state
SDL_SpinLock m_OverlayLock = 0;