From 5d58c9765ceb96dc1cd23d2bd3244c561466e507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 4 Feb 2025 14:04:59 +0100 Subject: [PATCH] iOS: Trigger expose on screen brightness change for windows that opt into EDR When the screen brightness of the display changes, the active EDR headroom of the display might also be updated. We don't have a specific signal for these kinds of changes on a screen or window level, so for now we do the next best thing, which is to trigger an expose even for any relevant windows that might need to re-render to reflect the updated EDR headroom. Change-Id: I72ed3b8335ad763f66043daf6fcbac616425845b Reviewed-by: Allan Sandfeld Jensen --- src/plugins/platforms/ios/qiosscreen.h | 3 +++ src/plugins/platforms/ios/qiosscreen.mm | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/plugins/platforms/ios/qiosscreen.h b/src/plugins/platforms/ios/qiosscreen.h index dd694283908..07c8f71a53d 100644 --- a/src/plugins/platforms/ios/qiosscreen.h +++ b/src/plugins/platforms/ios/qiosscreen.h @@ -8,6 +8,8 @@ #include +#include + @class QIOSOrientationListener; QT_BEGIN_NAMESPACE @@ -53,6 +55,7 @@ private: #if !defined(Q_OS_VISIONOS) UIScreen *m_uiScreen = nullptr; + QMacNotificationObserver m_screenBrightnessObserver; #endif QRect m_geometry; QRect m_availableGeometry; diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index c5944ba1a7e..843e33bb8de 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -180,6 +180,27 @@ QIOSScreen::QIOSScreen(UIScreen *screen) m_displayLink.paused = YES; // Enabled when clients call QWindow::requestUpdate() [m_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; + + // The screen brightness might affect the EDR headroom of the display, + // which might affect the rendering of windows that opt in to EDR. + m_screenBrightnessObserver = QMacNotificationObserver(m_uiScreen, + UIScreenBrightnessDidChangeNotification, [&]() { + if (@available(iOS 17, *)) { + for (auto *window : QPlatformScreen::windows()) { + auto *platformWindow = static_cast(window->handle()); + if (!platformWindow) + continue; + + UIView *view = platformWindow->view(); + + if (!view.layer.wantsExtendedDynamicRangeContent) + continue; + + [view setNeedsDisplay]; + } + } + }); + #endif // !defined(Q_OS_VISIONOS)) updateProperties();