Title: [264476] trunk
Revision
264476
Author
[email protected]
Date
2020-07-16 13:49:35 -0700 (Thu, 16 Jul 2020)

Log Message

[Cocoa] Add MediaCapabilities support for SW VP9 decoder.
https://bugs.webkit.org/show_bug.cgi?id=214316

Reviewed by Eric Carlson.

Source/WebCore:

Test: platform/mac/media/mediacapabilities/vp9-decodingInfo-sw.html

Add some foundational support for SW VP9, which due to policy decisions will need information
both on the system battery status and the power adapter status, and these need to be shipped
into the WebContent process from the UIProcess.

Add some Internal override settings to allow the policies to be effectively tested through
LayouTests. This includes overrides for system battery and AC state, as well as overrides for
screen size and resolution.

* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/PlatformScreen.cpp:
(WebCore::getScreenProperties):
* platform/PlatformScreen.h:
* platform/ScreenProperties.h:
(WebCore::ScreenData::encode const):
(WebCore::ScreenData::decode):
* platform/cocoa/PowerSourceNotifier.h:
* platform/cocoa/PowerSourceNotifier.mm:
(WebCore::PowerSourceNotifier::PowerSourceNotifier):
(WebCore::PowerSourceNotifier::~PowerSourceNotifier):
(WebCore::PowerSourceNotifier::notifyPowerSourceChanged):
* platform/cocoa/SystemBattery.h:
* platform/cocoa/SystemBattery.mm:
(WebCore::systemHasBattery):
(WebCore::resetSystemHasAC):
(WebCore::setSystemHasAC):
(WebCore::systemHasAC):
(WebCore::setOverrideSystemHasBatteryForTesting):
(WebCore::setOverrideSystemHasACForTesting):
* platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp:
(WebCore::videoCodecTypeFromRFC4281Type):
(WebCore::createMediaPlayerDecodingConfigurationCocoa):
* platform/graphics/cocoa/VP9UtilitiesCocoa.h: Copied from Source/WebCore/PAL/pal/spi/cocoa/IOPSLibSPI.h.
* platform/graphics/cocoa/VP9UtilitiesCocoa.mm: Added.
(WebCore::setOverrideVP9HardwareDecoderDisabledForTesting):
(WebCore::setOverrideVP9ScreenSizeAndScaleForTesting):
(WebCore::resetOverrideVP9ScreenSizeAndScaleForTesting):
(WebCore::validateVPParameters):
* platform/ios/PlatformScreenIOS.mm:
(WebCore::collectScreenProperties):
* platform/mac/PlatformScreenMac.mm:
(WebCore::collectScreenProperties):
* testing/Internals.cpp:
(WebCore::Internals::Internals):
(WebCore::Internals::setSystemHasBattery):
(WebCore::Internals::setSystemHasAC):
(WebCore::Internals::setHardwareVP9DecoderDisabledForTesting):
(WebCore::Internals::setVP9ScreenSizeAndScale):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebCore/PAL:

* pal/spi/cocoa/IOPSLibSPI.h:

Source/WebKit:

Pass the system AC state to the WebContent process at creation time, and also create
a power state listener so the WebProcess can be updated dynamically.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeWebProcess):
(WebKit::WebProcessPool::registerNotificationObservers):
* UIProcess/WebProcessPool.cpp:
* UIProcess/WebProcessPool.h:
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):
(WebKit::WebProcess::powerSourceDidChange):

LayoutTests:

* platform/mac/media/mediacapabilities/vp9-decodingInfo-sw-expected.txt: Added.
* platform/mac/media/mediacapabilities/vp9-decodingInfo-sw.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (264475 => 264476)


--- trunk/LayoutTests/ChangeLog	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/LayoutTests/ChangeLog	2020-07-16 20:49:35 UTC (rev 264476)
@@ -1,3 +1,13 @@
+2020-07-16  Jer Noble  <[email protected]>
+
+        [Cocoa] Add MediaCapabilities support for SW VP9 decoder.
+        https://bugs.webkit.org/show_bug.cgi?id=214316
+
+        Reviewed by Eric Carlson.
+
+        * platform/mac/media/mediacapabilities/vp9-decodingInfo-sw-expected.txt: Added.
+        * platform/mac/media/mediacapabilities/vp9-decodingInfo-sw.html: Added.
+
 2020-07-16  Hector Lopez  <[email protected]>
 
         Regression tests cannot load video over HTTPS with self-signed certificate

Modified: trunk/LayoutTests/platform/mac/TestExpectations (264475 => 264476)


--- trunk/LayoutTests/platform/mac/TestExpectations	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2020-07-16 20:49:35 UTC (rev 264476)
@@ -1920,3 +1920,6 @@
 fast/text/text-styles/-apple-system [ Pass ]
 
 webkit.org/b/214155 imported/w3c/web-platform-tests/html/cross-origin-embedder-policy/blob.https.html [ Pass Failure ]
+
+# This test requires system platform support.
+platform/mac/media/mediacapabilities/vp9-decodingInfo-sw.html [ Skip ]

Added: trunk/LayoutTests/platform/mac/media/mediacapabilities/vp9-decodingInfo-sw-expected.txt (0 => 264476)


--- trunk/LayoutTests/platform/mac/media/mediacapabilities/vp9-decodingInfo-sw-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/media/mediacapabilities/vp9-decodingInfo-sw-expected.txt	2020-07-16 20:49:35 UTC (rev 264476)
@@ -0,0 +1,36 @@
+RUN(internals.setSystemHasBatteryForTesting(true))
+RUN(internals.setSystemHasACForTesting(true))
+RUN(internals.setHardwareVP9DecoderDisabledForTesting(true))
+RUN(internals.setVP9ScreenSizeAndScaleForTesting(1024, 768, 1))
+
+Test that 4k @ 30fps is supported, smooth, but not powerEfficient
+RUN(promise = navigator.mediaCapabilities.decodingInfo({ type: 'media-source', video: { contentType: 'video/mp4; codecs="vp09.00.41.08"', height: 1080, bitrate: 800000, width: 3180, framerate: 30 }});)
+Promise resolved OK
+EXPECTED (info.supported == 'true') OK
+EXPECTED (info.powerEfficient == 'false') OK
+EXPECTED (info.smooth == 'true') OK
+
+Test that 4k @ 60fps is supported, but not smooth or powerEfficient
+RUN(promise = navigator.mediaCapabilities.decodingInfo({ type: 'media-source', video: { contentType: 'video/mp4; codecs="vp09.00.41.08"', height: 1080, bitrate: 800000, width: 3180, framerate: 60 }});)
+Promise resolved OK
+EXPECTED (info.supported == 'true') OK
+EXPECTED (info.powerEfficient == 'false') OK
+EXPECTED (info.smooth == 'false') OK
+
+Test that SW VP9 decoder is not supported on battery power when screen is not 4k resolution
+RUN(internals.setSystemHasACForTesting(false))
+RUN(promise = navigator.mediaCapabilities.decodingInfo({ type: 'media-source', video: { contentType: 'video/mp4; codecs="vp09.00.41.08"', height: 1080, bitrate: 800000, width: 3180, framerate: 30 }});)
+Promise resolved OK
+EXPECTED (info.supported == 'false') OK
+EXPECTED (info.powerEfficient == 'false') OK
+EXPECTED (info.smooth == 'false') OK
+
+Test that SW VP9 decoder is supported on battery power when screen is at least 4k resolution
+RUN(internals.setVP9ScreenSizeAndScaleForTesting(3840, 2160, 1))
+RUN(promise = navigator.mediaCapabilities.decodingInfo({ type: 'media-source', video: { contentType: 'video/mp4; codecs="vp09.00.41.08"', height: 1080, bitrate: 800000, width: 3180, framerate: 30 }});)
+Promise resolved OK
+EXPECTED (info.supported == 'true') OK
+EXPECTED (info.powerEfficient == 'false') OK
+EXPECTED (info.smooth == 'true') OK
+END OF TEST
+

Added: trunk/LayoutTests/platform/mac/media/mediacapabilities/vp9-decodingInfo-sw.html (0 => 264476)


--- trunk/LayoutTests/platform/mac/media/mediacapabilities/vp9-decodingInfo-sw.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/media/mediacapabilities/vp9-decodingInfo-sw.html	2020-07-16 20:49:35 UTC (rev 264476)
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script type="text/_javascript_">
+    var promise;
+    var info;
+
+    async function doTest()
+    {
+        if (!window.internals) {
+            failTest("Internals is required for this test.")
+            return;
+        }
+
+        run('internals.setSystemHasBatteryForTesting(true)');
+        run('internals.setSystemHasACForTesting(true)');
+        run('internals.setHardwareVP9DecoderDisabledForTesting(true)');
+        run('internals.setVP9ScreenSizeAndScaleForTesting(1024, 768, 1)');
+
+        consoleWrite('');
+        consoleWrite('Test that 4k @ 30fps is supported, smooth, but not powerEfficient');
+        run("promise = navigator.mediaCapabilities.decodingInfo({ type: 'media-source', video: { contentType: 'video/mp4; codecs=\"vp09.00.41.08\"', height: 1080, bitrate: 800000, width: 3180, framerate: 30 }});");
+        info = await shouldResolve(promise);
+        testExpected('info.supported', true);
+        testExpected('info.powerEfficient', false);
+        testExpected('info.smooth', true);
+
+        consoleWrite('');
+        consoleWrite('Test that 4k @ 60fps is supported, but not smooth or powerEfficient');
+
+        run("promise = navigator.mediaCapabilities.decodingInfo({ type: 'media-source', video: { contentType: 'video/mp4; codecs=\"vp09.00.41.08\"', height: 1080, bitrate: 800000, width: 3180, framerate: 60 }});");
+        info = await shouldResolve(promise);
+        testExpected('info.supported', true);
+        testExpected('info.powerEfficient', false);
+        testExpected('info.smooth', false);
+
+        consoleWrite('');
+        consoleWrite('Test that SW VP9 decoder is not supported on battery power when screen is not 4k resolution');
+        run('internals.setSystemHasACForTesting(false)');
+        run("promise = navigator.mediaCapabilities.decodingInfo({ type: 'media-source', video: { contentType: 'video/mp4; codecs=\"vp09.00.41.08\"', height: 1080, bitrate: 800000, width: 3180, framerate: 30 }});");
+        info = await shouldResolve(promise);
+        testExpected('info.supported', false);
+        testExpected('info.powerEfficient', false);
+        testExpected('info.smooth', false);
+
+        consoleWrite('');
+        consoleWrite('Test that SW VP9 decoder is supported on battery power when screen is at least 4k resolution');
+        run('internals.setVP9ScreenSizeAndScaleForTesting(3840, 2160, 1)');
+        run("promise = navigator.mediaCapabilities.decodingInfo({ type: 'media-source', video: { contentType: 'video/mp4; codecs=\"vp09.00.41.08\"', height: 1080, bitrate: 800000, width: 3180, framerate: 30 }});");
+        info = await shouldResolve(promise);
+        testExpected('info.supported', true);
+        testExpected('info.powerEfficient', false);
+        testExpected('info.smooth', true);
+
+        endTest();
+    }
+    </script>
+</head>
+<body _onload_="doTest()" />
+</html>

Modified: trunk/Source/WebCore/ChangeLog (264475 => 264476)


--- trunk/Source/WebCore/ChangeLog	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/ChangeLog	2020-07-16 20:49:35 UTC (rev 264476)
@@ -1,3 +1,63 @@
+2020-07-16  Jer Noble  <[email protected]>
+
+        [Cocoa] Add MediaCapabilities support for SW VP9 decoder.
+        https://bugs.webkit.org/show_bug.cgi?id=214316
+
+        Reviewed by Eric Carlson.
+
+        Test: platform/mac/media/mediacapabilities/vp9-decodingInfo-sw.html
+
+        Add some foundational support for SW VP9, which due to policy decisions will need information
+        both on the system battery status and the power adapter status, and these need to be shipped
+        into the WebContent process from the UIProcess.
+
+        Add some Internal override settings to allow the policies to be effectively tested through
+        LayouTests. This includes overrides for system battery and AC state, as well as overrides for
+        screen size and resolution.
+
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/PlatformScreen.cpp:
+        (WebCore::getScreenProperties):
+        * platform/PlatformScreen.h:
+        * platform/ScreenProperties.h:
+        (WebCore::ScreenData::encode const):
+        (WebCore::ScreenData::decode):
+        * platform/cocoa/PowerSourceNotifier.h:
+        * platform/cocoa/PowerSourceNotifier.mm:
+        (WebCore::PowerSourceNotifier::PowerSourceNotifier):
+        (WebCore::PowerSourceNotifier::~PowerSourceNotifier):
+        (WebCore::PowerSourceNotifier::notifyPowerSourceChanged):
+        * platform/cocoa/SystemBattery.h:
+        * platform/cocoa/SystemBattery.mm:
+        (WebCore::systemHasBattery):
+        (WebCore::resetSystemHasAC):
+        (WebCore::setSystemHasAC):
+        (WebCore::systemHasAC):
+        (WebCore::setOverrideSystemHasBatteryForTesting):
+        (WebCore::setOverrideSystemHasACForTesting):
+        * platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp:
+        (WebCore::videoCodecTypeFromRFC4281Type):
+        (WebCore::createMediaPlayerDecodingConfigurationCocoa):
+        * platform/graphics/cocoa/VP9UtilitiesCocoa.h: Copied from Source/WebCore/PAL/pal/spi/cocoa/IOPSLibSPI.h.
+        * platform/graphics/cocoa/VP9UtilitiesCocoa.mm: Added.
+        (WebCore::setOverrideVP9HardwareDecoderDisabledForTesting):
+        (WebCore::setOverrideVP9ScreenSizeAndScaleForTesting):
+        (WebCore::resetOverrideVP9ScreenSizeAndScaleForTesting):
+        (WebCore::validateVPParameters):
+        * platform/ios/PlatformScreenIOS.mm:
+        (WebCore::collectScreenProperties):
+        * platform/mac/PlatformScreenMac.mm:
+        (WebCore::collectScreenProperties):
+        * testing/Internals.cpp:
+        (WebCore::Internals::Internals):
+        (WebCore::Internals::setSystemHasBattery):
+        (WebCore::Internals::setSystemHasAC):
+        (WebCore::Internals::setHardwareVP9DecoderDisabledForTesting):
+        (WebCore::Internals::setVP9ScreenSizeAndScale):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2020-07-16  Brady Eidson  <[email protected]>
 
         Remove (entirely unused) hat switch dpad support in HIDGamepad.

Modified: trunk/Source/WebCore/PAL/ChangeLog (264475 => 264476)


--- trunk/Source/WebCore/PAL/ChangeLog	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/PAL/ChangeLog	2020-07-16 20:49:35 UTC (rev 264476)
@@ -1,3 +1,12 @@
+2020-07-16  Jer Noble  <[email protected]>
+
+        [Cocoa] Add MediaCapabilities support for SW VP9 decoder.
+        https://bugs.webkit.org/show_bug.cgi?id=214316
+
+        Reviewed by Eric Carlson.
+
+        * pal/spi/cocoa/IOPSLibSPI.h:
+
 2020-07-16  Jonathan Bedard  <[email protected]>
 
         [Big Sur] De-duplicate SPI

Modified: trunk/Source/WebCore/PAL/pal/spi/cocoa/IOPSLibSPI.h (264475 => 264476)


--- trunk/Source/WebCore/PAL/pal/spi/cocoa/IOPSLibSPI.h	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/IOPSLibSPI.h	2020-07-16 20:49:35 UTC (rev 264476)
@@ -36,6 +36,9 @@
 
 #define kIOPSTypeKey "Type"
 #define kIOPSInternalBatteryType "InternalBattery"
+#define kIOPSPowerSourceStateKey "Power Source State"
+#define kIOPSACPowerValue "AC Power"
+#define kIOPSNotifyPowerSource "com.apple.system.powersources.source"
 
 #endif
 

Modified: trunk/Source/WebCore/SourcesCocoa.txt (264475 => 264476)


--- trunk/Source/WebCore/SourcesCocoa.txt	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2020-07-16 20:49:35 UTC (rev 264476)
@@ -241,6 +241,7 @@
 platform/cocoa/PasteboardCustomDataCocoa.mm
 platform/cocoa/PlatformPasteboardCocoa.mm
 platform/cocoa/PlaybackSessionModelMediaElement.mm
+platform/cocoa/PowerSourceNotifier.mm
 platform/cocoa/RuntimeApplicationChecksCocoa.mm
 platform/cocoa/ScrollController.mm
 platform/cocoa/ScrollSnapAnimatorState.mm
@@ -349,6 +350,7 @@
 platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp
 platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp
 platform/graphics/cocoa/TextTrackRepresentationCocoa.mm
+platform/graphics/cocoa/VP9UtilitiesCocoa.mm
 platform/graphics/cocoa/WebActionDisablingCALayerDelegate.mm
 platform/graphics/cocoa/WebCoreCALayerExtras.mm
 platform/graphics/cocoa/WebCoreDecompressionSession.mm

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (264475 => 264476)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-16 20:49:35 UTC (rev 264476)
@@ -4200,6 +4200,7 @@
 		CDC69DD61632026C007C38DF /* WebCoreFullScreenWarningView.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC69DD41632026C007C38DF /* WebCoreFullScreenWarningView.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CDC69DDA16371FD4007C38DF /* WebCoreFullScreenPlaceholderView.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC69DD816371FD3007C38DF /* WebCoreFullScreenPlaceholderView.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CDC734151977896D0046BFC5 /* CARingBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC734131977896C0046BFC5 /* CARingBuffer.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		CDC7470424BE2FC700C1868B /* PowerSourceNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC7470024BE267900C1868B /* PowerSourceNotifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CDC8B5A2180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDC8B5A0180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.mm */; };
 		CDC8B5A3180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC8B5A1180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.h */; };
 		CDC8B5A6180474F70016E685 /* MediaSourcePrivateAVFObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDC8B5A4180474F70016E685 /* MediaSourcePrivateAVFObjC.mm */; };
@@ -14107,6 +14108,8 @@
 		CD641EB11818F5ED00EE4C41 /* MediaSourcePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSourcePrivate.h; sourceTree = "<group>"; };
 		CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SourceBufferPrivate.h; sourceTree = "<group>"; };
 		CD641EC7181ED60100EE4C41 /* MediaSample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaSample.h; sourceTree = "<group>"; };
+		CD6FE5B724BCE645009FCDA4 /* VP9UtilitiesCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VP9UtilitiesCocoa.h; sourceTree = "<group>"; };
+		CD6FE5B824BCE645009FCDA4 /* VP9UtilitiesCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = VP9UtilitiesCocoa.mm; sourceTree = "<group>"; };
 		CD6FE5BA24BCE7B6009FCDA4 /* VP9Utilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VP9Utilities.h; sourceTree = "<group>"; };
 		CD6FE5BB24BCE7B6009FCDA4 /* VP9Utilities.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VP9Utilities.cpp; sourceTree = "<group>"; };
 		CD720B4722682C7E00047FDE /* ISOFairPlayStreamingPsshBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ISOFairPlayStreamingPsshBox.cpp; sourceTree = "<group>"; };
@@ -14283,6 +14286,8 @@
 		CDC69DD916371FD3007C38DF /* WebCoreFullScreenPlaceholderView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreFullScreenPlaceholderView.mm; sourceTree = "<group>"; };
 		CDC734121977896C0046BFC5 /* CARingBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CARingBuffer.cpp; sourceTree = "<group>"; };
 		CDC734131977896C0046BFC5 /* CARingBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CARingBuffer.h; sourceTree = "<group>"; };
+		CDC7470024BE267900C1868B /* PowerSourceNotifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PowerSourceNotifier.h; sourceTree = "<group>"; };
+		CDC7470124BE267900C1868B /* PowerSourceNotifier.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PowerSourceNotifier.mm; sourceTree = "<group>"; };
 		CDC8B5A0180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaPlayerPrivateMediaSourceAVFObjC.mm; sourceTree = "<group>"; };
 		CDC8B5A1180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaPlayerPrivateMediaSourceAVFObjC.h; sourceTree = "<group>"; };
 		CDC8B5A4180474F70016E685 /* MediaSourcePrivateAVFObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaSourcePrivateAVFObjC.mm; sourceTree = "<group>"; };
@@ -23630,6 +23635,8 @@
 				CDA29A0A1CBD9A7400901CCF /* PlaybackSessionModel.h */,
 				CDA29A0D1CBD9CFE00901CCF /* PlaybackSessionModelMediaElement.h */,
 				CDA29A0C1CBD9CFE00901CCF /* PlaybackSessionModelMediaElement.mm */,
+				CDC7470024BE267900C1868B /* PowerSourceNotifier.h */,
+				CDC7470124BE267900C1868B /* PowerSourceNotifier.mm */,
 				465A8E781C8A24CE00E7D3E4 /* RuntimeApplicationChecksCocoa.mm */,
 				1AA84F03143BA7BD0051D153 /* ScrollController.h */,
 				1AA84F02143BA7BD0051D153 /* ScrollController.mm */,
@@ -25744,11 +25751,11 @@
 				076E11BE1F683E0D00177395 /* TrackPrivateBase.cpp */,
 				BE913D7F181EF8E500DCB09E /* TrackPrivateBase.h */,
 				E4AFCFA40DAF29A300F5F55C /* UnitBezier.h */,
-				CD6FE5BA24BCE7B6009FCDA4 /* VP9Utilities.h */,
-				CD6FE5BB24BCE7B6009FCDA4 /* VP9Utilities.cpp */,
 				0F5A57CA229B18AE0025EDA9 /* VelocityData.cpp */,
 				0F1A0C36229A481800D37ADB /* VelocityData.h */,
 				BEF29EEA1715DD0900C4B4C9 /* VideoTrackPrivate.h */,
+				CD6FE5BB24BCE7B6009FCDA4 /* VP9Utilities.cpp */,
+				CD6FE5BA24BCE7B6009FCDA4 /* VP9Utilities.h */,
 				1411DCB0164C39A800D49BC1 /* WidthCache.h */,
 				939B02EC0EA2DBC400C54570 /* WidthIterator.cpp */,
 				939B02ED0EA2DBC400C54570 /* WidthIterator.h */,
@@ -25886,6 +25893,8 @@
 				E4E8B4EA216B79E500B8834D /* SystemFontDatabaseCoreText.h */,
 				526724F21CB2FDF60075974D /* TextTrackRepresentationCocoa.h */,
 				526724F11CB2FDF60075974D /* TextTrackRepresentationCocoa.mm */,
+				CD6FE5B724BCE645009FCDA4 /* VP9UtilitiesCocoa.h */,
+				CD6FE5B824BCE645009FCDA4 /* VP9UtilitiesCocoa.mm */,
 				2D3EF4441917915C00034184 /* WebActionDisablingCALayerDelegate.h */,
 				2D3EF4451917915C00034184 /* WebActionDisablingCALayerDelegate.mm */,
 				2D3EF4461917915C00034184 /* WebCoreCALayerExtras.h */,
@@ -32640,6 +32649,7 @@
 				A14978711ABAF3A500CEF7E4 /* PlatformContentFilter.h in Headers */,
 				BC5C762B1497FE1400BC4775 /* PlatformEvent.h in Headers */,
 				26601EBF14B3B9AD0012C0FE /* PlatformEventFactoryIOS.h in Headers */,
+				CDC7470424BE2FC700C1868B /* PowerSourceNotifier.h in Headers */,
 				BCAA487014A052530088FAC4 /* PlatformEventFactoryMac.h in Headers */,
 				A723F77B1484CA4C008C6DBE /* PlatformExportMacros.h in Headers */,
 				515BE1951D54F5FB00DD7C68 /* PlatformGamepad.h in Headers */,

Modified: trunk/Source/WebCore/platform/PlatformScreen.cpp (264475 => 264476)


--- trunk/Source/WebCore/platform/PlatformScreen.cpp	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/platform/PlatformScreen.cpp	2020-07-16 20:49:35 UTC (rev 264476)
@@ -38,6 +38,11 @@
     return screenProperties;
 }
 
+const ScreenProperties& getScreenProperties()
+{
+    return screenProperties();
+}
+
 PlatformDisplayID primaryScreenDisplayID()
 {
     return screenProperties().primaryDisplayID;

Modified: trunk/Source/WebCore/platform/PlatformScreen.h (264475 => 264476)


--- trunk/Source/WebCore/platform/PlatformScreen.h	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/platform/PlatformScreen.h	2020-07-16 20:49:35 UTC (rev 264476)
@@ -94,6 +94,7 @@
     
 WEBCORE_EXPORT ScreenProperties collectScreenProperties();
 WEBCORE_EXPORT void setScreenProperties(const ScreenProperties&);
+const ScreenProperties& getScreenProperties();
 const ScreenData* screenData(PlatformDisplayID screendisplayID);
 WEBCORE_EXPORT PlatformDisplayID primaryScreenDisplayID();
     

Modified: trunk/Source/WebCore/platform/ScreenProperties.h (264475 => 264476)


--- trunk/Source/WebCore/platform/ScreenProperties.h	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/platform/ScreenProperties.h	2020-07-16 20:49:35 UTC (rev 264476)
@@ -51,6 +51,10 @@
     IORegistryGPUID gpuID { 0 };
 #endif
 
+#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
+    float scaleFactor { 1 };
+#endif
+
     enum class ColorSpaceType : uint8_t { None, Name, Data };
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static Optional<ScreenData> decode(Decoder&);
@@ -98,6 +102,10 @@
     encoder << screenIsMonochrome << displayMask << gpuID;
 #endif
 
+#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
+    encoder << scaleFactor;
+#endif
+
     if (colorSpace) {
         // Try to encode the name.
         if (auto name = adoptCF(CGColorSpaceCopyName(colorSpace.get()))) {
@@ -176,6 +184,13 @@
         return WTF::nullopt;
 #endif
 
+#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
+    Optional<float> scaleFactor;
+    decoder >> scaleFactor;
+    if (!scaleFactor)
+        return WTF::nullopt;
+#endif
+
     ColorSpaceType dataType;
     if (!decoder.decode(dataType))
         return WTF::nullopt;
@@ -219,8 +234,11 @@
 #if PLATFORM(MAC)
         WTFMove(*screenIsMonochrome),
         WTFMove(*displayMask),
-        WTFMove(*gpuID)
+        WTFMove(*gpuID),
 #endif
+#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
+        WTFMove(*scaleFactor),
+#endif
     } };
 }
 

Copied: trunk/Source/WebCore/platform/cocoa/PowerSourceNotifier.h (from rev 264475, trunk/Source/WebCore/platform/graphics/VP9Utilities.h) (0 => 264476)


--- trunk/Source/WebCore/platform/cocoa/PowerSourceNotifier.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/cocoa/PowerSourceNotifier.h	2020-07-16 20:49:35 UTC (rev 264476)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2020 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
+
+#include <wtf/Function.h>
+
+namespace WebCore {
+
+class PowerSourceNotifier {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    using PowerSourceNotifierCallback = WTF::Function<void(bool hasAC)>;
+    WEBCORE_EXPORT explicit PowerSourceNotifier(PowerSourceNotifierCallback&&);
+    WEBCORE_EXPORT ~PowerSourceNotifier();
+
+    WEBCORE_EXPORT bool isLowPowerModeEnabled() const;
+
+private:
+    void notifyPowerSourceChanged();
+
+    Optional<int> m_tokenID;
+    PowerSourceNotifierCallback m_callback;
+};
+
+}

Copied: trunk/Source/WebCore/platform/cocoa/PowerSourceNotifier.mm (from rev 264475, trunk/Source/WebCore/platform/graphics/VP9Utilities.h) (0 => 264476)


--- trunk/Source/WebCore/platform/cocoa/PowerSourceNotifier.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/cocoa/PowerSourceNotifier.mm	2020-07-16 20:49:35 UTC (rev 264476)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2020 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"
+#include "PowerSourceNotifier.h"
+
+#import "SystemBattery.h"
+#import <notify.h>
+#import <pal/spi/cocoa/IOPSLibSPI.h>
+
+namespace WebCore {
+
+PowerSourceNotifier::PowerSourceNotifier(PowerSourceNotifierCallback&& callback)
+    : m_callback(WTFMove(callback))
+{
+    int token = 0;
+    auto status = notify_register_dispatch(kIOPSNotifyPowerSource, &token, dispatch_get_main_queue(), ^(int) {
+        notifyPowerSourceChanged();
+    });
+    if (status == NOTIFY_STATUS_OK)
+        m_tokenID = token;
+}
+
+PowerSourceNotifier::~PowerSourceNotifier()
+{
+    if (m_tokenID)
+        notify_cancel(*m_tokenID);
+}
+
+void PowerSourceNotifier::notifyPowerSourceChanged()
+{
+    resetSystemHasAC();
+    if (m_callback)
+        m_callback(systemHasAC());
+}
+
+}

Modified: trunk/Source/WebCore/platform/cocoa/SystemBattery.h (264475 => 264476)


--- trunk/Source/WebCore/platform/cocoa/SystemBattery.h	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/platform/cocoa/SystemBattery.h	2020-07-16 20:49:35 UTC (rev 264476)
@@ -30,4 +30,11 @@
 WEBCORE_EXPORT void setSystemHasBattery(bool);
 WEBCORE_EXPORT bool systemHasBattery();
 
+WEBCORE_EXPORT void resetSystemHasAC();
+WEBCORE_EXPORT void setSystemHasAC(bool);
+WEBCORE_EXPORT bool systemHasAC();
+
+WEBCORE_EXPORT void setOverrideSystemHasBatteryForTesting(Optional<bool>&&);
+WEBCORE_EXPORT void setOverrideSystemHasACForTesting(Optional<bool>&&);
+
 }

Modified: trunk/Source/WebCore/platform/cocoa/SystemBattery.mm (264475 => 264476)


--- trunk/Source/WebCore/platform/cocoa/SystemBattery.mm	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/platform/cocoa/SystemBattery.mm	2020-07-16 20:49:35 UTC (rev 264476)
@@ -26,11 +26,15 @@
 #import "config.h"
 #import "SystemBattery.h"
 
+#import <notify.h>
 #import <pal/spi/cocoa/IOPSLibSPI.h>
 
 namespace WebCore {
 
 static Optional<bool> hasBattery;
+static Optional<bool> hasAC;
+static Optional<bool> hasBatteryOverrideForTesting;
+static Optional<bool> hasACOverrideForTesting;
 
 void setSystemHasBattery(bool battery)
 {
@@ -39,6 +43,9 @@
 
 bool systemHasBattery()
 {
+    if (hasBatteryOverrideForTesting)
+        return *hasBatteryOverrideForTesting;
+
     if (!hasBattery.hasValue()) {
         hasBattery = [] {
 #if PLATFORM(IOS) || PLATFORM(WATCHOS)
@@ -67,4 +74,56 @@
     return *hasBattery;
 }
 
+void resetSystemHasAC()
+{
+    hasAC.reset();
 }
+
+void setSystemHasAC(bool ac)
+{
+    hasAC = ac;
+}
+
+bool systemHasAC()
+{
+    if (hasACOverrideForTesting)
+        return *hasACOverrideForTesting;
+
+    if (!hasAC.hasValue()) {
+        hasAC = [] {
+#if PLATFORM(APPLETV)
+            return true;
+#else
+            RetainPtr<CFTypeRef> powerSourcesInfo = adoptCF(IOPSCopyPowerSourcesInfo());
+            if (!powerSourcesInfo)
+                return false;
+            RetainPtr<CFArrayRef> powerSourcesList = adoptCF(IOPSCopyPowerSourcesList(powerSourcesInfo.get()));
+            if (!powerSourcesList)
+                return false;
+            for (CFIndex i = 0, count = CFArrayGetCount(powerSourcesList.get()); i < count; ++i) {
+                CFDictionaryRef description = IOPSGetPowerSourceDescription(powerSourcesInfo.get(), CFArrayGetValueAtIndex(powerSourcesList.get(), i));
+                if (!description)
+                    continue;
+                CFTypeRef value = CFDictionaryGetValue(description, CFSTR(kIOPSPowerSourceStateKey));
+                if (value && CFEqual(value, CFSTR(kIOPSACPowerValue)))
+                    return true;
+            }
+            return false;
+#endif
+        }();
+    }
+
+    return *hasAC;
+}
+
+void setOverrideSystemHasBatteryForTesting(Optional<bool>&& hasBattery)
+{
+    hasBatteryOverrideForTesting = WTFMove(hasBattery);
+}
+
+void setOverrideSystemHasACForTesting(Optional<bool>&& hasAC)
+{
+    hasACOverrideForTesting = WTFMove(hasAC);
+}
+
+}

Modified: trunk/Source/WebCore/platform/graphics/VP9Utilities.cpp (264475 => 264476)


--- trunk/Source/WebCore/platform/graphics/VP9Utilities.cpp	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/platform/graphics/VP9Utilities.cpp	2020-07-16 20:49:35 UTC (rev 264476)
@@ -34,20 +34,20 @@
 static bool isValidVPLevel(uint8_t level)
 {
     constexpr uint8_t validLevels[] = {
-        10,
-        11,
-        20,
-        21,
-        30,
-        31,
-        40,
-        41,
-        50,
-        51,
-        52,
-        60,
-        61,
-        62,
+        VPConfigurationLevel::Level_1,
+        VPConfigurationLevel::Level_1_1,
+        VPConfigurationLevel::Level_2,
+        VPConfigurationLevel::Level_2_1,
+        VPConfigurationLevel::Level_3,
+        VPConfigurationLevel::Level_3_1,
+        VPConfigurationLevel::Level_4,
+        VPConfigurationLevel::Level_4_1,
+        VPConfigurationLevel::Level_5,
+        VPConfigurationLevel::Level_5_1,
+        VPConfigurationLevel::Level_5_2,
+        VPConfigurationLevel::Level_6,
+        VPConfigurationLevel::Level_6_1,
+        VPConfigurationLevel::Level_6_2,
     };
 
     ASSERT(std::is_sorted(std::begin(validLevels), std::end(validLevels)));
@@ -130,7 +130,7 @@
 
     // Fourth element: chromaSubsampling. Legal values are 0-3.
     auto chromaSubsampling = toIntegralType<uint8_t>(*nextElement);
-    if (!chromaSubsampling || *chromaSubsampling > 3)
+    if (!chromaSubsampling || *chromaSubsampling > VPConfigurationChromaSubsampling::Subsampling_444)
         return WTF::nullopt;
     configuration.chromaSubsampling = *chromaSubsampling;
 

Modified: trunk/Source/WebCore/platform/graphics/VP9Utilities.h (264475 => 264476)


--- trunk/Source/WebCore/platform/graphics/VP9Utilities.h	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/platform/graphics/VP9Utilities.h	2020-07-16 20:49:35 UTC (rev 264476)
@@ -30,13 +30,42 @@
 
 namespace WebCore {
 
+namespace VPConfigurationLevel {
+constexpr uint8_t Level_1   = 10;
+constexpr uint8_t Level_1_1 = 11;
+constexpr uint8_t Level_2   = 20;
+constexpr uint8_t Level_2_1 = 21;
+constexpr uint8_t Level_3   = 30;
+constexpr uint8_t Level_3_1 = 31;
+constexpr uint8_t Level_4   = 40;
+constexpr uint8_t Level_4_1 = 41;
+constexpr uint8_t Level_5   = 50;
+constexpr uint8_t Level_5_1 = 51;
+constexpr uint8_t Level_5_2 = 52;
+constexpr uint8_t Level_6   = 60;
+constexpr uint8_t Level_6_1 = 61;
+constexpr uint8_t Level_6_2 = 62;
+}
+
+namespace VPConfigurationChromaSubsampling {
+constexpr uint8_t Subsampling_420_Vertical = 0;
+constexpr uint8_t Subsampling_420_Colocated = 1;
+constexpr uint8_t Subsampling_422 = 2;
+constexpr uint8_t Subsampling_444 = 3;
+}
+
+namespace VPConfigurationRange {
+constexpr uint8_t VideoRange = 0;
+constexpr uint8_t FullRange = 1;
+}
+
 struct VPCodecConfigurationRecord {
     String codecName;
     uint8_t profile { 0 };
-    uint8_t level { 0 };
-    uint8_t bitDepth { 0 };
-    uint8_t chromaSubsampling { 1 };
-    uint8_t videoFullRangeFlag { 0 };
+    uint8_t level { VPConfigurationLevel::Level_1 };
+    uint8_t bitDepth { 8 };
+    uint8_t chromaSubsampling { VPConfigurationChromaSubsampling::Subsampling_420_Colocated };
+    uint8_t videoFullRangeFlag { VPConfigurationRange::VideoRange };
     uint8_t colorPrimaries { 1 };
     uint8_t transferCharacteristics { 1 };
     uint8_t matrixCoefficients { 1 };

Modified: trunk/Source/WebCore/platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp (264475 => 264476)


--- trunk/Source/WebCore/platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp	2020-07-16 20:49:35 UTC (rev 264476)
@@ -32,11 +32,15 @@
 #include "MediaCapabilitiesDecodingInfo.h"
 #include "MediaDecodingConfiguration.h"
 #include "MediaPlayer.h"
+#include "VP9UtilitiesCocoa.h"
 
 #include "VideoToolboxSoftLink.h"
 
 namespace WebCore {
 
+// FIXME: Remove this once kCMVideoCodecType_VP9 is added to CMFormatDescription.h
+constexpr CMVideoCodecType kCMVideoCodecType_VP9 { 'vp09' };
+
 static CMVideoCodecType videoCodecTypeFromRFC4281Type(String type)
 {
     if (type.startsWith("mp4v"))
@@ -45,6 +49,8 @@
         return kCMVideoCodecType_H264;
     if (type.startsWith("hvc1") || type.startsWith("hev1"))
         return kCMVideoCodecType_HEVC;
+    if (type.startsWith("vp09"))
+        return kCMVideoCodecType_VP9;
     return 0;
 }
 
@@ -91,6 +97,12 @@
                 callback({{ }, WTFMove(configuration)});
                 return;
             }
+        } else if (videoCodecType == kCMVideoCodecType_VP9) {
+            auto codecConfiguration = parseVPCodecParameters(codec);
+            if (!codecConfiguration || !validateVPParameters(*codecConfiguration, info, videoConfiguration)) {
+                callback({{ }, WTFMove(configuration)});
+                return;
+            }
         } else {
             if (alphaChannel || hdrSupported) {
                 callback({{ }, WTFMove(configuration)});

Copied: trunk/Source/WebCore/platform/graphics/cocoa/VP9UtilitiesCocoa.h (from rev 264475, trunk/Source/WebCore/platform/graphics/VP9Utilities.h) (0 => 264476)


--- trunk/Source/WebCore/platform/graphics/cocoa/VP9UtilitiesCocoa.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cocoa/VP9UtilitiesCocoa.h	2020-07-16 20:49:35 UTC (rev 264476)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020 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 PLATFORM(COCOA)
+
+#include "VP9Utilities.h"
+
+namespace WebCore {
+
+struct MediaCapabilitiesInfo;
+struct VideoConfiguration;
+
+WEBCORE_EXPORT extern void setOverrideVP9HardwareDecoderDisabledForTesting(bool);
+WEBCORE_EXPORT extern void setOverrideVP9ScreenSizeAndScaleForTesting(float width, float height, float scale);
+WEBCORE_EXPORT extern void resetOverrideVP9ScreenSizeAndScaleForTesting();
+
+extern bool validateVPParameters(VPCodecConfigurationRecord&, MediaCapabilitiesInfo&, const VideoConfiguration&);
+
+}
+
+#endif

Added: trunk/Source/WebCore/platform/graphics/cocoa/VP9UtilitiesCocoa.mm (0 => 264476)


--- trunk/Source/WebCore/platform/graphics/cocoa/VP9UtilitiesCocoa.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cocoa/VP9UtilitiesCocoa.mm	2020-07-16 20:49:35 UTC (rev 264476)
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2020 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"
+#include "VP9UtilitiesCocoa.h"
+
+#if PLATFORM(COCOA)
+
+#import "FourCC.h"
+#import "MediaCapabilitiesInfo.h"
+#import "PlatformScreen.h"
+#import "ScreenProperties.h"
+#import "SystemBattery.h"
+#import "VideoConfiguration.h"
+#import <wtf/text/StringToIntegerConversion.h>
+
+#import <pal/cocoa/AVFoundationSoftLink.h>
+#import "VideoToolboxSoftLink.h"
+
+namespace WebCore {
+
+// FIXME: Remove this once kCMVideoCodecType_VP9 is added to CMFormatDescription.h
+constexpr CMVideoCodecType kCMVideoCodecType_VP9 { 'vp09' };
+
+static bool hardwareVP9DecoderDisabledForTesting { false };
+
+struct OverrideScreenData {
+    float width { 0 };
+    float height { 0 };
+    float scale { 1 };
+};
+static Optional<OverrideScreenData> screenSizeAndScaleForTesting;
+
+void setOverrideVP9HardwareDecoderDisabledForTesting(bool disabled)
+{
+    hardwareVP9DecoderDisabledForTesting = disabled;
+}
+
+void setOverrideVP9ScreenSizeAndScaleForTesting(float width, float height, float scale)
+{
+    screenSizeAndScaleForTesting = makeOptional<OverrideScreenData>({ width, height, scale });
+}
+
+void resetOverrideVP9ScreenSizeAndScaleForTesting()
+{
+    screenSizeAndScaleForTesting = WTF::nullopt;
+}
+
+enum class ResolutionCategory : uint8_t {
+    R_480p,
+    R_720p,
+    R_1080p,
+    R_2K,
+    R_4K,
+    R_8K,
+    R_12K,
+};
+
+static ResolutionCategory resolutionCategory(const FloatSize& size)
+{
+    auto pixels = size.area();
+    if (pixels > 7680 * 4320)
+        return ResolutionCategory::R_12K;
+    if (pixels > 4096 * 2160)
+        return ResolutionCategory::R_8K;
+    if (pixels > 2048 * 1080)
+        return ResolutionCategory::R_4K;
+    if (pixels > 1920 * 1080)
+        return ResolutionCategory::R_2K;
+    if (pixels > 1280 * 720)
+        return ResolutionCategory::R_1080p;
+    if (pixels > 640 * 480)
+        return ResolutionCategory::R_720p;
+    return ResolutionCategory::R_480p;
+}
+
+bool validateVPParameters(VPCodecConfigurationRecord& codecConfiguration, MediaCapabilitiesInfo& info, const VideoConfiguration& videoConfiguration)
+{
+    OSStatus status = VTSelectAndCreateVideoDecoderInstance(kCMVideoCodecType_VP9, kCFAllocatorDefault, nullptr, nullptr);
+    if (status != noErr)
+        return false;
+
+    // VideoConfiguration and VPCodecConfigurationRecord can have conflicting values for HDR properties. If so, reject.
+    if (videoConfiguration.transferFunction) {
+        // Note: Transfer Characteristics are defined by ISO/IEC 23091-2:2019.
+        if (*videoConfiguration.transferFunction == TransferFunction::SRGB && codecConfiguration.transferCharacteristics > 15)
+            return false;
+        if (*videoConfiguration.transferFunction == TransferFunction::PQ && codecConfiguration.transferCharacteristics != 16)
+            return false;
+        if (*videoConfiguration.transferFunction == TransferFunction::HLG && codecConfiguration.transferCharacteristics != 18)
+            return false;
+    }
+
+    if (videoConfiguration.colorGamut) {
+        if (*videoConfiguration.colorGamut == ColorGamut::Rec2020 && codecConfiguration.colorPrimaries != 9)
+            return false;
+    }
+
+    if (canLoad_VideoToolbox_VTIsHardwareDecodeSupported() && VTIsHardwareDecodeSupported(kCMVideoCodecType_VP9) && !hardwareVP9DecoderDisabledForTesting) {
+        info.powerEfficient = true;
+
+        // HW VP9 Decoder supports Profile 0 & 2:
+        if (!codecConfiguration.profile && codecConfiguration.profile != 2)
+            return false;
+
+        // HW VP9 Decoder supports up to Level 6:
+        if (codecConfiguration.level > VPConfigurationLevel::Level_6)
+            return false;
+
+        // HW VP9 Decoder supports 8 or 10 bit color:
+        if (codecConfiguration.bitDepth > 10)
+            return false;
+
+        // HW VP9 Decoder suports only 420 chroma subsampling:
+        if (codecConfiguration.chromaSubsampling > VPConfigurationChromaSubsampling::Subsampling_420_Colocated)
+            return false;
+
+        // HW VP9 Decoder does not support alpha channel:
+        if (videoConfiguration.alphaChannel && *videoConfiguration.alphaChannel)
+            return false;
+
+        // HW VP9 Decoder can support up to 4K @ 120 or 8K @ 30
+        auto resolution = resolutionCategory({ (float)videoConfiguration.width, (float)videoConfiguration.height });
+        if (resolution > ResolutionCategory::R_8K)
+            return false;
+        if (resolution == ResolutionCategory::R_8K && videoConfiguration.framerate > 30)
+            info.smooth = false;
+        else if (resolution <= ResolutionCategory::R_4K && videoConfiguration.framerate > 120)
+            info.smooth = false;
+        else
+            info.smooth = true;
+
+        return true;
+    }
+
+    // SW VP9 Decoder has much more variable capabilities depending on CPU characteristics.
+    // FIXME: Add a lookup table for device-to-capabilities. For now, assume that the SW VP9
+    // decoder can support 4K @ 30.
+    if (videoConfiguration.height <= 1080 && videoConfiguration.framerate > 60)
+        info.smooth = false;
+    if (videoConfiguration.height <= 2160 && videoConfiguration.framerate > 30)
+        info.smooth = false;
+    else
+        info.smooth = true;
+
+    // For wall-powered devices, always report VP9 as supported, even if not powerEfficient.
+    if (!systemHasBattery()) {
+        info.supported = true;
+        return true;
+    }
+
+    // For battery-powered devices, always report VP9 as supported when running on AC power,
+    // but only on battery when there is an attached screen whose resolution is large enough
+    // to support 4K video.
+    if (systemHasAC()) {
+        info.supported = true;
+        return true;
+    }
+
+    bool has4kScreen = false;
+
+    if (screenSizeAndScaleForTesting) {
+        auto screenSize = FloatSize(screenSizeAndScaleForTesting->width, screenSizeAndScaleForTesting->height).scaled(screenSizeAndScaleForTesting->scale);
+        has4kScreen = resolutionCategory(screenSize) >= ResolutionCategory::R_4K;
+    } else {
+        for (auto& screenData : getScreenProperties().screenDataMap.values()) {
+            if (resolutionCategory(screenData.screenRect.size().scaled(screenData.scaleFactor)) >= ResolutionCategory::R_4K) {
+                has4kScreen = true;
+                break;
+            }
+        }
+    }
+
+    if (!has4kScreen) {
+        info.supported = false;
+        return false;
+    }
+
+    return true;
+}
+
+}
+
+#endif // PLATFORM(COCOA)

Modified: trunk/Source/WebCore/platform/ios/PlatformScreenIOS.mm (264475 => 264476)


--- trunk/Source/WebCore/platform/ios/PlatformScreenIOS.mm	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/platform/ios/PlatformScreenIOS.mm	2020-07-16 20:49:35 UTC (rev 264476)
@@ -200,8 +200,10 @@
         int screenDepthPerComponent = WebCore::screenDepthPerComponent(nullptr);
         bool screenSupportsExtendedColor = WebCore::screenSupportsExtendedColor(nullptr);
         bool screenHasInvertedColors = WebCore::screenHasInvertedColors();
+        bool hdr = screenSupportsHighDynamicRange(nullptr);
+        float scaleFactor = WebCore::screenPPIFactor();
 
-        screenProperties.screenDataMap.set(++displayID, ScreenData { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors });
+        screenProperties.screenDataMap.set(++displayID, ScreenData { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors, hdr, scaleFactor });
         
         if (screen == [PAL::getUIScreenClass() mainScreen])
             screenProperties.primaryDisplayID = displayID;

Modified: trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm (264475 => 264476)


--- trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm	2020-07-16 20:49:35 UTC (rev 264476)
@@ -117,6 +117,7 @@
         uint32_t displayMask = CGDisplayIDToOpenGLDisplayMask(displayID);
         IORegistryGPUID gpuID = 0;
         bool screenSupportsHighDynamicRange = false;
+        float scaleFactor = screen.backingScaleFactor;
 
 #if USE(MEDIATOOLBOX)
         if (PAL::isMediaToolboxFrameworkAvailable() && PAL::canLoad_MediaToolbox_MTShouldPlayHDRVideo())
@@ -126,7 +127,7 @@
         if (displayMask)
             gpuID = gpuIDForDisplayMask(displayMask);
 
-        screenProperties.screenDataMap.set(displayID, ScreenData { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors, screenSupportsHighDynamicRange, screenIsMonochrome, displayMask, gpuID });
+        screenProperties.screenDataMap.set(displayID, ScreenData { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors, screenSupportsHighDynamicRange, screenIsMonochrome, displayMask, gpuID, scaleFactor });
 
         if (!screenProperties.primaryDisplayID)
             screenProperties.primaryDisplayID = displayID;

Modified: trunk/Source/WebCore/testing/Internals.cpp (264475 => 264476)


--- trunk/Source/WebCore/testing/Internals.cpp	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/testing/Internals.cpp	2020-07-16 20:49:35 UTC (rev 264476)
@@ -319,10 +319,6 @@
 #include "WebXRTest.h"
 #endif
 
-#if PLATFORM(MAC) && USE(LIBWEBRTC)
-#include <webrtc/sdk/WebKit/VideoProcessingSoftLink.h>
-#endif
-
 #if PLATFORM(MAC)
 #include "GraphicsContextGLOpenGLManager.h"
 #include "NSScrollerImpDetails.h"
@@ -331,10 +327,15 @@
 
 #if PLATFORM(COCOA)
 #include "SystemBattery.h"
+#include "VP9UtilitiesCocoa.h"
 #include <pal/spi/cocoa/CoreTextSPI.h>
 #include <wtf/spi/darwin/SandboxSPI.h>
 #endif
 
+#if PLATFORM(MAC) && USE(LIBWEBRTC)
+#include <webrtc/sdk/WebKit/VideoProcessingSoftLink.h>
+#endif
+
 using JSC::CallData;
 using JSC::CodeBlock;
 using JSC::FunctionExecutable;
@@ -630,6 +631,13 @@
 #if PLATFORM(COCOA) &&  ENABLE(WEB_AUDIO)
     AudioDestinationCocoa::createOverride = nullptr;
 #endif
+
+#if PLATFORM(COCOA)
+    setOverrideSystemHasBatteryForTesting(WTF::nullopt);
+    setOverrideSystemHasACForTesting(WTF::nullopt);
+    setOverrideVP9HardwareDecoderDisabledForTesting(false);
+    resetOverrideVP9ScreenSizeAndScaleForTesting();
+#endif
 }
 
 Document* Internals::contextDocument() const
@@ -5818,6 +5826,44 @@
 #endif
 }
 
+void Internals::setSystemHasBatteryForTesting(bool hasBattery)
+{
+#if PLATFORM(COCOA)
+    WebCore::setOverrideSystemHasBatteryForTesting(hasBattery);
+#else
+    UNUSED_PARAM(hasBattery);
+#endif
+}
+
+void Internals::setSystemHasACForTesting(bool hasAC)
+{
+#if PLATFORM(COCOA)
+    WebCore::setOverrideSystemHasACForTesting(hasAC);
+#else
+    UNUSED_PARAM(hasAC);
+#endif
+}
+
+void Internals::setHardwareVP9DecoderDisabledForTesting(bool disabled)
+{
+#if PLATFORM(COCOA)
+    WebCore::setOverrideVP9HardwareDecoderDisabledForTesting(disabled);
+#else
+    UNUSED_PARAM(disabled);
+#endif
+}
+
+void Internals::setVP9ScreenSizeAndScaleForTesting(double width, double height, double scale)
+{
+#if PLATFORM(COCOA)
+    WebCore::setOverrideVP9ScreenSizeAndScaleForTesting(width, height, scale);
+#else
+    UNUSED_PARAM(width);
+    UNUSED_PARAM(height);
+    UNUSED_PARAM(scale);
+#endif
+}
+
 int Internals::readPreferenceInteger(const String& domain, const String& key)
 {
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebCore/testing/Internals.h (264475 => 264476)


--- trunk/Source/WebCore/testing/Internals.h	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/testing/Internals.h	2020-07-16 20:49:35 UTC (rev 264476)
@@ -1018,6 +1018,12 @@
 
     bool systemHasBattery() const;
 
+    void setSystemHasBatteryForTesting(bool);
+    void setSystemHasACForTesting(bool);
+
+    void setHardwareVP9DecoderDisabledForTesting(bool);
+    void setVP9ScreenSizeAndScaleForTesting(double, double, double);
+
     int readPreferenceInteger(const String& domain, const String& key);
     String encodedPreferenceValue(const String& domain, const String& key);
 

Modified: trunk/Source/WebCore/testing/Internals.idl (264475 => 264476)


--- trunk/Source/WebCore/testing/Internals.idl	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebCore/testing/Internals.idl	2020-07-16 20:49:35 UTC (rev 264476)
@@ -932,6 +932,12 @@
 
     boolean systemHasBattery();
 
+    void setSystemHasBatteryForTesting(boolean hasBattery);
+    void setSystemHasACForTesting(boolean hasAC);
+
+    void setHardwareVP9DecoderDisabledForTesting(boolean disabled);
+    void setVP9ScreenSizeAndScaleForTesting(double width, double height, double scale);
+
     long readPreferenceInteger(DOMString domain, DOMString key);
     DOMString encodedPreferenceValue(DOMString domain, DOMString key);
 

Modified: trunk/Source/WebKit/ChangeLog (264475 => 264476)


--- trunk/Source/WebKit/ChangeLog	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebKit/ChangeLog	2020-07-16 20:49:35 UTC (rev 264476)
@@ -1,3 +1,28 @@
+2020-07-16  Jer Noble  <[email protected]>
+
+        [Cocoa] Add MediaCapabilities support for SW VP9 decoder.
+        https://bugs.webkit.org/show_bug.cgi?id=214316
+
+        Reviewed by Eric Carlson.
+
+        Pass the system AC state to the WebContent process at creation time, and also create
+        a power state listener so the WebProcess can be updated dynamically.
+
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeWebProcess):
+        (WebKit::WebProcessPool::registerNotificationObservers):
+        * UIProcess/WebProcessPool.cpp:
+        * UIProcess/WebProcessPool.h:
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+        (WebKit::WebProcess::powerSourceDidChange):
+
 2020-07-16  Per Arne Vollan  <[email protected]>
 
         [macOS] Add syscall to WebContent sandbox

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp (264475 => 264476)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2020-07-16 20:49:35 UTC (rev 264476)
@@ -170,6 +170,7 @@
 #if PLATFORM(COCOA)
     encoder << mapDBExtensionHandle;
     encoder << systemHasBattery;
+    encoder << systemHasAC;
 #endif
 
 #if PLATFORM(IOS_FAMILY)
@@ -459,6 +460,12 @@
     if (!systemHasBattery)
         return false;
     parameters.systemHasBattery = WTFMove(*systemHasBattery);
+
+    Optional<bool> systemHasAC;
+    decoder >> systemHasAC;
+    if (!systemHasAC)
+        return false;
+    parameters.systemHasAC = WTFMove(*systemHasAC);
 #endif
 
 #if PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.h (264475 => 264476)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2020-07-16 20:49:35 UTC (rev 264476)
@@ -214,6 +214,7 @@
 #if PLATFORM(COCOA)
     Optional<SandboxExtension::Handle> mapDBExtensionHandle;
     bool systemHasBattery { false };
+    bool systemHasAC { false };
 #endif
 
 #if PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (264475 => 264476)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2020-07-16 20:49:35 UTC (rev 264476)
@@ -55,6 +55,7 @@
 #import <WebCore/NotImplemented.h>
 #import <WebCore/PictureInPictureSupport.h>
 #import <WebCore/PlatformPasteboard.h>
+#import <WebCore/PowerSourceNotifier.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/SharedBuffer.h>
 #import <WebCore/UTIUtilities.h>
@@ -407,6 +408,7 @@
     
 #if PLATFORM(COCOA)
     parameters.systemHasBattery = systemHasBattery();
+    parameters.systemHasAC = systemHasAC();
 
     SandboxExtension::Handle mapDBHandle;
     if (SandboxExtension::createHandleForMachLookup("com.apple.lsd.mapdb"_s, WTF::nullopt, mapDBHandle, SandboxExtension::Flags::NoReport))
@@ -697,6 +699,10 @@
     }];
 #endif
 #endif
+
+    m_powerSourceNotifier = WTF::makeUnique<WebCore::PowerSourceNotifier>([this] (bool hasAC) {
+        sendToAllProcesses(Messages::WebProcess::PowerSourceDidChange(hasAC));
+    });
 }
 
 void WebProcessPool::unregisterNotificationObservers()
@@ -726,6 +732,8 @@
 #endif
 
     [[NSNotificationCenter defaultCenter] removeObserver:m_activationObserver.get()];
+
+    m_powerSourceNotifier = nullptr;
 }
 
 static CFURLStorageSessionRef privateBrowsingSession()

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (264475 => 264476)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2020-07-16 20:49:35 UTC (rev 264476)
@@ -127,6 +127,7 @@
 
 #if PLATFORM(COCOA)
 #include "VersionChecks.h"
+#include <WebCore/PowerSourceNotifier.h>
 #endif
 
 #if PLATFORM(MAC)

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (264475 => 264476)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2020-07-16 20:49:35 UTC (rev 264476)
@@ -94,6 +94,9 @@
 class RegistrableDomain;
 enum class EventMakesGamepadsVisible : bool;
 struct MockMediaDevice;
+#if PLATFORM(COCOA)
+class PowerSourceNotifier;
+#endif
 }
 
 namespace WebKit {
@@ -710,6 +713,7 @@
 #endif
 
 #if PLATFORM(COCOA)
+    std::unique_ptr<WebCore::PowerSourceNotifier> m_powerSourceNotifier;
     RetainPtr<NSObject> m_activationObserver;
     RetainPtr<NSObject> m_accessibilityEnabledObserver;
 #endif

Modified: trunk/Source/WebKit/WebProcess/WebProcess.h (264475 => 264476)


--- trunk/Source/WebKit/WebProcess/WebProcess.h	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebKit/WebProcess/WebProcess.h	2020-07-16 20:49:35 UTC (rev 264476)
@@ -307,6 +307,7 @@
     void notifyPreferencesChanged(const String& domain, const String& key, const Optional<String>& encodedValue);
     void unblockPreferenceService(SandboxExtension::HandleArray&&);
 #endif
+    void powerSourceDidChange(bool);
 #endif
 
     bool areAllPagesThrottleable() const;

Modified: trunk/Source/WebKit/WebProcess/WebProcess.messages.in (264475 => 264476)


--- trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2020-07-16 20:49:35 UTC (rev 264476)
@@ -172,6 +172,7 @@
     NotifyPreferencesChanged(String domain, String key, Optional<String> encodedValue)
     UnblockPreferenceService(WebKit::SandboxExtension::HandleArray handleArray)
 #endif
+    PowerSourceDidChange(bool hasAC)
 #endif
 
 #if PLATFORM(GTK) && !USE(GTK4)

Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (264475 => 264476)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-07-16 20:33:57 UTC (rev 264475)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-07-16 20:49:35 UTC (rev 264476)
@@ -312,6 +312,7 @@
 #endif
     
     setSystemHasBattery(parameters.systemHasBattery);
+    setSystemHasAC(parameters.systemHasAC);
 
 #if PLATFORM(IOS_FAMILY)
     RenderThemeIOS::setCSSValueToSystemColorMap(WTFMove(parameters.cssValueToSystemColorMap));
@@ -1022,7 +1023,12 @@
     registerWithAccessibility();
 }
 
+void WebProcess::powerSourceDidChange(bool hasAC)
+{
+    setSystemHasAC(hasAC);
+}
 
+
 } // namespace WebKit
 
 #undef RELEASE_LOG_SESSION_ID
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to