From 8133a6e2afb8b91701198c0f6e9df67e036dc015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 7 Jun 2023 14:05:17 +0200 Subject: [PATCH] rhi: Pick up HDR maxColorComponentValue from UIScreen if available Although QRhiSwapChainHdrInfo uses 'max' for this value, it's used by Qt Multimedia's QVideoWindowPrivate::render() as the current maximum, so we need to reflect UIScreen's currentEDRHeadroom rather than potentialEDRHeadroom (the absolute max), the same way we reflect maximumExtendedDynamicRangeColorComponentValue and not maximumPotentialExtendedDynamicRangeColorComponentValue from NSScreen. As we don't support HDRExtendedSrgbLinear on < iOS 16 there is no point in providing a heuristic fallback based on the iPhone 12 spec. Change-Id: If071bb64f269ce16886206df05eb9f27d260bf15 Reviewed-by: Laszlo Agocs (cherry picked from commit 74319d05b1e8e2b5dcf226ef11bc66776460fa3f) Reviewed-by: Qt Cherry-pick Bot --- src/gui/rhi/qrhimetal.mm | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index ac372e10864..4edf0ac865e 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -6331,22 +6331,24 @@ QRhiSwapChainHdrInfo QMetalSwapChain::hdrInfo() { QRhiSwapChainHdrInfo info; info.limitsType = QRhiSwapChainHdrInfo::ColorComponentValue; - if (m_format == SDR) { - info.limits.colorComponentValue.maxColorComponentValue = 1; - return info; + info.limits.colorComponentValue.maxColorComponentValue = 1; + info.isHardCodedDefaults = true; + + if (m_format != SDR && m_window) { + // Must use m_window, not window, given this may be called before createOrResize(). +#ifdef Q_OS_MACOS + NSView *view = reinterpret_cast(m_window->winId()); + info.limits.colorComponentValue.maxColorComponentValue = view.window.screen.maximumExtendedDynamicRangeColorComponentValue; + info.isHardCodedDefaults = false; +#else + if (@available(iOS 16.0, *)) { + UIView *view = reinterpret_cast(m_window->winId()); + info.limits.colorComponentValue.maxColorComponentValue = view.window.windowScene.screen.currentEDRHeadroom; + info.isHardCodedDefaults = false; + } +#endif } -#ifdef Q_OS_MACOS - info.isHardCodedDefaults = false; - // Must use m_window, not window, given this may be called before createOrResize(). - NSView *view = reinterpret_cast(m_window->winId()); - info.limits.colorComponentValue.maxColorComponentValue = view.window.screen.maximumExtendedDynamicRangeColorComponentValue; -#else - // ### Fixme: Maybe retrieve the brightness from the screen and if we're not at full brightness we might be able to do more. - // For now, assume 2, in line with iPhone 12 specs that claim 625 nits max brightness and 1200 nits max HDR brightness. - info.isHardCodedDefaults = true; - info.limits.colorComponentValue.maxColorComponentValue = 2; -#endif return info; }