From a5d896d70afbdc16c22429dbbb17a3ca0a255239 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] macOS: Trigger expose on screen param change for windows that opt into EDR When the active EDR headroom of a display is updated, due to its brightness setting changing e.g., the system sends us a screen parameter change. 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: I1edd8ff6b9714b558a9ae92d45aaee56a838af7c Reviewed-by: Allan Sandfeld Jensen --- src/plugins/platforms/cocoa/qcocoascreen.h | 2 ++ src/plugins/platforms/cocoa/qcocoascreen.mm | 25 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoascreen.h b/src/plugins/platforms/cocoa/qcocoascreen.h index 1ff9cddd5b5..4898255e022 100644 --- a/src/plugins/platforms/cocoa/qcocoascreen.h +++ b/src/plugins/platforms/cocoa/qcocoascreen.h @@ -66,6 +66,8 @@ private: static void updateScreens(); static void cleanupScreens(); + static void updateHdrWindows(); + static QMacNotificationObserver s_screenParameterObserver; static CGDisplayReconfigurationCallBack s_displayReconfigurationCallBack; diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm index ba6bda0f8ca..d8b9601f5d1 100644 --- a/src/plugins/platforms/cocoa/qcocoascreen.mm +++ b/src/plugins/platforms/cocoa/qcocoascreen.mm @@ -64,6 +64,10 @@ void QCocoaScreen::initializeScreens() NSApplicationDidChangeScreenParametersNotification, [&]() { qCDebug(lcQpaScreen) << "Received screen parameter change notification"; updateScreens(); + + // The notification is posted when the EDR headroom of a display changes, + // which might affect the rendering of windows that opt in to EDR. + updateHdrWindows(); }); } @@ -500,6 +504,27 @@ void QCocoaScreen::maybeStopDisplayLink() CVDisplayLinkStop(m_displayLink); } + +// ----------------------------------------------------------- + +void QCocoaScreen::updateHdrWindows() +{ + if (@available(macOS 14, *)) { + for (auto *window : QGuiApplication::allWindows()) { + auto *platformWindow = static_cast(window->handle()); + if (!platformWindow) + continue; + + NSView *view = platformWindow->view(); + + if (!view.layer.wantsExtendedDynamicRangeContent) + continue; + + [view setNeedsDisplay:YES]; + } + } +} + // ----------------------------------------------------------- QPlatformScreen::SubpixelAntialiasingType QCocoaScreen::subpixelAntialiasingTypeHint() const