Skip to content

Commit

Permalink
renderer: Auto enable wide color gamut in HDR mode (#9090)
Browse files Browse the repository at this point in the history
  • Loading branch information
UjinT34 authored Jan 17, 2025
1 parent 47d645d commit 078e13f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/helpers/Monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class CMonitor {

bool m_bEnabled = false;
bool m_bRenderingInitPassed = false;
WP<CWindow> m_previousFSWindow;

// For the list lookup

Expand Down
29 changes: 20 additions & 9 deletions src/render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,12 +1466,6 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) {
if (inFD >= 0)
pMonitor->output->state->setExplicitInFence(inFD);

static auto PWIDE = CConfigValue<Hyprlang::INT>("experimental:wide_color_gamut");
if (pMonitor->output->state->state().wideColorGamut != *PWIDE) {
Debug::log(TRACE, "Setting wide color gamut {}", *PWIDE ? "on" : "off");
pMonitor->output->state->setWideColorGamut(*PWIDE);
}

static auto PHDR = CConfigValue<Hyprlang::INT>("experimental:hdr");

const bool SUPPORTSPQ = pMonitor->output->parsedEDID.hdrMetadata.has_value() ? pMonitor->output->parsedEDID.hdrMetadata->supportsPQ : false;
Expand All @@ -1481,18 +1475,35 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) {
const auto WINDOW = pMonitor->activeWorkspace->getFullscreenWindow();
const auto SURF = WINDOW->m_pWLSurface->resource();
if (SURF->colorManagement.valid() && SURF->colorManagement->hasImageDescription()) {
bool needsHdrMetadataUpdate = SURF->colorManagement->needsHdrMetadataUpdate() || m_previousFSWindow != WINDOW;
bool needsHdrMetadataUpdate = SURF->colorManagement->needsHdrMetadataUpdate() || pMonitor->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 if ((pMonitor->output->state->state().hdrMetadata.hdmi_metadata_type1.eotf == 2) != *PHDR)
pMonitor->output->state->setHDRMetadata(*PHDR ? createHDRMetadata(2, pMonitor->output->parsedEDID) : createHDRMetadata(0, pMonitor->output->parsedEDID));
m_previousFSWindow = WINDOW;
pMonitor->m_previousFSWindow = WINDOW;
} else {
if ((pMonitor->output->state->state().hdrMetadata.hdmi_metadata_type1.eotf == 2) != *PHDR)
pMonitor->output->state->setHDRMetadata(*PHDR ? createHDRMetadata(2, pMonitor->output->parsedEDID) : createHDRMetadata(0, pMonitor->output->parsedEDID));
m_previousFSWindow.reset();
pMonitor->m_previousFSWindow.reset();
}
}

static auto PWIDE = CConfigValue<Hyprlang::INT>("experimental:wide_color_gamut");
const bool needsWCG = *PWIDE || pMonitor->output->state->state().hdrMetadata.hdmi_metadata_type1.eotf == 2;
if (pMonitor->output->state->state().wideColorGamut != needsWCG) {
Debug::log(TRACE, "Setting wide color gamut {}", needsWCG ? "on" : "off");
pMonitor->output->state->setWideColorGamut(needsWCG);

// FIXME do not trust enabled10bit, auto switch to 10bit and back if needed
if (needsWCG && !pMonitor->enabled10bit) {
Debug::log(WARN, "Wide color gamut is enabled but the display is not in 10bit mode");
static bool shown = false;
if (!shown) {
g_pHyprNotificationOverlay->addNotification("Wide color gamut is enabled but the display is not in 10bit mode", CHyprColor{}, 15000, ICON_WARNING);
shown = true;
}
}
}

Expand Down
1 change: 0 additions & 1 deletion src/render/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class CHyprRenderer {

bool commitPendingAndDoExplicitSync(PHLMONITOR pMonitor);

WP<CWindow> m_previousFSWindow;
bool m_bCursorHidden = false;
bool m_bCursorHasSurface = false;
SP<CRenderbuffer> m_pCurrentRenderbuffer = nullptr;
Expand Down

0 comments on commit 078e13f

Please sign in to comment.