summaryrefslogtreecommitdiffstats
path: root/widget/cocoa/ScreenHelperCocoa.mm
diff options
context:
space:
mode:
Diffstat (limited to 'widget/cocoa/ScreenHelperCocoa.mm')
-rw-r--r--widget/cocoa/ScreenHelperCocoa.mm28
1 files changed, 25 insertions, 3 deletions
diff --git a/widget/cocoa/ScreenHelperCocoa.mm b/widget/cocoa/ScreenHelperCocoa.mm
index 57e1313320..2f1408e345 100644
--- a/widget/cocoa/ScreenHelperCocoa.mm
+++ b/widget/cocoa/ScreenHelperCocoa.mm
@@ -9,6 +9,7 @@
#import <Cocoa/Cocoa.h>
#include "mozilla/Logging.h"
+#include "nsCocoaFeatures.h"
#include "nsCocoaUtils.h"
#include "nsObjCExceptions.h"
@@ -109,6 +110,26 @@ static already_AddRefed<Screen> MakeScreen(NSScreen* aScreen) {
pixelDepth = MAX_REPORTED_PIXEL_DEPTH;
}
+ // What's the maximum color component value this screen can display? This
+ // is a reasonable stand-in for measuring peak brightness.
+ CGFloat componentValueMax =
+ aScreen.maximumPotentialExtendedDynamicRangeColorComponentValue;
+
+ // Should we treat this as HDR? Based on spec at
+ // https://drafts.csswg.org/mediaqueries-5/#dynamic-range, we'll consider it
+ // HDR if it has pixel depth greater than 24, and if has high peak brightness,
+ // which we measure by checking if it can represent component values greater
+ // than 1.0.
+ //
+ // Also, on HDR screens, users may want to force SDR by setting a different
+ // colorspace, for example by using the "Photography (P3 D65)" preset. In that
+ // case, componentValueMax will be 1.0 and we want to treat the display as
+ // SDR.
+ bool isHDR = pixelDepth > 24 && componentValueMax > 1.0;
+
+ // Double-check HDR against the platform capabilities.
+ isHDR &= nsCocoaFeatures::OnBigSurOrLater();
+
float dpi = 96.0f;
CGDirectDisplayID displayID =
[[[aScreen deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
@@ -125,9 +146,10 @@ static already_AddRefed<Screen> MakeScreen(NSScreen* aScreen) {
// Getting the refresh rate is a little hard on OS X. We could use
// CVDisplayLinkGetNominalOutputVideoRefreshPeriod, but that's a little
// involved. Ideally we could query it from vsync. For now, we leave it out.
- RefPtr<Screen> screen = new Screen(rect, availRect, pixelDepth, pixelDepth, 0,
- contentsScaleFactor, defaultCssScaleFactor,
- dpi, Screen::IsPseudoDisplay::No);
+ RefPtr<Screen> screen =
+ new Screen(rect, availRect, pixelDepth, pixelDepth, 0,
+ contentsScaleFactor, defaultCssScaleFactor, dpi,
+ Screen::IsPseudoDisplay::No, Screen::IsHDR(isHDR));
return screen.forget();
NS_OBJC_END_TRY_BLOCK_RETURN(nullptr);