Title: [288662] trunk/Source
Revision
288662
Author
pvol...@apple.com
Date
2022-01-26 20:12:38 -0800 (Wed, 26 Jan 2022)

Log Message

[WP] Avoid calling IOSurfaceAlignProperty
https://bugs.webkit.org/show_bug.cgi?id=235659

Reviewed by Simon Fraser.

Source/WebCore:

Add information about alignment of bytes per row to IOSurface class.

* platform/graphics/cocoa/IOSurface.h:
* platform/graphics/cocoa/IOSurface.mm:
(WebCore::surfaceBytesPerRowAlignment):
(WebCore::IOSurface::bytesPerRowAlignment):
(WebCore::IOSurface::setBytesPerRowAlignment):

Source/WebKit:

Avoid calling IOSurfaceAlignProperty in the WebContent process, since it requires IOKit access.
Information about the alignment of bytes per row of IOSurface will be retrieved in the UI process,
and sent to the WebContent process, where it will be stored.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* Shared/cg/ShareableBitmapCG.cpp:
(WebKit::ShareableBitmap::calculateBytesPerRow):
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeWebProcess):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288661 => 288662)


--- trunk/Source/WebCore/ChangeLog	2022-01-27 03:20:09 UTC (rev 288661)
+++ trunk/Source/WebCore/ChangeLog	2022-01-27 04:12:38 UTC (rev 288662)
@@ -1,3 +1,18 @@
+2022-01-26  Per Arne Vollan  <pvol...@apple.com>
+
+        [WP] Avoid calling IOSurfaceAlignProperty
+        https://bugs.webkit.org/show_bug.cgi?id=235659
+
+        Reviewed by Simon Fraser.
+
+        Add information about alignment of bytes per row to IOSurface class.
+
+        * platform/graphics/cocoa/IOSurface.h:
+        * platform/graphics/cocoa/IOSurface.mm:
+        (WebCore::surfaceBytesPerRowAlignment):
+        (WebCore::IOSurface::bytesPerRowAlignment):
+        (WebCore::IOSurface::setBytesPerRowAlignment):
+
 2022-01-26  Alexey Shvayka  <ashva...@apple.com>
 
         Remove the now-unused JSGlobalObjectTask class

Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h (288661 => 288662)


--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2022-01-27 03:20:09 UTC (rev 288661)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2022-01-27 04:12:38 UTC (rev 288662)
@@ -117,6 +117,9 @@
     WEBCORE_EXPORT static IntSize maximumSize();
     WEBCORE_EXPORT static void setMaximumSize(IntSize);
 
+    WEBCORE_EXPORT static size_t bytesPerRowAlignment();
+    WEBCORE_EXPORT static void setBytesPerRowAlignment(size_t);
+
     WEBCORE_EXPORT WTF::MachSendRight createSendRight() const;
 
     // Any images created from a surface need to be released before releasing

Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm (288661 => 288662)


--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm	2022-01-27 03:20:09 UTC (rev 288661)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm	2022-01-27 04:12:38 UTC (rev 288662)
@@ -277,6 +277,32 @@
     return size;
 }
 
+static WTF::Atomic<size_t>& surfaceBytesPerRowAlignment()
+{
+    static WTF::Atomic<size_t> alignment = 0;
+    return alignment;
+}
+
+size_t IOSurface::bytesPerRowAlignment()
+{
+    auto alignment = surfaceBytesPerRowAlignment().load();
+    if (!alignment) {
+        surfaceBytesPerRowAlignment().store(IOSurfaceGetPropertyAlignment(kIOSurfaceBytesPerRow));
+        alignment = surfaceBytesPerRowAlignment().load();
+        // A return value for IOSurfaceGetPropertyAlignment(kIOSurfaceBytesPerRow) of 1 is invalid.
+        // See https://developer.apple.com/documentation/iosurface/1419453-iosurfacegetpropertyalignment?language=objc
+        // This likely means that the sandbox is blocking access to the IOSurface IOKit class,
+        // and that IOSurface::bytesPerRowAlignment() has been called before IOSurface::setBytesPerRowAlignment.
+        RELEASE_ASSERT(alignment > 1);
+    }
+    return alignment;
+}
+
+void IOSurface::setBytesPerRowAlignment(size_t bytesPerRowAlignment)
+{
+    surfaceBytesPerRowAlignment().store(bytesPerRowAlignment);
+}
+
 MachSendRight IOSurface::createSendRight() const
 {
     return MachSendRight::adopt(IOSurfaceCreateMachPort(m_surface.get()));

Modified: trunk/Source/WebKit/ChangeLog (288661 => 288662)


--- trunk/Source/WebKit/ChangeLog	2022-01-27 03:20:09 UTC (rev 288661)
+++ trunk/Source/WebKit/ChangeLog	2022-01-27 04:12:38 UTC (rev 288662)
@@ -1,3 +1,25 @@
+2022-01-26  Per Arne Vollan  <pvol...@apple.com>
+
+        [WP] Avoid calling IOSurfaceAlignProperty
+        https://bugs.webkit.org/show_bug.cgi?id=235659
+
+        Reviewed by Simon Fraser.
+
+        Avoid calling IOSurfaceAlignProperty in the WebContent process, since it requires IOKit access.
+        Information about the alignment of bytes per row of IOSurface will be retrieved in the UI process,
+        and sent to the WebContent process, where it will be stored.
+
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * Shared/cg/ShareableBitmapCG.cpp:
+        (WebKit::ShareableBitmap::calculateBytesPerRow):
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeWebProcess):
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
 2022-01-26  Chris Dumez  <cdu...@apple.com>
 
         Symbols not always properly hidden when using WebKitAdditions to introduce new API

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp (288661 => 288662)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2022-01-27 03:20:09 UTC (rev 288661)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2022-01-27 04:12:38 UTC (rev 288662)
@@ -203,6 +203,7 @@
 
 #if HAVE(IOSURFACE)
     encoder << maximumIOSurfaceSize;
+    encoder << bytesPerRowIOSurfaceAlignment;
 #endif
 
     encoder << accessibilityPreferences;
@@ -553,6 +554,8 @@
 #if HAVE(IOSURFACE)
     if (!decoder.decode(parameters.maximumIOSurfaceSize))
         return false;
+    if (!decoder.decode(parameters.bytesPerRowIOSurfaceAlignment))
+        return false;
 #endif
 
     std::optional<AccessibilityPreferences> accessibilityPreferences;

Modified: trunk/Source/WebKit/Shared/WebProcessCreationParameters.h (288661 => 288662)


--- trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2022-01-27 03:20:09 UTC (rev 288661)
+++ trunk/Source/WebKit/Shared/WebProcessCreationParameters.h	2022-01-27 04:12:38 UTC (rev 288662)
@@ -241,6 +241,7 @@
 
 #if HAVE(IOSURFACE)
     WebCore::IntSize maximumIOSurfaceSize;
+    size_t bytesPerRowIOSurfaceAlignment;
 #endif
     
     AccessibilityPreferences accessibilityPreferences;

Modified: trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp (288661 => 288662)


--- trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2022-01-27 03:20:09 UTC (rev 288661)
+++ trunk/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2022-01-27 04:12:38 UTC (rev 288662)
@@ -28,6 +28,7 @@
 
 #include <WebCore/BitmapImage.h>
 #include <WebCore/GraphicsContextCG.h>
+#include <WebCore/IOSurface.h>
 #include <WebCore/ImageBufferUtilitiesCG.h>
 #include <WebCore/NativeImage.h>
 #include <WebCore/PlatformScreen.h>
@@ -92,7 +93,8 @@
 #if HAVE(IOSURFACE)
     if (bytesPerRow.hasOverflowed())
         return bytesPerRow;
-    return IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, bytesPerRow);
+    size_t alignmentMask = WebCore::IOSurface::bytesPerRowAlignment() - 1;
+    return (bytesPerRow + alignmentMask) & ~alignmentMask;
 #else
     return bytesPerRow;
 #endif

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (288661 => 288662)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2022-01-27 03:20:09 UTC (rev 288661)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2022-01-27 04:12:38 UTC (rev 288662)
@@ -473,6 +473,8 @@
     if (m_defaultPageGroup->preferences().useGPUProcessForDOMRenderingEnabled())
         parameters.maximumIOSurfaceSize = WebCore::IOSurface::maximumSize();
 
+    parameters.bytesPerRowIOSurfaceAlignment = WebCore::IOSurface::bytesPerRowAlignment();
+
     parameters.accessibilityPreferences = accessibilityPreferences();
 }
 

Modified: trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (288661 => 288662)


--- trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2022-01-27 03:20:09 UTC (rev 288661)
+++ trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2022-01-27 04:12:38 UTC (rev 288662)
@@ -458,6 +458,8 @@
     if (!parameters.maximumIOSurfaceSize.isEmpty())
         WebCore::IOSurface::setMaximumSize(parameters.maximumIOSurfaceSize);
 
+    WebCore::IOSurface::setBytesPerRowAlignment(parameters.bytesPerRowIOSurfaceAlignment);
+
     accessibilityPreferencesDidChange(parameters.accessibilityPreferences);
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to