Changeset 264476 in webkit


Ignore:
Timestamp:
Jul 16, 2020 1:49:35 PM (4 years ago)
Author:
jer.noble@apple.com
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.
Location:
trunk
Files:
3 added
29 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r264472 r264476  
     12020-07-16  Jer Noble  <jer.noble@apple.com>
     2
     3        [Cocoa] Add MediaCapabilities support for SW VP9 decoder.
     4        https://bugs.webkit.org/show_bug.cgi?id=214316
     5
     6        Reviewed by Eric Carlson.
     7
     8        * platform/mac/media/mediacapabilities/vp9-decodingInfo-sw-expected.txt: Added.
     9        * platform/mac/media/mediacapabilities/vp9-decodingInfo-sw.html: Added.
     10
    1112020-07-16  Hector Lopez  <hector_i_lopez@apple.com>
    212
  • trunk/LayoutTests/platform/mac/TestExpectations

    r264356 r264476  
    19211921
    19221922webkit.org/b/214155 imported/w3c/web-platform-tests/html/cross-origin-embedder-policy/blob.https.html [ Pass Failure ]
     1923
     1924# This test requires system platform support.
     1925platform/mac/media/mediacapabilities/vp9-decodingInfo-sw.html [ Skip ]
  • trunk/Source/WebCore/ChangeLog

    r264475 r264476  
     12020-07-16  Jer Noble  <jer.noble@apple.com>
     2
     3        [Cocoa] Add MediaCapabilities support for SW VP9 decoder.
     4        https://bugs.webkit.org/show_bug.cgi?id=214316
     5
     6        Reviewed by Eric Carlson.
     7
     8        Test: platform/mac/media/mediacapabilities/vp9-decodingInfo-sw.html
     9
     10        Add some foundational support for SW VP9, which due to policy decisions will need information
     11        both on the system battery status and the power adapter status, and these need to be shipped
     12        into the WebContent process from the UIProcess.
     13
     14        Add some Internal override settings to allow the policies to be effectively tested through
     15        LayouTests. This includes overrides for system battery and AC state, as well as overrides for
     16        screen size and resolution.
     17
     18        * SourcesCocoa.txt:
     19        * WebCore.xcodeproj/project.pbxproj:
     20        * platform/PlatformScreen.cpp:
     21        (WebCore::getScreenProperties):
     22        * platform/PlatformScreen.h:
     23        * platform/ScreenProperties.h:
     24        (WebCore::ScreenData::encode const):
     25        (WebCore::ScreenData::decode):
     26        * platform/cocoa/PowerSourceNotifier.h:
     27        * platform/cocoa/PowerSourceNotifier.mm:
     28        (WebCore::PowerSourceNotifier::PowerSourceNotifier):
     29        (WebCore::PowerSourceNotifier::~PowerSourceNotifier):
     30        (WebCore::PowerSourceNotifier::notifyPowerSourceChanged):
     31        * platform/cocoa/SystemBattery.h:
     32        * platform/cocoa/SystemBattery.mm:
     33        (WebCore::systemHasBattery):
     34        (WebCore::resetSystemHasAC):
     35        (WebCore::setSystemHasAC):
     36        (WebCore::systemHasAC):
     37        (WebCore::setOverrideSystemHasBatteryForTesting):
     38        (WebCore::setOverrideSystemHasACForTesting):
     39        * platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp:
     40        (WebCore::videoCodecTypeFromRFC4281Type):
     41        (WebCore::createMediaPlayerDecodingConfigurationCocoa):
     42        * platform/graphics/cocoa/VP9UtilitiesCocoa.h: Copied from Source/WebCore/PAL/pal/spi/cocoa/IOPSLibSPI.h.
     43        * platform/graphics/cocoa/VP9UtilitiesCocoa.mm: Added.
     44        (WebCore::setOverrideVP9HardwareDecoderDisabledForTesting):
     45        (WebCore::setOverrideVP9ScreenSizeAndScaleForTesting):
     46        (WebCore::resetOverrideVP9ScreenSizeAndScaleForTesting):
     47        (WebCore::validateVPParameters):
     48        * platform/ios/PlatformScreenIOS.mm:
     49        (WebCore::collectScreenProperties):
     50        * platform/mac/PlatformScreenMac.mm:
     51        (WebCore::collectScreenProperties):
     52        * testing/Internals.cpp:
     53        (WebCore::Internals::Internals):
     54        (WebCore::Internals::setSystemHasBattery):
     55        (WebCore::Internals::setSystemHasAC):
     56        (WebCore::Internals::setHardwareVP9DecoderDisabledForTesting):
     57        (WebCore::Internals::setVP9ScreenSizeAndScale):
     58        * testing/Internals.h:
     59        * testing/Internals.idl:
     60
    1612020-07-16  Brady Eidson  <beidson@apple.com>
    262
  • trunk/Source/WebCore/PAL/ChangeLog

    r264474 r264476  
     12020-07-16  Jer Noble  <jer.noble@apple.com>
     2
     3        [Cocoa] Add MediaCapabilities support for SW VP9 decoder.
     4        https://bugs.webkit.org/show_bug.cgi?id=214316
     5
     6        Reviewed by Eric Carlson.
     7
     8        * pal/spi/cocoa/IOPSLibSPI.h:
     9
    1102020-07-16  Jonathan Bedard  <jbedard@apple.com>
    211
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/IOPSLibSPI.h

    r220506 r264476  
    3737#define kIOPSTypeKey "Type"
    3838#define kIOPSInternalBatteryType "InternalBattery"
     39#define kIOPSPowerSourceStateKey "Power Source State"
     40#define kIOPSACPowerValue "AC Power"
     41#define kIOPSNotifyPowerSource "com.apple.system.powersources.source"
    3942
    4043#endif
  • trunk/Source/WebCore/SourcesCocoa.txt

    r264207 r264476  
    242242platform/cocoa/PlatformPasteboardCocoa.mm
    243243platform/cocoa/PlaybackSessionModelMediaElement.mm
     244platform/cocoa/PowerSourceNotifier.mm
    244245platform/cocoa/RuntimeApplicationChecksCocoa.mm
    245246platform/cocoa/ScrollController.mm
     
    350351platform/graphics/cocoa/SystemFontDatabaseCoreText.cpp
    351352platform/graphics/cocoa/TextTrackRepresentationCocoa.mm
     353platform/graphics/cocoa/VP9UtilitiesCocoa.mm
    352354platform/graphics/cocoa/WebActionDisablingCALayerDelegate.mm
    353355platform/graphics/cocoa/WebCoreCALayerExtras.mm
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r264367 r264476  
    42014201                CDC69DDA16371FD4007C38DF /* WebCoreFullScreenPlaceholderView.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC69DD816371FD3007C38DF /* WebCoreFullScreenPlaceholderView.h */; settings = {ATTRIBUTES = (Private, ); }; };
    42024202                CDC734151977896D0046BFC5 /* CARingBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC734131977896C0046BFC5 /* CARingBuffer.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4203                CDC7470424BE2FC700C1868B /* PowerSourceNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC7470024BE267900C1868B /* PowerSourceNotifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
    42034204                CDC8B5A2180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDC8B5A0180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.mm */; };
    42044205                CDC8B5A3180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC8B5A1180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.h */; };
     
    1410814109                CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SourceBufferPrivate.h; sourceTree = "<group>"; };
    1410914110                CD641EC7181ED60100EE4C41 /* MediaSample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaSample.h; sourceTree = "<group>"; };
     14111                CD6FE5B724BCE645009FCDA4 /* VP9UtilitiesCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VP9UtilitiesCocoa.h; sourceTree = "<group>"; };
     14112                CD6FE5B824BCE645009FCDA4 /* VP9UtilitiesCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = VP9UtilitiesCocoa.mm; sourceTree = "<group>"; };
    1411014113                CD6FE5BA24BCE7B6009FCDA4 /* VP9Utilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VP9Utilities.h; sourceTree = "<group>"; };
    1411114114                CD6FE5BB24BCE7B6009FCDA4 /* VP9Utilities.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VP9Utilities.cpp; sourceTree = "<group>"; };
     
    1428414287                CDC734121977896C0046BFC5 /* CARingBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CARingBuffer.cpp; sourceTree = "<group>"; };
    1428514288                CDC734131977896C0046BFC5 /* CARingBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CARingBuffer.h; sourceTree = "<group>"; };
     14289                CDC7470024BE267900C1868B /* PowerSourceNotifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PowerSourceNotifier.h; sourceTree = "<group>"; };
     14290                CDC7470124BE267900C1868B /* PowerSourceNotifier.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PowerSourceNotifier.mm; sourceTree = "<group>"; };
    1428614291                CDC8B5A0180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaPlayerPrivateMediaSourceAVFObjC.mm; sourceTree = "<group>"; };
    1428714292                CDC8B5A1180463470016E685 /* MediaPlayerPrivateMediaSourceAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaPlayerPrivateMediaSourceAVFObjC.h; sourceTree = "<group>"; };
     
    2363123636                                CDA29A0D1CBD9CFE00901CCF /* PlaybackSessionModelMediaElement.h */,
    2363223637                                CDA29A0C1CBD9CFE00901CCF /* PlaybackSessionModelMediaElement.mm */,
     23638                                CDC7470024BE267900C1868B /* PowerSourceNotifier.h */,
     23639                                CDC7470124BE267900C1868B /* PowerSourceNotifier.mm */,
    2363323640                                465A8E781C8A24CE00E7D3E4 /* RuntimeApplicationChecksCocoa.mm */,
    2363423641                                1AA84F03143BA7BD0051D153 /* ScrollController.h */,
     
    2574525752                                BE913D7F181EF8E500DCB09E /* TrackPrivateBase.h */,
    2574625753                                E4AFCFA40DAF29A300F5F55C /* UnitBezier.h */,
    25747                                 CD6FE5BA24BCE7B6009FCDA4 /* VP9Utilities.h */,
    25748                                 CD6FE5BB24BCE7B6009FCDA4 /* VP9Utilities.cpp */,
    2574925754                                0F5A57CA229B18AE0025EDA9 /* VelocityData.cpp */,
    2575025755                                0F1A0C36229A481800D37ADB /* VelocityData.h */,
    2575125756                                BEF29EEA1715DD0900C4B4C9 /* VideoTrackPrivate.h */,
     25757                                CD6FE5BB24BCE7B6009FCDA4 /* VP9Utilities.cpp */,
     25758                                CD6FE5BA24BCE7B6009FCDA4 /* VP9Utilities.h */,
    2575225759                                1411DCB0164C39A800D49BC1 /* WidthCache.h */,
    2575325760                                939B02EC0EA2DBC400C54570 /* WidthIterator.cpp */,
     
    2588725894                                526724F21CB2FDF60075974D /* TextTrackRepresentationCocoa.h */,
    2588825895                                526724F11CB2FDF60075974D /* TextTrackRepresentationCocoa.mm */,
     25896                                CD6FE5B724BCE645009FCDA4 /* VP9UtilitiesCocoa.h */,
     25897                                CD6FE5B824BCE645009FCDA4 /* VP9UtilitiesCocoa.mm */,
    2588925898                                2D3EF4441917915C00034184 /* WebActionDisablingCALayerDelegate.h */,
    2589025899                                2D3EF4451917915C00034184 /* WebActionDisablingCALayerDelegate.mm */,
     
    3264132650                                BC5C762B1497FE1400BC4775 /* PlatformEvent.h in Headers */,
    3264232651                                26601EBF14B3B9AD0012C0FE /* PlatformEventFactoryIOS.h in Headers */,
     32652                                CDC7470424BE2FC700C1868B /* PowerSourceNotifier.h in Headers */,
    3264332653                                BCAA487014A052530088FAC4 /* PlatformEventFactoryMac.h in Headers */,
    3264432654                                A723F77B1484CA4C008C6DBE /* PlatformExportMacros.h in Headers */,
  • trunk/Source/WebCore/platform/PlatformScreen.cpp

    r261546 r264476  
    3939}
    4040
     41const ScreenProperties& getScreenProperties()
     42{
     43    return screenProperties();
     44}
     45
    4146PlatformDisplayID primaryScreenDisplayID()
    4247{
  • trunk/Source/WebCore/platform/PlatformScreen.h

    r261546 r264476  
    9595WEBCORE_EXPORT ScreenProperties collectScreenProperties();
    9696WEBCORE_EXPORT void setScreenProperties(const ScreenProperties&);
     97const ScreenProperties& getScreenProperties();
    9798const ScreenData* screenData(PlatformDisplayID screendisplayID);
    9899WEBCORE_EXPORT PlatformDisplayID primaryScreenDisplayID();
  • trunk/Source/WebCore/platform/ScreenProperties.h

    r263090 r264476  
    5252#endif
    5353
     54#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
     55    float scaleFactor { 1 };
     56#endif
     57
    5458    enum class ColorSpaceType : uint8_t { None, Name, Data };
    5559    template<class Encoder> void encode(Encoder&) const;
     
    97101#if PLATFORM(MAC)
    98102    encoder << screenIsMonochrome << displayMask << gpuID;
     103#endif
     104
     105#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
     106    encoder << scaleFactor;
    99107#endif
    100108
     
    174182    decoder >> gpuID;
    175183    if (!gpuID)
     184        return WTF::nullopt;
     185#endif
     186
     187#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
     188    Optional<float> scaleFactor;
     189    decoder >> scaleFactor;
     190    if (!scaleFactor)
    176191        return WTF::nullopt;
    177192#endif
     
    220235        WTFMove(*screenIsMonochrome),
    221236        WTFMove(*displayMask),
    222         WTFMove(*gpuID)
     237        WTFMove(*gpuID),
     238#endif
     239#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
     240        WTFMove(*scaleFactor),
    223241#endif
    224242    } };
  • trunk/Source/WebCore/platform/cocoa/PowerSourceNotifier.h

    r264475 r264476  
    2626#pragma once
    2727
    28 #include <wtf/text/StringView.h>
    29 #include <wtf/text/WTFString.h>
     28#include <wtf/Function.h>
    3029
    3130namespace WebCore {
    3231
    33 struct VPCodecConfigurationRecord {
    34     String codecName;
    35     uint8_t profile { 0 };
    36     uint8_t level { 0 };
    37     uint8_t bitDepth { 0 };
    38     uint8_t chromaSubsampling { 1 };
    39     uint8_t videoFullRangeFlag { 0 };
    40     uint8_t colorPrimaries { 1 };
    41     uint8_t transferCharacteristics { 1 };
    42     uint8_t matrixCoefficients { 1 };
     32class PowerSourceNotifier {
     33    WTF_MAKE_FAST_ALLOCATED;
     34public:
     35    using PowerSourceNotifierCallback = WTF::Function<void(bool hasAC)>;
     36    WEBCORE_EXPORT explicit PowerSourceNotifier(PowerSourceNotifierCallback&&);
     37    WEBCORE_EXPORT ~PowerSourceNotifier();
     38
     39    WEBCORE_EXPORT bool isLowPowerModeEnabled() const;
     40
     41private:
     42    void notifyPowerSourceChanged();
     43
     44    Optional<int> m_tokenID;
     45    PowerSourceNotifierCallback m_callback;
    4346};
    4447
    45 WEBCORE_EXPORT Optional<VPCodecConfigurationRecord> parseVPCodecParameters(StringView codecString);
    46 
    4748}
  • trunk/Source/WebCore/platform/cocoa/PowerSourceNotifier.mm

    r264475 r264476  
    2424 */
    2525
    26 #pragma once
     26#include "config.h"
     27#include "PowerSourceNotifier.h"
    2728
    28 #include <wtf/text/StringView.h>
    29 #include <wtf/text/WTFString.h>
     29#import "SystemBattery.h"
     30#import <notify.h>
     31#import <pal/spi/cocoa/IOPSLibSPI.h>
    3032
    3133namespace WebCore {
    3234
    33 struct VPCodecConfigurationRecord {
    34     String codecName;
    35     uint8_t profile { 0 };
    36     uint8_t level { 0 };
    37     uint8_t bitDepth { 0 };
    38     uint8_t chromaSubsampling { 1 };
    39     uint8_t videoFullRangeFlag { 0 };
    40     uint8_t colorPrimaries { 1 };
    41     uint8_t transferCharacteristics { 1 };
    42     uint8_t matrixCoefficients { 1 };
    43 };
     35PowerSourceNotifier::PowerSourceNotifier(PowerSourceNotifierCallback&& callback)
     36    : m_callback(WTFMove(callback))
     37{
     38    int token = 0;
     39    auto status = notify_register_dispatch(kIOPSNotifyPowerSource, &token, dispatch_get_main_queue(), ^(int) {
     40        notifyPowerSourceChanged();
     41    });
     42    if (status == NOTIFY_STATUS_OK)
     43        m_tokenID = token;
     44}
    4445
    45 WEBCORE_EXPORT Optional<VPCodecConfigurationRecord> parseVPCodecParameters(StringView codecString);
     46PowerSourceNotifier::~PowerSourceNotifier()
     47{
     48    if (m_tokenID)
     49        notify_cancel(*m_tokenID);
     50}
     51
     52void PowerSourceNotifier::notifyPowerSourceChanged()
     53{
     54    resetSystemHasAC();
     55    if (m_callback)
     56        m_callback(systemHasAC());
     57}
    4658
    4759}
  • trunk/Source/WebCore/platform/cocoa/SystemBattery.h

    r254995 r264476  
    3131WEBCORE_EXPORT bool systemHasBattery();
    3232
     33WEBCORE_EXPORT void resetSystemHasAC();
     34WEBCORE_EXPORT void setSystemHasAC(bool);
     35WEBCORE_EXPORT bool systemHasAC();
     36
     37WEBCORE_EXPORT void setOverrideSystemHasBatteryForTesting(Optional<bool>&&);
     38WEBCORE_EXPORT void setOverrideSystemHasACForTesting(Optional<bool>&&);
     39
    3340}
  • trunk/Source/WebCore/platform/cocoa/SystemBattery.mm

    r260960 r264476  
    2727#import "SystemBattery.h"
    2828
     29#import <notify.h>
    2930#import <pal/spi/cocoa/IOPSLibSPI.h>
    3031
     
    3233
    3334static Optional<bool> hasBattery;
     35static Optional<bool> hasAC;
     36static Optional<bool> hasBatteryOverrideForTesting;
     37static Optional<bool> hasACOverrideForTesting;
    3438
    3539void setSystemHasBattery(bool battery)
     
    4044bool systemHasBattery()
    4145{
     46    if (hasBatteryOverrideForTesting)
     47        return *hasBatteryOverrideForTesting;
     48
    4249    if (!hasBattery.hasValue()) {
    4350        hasBattery = [] {
     
    6875}
    6976
     77void resetSystemHasAC()
     78{
     79    hasAC.reset();
    7080}
     81
     82void setSystemHasAC(bool ac)
     83{
     84    hasAC = ac;
     85}
     86
     87bool systemHasAC()
     88{
     89    if (hasACOverrideForTesting)
     90        return *hasACOverrideForTesting;
     91
     92    if (!hasAC.hasValue()) {
     93        hasAC = [] {
     94#if PLATFORM(APPLETV)
     95            return true;
     96#else
     97            RetainPtr<CFTypeRef> powerSourcesInfo = adoptCF(IOPSCopyPowerSourcesInfo());
     98            if (!powerSourcesInfo)
     99                return false;
     100            RetainPtr<CFArrayRef> powerSourcesList = adoptCF(IOPSCopyPowerSourcesList(powerSourcesInfo.get()));
     101            if (!powerSourcesList)
     102                return false;
     103            for (CFIndex i = 0, count = CFArrayGetCount(powerSourcesList.get()); i < count; ++i) {
     104                CFDictionaryRef description = IOPSGetPowerSourceDescription(powerSourcesInfo.get(), CFArrayGetValueAtIndex(powerSourcesList.get(), i));
     105                if (!description)
     106                    continue;
     107                CFTypeRef value = CFDictionaryGetValue(description, CFSTR(kIOPSPowerSourceStateKey));
     108                if (value && CFEqual(value, CFSTR(kIOPSACPowerValue)))
     109                    return true;
     110            }
     111            return false;
     112#endif
     113        }();
     114    }
     115
     116    return *hasAC;
     117}
     118
     119void setOverrideSystemHasBatteryForTesting(Optional<bool>&& hasBattery)
     120{
     121    hasBatteryOverrideForTesting = WTFMove(hasBattery);
     122}
     123
     124void setOverrideSystemHasACForTesting(Optional<bool>&& hasAC)
     125{
     126    hasACOverrideForTesting = WTFMove(hasAC);
     127}
     128
     129}
  • trunk/Source/WebCore/platform/graphics/VP9Utilities.cpp

    r264367 r264476  
    3535{
    3636    constexpr uint8_t validLevels[] = {
    37         10,
    38         11,
    39         20,
    40         21,
    41         30,
    42         31,
    43         40,
    44         41,
    45         50,
    46         51,
    47         52,
    48         60,
    49         61,
    50         62,
     37        VPConfigurationLevel::Level_1,
     38        VPConfigurationLevel::Level_1_1,
     39        VPConfigurationLevel::Level_2,
     40        VPConfigurationLevel::Level_2_1,
     41        VPConfigurationLevel::Level_3,
     42        VPConfigurationLevel::Level_3_1,
     43        VPConfigurationLevel::Level_4,
     44        VPConfigurationLevel::Level_4_1,
     45        VPConfigurationLevel::Level_5,
     46        VPConfigurationLevel::Level_5_1,
     47        VPConfigurationLevel::Level_5_2,
     48        VPConfigurationLevel::Level_6,
     49        VPConfigurationLevel::Level_6_1,
     50        VPConfigurationLevel::Level_6_2,
    5151    };
    5252
     
    131131    // Fourth element: chromaSubsampling. Legal values are 0-3.
    132132    auto chromaSubsampling = toIntegralType<uint8_t>(*nextElement);
    133     if (!chromaSubsampling || *chromaSubsampling > 3)
     133    if (!chromaSubsampling || *chromaSubsampling > VPConfigurationChromaSubsampling::Subsampling_444)
    134134        return WTF::nullopt;
    135135    configuration.chromaSubsampling = *chromaSubsampling;
  • trunk/Source/WebCore/platform/graphics/VP9Utilities.h

    r264367 r264476  
    3131namespace WebCore {
    3232
     33namespace VPConfigurationLevel {
     34constexpr uint8_t Level_1   = 10;
     35constexpr uint8_t Level_1_1 = 11;
     36constexpr uint8_t Level_2   = 20;
     37constexpr uint8_t Level_2_1 = 21;
     38constexpr uint8_t Level_3   = 30;
     39constexpr uint8_t Level_3_1 = 31;
     40constexpr uint8_t Level_4   = 40;
     41constexpr uint8_t Level_4_1 = 41;
     42constexpr uint8_t Level_5   = 50;
     43constexpr uint8_t Level_5_1 = 51;
     44constexpr uint8_t Level_5_2 = 52;
     45constexpr uint8_t Level_6   = 60;
     46constexpr uint8_t Level_6_1 = 61;
     47constexpr uint8_t Level_6_2 = 62;
     48}
     49
     50namespace VPConfigurationChromaSubsampling {
     51constexpr uint8_t Subsampling_420_Vertical = 0;
     52constexpr uint8_t Subsampling_420_Colocated = 1;
     53constexpr uint8_t Subsampling_422 = 2;
     54constexpr uint8_t Subsampling_444 = 3;
     55}
     56
     57namespace VPConfigurationRange {
     58constexpr uint8_t VideoRange = 0;
     59constexpr uint8_t FullRange = 1;
     60}
     61
    3362struct VPCodecConfigurationRecord {
    3463    String codecName;
    3564    uint8_t profile { 0 };
    36     uint8_t level { 0 };
    37     uint8_t bitDepth { 0 };
    38     uint8_t chromaSubsampling { 1 };
    39     uint8_t videoFullRangeFlag { 0 };
     65    uint8_t level { VPConfigurationLevel::Level_1 };
     66    uint8_t bitDepth { 8 };
     67    uint8_t chromaSubsampling { VPConfigurationChromaSubsampling::Subsampling_420_Colocated };
     68    uint8_t videoFullRangeFlag { VPConfigurationRange::VideoRange };
    4069    uint8_t colorPrimaries { 1 };
    4170    uint8_t transferCharacteristics { 1 };
  • trunk/Source/WebCore/platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp

    r253397 r264476  
    3333#include "MediaDecodingConfiguration.h"
    3434#include "MediaPlayer.h"
     35#include "VP9UtilitiesCocoa.h"
    3536
    3637#include "VideoToolboxSoftLink.h"
    3738
    3839namespace WebCore {
     40
     41// FIXME: Remove this once kCMVideoCodecType_VP9 is added to CMFormatDescription.h
     42constexpr CMVideoCodecType kCMVideoCodecType_VP9 { 'vp09' };
    3943
    4044static CMVideoCodecType videoCodecTypeFromRFC4281Type(String type)
     
    4650    if (type.startsWith("hvc1") || type.startsWith("hev1"))
    4751        return kCMVideoCodecType_HEVC;
     52    if (type.startsWith("vp09"))
     53        return kCMVideoCodecType_VP9;
    4854    return 0;
    4955}
     
    9298                return;
    9399            }
     100        } else if (videoCodecType == kCMVideoCodecType_VP9) {
     101            auto codecConfiguration = parseVPCodecParameters(codec);
     102            if (!codecConfiguration || !validateVPParameters(*codecConfiguration, info, videoConfiguration)) {
     103                callback({{ }, WTFMove(configuration)});
     104                return;
     105            }
    94106        } else {
    95107            if (alphaChannel || hdrSupported) {
  • trunk/Source/WebCore/platform/graphics/cocoa/VP9UtilitiesCocoa.h

    r264475 r264476  
    2626#pragma once
    2727
    28 #include <wtf/text/StringView.h>
    29 #include <wtf/text/WTFString.h>
     28#if PLATFORM(COCOA)
     29
     30#include "VP9Utilities.h"
    3031
    3132namespace WebCore {
    3233
    33 struct VPCodecConfigurationRecord {
    34     String codecName;
    35     uint8_t profile { 0 };
    36     uint8_t level { 0 };
    37     uint8_t bitDepth { 0 };
    38     uint8_t chromaSubsampling { 1 };
    39     uint8_t videoFullRangeFlag { 0 };
    40     uint8_t colorPrimaries { 1 };
    41     uint8_t transferCharacteristics { 1 };
    42     uint8_t matrixCoefficients { 1 };
    43 };
     34struct MediaCapabilitiesInfo;
     35struct VideoConfiguration;
    4436
    45 WEBCORE_EXPORT Optional<VPCodecConfigurationRecord> parseVPCodecParameters(StringView codecString);
     37WEBCORE_EXPORT extern void setOverrideVP9HardwareDecoderDisabledForTesting(bool);
     38WEBCORE_EXPORT extern void setOverrideVP9ScreenSizeAndScaleForTesting(float width, float height, float scale);
     39WEBCORE_EXPORT extern void resetOverrideVP9ScreenSizeAndScaleForTesting();
     40
     41extern bool validateVPParameters(VPCodecConfigurationRecord&, MediaCapabilitiesInfo&, const VideoConfiguration&);
    4642
    4743}
     44
     45#endif
  • trunk/Source/WebCore/platform/ios/PlatformScreenIOS.mm

    r263090 r264476  
    201201        bool screenSupportsExtendedColor = WebCore::screenSupportsExtendedColor(nullptr);
    202202        bool screenHasInvertedColors = WebCore::screenHasInvertedColors();
    203 
    204         screenProperties.screenDataMap.set(++displayID, ScreenData { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors });
     203        bool hdr = screenSupportsHighDynamicRange(nullptr);
     204        float scaleFactor = WebCore::screenPPIFactor();
     205
     206        screenProperties.screenDataMap.set(++displayID, ScreenData { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors, hdr, scaleFactor });
    205207       
    206208        if (screen == [PAL::getUIScreenClass() mainScreen])
  • trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm

    r263090 r264476  
    118118        IORegistryGPUID gpuID = 0;
    119119        bool screenSupportsHighDynamicRange = false;
     120        float scaleFactor = screen.backingScaleFactor;
    120121
    121122#if USE(MEDIATOOLBOX)
     
    127128            gpuID = gpuIDForDisplayMask(displayMask);
    128129
    129         screenProperties.screenDataMap.set(displayID, ScreenData { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors, screenSupportsHighDynamicRange, screenIsMonochrome, displayMask, gpuID });
     130        screenProperties.screenDataMap.set(displayID, ScreenData { screenAvailableRect, screenRect, colorSpace, screenDepth, screenDepthPerComponent, screenSupportsExtendedColor, screenHasInvertedColors, screenSupportsHighDynamicRange, screenIsMonochrome, displayMask, gpuID, scaleFactor });
    130131
    131132        if (!screenProperties.primaryDisplayID)
  • trunk/Source/WebCore/testing/Internals.cpp

    r264367 r264476  
    320320#endif
    321321
    322 #if PLATFORM(MAC) && USE(LIBWEBRTC)
    323 #include <webrtc/sdk/WebKit/VideoProcessingSoftLink.h>
    324 #endif
    325 
    326322#if PLATFORM(MAC)
    327323#include "GraphicsContextGLOpenGLManager.h"
     
    332328#if PLATFORM(COCOA)
    333329#include "SystemBattery.h"
     330#include "VP9UtilitiesCocoa.h"
    334331#include <pal/spi/cocoa/CoreTextSPI.h>
    335332#include <wtf/spi/darwin/SandboxSPI.h>
     333#endif
     334
     335#if PLATFORM(MAC) && USE(LIBWEBRTC)
     336#include <webrtc/sdk/WebKit/VideoProcessingSoftLink.h>
    336337#endif
    337338
     
    630631#if PLATFORM(COCOA) &&  ENABLE(WEB_AUDIO)
    631632    AudioDestinationCocoa::createOverride = nullptr;
     633#endif
     634
     635#if PLATFORM(COCOA)
     636    setOverrideSystemHasBatteryForTesting(WTF::nullopt);
     637    setOverrideSystemHasACForTesting(WTF::nullopt);
     638    setOverrideVP9HardwareDecoderDisabledForTesting(false);
     639    resetOverrideVP9ScreenSizeAndScaleForTesting();
    632640#endif
    633641}
     
    58195827}
    58205828
     5829void Internals::setSystemHasBatteryForTesting(bool hasBattery)
     5830{
     5831#if PLATFORM(COCOA)
     5832    WebCore::setOverrideSystemHasBatteryForTesting(hasBattery);
     5833#else
     5834    UNUSED_PARAM(hasBattery);
     5835#endif
     5836}
     5837
     5838void Internals::setSystemHasACForTesting(bool hasAC)
     5839{
     5840#if PLATFORM(COCOA)
     5841    WebCore::setOverrideSystemHasACForTesting(hasAC);
     5842#else
     5843    UNUSED_PARAM(hasAC);
     5844#endif
     5845}
     5846
     5847void Internals::setHardwareVP9DecoderDisabledForTesting(bool disabled)
     5848{
     5849#if PLATFORM(COCOA)
     5850    WebCore::setOverrideVP9HardwareDecoderDisabledForTesting(disabled);
     5851#else
     5852    UNUSED_PARAM(disabled);
     5853#endif
     5854}
     5855
     5856void Internals::setVP9ScreenSizeAndScaleForTesting(double width, double height, double scale)
     5857{
     5858#if PLATFORM(COCOA)
     5859    WebCore::setOverrideVP9ScreenSizeAndScaleForTesting(width, height, scale);
     5860#else
     5861    UNUSED_PARAM(width);
     5862    UNUSED_PARAM(height);
     5863    UNUSED_PARAM(scale);
     5864#endif
     5865}
     5866
    58215867int Internals::readPreferenceInteger(const String& domain, const String& key)
    58225868{
  • trunk/Source/WebCore/testing/Internals.h

    r264367 r264476  
    10191019    bool systemHasBattery() const;
    10201020
     1021    void setSystemHasBatteryForTesting(bool);
     1022    void setSystemHasACForTesting(bool);
     1023
     1024    void setHardwareVP9DecoderDisabledForTesting(bool);
     1025    void setVP9ScreenSizeAndScaleForTesting(double, double, double);
     1026
    10211027    int readPreferenceInteger(const String& domain, const String& key);
    10221028    String encodedPreferenceValue(const String& domain, const String& key);
  • trunk/Source/WebCore/testing/Internals.idl

    r264367 r264476  
    933933    boolean systemHasBattery();
    934934
     935    void setSystemHasBatteryForTesting(boolean hasBattery);
     936    void setSystemHasACForTesting(boolean hasAC);
     937
     938    void setHardwareVP9DecoderDisabledForTesting(boolean disabled);
     939    void setVP9ScreenSizeAndScaleForTesting(double width, double height, double scale);
     940
    935941    long readPreferenceInteger(DOMString domain, DOMString key);
    936942    DOMString encodedPreferenceValue(DOMString domain, DOMString key);
  • trunk/Source/WebKit/ChangeLog

    r264457 r264476  
     12020-07-16  Jer Noble  <jer.noble@apple.com>
     2
     3        [Cocoa] Add MediaCapabilities support for SW VP9 decoder.
     4        https://bugs.webkit.org/show_bug.cgi?id=214316
     5
     6        Reviewed by Eric Carlson.
     7
     8        Pass the system AC state to the WebContent process at creation time, and also create
     9        a power state listener so the WebProcess can be updated dynamically.
     10
     11        * Shared/WebProcessCreationParameters.cpp:
     12        (WebKit::WebProcessCreationParameters::encode const):
     13        (WebKit::WebProcessCreationParameters::decode):
     14        * Shared/WebProcessCreationParameters.h:
     15        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
     16        (WebKit::WebProcessPool::platformInitializeWebProcess):
     17        (WebKit::WebProcessPool::registerNotificationObservers):
     18        * UIProcess/WebProcessPool.cpp:
     19        * UIProcess/WebProcessPool.h:
     20        * WebProcess/WebProcess.h:
     21        * WebProcess/WebProcess.messages.in:
     22        * WebProcess/cocoa/WebProcessCocoa.mm:
     23        (WebKit::WebProcess::platformInitializeWebProcess):
     24        (WebKit::WebProcess::powerSourceDidChange):
     25
    1262020-07-16  Per Arne Vollan  <pvollan@apple.com>
    227
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp

    r263320 r264476  
    171171    encoder << mapDBExtensionHandle;
    172172    encoder << systemHasBattery;
     173    encoder << systemHasAC;
    173174#endif
    174175
     
    460461        return false;
    461462    parameters.systemHasBattery = WTFMove(*systemHasBattery);
     463
     464    Optional<bool> systemHasAC;
     465    decoder >> systemHasAC;
     466    if (!systemHasAC)
     467        return false;
     468    parameters.systemHasAC = WTFMove(*systemHasAC);
    462469#endif
    463470
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.h

    r263320 r264476  
    215215    Optional<SandboxExtension::Handle> mapDBExtensionHandle;
    216216    bool systemHasBattery { false };
     217    bool systemHasAC { false };
    217218#endif
    218219
  • trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm

    r264178 r264476  
    5656#import <WebCore/PictureInPictureSupport.h>
    5757#import <WebCore/PlatformPasteboard.h>
     58#import <WebCore/PowerSourceNotifier.h>
    5859#import <WebCore/RuntimeApplicationChecks.h>
    5960#import <WebCore/SharedBuffer.h>
     
    408409#if PLATFORM(COCOA)
    409410    parameters.systemHasBattery = systemHasBattery();
     411    parameters.systemHasAC = systemHasAC();
    410412
    411413    SandboxExtension::Handle mapDBHandle;
     
    698700#endif
    699701#endif
     702
     703    m_powerSourceNotifier = WTF::makeUnique<WebCore::PowerSourceNotifier>([this] (bool hasAC) {
     704        sendToAllProcesses(Messages::WebProcess::PowerSourceDidChange(hasAC));
     705    });
    700706}
    701707
     
    727733
    728734    [[NSNotificationCenter defaultCenter] removeObserver:m_activationObserver.get()];
     735
     736    m_powerSourceNotifier = nullptr;
    729737}
    730738
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r264004 r264476  
    128128#if PLATFORM(COCOA)
    129129#include "VersionChecks.h"
     130#include <WebCore/PowerSourceNotifier.h>
    130131#endif
    131132
  • trunk/Source/WebKit/UIProcess/WebProcessPool.h

    r264178 r264476  
    9595enum class EventMakesGamepadsVisible : bool;
    9696struct MockMediaDevice;
     97#if PLATFORM(COCOA)
     98class PowerSourceNotifier;
     99#endif
    97100}
    98101
     
    711714
    712715#if PLATFORM(COCOA)
     716    std::unique_ptr<WebCore::PowerSourceNotifier> m_powerSourceNotifier;
    713717    RetainPtr<NSObject> m_activationObserver;
    714718    RetainPtr<NSObject> m_accessibilityEnabledObserver;
  • trunk/Source/WebKit/WebProcess/WebProcess.h

    r264178 r264476  
    308308    void unblockPreferenceService(SandboxExtension::HandleArray&&);
    309309#endif
     310    void powerSourceDidChange(bool);
    310311#endif
    311312
  • trunk/Source/WebKit/WebProcess/WebProcess.messages.in

    r264004 r264476  
    173173    UnblockPreferenceService(WebKit::SandboxExtension::HandleArray handleArray)
    174174#endif
     175    PowerSourceDidChange(bool hasAC)
    175176#endif
    176177
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r264199 r264476  
    313313   
    314314    setSystemHasBattery(parameters.systemHasBattery);
     315    setSystemHasAC(parameters.systemHasAC);
    315316
    316317#if PLATFORM(IOS_FAMILY)
     
    10231024}
    10241025
     1026void WebProcess::powerSourceDidChange(bool hasAC)
     1027{
     1028    setSystemHasAC(hasAC);
     1029}
     1030
    10251031
    10261032} // namespace WebKit
Note: See TracChangeset for help on using the changeset viewer.