Title: [266898] trunk/Source
Revision
266898
Author
[email protected]
Date
2020-09-10 16:52:11 -0700 (Thu, 10 Sep 2020)

Log 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:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (266897 => 266898)


--- trunk/Source/WTF/ChangeLog	2020-09-10 23:25:32 UTC (rev 266897)
+++ trunk/Source/WTF/ChangeLog	2020-09-10 23:52:11 UTC (rev 266898)
@@ -1,3 +1,16 @@
+2020-09-10  Ben Nham  <[email protected]>
+
+        Disable hardware JPEG decoding on x86 Mac
+        https://bugs.webkit.org/show_bug.cgi?id=216377
+
+        Reviewed by Geoff Garen.
+
+        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:
+
 2020-09-10  Devin Rousso  <[email protected]>
 
         Web Inspector: modernize generated backend protocol code

Modified: trunk/Source/WTF/wtf/PlatformEnableCocoa.h (266897 => 266898)


--- trunk/Source/WTF/wtf/PlatformEnableCocoa.h	2020-09-10 23:25:32 UTC (rev 266897)
+++ trunk/Source/WTF/wtf/PlatformEnableCocoa.h	2020-09-10 23:52:11 UTC (rev 266898)
@@ -232,6 +232,10 @@
 #define ENABLE_GPU_DRIVER_PREWARMING 1
 #endif
 
+#if !defined(ENABLE_HARDWARE_JPEG) && !(PLATFORM(MAC) && CPU(X86_64))
+#define ENABLE_HARDWARE_JPEG 1
+#endif
+
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000
 #define ENABLE_UI_PROCESS_PDF_HUD 1
 #endif

Modified: trunk/Source/WTF/wtf/PlatformHave.h (266897 => 266898)


--- trunk/Source/WTF/wtf/PlatformHave.h	2020-09-10 23:25:32 UTC (rev 266897)
+++ trunk/Source/WTF/wtf/PlatformHave.h	2020-09-10 23:52:11 UTC (rev 266898)
@@ -238,6 +238,10 @@
 #define HAVE_CELESTIAL 1
 #endif
 
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000
+#define HAVE_FIG_PHOTO_DECOMPRESSION_SET_HARDWARE_CUTOFF 1
+#endif
+
 #if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
 #define HAVE_CORE_ANIMATION_RENDER_SERVER 1
 #endif

Modified: trunk/Source/WebCore/PAL/ChangeLog (266897 => 266898)


--- trunk/Source/WebCore/PAL/ChangeLog	2020-09-10 23:25:32 UTC (rev 266897)
+++ trunk/Source/WebCore/PAL/ChangeLog	2020-09-10 23:52:11 UTC (rev 266898)
@@ -1,3 +1,17 @@
+2020-09-10  Ben Nham  <[email protected]>
+
+        Disable hardware JPEG decoding on x86 Mac
+        https://bugs.webkit.org/show_bug.cgi?id=216377
+
+        Reviewed by Geoff Garen.
+
+        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:
+
 2020-09-10  Jer Noble  <[email protected]>
 
         [Cocoa] PERF: Don't instantiate AVPlayer-based audio decoders or renderers if an element is initially muted.

Modified: trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj (266897 => 266898)


--- trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2020-09-10 23:25:32 UTC (rev 266897)
+++ trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2020-09-10 23:52:11 UTC (rev 266898)
@@ -183,6 +183,7 @@
 		CE5673872151A7B9002F92D7 /* IOKitSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE5673862151A7B9002F92D7 /* IOKitSPI.h */; };
 		E5D45D122106A07400D2B738 /* NSColorWellSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = E5D45D112106A07400D2B738 /* NSColorWellSPI.h */; };
 		E5D45D142106A18700D2B738 /* NSPopoverColorWellSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = E5D45D132106A18700D2B738 /* NSPopoverColorWellSPI.h */; };
+		EB8A8DC22509E87E00D1BF90 /* MediaToolboxSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = EB8A8DC12509E87E00D1BF90 /* MediaToolboxSPI.h */; };
 		F442915E1FA52473002CC93E /* NSFileSizeFormatterSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */; };
 		F44291601FA5261E002CC93E /* FileSizeFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = F442915F1FA5261E002CC93E /* FileSizeFormatter.h */; };
 		F44291641FA52670002CC93E /* FileSizeFormatter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F44291621FA52670002CC93E /* FileSizeFormatter.cpp */; };
@@ -374,6 +375,7 @@
 		CE5673862151A7B9002F92D7 /* IOKitSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IOKitSPI.h; sourceTree = "<group>"; };
 		E5D45D112106A07400D2B738 /* NSColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSColorWellSPI.h; sourceTree = "<group>"; };
 		E5D45D132106A18700D2B738 /* NSPopoverColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSPopoverColorWellSPI.h; sourceTree = "<group>"; };
+		EB8A8DC12509E87E00D1BF90 /* MediaToolboxSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaToolboxSPI.h; sourceTree = "<group>"; };
 		F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSFileSizeFormatterSPI.h; sourceTree = "<group>"; };
 		F442915F1FA5261E002CC93E /* FileSizeFormatter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FileSizeFormatter.h; sourceTree = "<group>"; };
 		F44291621FA52670002CC93E /* FileSizeFormatter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FileSizeFormatter.cpp; sourceTree = "<group>"; };
@@ -459,6 +461,7 @@
 				0C2DA1291F3BEB4900DBC317 /* IOSurfaceSPI.h */,
 				0C2DA12A1F3BEB4900DBC317 /* IOTypesSPI.h */,
 				0C5AF9121F43A4C7002EAC02 /* LaunchServicesSPI.h */,
+				EB8A8DC12509E87E00D1BF90 /* MediaToolboxSPI.h */,
 				1CC3ACE722BD7EB800F360F0 /* MetalSPI.h */,
 				0C2DA12D1F3BEB4900DBC317 /* NEFilterSourceSPI.h */,
 				0C7785741F45130F00F4EBB6 /* NSAccessibilitySPI.h */,
@@ -792,6 +795,7 @@
 				A39DE74E1F7C443D007BCB00 /* HysteresisActivity.h in Headers */,
 				0C2DA11F1F3BE9E000DBC317 /* ImageIOSPI.h in Headers */,
 				CE5673872151A7B9002F92D7 /* IOKitSPI.h in Headers */,
+				517E03F924B7C0070054895A /* IOKitSPIMac.h in Headers */,
 				0C2DA1421F3BEB4900DBC317 /* IOPMLibSPI.h in Headers */,
 				0C2DA1431F3BEB4900DBC317 /* IOPSLibSPI.h in Headers */,
 				0C2DA1441F3BEB4900DBC317 /* IOReturnSPI.h in Headers */,
@@ -808,6 +812,7 @@
 				0C77858C1F45130F00F4EBB6 /* MediaRemoteSPI.h in Headers */,
 				0C00CFD41F68CE4600AAC26D /* MediaTimeAVFoundation.h in Headers */,
 				CDACB361238742740018D7CE /* MediaToolboxSoftLink.h in Headers */,
+				EB8A8DC22509E87E00D1BF90 /* MediaToolboxSPI.h in Headers */,
 				1CC3ACE822BD7EC500F360F0 /* MetalSPI.h in Headers */,
 				0C5AF91E1F43A4C7002EAC02 /* MobileGestaltSPI.h in Headers */,
 				0C2DA1491F3BEB4900DBC317 /* NEFilterSourceSPI.h in Headers */,
@@ -880,7 +885,6 @@
 				2E1342CC215AA10A007199D2 /* UIKitSoftLink.h in Headers */,
 				0C5AF9221F43A4C7002EAC02 /* UIKitSPI.h in Headers */,
 				0C2DA1471F3BEB4900DBC317 /* URLFormattingSPI.h in Headers */,
-				517E03F924B7C0070054895A /* IOKitSPIMac.h in Headers */,
 				07611DB6243FA5BF00D80704 /* UsageTrackingSoftLink.h in Headers */,
 				0C2DA1591F3BEB4900DBC317 /* WebFilterEvaluatorSPI.h in Headers */,
 				A10826F91F576292004772AC /* WebPanel.h in Headers */,

Modified: trunk/Source/WebCore/PAL/pal/PlatformMac.cmake (266897 => 266898)


--- trunk/Source/WebCore/PAL/pal/PlatformMac.cmake	2020-09-10 23:25:32 UTC (rev 266897)
+++ trunk/Source/WebCore/PAL/pal/PlatformMac.cmake	2020-09-10 23:52:11 UTC (rev 266898)
@@ -38,6 +38,7 @@
     spi/cocoa/IOSurfaceSPI.h
     spi/cocoa/IOTypesSPI.h
     spi/cocoa/LaunchServicesSPI.h
+    spi/cocoa/MediaToolboxSPI.h
     spi/cocoa/MetalSPI.h
     spi/cocoa/NEFilterSourceSPI.h
     spi/cocoa/NSAccessibilitySPI.h

Modified: trunk/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.cpp (266897 => 266898)


--- trunk/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.cpp	2020-09-10 23:25:32 UTC (rev 266897)
+++ trunk/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.cpp	2020-09-10 23:52:11 UTC (rev 266898)
@@ -28,13 +28,17 @@
 #if USE(MEDIATOOLBOX)
 
 #include <MediaToolbox/MediaToolbox.h>
+#include <pal/spi/cocoa/MediaToolboxSPI.h>
 #include <wtf/SoftLinking.h>
 
 SOFT_LINK_FRAMEWORK_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, PAL_EXPORT)
 
+SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, FigPhotoDecompressionSetHardwareCutoff, void, (FigPhotoContainerFormat format, size_t numPixelsCutoff), (format, numPixelsCutoff), PAL_EXPORT)
+
 SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, MTShouldPlayHDRVideo, Boolean, (CFArrayRef displayList), (displayList), PAL_EXPORT)
 SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, MTOverrideShouldPlayHDRVideo, void, (Boolean override, Boolean playHDRVideo), (override, playHDRVideo), PAL_EXPORT)
 SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, MT_GetShouldPlayHDRVideoNotificationSingleton, CFTypeRef, (void), (), PAL_EXPORT)
 
 SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, MediaToolbox, kMTSupportNotification_ShouldPlayHDRVideoChanged, CFStringRef, PAL_EXPORT)
+
 #endif

Modified: trunk/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.h (266897 => 266898)


--- trunk/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.h	2020-09-10 23:25:32 UTC (rev 266897)
+++ trunk/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.h	2020-09-10 23:52:11 UTC (rev 266898)
@@ -28,10 +28,13 @@
 #if USE(MEDIATOOLBOX)
 
 #include <MediaToolbox/MediaToolbox.h>
+#include <pal/spi/cocoa/MediaToolboxSPI.h>
 #include <wtf/SoftLinking.h>
 
 SOFT_LINK_FRAMEWORK_FOR_HEADER(PAL, MediaToolbox)
 
+SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(PAL, MediaToolbox, FigPhotoDecompressionSetHardwareCutoff, void, (FigPhotoContainerFormat format, size_t numPixelsCutoff), (format, numPixelsCutoff))
+
 SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(PAL, MediaToolbox, MTShouldPlayHDRVideo, Boolean, (CFArrayRef displayList), (displayList))
 SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(PAL, MediaToolbox, MTOverrideShouldPlayHDRVideo, void, (Boolean override, Boolean playHDRVideo), (override, playHDRVideo))
 SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(PAL, MediaToolbox, MT_GetShouldPlayHDRVideoNotificationSingleton, CFTypeRef, (void), ())

Copied: trunk/Source/WebCore/PAL/pal/spi/cocoa/MediaToolboxSPI.h (from rev 266897, trunk/Source/WebCore/PAL/pal/cocoa/MediaToolboxSoftLink.h) (0 => 266898)


--- trunk/Source/WebCore/PAL/pal/spi/cocoa/MediaToolboxSPI.h	                        (rev 0)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/MediaToolboxSPI.h	2020-09-10 23:52:11 UTC (rev 266898)
@@ -0,0 +1,43 @@
+/*
+ * 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 USE(MEDIATOOLBOX)
+
+#if USE(APPLE_INTERNAL_SDK)
+#include <MediaToolbox/FigPhoto.h>
+#else
+#include <CoreFoundation/CoreFoundation.h>
+
+typedef CF_ENUM(int, FigPhotoContainerFormat)
+{
+    kFigPhotoContainerFormat_HEIF,
+    kFigPhotoContainerFormat_JFIF,
+
+};
+#endif
+
+#endif

Modified: trunk/Source/WebKit/ChangeLog (266897 => 266898)


--- trunk/Source/WebKit/ChangeLog	2020-09-10 23:25:32 UTC (rev 266897)
+++ trunk/Source/WebKit/ChangeLog	2020-09-10 23:52:11 UTC (rev 266898)
@@ -1,3 +1,22 @@
+2020-09-10  Ben Nham  <[email protected]>
+
+        Disable hardware JPEG decoding on x86 Mac
+        https://bugs.webkit.org/show_bug.cgi?id=216377
+
+        Reviewed by Geoff Garen.
+
+        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):
+
 2020-09-10  Chris Dumez  <[email protected]>
 
         Unreviewed, reverting r266842 and r266883.

Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (266897 => 266898)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-09-10 23:25:32 UTC (rev 266897)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2020-09-10 23:52:11 UTC (rev 266898)
@@ -71,6 +71,7 @@
 #import <algorithm>
 #import <dispatch/dispatch.h>
 #import <objc/runtime.h>
+#import <pal/cocoa/MediaToolboxSoftLink.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
 #import <pal/spi/cf/CFUtilitiesSPI.h>
 #import <pal/spi/cg/CoreGraphicsSPI.h>
@@ -336,6 +337,11 @@
         
     WebCore::sleepDisablerClient() = makeUnique<WebSleepDisablerClient>();
 
+#if HAVE(FIG_PHOTO_DECOMPRESSION_SET_HARDWARE_CUTOFF) && !ENABLE(HARDWARE_JPEG)
+    if (PAL::isMediaToolboxFrameworkAvailable() && PAL::canLoad_MediaToolbox_FigPhotoDecompressionSetHardwareCutoff())
+        PAL::softLinkMediaToolboxFigPhotoDecompressionSetHardwareCutoff(kFigPhotoContainerFormat_JFIF, INT_MAX);
+#endif
+
     updateProcessName();
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to