Title: [291631] branches/safari-613-branch/Source
Revision
291631
Author
alanc...@apple.com
Date
2022-03-22 10:54:21 -0700 (Tue, 22 Mar 2022)

Log Message

Cherry-pick r288662. rdar://problem/89582442

    [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):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288662 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (291630 => 291631)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-03-22 17:43:51 UTC (rev 291630)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-03-22 17:54:21 UTC (rev 291631)
@@ -1,3 +1,57 @@
+2022-03-21  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r288662. rdar://problem/89582442
+
+    [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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288662 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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-03-09  Russell Epstein  <repst...@apple.com>
 
         Cherry-pick r290515. rdar://problem/89376484

Modified: branches/safari-613-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.h (291630 => 291631)


--- branches/safari-613-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2022-03-22 17:43:51 UTC (rev 291630)
+++ branches/safari-613-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2022-03-22 17:54:21 UTC (rev 291631)
@@ -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: branches/safari-613-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.mm (291630 => 291631)


--- branches/safari-613-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.mm	2022-03-22 17:43:51 UTC (rev 291630)
+++ branches/safari-613-branch/Source/WebCore/platform/graphics/cocoa/IOSurface.mm	2022-03-22 17:54:21 UTC (rev 291631)
@@ -269,6 +269,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: branches/safari-613-branch/Source/WebKit/ChangeLog (291630 => 291631)


--- branches/safari-613-branch/Source/WebKit/ChangeLog	2022-03-22 17:43:51 UTC (rev 291630)
+++ branches/safari-613-branch/Source/WebKit/ChangeLog	2022-03-22 17:54:21 UTC (rev 291631)
@@ -1,3 +1,64 @@
+2022-03-21  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r288662. rdar://problem/89582442
+
+    [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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@288662 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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-03-17  Alan Coon  <alanc...@apple.com>
 
         Revert r290967. rdar://problem/90331977

Modified: branches/safari-613-branch/Source/WebKit/Shared/WebProcessCreationParameters.cpp (291630 => 291631)


--- branches/safari-613-branch/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2022-03-22 17:43:51 UTC (rev 291630)
+++ branches/safari-613-branch/Source/WebKit/Shared/WebProcessCreationParameters.cpp	2022-03-22 17:54:21 UTC (rev 291631)
@@ -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: branches/safari-613-branch/Source/WebKit/Shared/WebProcessCreationParameters.h (291630 => 291631)


--- branches/safari-613-branch/Source/WebKit/Shared/WebProcessCreationParameters.h	2022-03-22 17:43:51 UTC (rev 291630)
+++ branches/safari-613-branch/Source/WebKit/Shared/WebProcessCreationParameters.h	2022-03-22 17:54:21 UTC (rev 291631)
@@ -241,6 +241,7 @@
 
 #if HAVE(IOSURFACE)
     WebCore::IntSize maximumIOSurfaceSize;
+    size_t bytesPerRowIOSurfaceAlignment;
 #endif
     
     AccessibilityPreferences accessibilityPreferences;

Modified: branches/safari-613-branch/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp (291630 => 291631)


--- branches/safari-613-branch/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2022-03-22 17:43:51 UTC (rev 291630)
+++ branches/safari-613-branch/Source/WebKit/Shared/cg/ShareableBitmapCG.cpp	2022-03-22 17:54:21 UTC (rev 291631)
@@ -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: branches/safari-613-branch/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (291630 => 291631)


--- branches/safari-613-branch/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2022-03-22 17:43:51 UTC (rev 291630)
+++ branches/safari-613-branch/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2022-03-22 17:54:21 UTC (rev 291631)
@@ -473,6 +473,8 @@
     if (m_defaultPageGroup->preferences().useGPUProcessForDOMRenderingEnabled())
         parameters.maximumIOSurfaceSize = WebCore::IOSurface::maximumSize();
 
+    parameters.bytesPerRowIOSurfaceAlignment = WebCore::IOSurface::bytesPerRowAlignment();
+
     parameters.accessibilityPreferences = accessibilityPreferences();
 }
 

Modified: branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm (291630 => 291631)


--- branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2022-03-22 17:43:51 UTC (rev 291630)
+++ branches/safari-613-branch/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm	2022-03-22 17:54:21 UTC (rev 291631)
@@ -456,6 +456,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