Changeset 266898 in webkit


Ignore:
Timestamp:
Sep 10, 2020 4:52:11 PM (4 years ago)
Author:
Ben Nham
Message:

Disable hardware JPEG decoding on x86 Mac
https://bugs.webkit.org/show_bug.cgi?id=216377

Reviewed by Geoff Garen.

Source/WebCore/PAL:

Add wrappers for a new MediaToolbox SPI that allows us to disable HW JPEG decoding.

  • PAL.xcodeproj/project.pbxproj:
  • pal/PlatformMac.cmake:
  • pal/cocoa/MediaToolboxSoftLink.cpp:
  • pal/cocoa/MediaToolboxSoftLink.h:

Source/WebKit:

In Big Sur, ImageIO uses hardware JPEG decoding automatically for certain JPEGs. This caused
a small regression in our battery life benchmark since the one-time setup cost for the
decoder (~20-30 ms per process) was higher than the per-decode win we got from the HW decoder.

For now, we're reverting to the Catalina behavior of not using hardware JPEG on x86 Macs by
calling a MediaToolbox SPI. (The tradeoffs for Apple Silicon are different so we use
ImageIO's default heuristics on that architecture.) We plan to revisit this decision once we
move to a GPUProcess world.

  • WebProcess/cocoa/WebProcessCocoa.mm:

(WebKit::WebProcess::platformInitializeWebProcess):

Source/WTF:

Add macros to disable HW JPEG decoding on x86 Macs and indicate the presence of a new MediaToolbox SPI.
(The latter is to prevent unnecessary dlopen/dlsym calls since we soft-link MediaToolbox.)

  • wtf/PlatformEnableCocoa.h:
  • wtf/PlatformHave.h:
Location:
trunk/Source
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r266885 r266898  
     12020-09-10  Ben Nham  <nham@apple.com>
     2
     3        Disable hardware JPEG decoding on x86 Mac
     4        https://bugs.webkit.org/show_bug.cgi?id=216377
     5
     6        Reviewed by Geoff Garen.
     7
     8        Add macros to disable HW JPEG decoding on x86 Macs and indicate the presence of a new MediaToolbox SPI.
     9        (The latter is to prevent unnecessary dlopen/dlsym calls since we soft-link MediaToolbox.)
     10
     11        * wtf/PlatformEnableCocoa.h:
     12        * wtf/PlatformHave.h:
     13
    1142020-09-10  Devin Rousso  <drousso@apple.com>
    215
  • trunk/Source/WTF/wtf/PlatformEnableCocoa.h

    r266829 r266898  
    233233#endif
    234234
     235#if !defined(ENABLE_HARDWARE_JPEG) && !(PLATFORM(MAC) && CPU(X86_64))
     236#define ENABLE_HARDWARE_JPEG 1
     237#endif
     238
    235239#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000
    236240#define ENABLE_UI_PROCESS_PDF_HUD 1
  • trunk/Source/WTF/wtf/PlatformHave.h

    r266844 r266898  
    239239#endif
    240240
     241#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000
     242#define HAVE_FIG_PHOTO_DECOMPRESSION_SET_HARDWARE_CUTOFF 1
     243#endif
     244
    241245#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
    242246#define HAVE_CORE_ANIMATION_RENDER_SERVER 1
  • trunk/Source/WebCore/PAL/ChangeLog

    r266844 r266898  
     12020-09-10  Ben Nham  <nham@apple.com>
     2
     3        Disable hardware JPEG decoding on x86 Mac
     4        https://bugs.webkit.org/show_bug.cgi?id=216377
     5
     6        Reviewed by Geoff Garen.
     7
     8        Add wrappers for a new MediaToolbox SPI that allows us to disable HW JPEG decoding.
     9
     10        * PAL.xcodeproj/project.pbxproj:
     11        * pal/PlatformMac.cmake:
     12        * pal/cocoa/MediaToolboxSoftLink.cpp:
     13        * pal/cocoa/MediaToolboxSoftLink.h:
     14
    1152020-09-10  Jer Noble  <jer.noble@apple.com>
    216
  • trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj

    r264207 r266898  
    184184                E5D45D122106A07400D2B738 /* NSColorWellSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = E5D45D112106A07400D2B738 /* NSColorWellSPI.h */; };
    185185                E5D45D142106A18700D2B738 /* NSPopoverColorWellSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = E5D45D132106A18700D2B738 /* NSPopoverColorWellSPI.h */; };
     186                EB8A8DC22509E87E00D1BF90 /* MediaToolboxSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = EB8A8DC12509E87E00D1BF90 /* MediaToolboxSPI.h */; };
    186187                F442915E1FA52473002CC93E /* NSFileSizeFormatterSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */; };
    187188                F44291601FA5261E002CC93E /* FileSizeFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = F442915F1FA5261E002CC93E /* FileSizeFormatter.h */; };
     
    375376                E5D45D112106A07400D2B738 /* NSColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSColorWellSPI.h; sourceTree = "<group>"; };
    376377                E5D45D132106A18700D2B738 /* NSPopoverColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSPopoverColorWellSPI.h; sourceTree = "<group>"; };
     378                EB8A8DC12509E87E00D1BF90 /* MediaToolboxSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaToolboxSPI.h; sourceTree = "<group>"; };
    377379                F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSFileSizeFormatterSPI.h; sourceTree = "<group>"; };
    378380                F442915F1FA5261E002CC93E /* FileSizeFormatter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FileSizeFormatter.h; sourceTree = "<group>"; };
     
    460462                                0C2DA12A1F3BEB4900DBC317 /* IOTypesSPI.h */,
    461463                                0C5AF9121F43A4C7002EAC02 /* LaunchServicesSPI.h */,
     464                                EB8A8DC12509E87E00D1BF90 /* MediaToolboxSPI.h */,
    462465                                1CC3ACE722BD7EB800F360F0 /* MetalSPI.h */,
    463466                                0C2DA12D1F3BEB4900DBC317 /* NEFilterSourceSPI.h */,
     
    793796                                0C2DA11F1F3BE9E000DBC317 /* ImageIOSPI.h in Headers */,
    794797                                CE5673872151A7B9002F92D7 /* IOKitSPI.h in Headers */,
     798                                517E03F924B7C0070054895A /* IOKitSPIMac.h in Headers */,
    795799                                0C2DA1421F3BEB4900DBC317 /* IOPMLibSPI.h in Headers */,
    796800                                0C2DA1431F3BEB4900DBC317 /* IOPSLibSPI.h in Headers */,
     
    809813                                0C00CFD41F68CE4600AAC26D /* MediaTimeAVFoundation.h in Headers */,
    810814                                CDACB361238742740018D7CE /* MediaToolboxSoftLink.h in Headers */,
     815                                EB8A8DC22509E87E00D1BF90 /* MediaToolboxSPI.h in Headers */,
    811816                                1CC3ACE822BD7EC500F360F0 /* MetalSPI.h in Headers */,
    812817                                0C5AF91E1F43A4C7002EAC02 /* MobileGestaltSPI.h in Headers */,
     
    881886                                0C5AF9221F43A4C7002EAC02 /* UIKitSPI.h in Headers */,
    882887                                0C2DA1471F3BEB4900DBC317 /* URLFormattingSPI.h in Headers */,
    883                                 517E03F924B7C0070054895A /* IOKitSPIMac.h in Headers */,
    884888                                07611DB6243FA5BF00D80704 /* UsageTrackingSoftLink.h in Headers */,
    885889                                0C2DA1591F3BEB4900DBC317 /* WebFilterEvaluatorSPI.h in Headers */,
  • trunk/Source/WebCore/PAL/pal/PlatformMac.cmake

    r261320 r266898  
    3939    spi/cocoa/IOTypesSPI.h
    4040    spi/cocoa/LaunchServicesSPI.h
     41    spi/cocoa/MediaToolboxSPI.h
    4142    spi/cocoa/MetalSPI.h
    4243    spi/cocoa/NEFilterSourceSPI.h
  • trunk/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.cpp

    r260832 r266898  
    2929
    3030#include <MediaToolbox/MediaToolbox.h>
     31#include <pal/spi/cocoa/MediaToolboxSPI.h>
    3132#include <wtf/SoftLinking.h>
    3233
    3334SOFT_LINK_FRAMEWORK_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, PAL_EXPORT)
     35
     36SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, FigPhotoDecompressionSetHardwareCutoff, void, (FigPhotoContainerFormat format, size_t numPixelsCutoff), (format, numPixelsCutoff), PAL_EXPORT)
    3437
    3538SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, MTShouldPlayHDRVideo, Boolean, (CFArrayRef displayList), (displayList), PAL_EXPORT)
     
    3841
    3942SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, kMTSupportNotification_ShouldPlayHDRVideoChanged, CFStringRef, PAL_EXPORT)
     43
    4044#endif
  • trunk/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.h

    r260832 r266898  
    2929
    3030#include <MediaToolbox/MediaToolbox.h>
     31#include <pal/spi/cocoa/MediaToolboxSPI.h>
    3132#include <wtf/SoftLinking.h>
    3233
    3334SOFT_LINK_FRAMEWORK_FOR_HEADER(PAL, MediaToolbox)
     35
     36SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(PAL, MediaToolbox, FigPhotoDecompressionSetHardwareCutoff, void, (FigPhotoContainerFormat format, size_t numPixelsCutoff), (format, numPixelsCutoff))
    3437
    3538SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(PAL, MediaToolbox, MTShouldPlayHDRVideo, Boolean, (CFArrayRef displayList), (displayList))
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/MediaToolboxSPI.h

    r266897 r266898  
    11/*
    2  * Copyright (C) 2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828#if USE(MEDIATOOLBOX)
    2929
    30 #include <MediaToolbox/MediaToolbox.h>
    31 #include <wtf/SoftLinking.h>
     30#if USE(APPLE_INTERNAL_SDK)
     31#include <MediaToolbox/FigPhoto.h>
     32#else
     33#include <CoreFoundation/CoreFoundation.h>
    3234
    33 SOFT_LINK_FRAMEWORK_FOR_HEADER(PAL, MediaToolbox)
     35typedef CF_ENUM(int, FigPhotoContainerFormat)
     36{
     37    kFigPhotoContainerFormat_HEIF,
     38    kFigPhotoContainerFormat_JFIF,
    3439
    35 SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(PAL, MediaToolbox, MTShouldPlayHDRVideo, Boolean, (CFArrayRef displayList), (displayList))
    36 SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(PAL, MediaToolbox, MTOverrideShouldPlayHDRVideo, void, (Boolean override, Boolean playHDRVideo), (override, playHDRVideo))
    37 SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(PAL, MediaToolbox, MT_GetShouldPlayHDRVideoNotificationSingleton, CFTypeRef, (void), ())
    38 
    39 SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, MediaToolbox, kMTSupportNotification_ShouldPlayHDRVideoChanged, CFStringRef)
     40};
     41#endif
    4042
    4143#endif
  • trunk/Source/WebKit/ChangeLog

    r266895 r266898  
     12020-09-10  Ben Nham  <nham@apple.com>
     2
     3        Disable hardware JPEG decoding on x86 Mac
     4        https://bugs.webkit.org/show_bug.cgi?id=216377
     5
     6        Reviewed by Geoff Garen.
     7
     8        In Big Sur, ImageIO uses hardware JPEG decoding automatically for certain JPEGs. This caused
     9        a small regression in our battery life benchmark since the one-time setup cost for the
     10        decoder (~20-30 ms per process) was higher than the per-decode win we got from the HW decoder.
     11
     12        For now, we're reverting to the Catalina behavior of not using hardware JPEG on x86 Macs by
     13        calling a MediaToolbox SPI. (The tradeoffs for Apple Silicon are different so we use
     14        ImageIO's default heuristics on that architecture.) We plan to revisit this decision once we
     15        move to a GPUProcess world.
     16
     17        * WebProcess/cocoa/WebProcessCocoa.mm:
     18        (WebKit::WebProcess::platformInitializeWebProcess):
     19
    1202020-09-10  Chris Dumez  <cdumez@apple.com>
    221
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r266804 r266898  
    7272#import <dispatch/dispatch.h>
    7373#import <objc/runtime.h>
     74#import <pal/cocoa/MediaToolboxSoftLink.h>
    7475#import <pal/spi/cf/CFNetworkSPI.h>
    7576#import <pal/spi/cf/CFUtilitiesSPI.h>
     
    337338    WebCore::sleepDisablerClient() = makeUnique<WebSleepDisablerClient>();
    338339
     340#if HAVE(FIG_PHOTO_DECOMPRESSION_SET_HARDWARE_CUTOFF) && !ENABLE(HARDWARE_JPEG)
     341    if (PAL::isMediaToolboxFrameworkAvailable() && PAL::canLoad_MediaToolbox_FigPhotoDecompressionSetHardwareCutoff())
     342        PAL::softLinkMediaToolboxFigPhotoDecompressionSetHardwareCutoff(kFigPhotoContainerFormat_JFIF, INT_MAX);
     343#endif
     344
    339345    updateProcessName();
    340346}
Note: See TracChangeset for help on using the changeset viewer.