From bc120c5e3206f2818a9fb65f4e178f54faaf04c6 Mon Sep 17 00:00:00 2001 From: "dino@apple.com" Date: Wed, 18 May 2016 02:07:11 +0000 Subject: [PATCH] Add media query support for wide gamut displays on Mac https://bugs.webkit.org/show_bug.cgi?id=157824 Reviewed by Simon Fraser. Source/WebCore: Implement the Mac version of the color-gamut media query by filling out the screenSupportsExtendedColor function. On Yosemite, we always return false. On El Capitan, we can check the ColorProfile via ColorSync to see if the screen is wide gamut. There is already a test in fast/media/mq-color-gamut.html * css/MediaQueryEvaluator.cpp: (WebCore::color_gamutMediaFeatureEval): Pass the mainFrame's view to screenSupportsExtendedColor, so that it can fetch the NSScreen. * platform/PlatformScreen.h: screenSupportsExtendedColor now takes an optional Widget parameter. * platform/ios/PlatformScreenIOS.mm: (WebCore::screenSupportsExtendedColor): Add empty parameter. * platform/mac/PlatformScreenMac.mm: (WebCore::screenSupportsExtendedColor): Get the NSWindow, then the NSScreen, then the ColorSpace, then the ColorSyncProfile, and check if it is a wide gamut profile. * platform/spi/cg/CoreGraphicsSPI.h: Add the SPI declarations. LayoutTests: Remove the check for sRGB, since it is confusingly false on browsers that don't implement this query, and is likely to be dropped from the specification. Also, make the text readable. * fast/media/mq-color-gamut-expected.html: * fast/media/mq-color-gamut.html: git-svn-id: https://svn.webkit.org/repository/webkit/trunk@201065 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 17 ++++++++++++ .../fast/media/mq-color-gamut-expected.html | 8 +++--- LayoutTests/fast/media/mq-color-gamut.html | 14 +++------- Source/WebCore/ChangeLog | 30 ++++++++++++++++++++++ Source/WebCore/css/MediaQueryEvaluator.cpp | 4 +-- Source/WebCore/platform/PlatformScreen.h | 2 +- Source/WebCore/platform/efl/PlatformScreenEfl.cpp | 2 +- Source/WebCore/platform/gtk/PlatformScreenGtk.cpp | 2 +- Source/WebCore/platform/ios/PlatformScreenIOS.mm | 2 +- Source/WebCore/platform/mac/PlatformScreenMac.mm | 28 ++++++++++++++++++-- Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h | 7 +++++ Source/WebCore/platform/win/PlatformScreenWin.cpp | 2 +- 12 files changed, 94 insertions(+), 24 deletions(-) diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index dad0290..a2d46b3 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,20 @@ +2016-05-17 Dean Jackson + + Add media query support for wide gamut displays on Mac + https://bugs.webkit.org/show_bug.cgi?id=157824 + + + Reviewed by Simon Fraser. + + Remove the check for sRGB, since it is confusingly false + on browsers that don't implement this query, and is likely + to be dropped from the specification. + + Also, make the text readable. + + * fast/media/mq-color-gamut-expected.html: + * fast/media/mq-color-gamut.html: + 2016-05-17 Joseph Pecoraro REGRESSION(r192855): Math.random() always produces the same first 7 decimal points the first two invocations diff --git a/LayoutTests/fast/media/mq-color-gamut-expected.html b/LayoutTests/fast/media/mq-color-gamut-expected.html index 014716f..be1d070 100644 --- a/LayoutTests/fast/media/mq-color-gamut-expected.html +++ b/LayoutTests/fast/media/mq-color-gamut-expected.html @@ -2,15 +2,13 @@ CSS4 media query test: color-gamut.

This paragraph should have a green background.

-

This paragraph should have a blue background on a device with a display that supports something close to sRGB, which is nearly all displays. Otherwise the background should be green.

-

This paragraph should have a blue background on a device with a display that supports something close to P3. Otherwise the background should be green.

+

This paragraph should have a blue background on a device with a display that supports something close to P3. Otherwise the background should be green.

Note that the expected results of this test assume a display that is not significantly wider than sRGB.

diff --git a/LayoutTests/fast/media/mq-color-gamut.html b/LayoutTests/fast/media/mq-color-gamut.html index 8597438..e7c2042 100644 --- a/LayoutTests/fast/media/mq-color-gamut.html +++ b/LayoutTests/fast/media/mq-color-gamut.html @@ -2,23 +2,17 @@ CSS4 media query test: color-gamut.

This paragraph should have a green background.

-

This paragraph should have a blue background on a device with a display that supports something close to sRGB, which is nearly all displays. Otherwise the background should be green.

-

This paragraph should have a blue background on a device with a display that supports something close to P3. Otherwise the background should be green.

+

This paragraph should have a blue background on a device with a display that supports something close to P3. Otherwise the background should be green.

Note that the expected results of this test assume a display that is not significantly wider than sRGB.

diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 02aba77..f6ffcb0 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,33 @@ +2016-05-17 Dean Jackson + + Add media query support for wide gamut displays on Mac + https://bugs.webkit.org/show_bug.cgi?id=157824 + + + Reviewed by Simon Fraser. + + Implement the Mac version of the color-gamut media query + by filling out the screenSupportsExtendedColor function. + + On Yosemite, we always return false. On El Capitan, we + can check the ColorProfile via ColorSync to see if the + screen is wide gamut. + + There is already a test in fast/media/mq-color-gamut.html + + * css/MediaQueryEvaluator.cpp: + (WebCore::color_gamutMediaFeatureEval): Pass the mainFrame's view + to screenSupportsExtendedColor, so that it can fetch the NSScreen. + * platform/PlatformScreen.h: screenSupportsExtendedColor now takes + an optional Widget parameter. + * platform/ios/PlatformScreenIOS.mm: + (WebCore::screenSupportsExtendedColor): Add empty parameter. + * platform/mac/PlatformScreenMac.mm: + (WebCore::screenSupportsExtendedColor): Get the NSWindow, then the + NSScreen, then the ColorSpace, then the ColorSyncProfile, and + check if it is a wide gamut profile. + * platform/spi/cg/CoreGraphicsSPI.h: Add the SPI declarations. + 2016-05-17 Chris Dumez Unreviewed, fix Darin's post-mortem review comments for r201052. diff --git a/Source/WebCore/css/MediaQueryEvaluator.cpp b/Source/WebCore/css/MediaQueryEvaluator.cpp index 6cf042d..fdce89a 100644 --- a/Source/WebCore/css/MediaQueryEvaluator.cpp +++ b/Source/WebCore/css/MediaQueryEvaluator.cpp @@ -246,7 +246,7 @@ static bool color_indexMediaFeatureEval(CSSValue* value, const CSSToLengthConver return numberValue(value, number) && compareValue(0, static_cast(number), op); } -static bool color_gamutMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix) +static bool color_gamutMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix) { if (!value) return true; @@ -257,7 +257,7 @@ static bool color_gamutMediaFeatureEval(CSSValue* value, const CSSToLengthConver case CSSValueP3: // FIXME: For the moment we'll just assume an "extended // color" display is at least as good as P3. - return screenSupportsExtendedColor(); + return screenSupportsExtendedColor(frame->page()->mainFrame().view()); case CSSValueRec2020: // FIXME: At some point we should start detecting displays that // support more colors. diff --git a/Source/WebCore/platform/PlatformScreen.h b/Source/WebCore/platform/PlatformScreen.h index 8774ae3..0d80736 100644 --- a/Source/WebCore/platform/PlatformScreen.h +++ b/Source/WebCore/platform/PlatformScreen.h @@ -63,7 +63,7 @@ namespace WebCore { FloatRect screenRect(Widget*); FloatRect screenAvailableRect(Widget*); - WEBCORE_EXPORT bool screenSupportsExtendedColor(); + WEBCORE_EXPORT bool screenSupportsExtendedColor(Widget* widget = nullptr); #if PLATFORM(MAC) NSScreen *screenForWindow(NSWindow *); diff --git a/Source/WebCore/platform/efl/PlatformScreenEfl.cpp b/Source/WebCore/platform/efl/PlatformScreenEfl.cpp index a43d82c..213712d 100644 --- a/Source/WebCore/platform/efl/PlatformScreenEfl.cpp +++ b/Source/WebCore/platform/efl/PlatformScreenEfl.cpp @@ -118,7 +118,7 @@ FloatRect screenAvailableRect(Widget* widget) return screenRect(widget); } -bool screenSupportsExtendedColor() +bool screenSupportsExtendedColor(Widget*) { return false; } diff --git a/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp b/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp index 1ee59d3..3edf434 100644 --- a/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp +++ b/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp @@ -130,7 +130,7 @@ FloatRect screenAvailableRect(Widget* widget) } -bool screenSupportsExtendedColor() +bool screenSupportsExtendedColor(Widget*) { return false; } diff --git a/Source/WebCore/platform/ios/PlatformScreenIOS.mm b/Source/WebCore/platform/ios/PlatformScreenIOS.mm index f4c6953..c6dc13f 100644 --- a/Source/WebCore/platform/ios/PlatformScreenIOS.mm +++ b/Source/WebCore/platform/ios/PlatformScreenIOS.mm @@ -69,7 +69,7 @@ bool screenHasInvertedColors() return UIAccessibilityIsInvertColorsEnabled(); } -bool screenSupportsExtendedColor() +bool screenSupportsExtendedColor(Widget*) { #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 90300 return MGGetBoolAnswer(kMGQHasExtendedColorDisplay); diff --git a/Source/WebCore/platform/mac/PlatformScreenMac.mm b/Source/WebCore/platform/mac/PlatformScreenMac.mm index 095fbe8..fe11ede 100644 --- a/Source/WebCore/platform/mac/PlatformScreenMac.mm +++ b/Source/WebCore/platform/mac/PlatformScreenMac.mm @@ -26,10 +26,13 @@ #import "config.h" #import "PlatformScreen.h" +#import "CoreGraphicsSPI.h" #import "FloatRect.h" #import "FrameView.h" #import "HostWindow.h" +#import + extern "C" { bool CGDisplayUsesInvertedPolarity(void); bool CGDisplayUsesForceToGray(void); @@ -135,9 +138,30 @@ NSScreen *screenForDisplayID(PlatformDisplayID displayID) return nil; } -bool screenSupportsExtendedColor() +bool screenSupportsExtendedColor(Widget* widget) { - return false; // FIXME: Update this to detect extended color screens. +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101100 + UNUSED_PARAM(widget); + return false; +#else + if (!widget) + return false; + + NSWindow *window = [widget->platformWidget() window]; + NSScreen *screen = screenForWidget(widget, window); + CGColorSpaceRef colorSpace = screen.colorSpace.CGColorSpace; + +#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 + return CGColorSpaceIsWideGamutRGB(colorSpace); +#else + bool isWideGamut = false; + RetainPtr iccData = adoptCF(CGColorSpaceCopyICCProfile(colorSpace)); + RetainPtr profile = adoptCF(ColorSyncProfileCreate(iccData.get(), NULL)); + if (profile) + isWideGamut = ColorSyncProfileIsWideGamut(profile.get()); + return isWideGamut; +#endif +#endif } FloatRect toUserSpace(const NSRect& rect, NSWindow *destination) diff --git a/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h b/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h index 38cf4eb..7775b97 100644 --- a/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h +++ b/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h @@ -33,8 +33,13 @@ #include "IOSurfaceSPI.h" #endif +#if PLATFORM(MAC) +#include +#endif + #if USE(APPLE_INTERNAL_SDK) +#include #include #include @@ -195,6 +200,8 @@ CFArrayRef CGSHWCaptureWindowList(CGSConnectionID cid, CGSWindowIDList windowLis CGError CGSSetConnectionProperty(CGSConnectionID, CGSConnectionID ownerCid, CFStringRef key, CFTypeRef value); CGError CGSCopyConnectionProperty(CGSConnectionID, CGSConnectionID ownerCid, CFStringRef key, CFTypeRef *value); CGError CGSGetScreenRectForWindow(CGSConnectionID, CGSWindowID, CGRect *); + +bool ColorSyncProfileIsWideGamut(ColorSyncProfileRef); #endif WTF_EXTERN_C_END diff --git a/Source/WebCore/platform/win/PlatformScreenWin.cpp b/Source/WebCore/platform/win/PlatformScreenWin.cpp index 15dff9f..b77c622 100644 --- a/Source/WebCore/platform/win/PlatformScreenWin.cpp +++ b/Source/WebCore/platform/win/PlatformScreenWin.cpp @@ -101,7 +101,7 @@ FloatRect screenAvailableRect(Widget* widget) return monitorInfo.rcWork; } -bool screenSupportsExtendedColor() +bool screenSupportsExtendedColor(Widget*) { return false; } -- 1.8.3.1