From 8d9c72b1dbc7fedbae64801d2d786c4084132d00 Mon Sep 17 00:00:00 2001 From: UjinT34 Date: Sun, 5 Jan 2025 17:12:19 +0300 Subject: [PATCH] do not set hdr metadata unless needed --- src/protocols/ColorManagement.cpp | 26 ++++++++++++++++++++++---- src/protocols/ColorManagement.hpp | 7 +++++++ src/protocols/FrogColorManagement.cpp | 10 +++++----- src/render/Renderer.cpp | 15 +++++++++++---- src/render/Renderer.hpp | 1 + 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/protocols/ColorManagement.cpp b/src/protocols/ColorManagement.cpp index 7ff4db4f..a76e13c0 100644 --- a/src/protocols/ColorManagement.cpp +++ b/src/protocols/ColorManagement.cpp @@ -194,13 +194,13 @@ CColorManagementSurface::CColorManagementSurface(SP return; } - m_hasImageDescription = true; - m_imageDescription = imageDescription->get()->settings; + setHasImageDescription(true); + m_imageDescription = imageDescription->get()->settings; }); resource->setUnsetImageDescription([this](CXxColorManagementSurfaceV4* r) { LOGM(TRACE, "Unset image description for surface={}", (uintptr_t)r); - m_imageDescription = SImageDescription{}; - m_hasImageDescription = false; + m_imageDescription = SImageDescription{}; + setHasImageDescription(false); }); } @@ -222,6 +222,24 @@ bool CColorManagementSurface::hasImageDescription() { return m_hasImageDescription; } +void CColorManagementSurface::setHasImageDescription(bool has) { + m_hasImageDescription = has; + m_needsNewMetadata = true; +} + +const hdr_output_metadata& CColorManagementSurface::hdrMetadata() { + return m_hdrMetadata; +} + +void CColorManagementSurface::setHDRMetadata(const hdr_output_metadata& metadata) { + m_hdrMetadata = metadata; + m_needsNewMetadata = false; +} + +bool CColorManagementSurface::needsHdrMetadataUpdate() { + return m_needsNewMetadata; +} + CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SP resource_, SP surface_) : surface(surface_), resource(resource_) { if (!good()) diff --git a/src/protocols/ColorManagement.hpp b/src/protocols/ColorManagement.hpp index 573abf69..e387b3b7 100644 --- a/src/protocols/ColorManagement.hpp +++ b/src/protocols/ColorManagement.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -54,12 +55,18 @@ class CColorManagementSurface { const SImageDescription& imageDescription(); bool hasImageDescription(); + void setHasImageDescription(bool has); + const hdr_output_metadata& hdrMetadata(); + void setHDRMetadata(const hdr_output_metadata& metadata); + bool needsHdrMetadataUpdate(); private: SP resource; wl_client* pClient = nullptr; SImageDescription m_imageDescription; bool m_hasImageDescription = false; + bool m_needsNewMetadata = false; + hdr_output_metadata m_hdrMetadata; friend class CFrogColorManagementSurface; }; diff --git a/src/protocols/FrogColorManagement.cpp b/src/protocols/FrogColorManagement.cpp index 6a921981..f27af5c8 100644 --- a/src/protocols/FrogColorManagement.cpp +++ b/src/protocols/FrogColorManagement.cpp @@ -92,7 +92,7 @@ CFrogColorManagementSurface::CFrogColorManagementSurface(SPcolorManagement->m_imageDescription.transferFunction = XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_SRGB; - surface->colorManagement->m_hasImageDescription = true; + surface->colorManagement->setHasImageDescription(true); } }); resource->setSetKnownContainerColorVolume([this](CFrogColorManagedSurface* r, frogColorManagedSurfacePrimaries primariesName) { @@ -103,12 +103,12 @@ CFrogColorManagementSurface::CFrogColorManagementSurface(SPcolorManagement->m_imageDescription.primaries = NColorPrimaries::BT2020; break; } - surface->colorManagement->m_hasImageDescription = true; + surface->colorManagement->setHasImageDescription(true); }); resource->setSetRenderIntent([this](CFrogColorManagedSurface* r, frogColorManagedSurfaceRenderIntent intent) { LOGM(TRACE, "Set frog cm intent {}", (uint32_t)intent); - pqIntentSent = intent == FROG_COLOR_MANAGED_SURFACE_RENDER_INTENT_PERCEPTUAL; - surface->colorManagement->m_hasImageDescription = true; + pqIntentSent = intent == FROG_COLOR_MANAGED_SURFACE_RENDER_INTENT_PERCEPTUAL; + surface->colorManagement->setHasImageDescription(true); }); resource->setSetHdrMetadata([this](CFrogColorManagedSurface* r, uint32_t r_x, uint32_t r_y, uint32_t g_x, uint32_t g_y, uint32_t b_x, uint32_t b_y, uint32_t w_x, uint32_t w_y, uint32_t max_lum, uint32_t min_lum, uint32_t cll, uint32_t fall) { @@ -122,7 +122,7 @@ CFrogColorManagementSurface::CFrogColorManagementSurface(SPcolorManagement->m_imageDescription.maxCLL = cll; surface->colorManagement->m_imageDescription.maxFALL = fall; - surface->colorManagement->m_hasImageDescription = true; + surface->colorManagement->setHasImageDescription(true); }); } diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index cf25d477..977bebb6 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1472,12 +1472,19 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) { if (pMonitor->activeWorkspace && pMonitor->activeWorkspace->m_bHasFullscreenWindow && pMonitor->activeWorkspace->m_efFullscreenMode == FSMODE_FULLSCREEN) { const auto WINDOW = pMonitor->activeWorkspace->getFullscreenWindow(); const auto SURF = WINDOW->m_pWLSurface->resource(); - if (SURF->colorManagement.valid() && SURF->colorManagement->hasImageDescription()) - pMonitor->output->state->setHDRMetadata(createHDRMetadata(SURF->colorManagement.get()->imageDescription(), pMonitor->output->parsedEDID)); - else + if (SURF->colorManagement.valid() && SURF->colorManagement->hasImageDescription()) { + bool needsHdrMetadataUpdate = SURF->colorManagement->needsHdrMetadataUpdate() || m_previousFSWindow != WINDOW; + if (SURF->colorManagement->needsHdrMetadataUpdate()) + SURF->colorManagement->setHDRMetadata(createHDRMetadata(SURF->colorManagement.get()->imageDescription(), pMonitor->output->parsedEDID)); + if (needsHdrMetadataUpdate) + pMonitor->output->state->setHDRMetadata(SURF->colorManagement->hdrMetadata()); + } else pMonitor->output->state->setHDRMetadata(*PHDR ? createHDRMetadata(2, pMonitor->output->parsedEDID) : createHDRMetadata(0, pMonitor->output->parsedEDID)); - } else + m_previousFSWindow = WINDOW; + } else { pMonitor->output->state->setHDRMetadata(*PHDR ? createHDRMetadata(2, pMonitor->output->parsedEDID) : createHDRMetadata(0, pMonitor->output->parsedEDID)); + m_previousFSWindow.reset(); + } } if (pMonitor->ctmUpdated) { diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 6900c775..f3e0c5a2 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -129,6 +129,7 @@ class CHyprRenderer { bool commitPendingAndDoExplicitSync(PHLMONITOR pMonitor); + WP m_previousFSWindow; bool m_bCursorHidden = false; bool m_bCursorHasSurface = false; SP m_pCurrentRenderbuffer = nullptr;