From e2e3323a409d47204410b808b756c3cb70ed1078 Mon Sep 17 00:00:00 2001 From: Brad Werth Date: Tue, 29 Nov 2022 02:31:18 +0000 Subject: [PATCH] Bug 1798067 Part 1: Add SupportsHDR to gfxPlatform, refactor macOS to use it. r=gfx-reviewers,lsalzman Differential Revision: https://phabricator.services.mozilla.com/D161364 --- gfx/thebes/gfxPlatform.h | 2 ++ gfx/thebes/gfxPlatformMac.cpp | 18 ++++++++++++++++++ gfx/thebes/gfxPlatformMac.h | 2 ++ widget/cocoa/nsLookAndFeel.mm | 16 ++++++++-------- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index 7ce11d08e67b..f484b8e5126a 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -805,6 +805,8 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener { static bool UseDesktopZoomingScrollbars(); + virtual bool SupportsHDR() { return false; } + protected: gfxPlatform(); virtual ~gfxPlatform(); diff --git a/gfx/thebes/gfxPlatformMac.cpp b/gfx/thebes/gfxPlatformMac.cpp index c1dbd2b7823e..af4de9217845 100644 --- a/gfx/thebes/gfxPlatformMac.cpp +++ b/gfx/thebes/gfxPlatformMac.cpp @@ -996,6 +996,24 @@ gfxPlatformMac::CreateGlobalHardwareVsyncSource() { return osxVsyncSource.forget(); } +bool gfxPlatformMac::SupportsHDR() { + // HDR has 3 requirements: + // 1) high peak brightness + // 2) high contrast ratio + // 3) color depth > 24 + if (GetScreenDepth() <= 24) { + return false; + } + // Screen is capable. Is the OS capable? +#ifdef EARLY_BETA_OR_EARLIER + // More-or-less supported in Catalina. + return nsCocoaFeatures::OnCatalinaOrLater(); +#else + // Definitely supported in Big Sur. + return nsCocoaFeatures::OnBigSurOrLater(); +#endif +} + nsTArray gfxPlatformMac::GetPlatformCMSOutputProfileData() { nsTArray prefProfileData = GetPrefCMSOutputProfileData(); if (!prefProfileData.IsEmpty()) { diff --git a/gfx/thebes/gfxPlatformMac.h b/gfx/thebes/gfxPlatformMac.h index 00ab2c1ca864..29bbd7e877f7 100644 --- a/gfx/thebes/gfxPlatformMac.h +++ b/gfx/thebes/gfxPlatformMac.h @@ -76,6 +76,8 @@ class gfxPlatformMac : public gfxPlatform { static bool CheckVariationFontSupport(); + bool SupportsHDR() override; + protected: bool AccelerateLayersByDefault() override; diff --git a/widget/cocoa/nsLookAndFeel.mm b/widget/cocoa/nsLookAndFeel.mm index 23085324b244..7d9222566d66 100644 --- a/widget/cocoa/nsLookAndFeel.mm +++ b/widget/cocoa/nsLookAndFeel.mm @@ -484,13 +484,13 @@ nsresult nsLookAndFeel::NativeGetInt(IntID aID, int32_t& aResult) { case IntID::UseAccessibilityTheme: aResult = NSWorkspace.sharedWorkspace.accessibilityDisplayShouldIncreaseContrast; break; - case IntID::VideoDynamicRange: -#ifdef EARLY_BETA_OR_EARLIER - aResult = nsCocoaFeatures::OnCatalinaOrLater(); -#else - aResult = nsCocoaFeatures::OnBigSurOrLater(); -#endif + case IntID::VideoDynamicRange: { + // If the platform says it supports HDR, then we claim to support video-dynamic-range. + gfxPlatform* platform = gfxPlatform::GetPlatform(); + MOZ_ASSERT(platform); + aResult = platform->SupportsHDR(); break; + } case IntID::PanelAnimations: aResult = 1; break; @@ -687,8 +687,8 @@ void nsLookAndFeel::RecordAccessibilityTelemetry() { } - (void)cachedValuesChanged { - // We only need to re-cache (and broadcast) updated LookAndFeel values, so that they're up-to-date - // the next time they're queried. No further change handling is needed. + // We only need to re-cache (and broadcast) updated LookAndFeel values, so that they're + // up-to-date the next time they're queried. No further change handling is needed. // TODO: Add a change hint for this which avoids the unnecessary media query invalidation. LookAndFeel::NotifyChangedAllWindows(widget::ThemeChangeKind::MediaQueriesOnly); }