Experimental support for HDR media query
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Nov 2019 05:17:02 +0000 (05:17 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Nov 2019 05:17:02 +0000 (05:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204422

Reviewed by Eric Carlson.

Source/WebCore:

Test: fast/media/mq-highdynamicrange-live-update.html

Add support for the dynamic-range: media query.

* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSValueKeywords.in:
* css/MediaFeatureNames.h:
* css/MediaQueryEvaluator.cpp:
(WebCore::dynamicRangeEvaluate):
* css/MediaQueryExpression.cpp:
(WebCore::featureWithValidIdent):
* page/Chrome.cpp:
(WebCore::Chrome::windowScreenDidChange):
* page/Settings.yaml:
* page/SettingsBase.h:
* platform/PlatformScreen.h:
* platform/ScreenProperties.h:
(WebCore::ScreenData::encode const):
(WebCore::ScreenData::decode):
* platform/ios/PlatformScreenIOS.mm:
(WebCore::screenSupportsHighDynamicRange):
* platform/mac/PlatformScreenMac.mm:
(WebCore::collectScreenProperties):
(WebCore::screenSupportsHighDynamicRange):
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::forcedSupportsHighDynamicRangeValue const):
(WebCore::InternalSettings::setForcedSupportsHighDynamicRangeValue):
* testing/InternalSettings.h:
* testing/InternalSettings.idl:

Source/WebCore/PAL:

* PAL.xcodeproj/project.pbxproj:
* pal/PlatformMac.cmake:
* pal/cocoa/MediaToolboxSoftLink.cpp: Renamed from Source/WebCore/platform/cocoa/MediaToolboxSoftLink.h.
* pal/cocoa/MediaToolboxSoftLink.h: Renamed from Source/WebCore/platform/cocoa/MediaToolboxSoftLink.cpp.

Source/WebKit:

Notify the WebContent process of updated screen properties when the screen's
color space changes.

* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(-[WKWindowVisibilityObserver startObserving:]):
(-[WKWindowVisibilityObserver stopObserving:]):
(-[WKWindowVisibilityObserver _screenDidChangeColorSpace:]):
(WebKit::WebViewImpl::screenDidChangeColorSpace):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::screenPropertiesDidChange):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::setScreenProperties):

LayoutTests:

* fast/media/mq-highdynamicrange-live-update-expected.txt: Added.
* fast/media/mq-highdynamicrange-live-update.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252762 268f45cc-cd09-0410-ab3c-d52691b4dbfc

30 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/media/mq-highdynamicrange-live-update-expected.txt [new file with mode: 0644]
LayoutTests/fast/media/mq-highdynamicrange-live-update.html [new file with mode: 0644]
Source/WTF/wtf/cocoa/SoftLinking.h
Source/WebCore/ChangeLog
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj
Source/WebCore/PAL/pal/PlatformMac.cmake
Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.cpp [new file with mode: 0644]
Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.h [new file with mode: 0644]
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/MediaFeatureNames.h
Source/WebCore/css/MediaQueryEvaluator.cpp
Source/WebCore/css/MediaQueryExpression.cpp
Source/WebCore/page/Chrome.cpp
Source/WebCore/page/Settings.yaml
Source/WebCore/page/SettingsBase.h
Source/WebCore/platform/PlatformScreen.h
Source/WebCore/platform/ScreenProperties.h
Source/WebCore/platform/ios/PlatformScreenIOS.mm
Source/WebCore/platform/mac/PlatformScreenMac.mm
Source/WebCore/testing/InternalSettings.cpp
Source/WebCore/testing/InternalSettings.h
Source/WebCore/testing/InternalSettings.idl
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/WebViewImpl.h
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebProcess.cpp

index f2d8e3f..5ce3efc 100644 (file)
@@ -1,3 +1,13 @@
+2019-11-21  Jer Noble  <jer.noble@apple.com>
+
+        Experimental support for HDR media query
+        https://bugs.webkit.org/show_bug.cgi?id=204422
+
+        Reviewed by Eric Carlson.
+
+        * fast/media/mq-highdynamicrange-live-update-expected.txt: Added.
+        * fast/media/mq-highdynamicrange-live-update.html: Added.
+
 2019-11-21  Ryosuke Niwa  <rniwa@webkit.org>
 
         Scrolling to fragment shouldn't happen as a part of updating style
diff --git a/LayoutTests/fast/media/mq-highdynamicrange-live-update-expected.txt b/LayoutTests/fast/media/mq-highdynamicrange-live-update-expected.txt
new file mode 100644 (file)
index 0000000..4cf7975
--- /dev/null
@@ -0,0 +1,3 @@
+Before was: rgb(0, 0, 0) - should be rgb(0, 0, 0)
+
+After was: rgb(0, 128, 0) - should be rgb(0, 128, 0)
diff --git a/LayoutTests/fast/media/mq-highdynamicrange-live-update.html b/LayoutTests/fast/media/mq-highdynamicrange-live-update.html
new file mode 100644 (file)
index 0000000..23048b7
--- /dev/null
@@ -0,0 +1,36 @@
+<html>
+<head>
+<title>CSS4 media query test: dynamic-range: high.</title>
+<style type="text/css">
+p { color: black; }
+
+@media (dynamic-range: high) {
+    #a { color: green; }
+}
+</style>
+<script>
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+window.addEventListener('load', event => {
+    if (!window.internals)
+        return;
+
+    window.internals.settings.setHDRMediaCapabilitiesEnabled(true);
+    window.internals.settings.forcedSupportsHighDynamicRangeValue = "off";
+    var element = document.getElementById("a");
+    document.getElementById("before").textContent = window.getComputedStyle(element).color;
+    window.internals.settings.forcedSupportsHighDynamicRangeValue = "on";
+    document.getElementById("after").textContent = window.getComputedStyle(element).color;
+    testRunner.notifyDone();
+});
+</script>
+</head>
+<body>
+  <p id="a"></p>
+  <p>Before was: <span id="before"></span> - should be rgb(0, 0, 0)</p>
+  <p>After was: <span id="after"></span> - should be rgb(0, 128, 0)</p>
+</body>
+</html>
index b890ede..3629532 100644 (file)
     resultType softLink_##framework##_##functionName parameterDeclarations; \
     }
 
-#define SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(functionNamespace, framework, functionName, resultType, parameterDeclarations, parameterNames) \
+#define SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(functionNamespace, framework, functionName, resultType, parameterDeclarations, parameterNames, export) \
     WTF_EXTERN_C_BEGIN \
     resultType functionName parameterDeclarations; \
     WTF_EXTERN_C_END \
     namespace functionNamespace { \
-    resultType (*softLink##framework##functionName) parameterDeclarations = 0; \
+    export resultType (*softLink##framework##functionName) parameterDeclarations = 0; \
     bool init_##framework##_##functionName(); \
     bool init_##framework##_##functionName() \
     { \
     } \
     \
     bool canLoad_##framework##_##functionName(); \
-    bool canLoad_##framework##_##functionName() \
+    export bool canLoad_##framework##_##functionName() \
     { \
         static bool loaded = init_##framework##_##functionName(); \
         return loaded; \
     } \
     }
 
+#define SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(functionNamespace, framework, functionName, resultType, parameterDeclarations, parameterNames) \
+    SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(functionNamespace, framework, functionName, resultType, parameterDeclarations, parameterNames, )
+
 #define SOFT_LINK_POINTER_FOR_HEADER(functionNamespace, framework, variableName, variableType) \
     namespace functionNamespace { \
     extern variableType (*get_##framework##_##variableName)(); \
index ca012f3..a2b3f49 100644 (file)
@@ -1,3 +1,41 @@
+2019-11-21  Jer Noble  <jer.noble@apple.com>
+
+        Experimental support for HDR media query
+        https://bugs.webkit.org/show_bug.cgi?id=204422
+
+        Reviewed by Eric Carlson.
+
+        Test: fast/media/mq-highdynamicrange-live-update.html
+
+        Add support for the dynamic-range: media query.
+
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSValueKeywords.in:
+        * css/MediaFeatureNames.h:
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::dynamicRangeEvaluate):
+        * css/MediaQueryExpression.cpp:
+        (WebCore::featureWithValidIdent):
+        * page/Chrome.cpp:
+        (WebCore::Chrome::windowScreenDidChange):
+        * page/Settings.yaml:
+        * page/SettingsBase.h:
+        * platform/PlatformScreen.h:
+        * platform/ScreenProperties.h:
+        (WebCore::ScreenData::encode const):
+        (WebCore::ScreenData::decode):
+        * platform/ios/PlatformScreenIOS.mm:
+        (WebCore::screenSupportsHighDynamicRange):
+        * platform/mac/PlatformScreenMac.mm:
+        (WebCore::collectScreenProperties):
+        (WebCore::screenSupportsHighDynamicRange):
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::forcedSupportsHighDynamicRangeValue const):
+        (WebCore::InternalSettings::setForcedSupportsHighDynamicRangeValue):
+        * testing/InternalSettings.h:
+        * testing/InternalSettings.idl:
+
 2019-11-21  Ryosuke Niwa  <rniwa@webkit.org>
 
         Scrolling to fragment shouldn't happen as a part of updating style
index b16a5f1..c150dcd 100644 (file)
@@ -1,3 +1,15 @@
+2019-11-21  Jer Noble  <jer.noble@apple.com>
+
+        Experimental support for HDR media query
+        https://bugs.webkit.org/show_bug.cgi?id=204422
+
+        Reviewed by Eric Carlson.
+
+        * PAL.xcodeproj/project.pbxproj:
+        * pal/PlatformMac.cmake:
+        * pal/cocoa/MediaToolboxSoftLink.cpp: Renamed from Source/WebCore/platform/cocoa/MediaToolboxSoftLink.h.
+        * pal/cocoa/MediaToolboxSoftLink.h: Renamed from Source/WebCore/platform/cocoa/MediaToolboxSoftLink.cpp.
+
 2019-11-15  Eric Carlson  <eric.carlson@apple.com>
 
         Don't use AVCapture on watchOS and tvOS
index 112b870..6fda456 100644 (file)
                A3AB6E651F3D217F009C14B1 /* SystemSleepListenerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A3AB6E631F3D217F009C14B1 /* SystemSleepListenerMac.mm */; };
                A3C66CDC1F462D6A009E6EE9 /* SessionID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A3C66CDA1F462D6A009E6EE9 /* SessionID.cpp */; };
                A3C66CDD1F462D6A009E6EE9 /* SessionID.h in Headers */ = {isa = PBXBuildFile; fileRef = A3C66CDB1F462D6A009E6EE9 /* SessionID.h */; };
+               CDACB3602387425B0018D7CE /* MediaToolboxSoftLink.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDACB35E23873E480018D7CE /* MediaToolboxSoftLink.cpp */; };
+               CDACB361238742740018D7CE /* MediaToolboxSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = CDACB35F23873E480018D7CE /* MediaToolboxSoftLink.h */; };
                CDF91113220E4EEC001EA39E /* CelestialSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CDF91112220E4EEC001EA39E /* CelestialSPI.h */; };
                CE5673872151A7B9002F92D7 /* IOKitSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE5673862151A7B9002F92D7 /* IOKitSPI.h */; };
                E5D45D122106A07400D2B738 /* NSColorWellSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = E5D45D112106A07400D2B738 /* NSColorWellSPI.h */; };
                A3C66CDA1F462D6A009E6EE9 /* SessionID.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SessionID.cpp; sourceTree = "<group>"; };
                A3C66CDB1F462D6A009E6EE9 /* SessionID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SessionID.h; sourceTree = "<group>"; };
                C2147A4A1EFD0AA600056FA5 /* CopyPALHeaders.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CopyPALHeaders.xcconfig; sourceTree = "<group>"; };
+               CDACB35E23873E480018D7CE /* MediaToolboxSoftLink.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MediaToolboxSoftLink.cpp; sourceTree = "<group>"; };
+               CDACB35F23873E480018D7CE /* MediaToolboxSoftLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaToolboxSoftLink.h; sourceTree = "<group>"; };
                CDF91112220E4EEC001EA39E /* CelestialSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CelestialSPI.h; sourceTree = "<group>"; };
                CE5673862151A7B9002F92D7 /* IOKitSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IOKitSPI.h; sourceTree = "<group>"; };
                E5D45D112106A07400D2B738 /* NSColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSColorWellSPI.h; sourceTree = "<group>"; };
                                077E87AF226A460200A2AFF0 /* AVFoundationSoftLink.mm */,
                                F44291661FA52705002CC93E /* FileSizeFormatterCocoa.mm */,
                                1C022EFC22CFE8E0006DF01B /* Gunzip.cpp */,
+                               CDACB35E23873E480018D7CE /* MediaToolboxSoftLink.cpp */,
+                               CDACB35F23873E480018D7CE /* MediaToolboxSoftLink.h */,
                                A1F63C9D21A4DBF7006FB43B /* PassKitSoftLink.h */,
                                A1F63C9E21A4DBF7006FB43B /* PassKitSoftLink.mm */,
                        );
                                570AB8F120AE2E8D00B8BE87 /* SecKeyProxySPI.h in Headers */,
                                0C2DA1581F3BEB4900DBC317 /* ServersSPI.h in Headers */,
                                A3C66CDD1F462D6A009E6EE9 /* SessionID.h in Headers */,
+                               CDACB361238742740018D7CE /* MediaToolboxSoftLink.h in Headers */,
                                A3AB6E561F3D1DDB009C14B1 /* SleepDisabler.h in Headers */,
                                A3AB6E611F3D1E39009C14B1 /* SleepDisablerCocoa.h in Headers */,
                                A3788E981F05B6CE00679425 /* Sound.h in Headers */,
                                A3AB6E521F3D1DC5009C14B1 /* SleepDisabler.cpp in Sources */,
                                A3AB6E601F3D1E39009C14B1 /* SleepDisablerCocoa.cpp in Sources */,
                                A3788E9C1F05B78200679425 /* Sound.cpp in Sources */,
+                               CDACB3602387425B0018D7CE /* MediaToolboxSoftLink.cpp in Sources */,
                                A3788E9E1F05B78E00679425 /* SoundMac.mm in Sources */,
                                A3AB6E571F3D1DDB009C14B1 /* SystemSleepListener.cpp in Sources */,
                                A3AB6E651F3D217F009C14B1 /* SystemSleepListenerMac.mm in Sources */,
index f71c856..e3f7a32 100644 (file)
@@ -5,6 +5,7 @@ list(APPEND PAL_PUBLIC_HEADERS
 
     cocoa/AppSSOSoftLink.h
     cocoa/AVFoundationSoftLink.h
+    cocoa/MediaToolboxSoftLink.h
     cocoa/PassKitSoftLink.h
 
     mac/LookupSoftLink.h
@@ -118,6 +119,7 @@ list(APPEND PAL_SOURCES
     cocoa/AVFoundationSoftLink.mm
     cocoa/FileSizeFormatterCocoa.mm
     cocoa/Gunzip.cpp
+    cocoa/MediaToolboxSoftLink.cpp
     cocoa/PassKitSoftLink.mm
 
     crypto/commoncrypto/CryptoDigestCommonCrypto.cpp
diff --git a/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.cpp b/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.cpp
new file mode 100644 (file)
index 0000000..f0689ec
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if USE(MEDIATOOLBOX)
+
+#include <MediaToolbox/MediaToolbox.h>
+#include <wtf/SoftLinking.h>
+
+SOFT_LINK_FRAMEWORK_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, PAL_EXPORT)
+
+SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, MTShouldPlayHDRVideo, Boolean, (CFArrayRef displayList), (displayList), PAL_EXPORT)
+
+#endif
diff --git a/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.h b/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.h
new file mode 100644 (file)
index 0000000..510212b
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(MEDIATOOLBOX)
+
+#include <MediaToolbox/MediaToolbox.h>
+#include <wtf/SoftLinking.h>
+
+SOFT_LINK_FRAMEWORK_FOR_HEADER(PAL, MediaToolbox)
+
+SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(PAL, MediaToolbox, MTShouldPlayHDRVideo, Boolean, (CFArrayRef displayList), (displayList))
+
+#endif
index 39a089f..5d7f408 100644 (file)
@@ -1441,3 +1441,7 @@ browser
 
 // text-decoration-thickness, text-underline-offset
 from-font
+
+// dynamic-range
+standard
+high
index d86e664..ab597f4 100644 (file)
@@ -47,6 +47,7 @@
     macro(deviceHeight, "device-height") \
     macro(devicePixelRatio, "-webkit-device-pixel-ratio") \
     macro(deviceWidth, "device-width") \
+    macro(dynamicRange, "dynamic-range") \
     macro(grid, "grid") \
     macro(height, "height") \
     macro(hover, "hover") \
index 0581caa..749e4c3 100644 (file)
@@ -419,6 +419,33 @@ static bool resolutionEvaluate(CSSValue* value, const CSSToLengthConversionData&
 #endif
 }
 
+static bool dynamicRangeEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix)
+{
+    if (!value)
+        return false;
+
+    if (!frame.settings().hdrMediaCapabilitiesEnabled())
+        return false;
+
+    bool supportsHighDynamicRange;
+
+    if (frame.settings().forcedSupportsHighDynamicRangeValue() == Settings::ForcedAccessibilityValue::On)
+        supportsHighDynamicRange = true;
+    else if (frame.settings().forcedSupportsHighDynamicRangeValue() == Settings::ForcedAccessibilityValue::Off)
+        supportsHighDynamicRange = false;
+    else
+        supportsHighDynamicRange = screenSupportsHighDynamicRange(frame.mainFrame().view());
+
+    switch (downcast<CSSPrimitiveValue>(*value).valueID()) {
+    case CSSValueHigh:
+        return supportsHighDynamicRange;
+    case CSSValueStandard:
+        return true;
+    default:
+        return false; // Any unknown value should not be considered a match.
+    }
+}
+
 static bool gridEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix op)
 {
     return zeroEvaluate(value, op);
index eef367a..eeba994 100644 (file)
@@ -57,7 +57,8 @@ static inline bool featureWithValidIdent(const AtomString& mediaFeature, const C
     || (mediaFeature == MediaFeatureNames::prefersColorScheme)
 #endif
     || mediaFeature == MediaFeatureNames::prefersReducedMotion
-    || (mediaFeature == MediaFeatureNames::prefersDarkInterface && (context.useSystemAppearance || isUASheetBehavior(context.mode)));
+    || (mediaFeature == MediaFeatureNames::prefersDarkInterface && (context.useSystemAppearance || isUASheetBehavior(context.mode)))
+    || mediaFeature == MediaFeatureNames::dynamicRange;
 }
 
 static inline bool featureWithValidDensity(const String& mediaFeature, const CSSPrimitiveValue& value)
index aec14db..6233e4b 100644 (file)
@@ -518,6 +518,8 @@ void Chrome::windowScreenDidChange(PlatformDisplayID displayID)
             frame->document()->windowScreenDidChange(displayID);
     }
 
+    m_page.setNeedsRecalcStyleInAllFrames();
+
 #if PLATFORM(MAC) && ENABLE(GRAPHICS_CONTEXT_3D)
     GraphicsContext3DManager::sharedManager().screenDidChange(displayID, this);
 #endif
index ba2f456..d669c4a 100644 (file)
@@ -632,6 +632,10 @@ forcedDisplayIsMonochromeAccessibilityValue:
 forcedPrefersReducedMotionAccessibilityValue:
   type: ForcedAccessibilityValue
   initial: defaultForcedPrefersReducedMotionAccessibilityValue
+forcedSupportsHighDynamicRangeValue:
+  type: ForcedAccessibilityValue
+  initial: defaultForcedSupportsHighDynamicRangeValue
+  onChange: setNeedsRecalcStyleInAllFrames
 
 largeImageAsyncDecodingEnabled:
   initial: true
index 1d983a2..f1a65f6 100644 (file)
@@ -111,6 +111,7 @@ public:
     static const SettingsBase::ForcedAccessibilityValue defaultForcedColorsAreInvertedAccessibilityValue = ForcedAccessibilityValue::System;
     static const SettingsBase::ForcedAccessibilityValue defaultForcedDisplayIsMonochromeAccessibilityValue = ForcedAccessibilityValue::System;
     static const SettingsBase::ForcedAccessibilityValue defaultForcedPrefersReducedMotionAccessibilityValue = ForcedAccessibilityValue::System;
+    static const SettingsBase::ForcedAccessibilityValue defaultForcedSupportsHighDynamicRangeValue = ForcedAccessibilityValue::System;
 
     WEBCORE_EXPORT static bool defaultTextAutosizingEnabled();
     WEBCORE_EXPORT static float defaultMinimumZoomFontSize();
index 9ff282b..4ad2868 100644 (file)
@@ -75,6 +75,12 @@ FloatRect screenAvailableRect(Widget*);
 
 WEBCORE_EXPORT bool screenSupportsExtendedColor(Widget* = nullptr);
 
+#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
+bool screenSupportsHighDynamicRange(Widget* = nullptr);
+#else
+constexpr bool screenSupportsHighDynamicRange(Widget* = nullptr) { return false; }
+#endif
+
 #if USE(CG)
 WEBCORE_EXPORT CGColorSpaceRef screenColorSpace(Widget* = nullptr);
 #endif
index 2485280..edae53b 100644 (file)
@@ -45,6 +45,7 @@ struct ScreenData {
     bool screenSupportsExtendedColor { false };
     bool screenHasInvertedColors { false };
     bool screenIsMonochrome { false };
+    bool screenSupportsHighDynamicRange { false };
     uint32_t displayMask { 0 };
     IORegistryGPUID gpuID { 0 };
 
@@ -94,7 +95,7 @@ Optional<ScreenProperties> ScreenProperties::decode(Decoder& decoder)
 template<class Encoder>
 void ScreenData::encode(Encoder& encoder) const
 {
-    encoder << screenAvailableRect << screenRect << screenDepth << screenDepthPerComponent << screenSupportsExtendedColor << screenHasInvertedColors << screenIsMonochrome << displayMask << gpuID;
+    encoder << screenAvailableRect << screenRect << screenDepth << screenDepthPerComponent << screenSupportsExtendedColor << screenHasInvertedColors << screenIsMonochrome << screenSupportsHighDynamicRange << displayMask << gpuID;
 
     if (colorSpace) {
         // Try to encode the name.
@@ -158,6 +159,11 @@ Optional<ScreenData> ScreenData::decode(Decoder& decoder)
     if (!screenIsMonochrome)
         return WTF::nullopt;
 
+    Optional<bool> screenSupportsHighDynamicRange;
+    decoder >> screenSupportsHighDynamicRange;
+    if (!screenSupportsHighDynamicRange)
+        return WTF::nullopt;
+
     Optional<uint32_t> displayMask;
     decoder >> displayMask;
     if (!displayMask)
@@ -199,7 +205,7 @@ Optional<ScreenData> ScreenData::decode(Decoder& decoder)
     }
     }
 
-    return { { WTFMove(*screenAvailableRect), WTFMove(*screenRect), WTFMove(cgColorSpace), WTFMove(*screenDepth), WTFMove(*screenDepthPerComponent), WTFMove(*screenSupportsExtendedColor), WTFMove(*screenHasInvertedColors), WTFMove(*screenIsMonochrome), WTFMove(*displayMask), WTFMove(*gpuID) } };
+    return { { WTFMove(*screenAvailableRect), WTFMove(*screenRect), WTFMove(cgColorSpace), WTFMove(*screenDepth), WTFMove(*screenDepthPerComponent), WTFMove(*screenSupportsExtendedColor), WTFMove(*screenHasInvertedColors), WTFMove(*screenIsMonochrome), WTFMove(*screenSupportsHighDynamicRange), WTFMove(*displayMask), WTFMove(*gpuID) } };
 }
 
 } // namespace WebCore
index 41adc2a..db5ab7a 100644 (file)
@@ -38,6 +38,7 @@
 #import "IntRect.h"
 #import "WAKWindow.h"
 #import "Widget.h"
+#import <pal/cocoa/MediaToolboxSoftLink.h>
 #import <pal/ios/UIKitSoftLink.h>
 #import <pal/spi/ios/MobileGestaltSPI.h>
 #import <pal/spi/ios/UIKitSPI.h>
@@ -71,6 +72,15 @@ bool screenSupportsExtendedColor(Widget*)
     return MGGetBoolAnswer(kMGQHasExtendedColorDisplay);
 }
 
+bool screenSupportsHighDynamicRange(Widget*)
+{
+#if USE(MEDIATOOLBOX)
+    if (PAL::canLoad_MediaToolbox_MTShouldPlayHDRVideo())
+        return PAL::softLink_MediaToolbox_MTShouldPlayHDRVideo(nullptr);
+#endif
+    return false;
+}
+
 CGColorSpaceRef screenColorSpace(Widget* widget)
 {
     return screenSupportsExtendedColor(widget) ? extendedSRGBColorSpaceRef() : sRGBColorSpaceRef();
index 6d7e9dd..bb73352 100644 (file)
 #import <pal/spi/cg/CoreGraphicsSPI.h>
 #import <wtf/ProcessPrivilege.h>
 
+#if USE(MEDIATOOLBOX)
+#import <pal/cocoa/MediaToolboxSoftLink.h>
+#endif
+
 extern "C" {
 bool CGDisplayUsesInvertedPolarity(void);
 bool CGDisplayUsesForceToGray(void);
@@ -128,11 +132,17 @@ ScreenProperties collectScreenProperties()
         bool screenIsMonochrome = CGDisplayUsesForceToGray();
         uint32_t displayMask = CGDisplayIDToOpenGLDisplayMask(displayID);
         IORegistryGPUID gpuID = 0;
+        bool screenSupportsHighDynamicRange = false;
+
+#if USE(MEDIATOOLBOX)
+        if (PAL::canLoad_MediaToolbox_MTShouldPlayHDRVideo())
+            screenSupportsHighDynamicRange = PAL::softLink_MediaToolbox_MTShouldPlayHDRVideo((__bridge CFArrayRef)@[ @(displayID) ]);
+#endif
 
         if (displayMask)
             gpuID = gpuIDForDisplayMask(displayMask);
 
-        screenProperties.screenDataMap.set(displayID, ScreenData { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors, screenIsMonochrome, displayMask, gpuID });
+        screenProperties.screenDataMap.set(displayID, ScreenData { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors, screenIsMonochrome, screenSupportsHighDynamicRange, displayMask, gpuID });
 
         if (!screenProperties.primaryDisplayID)
             screenProperties.primaryDisplayID = displayID;
@@ -348,6 +358,21 @@ bool screenSupportsExtendedColor(Widget* widget)
     return [screen(widget) canRepresentDisplayGamut:NSDisplayGamutP3];
 }
 
+bool screenSupportsHighDynamicRange(Widget* widget)
+{
+    if (!screenProperties().screenDataMap.isEmpty())
+        return getScreenProperties(widget).screenSupportsHighDynamicRange;
+
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
+#if USE(MEDIATOOLBOX)
+    if (PAL::canLoad_MediaToolbox_MTShouldPlayHDRVideo()) {
+        auto displayID = WebCore::displayID(screen(widget));
+        return PAL::softLink_MediaToolbox_MTShouldPlayHDRVideo((__bridge CFArrayRef)@[ @(displayID) ]);
+    }
+#endif
+    return false;
+}
+
 FloatRect toUserSpace(const NSRect& rect, NSWindow *destination)
 {
     FloatRect userRect = rect;
index 0758b75..5d9ac28 100644 (file)
@@ -1020,6 +1020,16 @@ void InternalSettings::setForcedPrefersReducedMotionAccessibilityValue(InternalS
     settings().setForcedPrefersReducedMotionAccessibilityValue(internalSettingsToSettingsValue(value));
 }
 
+InternalSettings::ForcedAccessibilityValue InternalSettings::forcedSupportsHighDynamicRangeValue() const
+{
+    return settingsToInternalSettingsValue(settings().forcedSupportsHighDynamicRangeValue());
+}
+
+void InternalSettings::setForcedSupportsHighDynamicRangeValue(InternalSettings::ForcedAccessibilityValue value)
+{
+    settings().setForcedSupportsHighDynamicRangeValue(internalSettingsToSettingsValue(value));
+}
+
 bool InternalSettings::webAnimationsCSSIntegrationEnabled()
 {
     return RuntimeEnabledFeatures::sharedFeatures().webAnimationsCSSIntegrationEnabled();
index 8a68292..673d790 100644 (file)
@@ -122,6 +122,8 @@ public:
     void setForcedDisplayIsMonochromeAccessibilityValue(ForcedAccessibilityValue);
     ForcedAccessibilityValue forcedPrefersReducedMotionAccessibilityValue() const;
     void setForcedPrefersReducedMotionAccessibilityValue(ForcedAccessibilityValue);
+    ForcedAccessibilityValue forcedSupportsHighDynamicRangeValue() const;
+    void setForcedSupportsHighDynamicRangeValue(ForcedAccessibilityValue);
 
     // RuntimeEnabledFeatures.
     static void setIndexedDBWorkersEnabled(bool);
index 9c30b48..459e974 100644 (file)
@@ -112,6 +112,7 @@ enum FontLoadTimingOverride { "Block", "Swap", "Failure" };
     attribute ForcedAccessibilityValue forcedColorsAreInvertedAccessibilityValue;
     attribute ForcedAccessibilityValue forcedDisplayIsMonochromeAccessibilityValue;
     attribute ForcedAccessibilityValue forcedPrefersReducedMotionAccessibilityValue;
+    attribute ForcedAccessibilityValue forcedSupportsHighDynamicRangeValue;
 
     [MayThrowException] void setShouldManageAudioSessionCategory(boolean should);
     [MayThrowException] void setCustomPasteboardDataEnabled(boolean enabled);
index 101b08e..bfe7361 100644 (file)
@@ -1,3 +1,25 @@
+2019-11-21  Jer Noble  <jer.noble@apple.com>
+
+        Experimental support for HDR media query
+        https://bugs.webkit.org/show_bug.cgi?id=204422
+
+        Reviewed by Eric Carlson.
+
+        Notify the WebContent process of updated screen properties when the screen's
+        color space changes.
+
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (-[WKWindowVisibilityObserver startObserving:]):
+        (-[WKWindowVisibilityObserver stopObserving:]):
+        (-[WKWindowVisibilityObserver _screenDidChangeColorSpace:]):
+        (WebKit::WebViewImpl::screenDidChangeColorSpace):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::screenPropertiesDidChange):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::setScreenProperties):
+
 2019-11-21  Brian Burg  <bburg@apple.com>
 
         Unreviewed, sort WebKit's project file after changes in r252702 and r252637.
index 7fe4474..0a4ee83 100644 (file)
@@ -255,6 +255,7 @@ public:
     void windowDidChangeScreen();
     void windowDidChangeLayerHosting();
     void windowDidChangeOcclusionState();
+    void screenDidChangeColorSpace();
     bool shouldDelayWindowOrderingForEvent(NSEvent *);
     bool windowResizeMouseLocationIsInVisibleScrollerThumb(CGPoint);
 
index 673ab45..d21167a 100644 (file)
@@ -263,6 +263,8 @@ static void* keyValueObservingContext = &keyValueObservingContext;
     [defaultNotificationCenter addObserver:self selector:@selector(_windowDidChangeLayerHosting:) name:@"_NSWindowDidChangeContentsHostedInLayerSurfaceNotification" object:window];
     [defaultNotificationCenter addObserver:self selector:@selector(_windowDidChangeOcclusionState:) name:NSWindowDidChangeOcclusionStateNotification object:window];
 
+    [defaultNotificationCenter addObserver:self selector:@selector(_screenDidChangeColorSpace:) name:NSScreenColorSpaceDidChangeNotification object:nil];
+
     [window addObserver:self forKeyPath:@"contentLayoutRect" options:NSKeyValueObservingOptionInitial context:keyValueObservingContext];
     [window addObserver:self forKeyPath:@"titlebarAppearsTransparent" options:NSKeyValueObservingOptionInitial context:keyValueObservingContext];
 }
@@ -288,6 +290,8 @@ static void* keyValueObservingContext = &keyValueObservingContext;
     [defaultNotificationCenter removeObserver:self name:@"_NSWindowDidChangeContentsHostedInLayerSurfaceNotification" object:window];
     [defaultNotificationCenter removeObserver:self name:NSWindowDidChangeOcclusionStateNotification object:window];
 
+    [defaultNotificationCenter removeObserver:self name:NSScreenColorSpaceDidChangeNotification object:nil];
+
     if (_impl->isEditable())
         [[NSFontPanel sharedFontPanel] removeObserver:self forKeyPath:@"visible" context:keyValueObservingContext];
     [window removeObserver:self forKeyPath:@"contentLayoutRect" context:keyValueObservingContext];
@@ -372,6 +376,11 @@ static void* keyValueObservingContext = &keyValueObservingContext;
     _impl->windowDidChangeOcclusionState();
 }
 
+- (void)_screenDidChangeColorSpace:(NSNotification *)notification
+{
+    _impl->screenDidChangeColorSpace();
+}
+
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
 {
     if (context != keyValueObservingContext) {
@@ -2117,6 +2126,11 @@ void WebViewImpl::windowDidChangeOcclusionState()
     m_page->activityStateDidChange(WebCore::ActivityState::IsVisible);
 }
 
+void WebViewImpl::screenDidChangeColorSpace()
+{
+    m_page->process().processPool().screenPropertiesStateChanged();
+}
+
 bool WebViewImpl::mightBeginDragWhileInactive()
 {
     if ([m_view window].isKeyWindow)
index c43d3bd..d23e00c 100644 (file)
@@ -2075,6 +2075,11 @@ void WebPage::accessibilitySettingsDidChange()
     m_page->accessibilitySettingsDidChange();
 }
 
+void WebPage::screenPropertiesDidChange()
+{
+    m_page->setNeedsRecalcStyleInAllFrames();
+}
+
 void WebPage::setUseFixedLayout(bool fixed)
 {
     // Do not overwrite current settings if initially setting it to false.
index a12658c..f530c7d 100644 (file)
@@ -494,6 +494,7 @@ public:
     void clearHistory();
 
     void accessibilitySettingsDidChange();
+    void screenPropertiesDidChange();
 
     void scalePage(double scale, const WebCore::IntPoint& origin);
     void scalePageInViewCoordinates(double scale, WebCore::IntPoint centerInViewCoordinates);
index 92fad43..0c92cd9 100644 (file)
@@ -1798,6 +1798,8 @@ bool WebProcess::removeServiceWorkerRegistration(WebCore::ServiceWorkerRegistrat
 void WebProcess::setScreenProperties(const WebCore::ScreenProperties& properties)
 {
     WebCore::setScreenProperties(properties);
+    for (auto& page : m_pageMap.values())
+        page->screenPropertiesDidChange();
 }
 #endif