Skip to content

Commit

Permalink
Disable all image hardware decoding in the WebContent process
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259457
rdar://112477703

Reviewed by Brent Fulgham.

Disable hardware decoding for all image formats in the WebContent process when IOKit is blocked.

* Source/WTF/wtf/PlatformHave.h:
* Source/WebCore/PAL/pal/spi/cg/ImageIOSPI.h:
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
* Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Canonical link: https://commits.webkit.org/266335@main
  • Loading branch information
pvollan committed Jul 26, 2023
1 parent e8ee25a commit c0fc79a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Source/WTF/wtf/PlatformHave.h
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,15 @@
#define HAVE_NSVIEW_CLIPSTOBOUNDS_API 1
#endif

#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000) \
|| (PLATFORM(MACCATALYST) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 170000) \
|| (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 170000) \
|| (PLATFORM(APPLETV) && __TV_OS_VERSION_MAX_ALLOWED >= 170000) \
|| (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 100000)
#define HAVE_CGIMAGESOURCE_DISABLE_HARDWARE_DECODING 1
#define HAVE_CGIMAGESOURCE_ENABLE_RESTRICTED_DECODING 1
#endif

#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000) \
|| (PLATFORM(MACCATALYST) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 170000) \
|| (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 170000) \
Expand Down
9 changes: 9 additions & 0 deletions Source/WebCore/PAL/pal/spi/cg/ImageIOSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ CFStringRef CGImageSourceGetTypeWithData(CFDataRef, CFStringRef, bool*);
#if HAVE(CGIMAGESOURCE_WITH_SET_ALLOWABLE_TYPES)
OSStatus CGImageSourceSetAllowableTypes(CFArrayRef allowableTypes);
#endif

#if HAVE(CGIMAGESOURCE_DISABLE_HARDWARE_DECODING)
IMAGEIO_EXTERN OSStatus CGImageSourceDisableHardwareDecoding();
#endif

#if HAVE(CGIMAGESOURCE_ENABLE_RESTRICTED_DECODING)
IMAGEIO_EXTERN OSStatus CGImageSourceEnableRestrictedDecoding();
#endif

WTF_EXTERN_C_END
5 changes: 5 additions & 0 deletions Source/WebKit/WebProcess/WebPage/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
#include "WebRemoteObjectRegistry.h"
#include <WebCore/LegacyWebArchive.h>
#include <WebCore/UTIRegistry.h>
#include <pal/spi/cg/ImageIOSPI.h>
#include <wtf/MachSendRight.h>
#include <wtf/spi/darwin/SandboxSPI.h>
#endif
Expand Down Expand Up @@ -639,6 +640,10 @@ WebPage::WebPage(PageIdentifier pageID, WebPageCreationParameters&& parameters)
#endif
ProcessCapabilities::setHardwareAcceleratedDecodingDisabled(true);
ProcessCapabilities::setCanUseAcceleratedBuffers(false);
#if HAVE(CGIMAGESOURCE_DISABLE_HARDWARE_DECODING)
OSStatus ok = CGImageSourceDisableHardwareDecoding();
ASSERT_UNUSED(ok, ok == noErr);
#endif
}
#endif

Expand Down
8 changes: 8 additions & 0 deletions Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#import <JavaScriptCore/Options.h>
#import <WebCore/AVAssetMIMETypeCache.h>
#import <pal/spi/cf/VideoToolboxSPI.h>
#import <pal/spi/cg/ImageIOSPI.h>

#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
#import <WebCore/AXIsolatedObject.h>
Expand Down Expand Up @@ -373,6 +374,13 @@ static void setVideoDecoderBehaviors(OptionSet<VideoDecoderBehavior> videoDecode
videoDecoderBehavior.add(VideoDecoderBehavior::EnableAVIF);
}

#if HAVE(CGIMAGESOURCE_ENABLE_RESTRICTED_DECODING)
if (parameters.enableDecodingHEIC || parameters.enableDecodingAVIF) {
OSStatus ok = CGImageSourceEnableRestrictedDecoding();
ASSERT_UNUSED(ok, ok == noErr);
}
#endif

if (videoDecoderBehavior) {
videoDecoderBehavior.add({ VideoDecoderBehavior::AvoidIOSurface, VideoDecoderBehavior::AvoidHardware });
setVideoDecoderBehaviors(videoDecoderBehavior);
Expand Down

0 comments on commit c0fc79a

Please sign in to comment.