Bug 1812647: Make macOS screen HDR detection additionally check color component maximum. r=mac-reviewers,mstange

This is useful to discriminate between different colorspace options,
some of which are unable to supprt macOS Extended Dynamic Range
values. This is a reliable standin for measuring nits/brightness.

Differential Revision: https://phabricator.services.mozilla.com/D206163
This commit is contained in:
Brad Werth 2024-04-01 19:07:52 +00:00
parent 748e156587
commit 16567174cf

View file

@ -109,10 +109,23 @@ static already_AddRefed<Screen> MakeScreen(NSScreen* aScreen) {
if (pixelDepth > MAX_REPORTED_PIXEL_DEPTH) {
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.
bool isHDR = pixelDepth > 24;
// 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();