Bug 235659 - [WP] Avoid calling IOSurfaceAlignProperty
Summary: [WP] Avoid calling IOSurfaceAlignProperty
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Per Arne Vollan
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-01-26 11:33 PST by Per Arne Vollan
Modified: 2022-01-27 13:51 PST (History)
6 users (show)

See Also:


Attachments
Patch (7.10 KB, patch)
2022-01-26 11:41 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (7.20 KB, patch)
2022-01-26 13:32 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (7.81 KB, patch)
2022-01-26 15:46 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Per Arne Vollan 2022-01-26 11:33:04 PST
Avoid calling IOSurfaceAlignProperty in the WebContent process, since it requires IOKit access.
Comment 1 Per Arne Vollan 2022-01-26 11:41:11 PST
Created attachment 450048 [details]
Patch
Comment 2 Simon Fraser (smfr) 2022-01-26 11:48:13 PST
Comment on attachment 450048 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=450048&action=review

> Source/WebCore/platform/graphics/cocoa/IOSurface.h:121
> +    WEBCORE_EXPORT static size_t bytesPerRowAlignment();
> +    WEBCORE_EXPORT static void setBytesPerRowAlignment(size_t);

This doesn't protect against bytesPerRowAlignment() being called before setBytesPerRowAlignment(). Maybe bytesPerRowAlignment() should return an optional.

> Source/WebCore/platform/graphics/cocoa/IOSurface.mm:282
> +        surfaceBytesPerRowAlignment().store(IOSurfaceGetPropertyAlignment(kIOSurfaceBytesPerRow));

This is surprising, since calling bytesPerRowAlignment() in the WP before setBytesPerRowAlignment() will trigger the IOSurface call.
Comment 3 Per Arne Vollan 2022-01-26 13:32:52 PST
Created attachment 450062 [details]
Patch
Comment 4 Per Arne Vollan 2022-01-26 13:33:47 PST
(In reply to Simon Fraser (smfr) from comment #2)
> Comment on attachment 450048 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=450048&action=review
> 
> > Source/WebCore/platform/graphics/cocoa/IOSurface.h:121
> > +    WEBCORE_EXPORT static size_t bytesPerRowAlignment();
> > +    WEBCORE_EXPORT static void setBytesPerRowAlignment(size_t);
> 
> This doesn't protect against bytesPerRowAlignment() being called before
> setBytesPerRowAlignment(). Maybe bytesPerRowAlignment() should return an
> optional.
> 
> > Source/WebCore/platform/graphics/cocoa/IOSurface.mm:282
> > +        surfaceBytesPerRowAlignment().store(IOSurfaceGetPropertyAlignment(kIOSurfaceBytesPerRow));
> 
> This is surprising, since calling bytesPerRowAlignment() in the WP before
> setBytesPerRowAlignment() will trigger the IOSurface call.

That is a good point. I have uploaded a new patch to address this.

Thanks for reviewing!
Comment 5 Simon Fraser (smfr) 2022-01-26 13:41:39 PST
Comment on attachment 450062 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=450062&action=review

> Source/WebKit/Shared/cg/ShareableBitmapCG.cpp:97
> +    return (bytesPerRow + alignmentMask) & ~alignmentMask;

Pretty sure we have a macro for this.

> Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:461
>      if (!parameters.maximumIOSurfaceSize.isEmpty())
>          WebCore::IOSurface::setMaximumSize(parameters.maximumIOSurfaceSize);
>  
> +    WebCore::IOSurface::setBytesPerRowAlignment(parameters.bytesPerRowIOSurfaceAlignment);

We should probably do both of these for the GPU Process too, right? Also maybe we need to revisit bug 235526 now that I see we already send over maximumIOSurfaceSize.
Comment 6 Per Arne Vollan 2022-01-26 15:46:27 PST
Created attachment 450080 [details]
Patch
Comment 7 Per Arne Vollan 2022-01-26 15:52:40 PST
(In reply to Simon Fraser (smfr) from comment #5)
> Comment on attachment 450062 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=450062&action=review
> 
> > Source/WebKit/Shared/cg/ShareableBitmapCG.cpp:97
> > +    return (bytesPerRow + alignmentMask) & ~alignmentMask;
> 
> Pretty sure we have a macro for this.
> 

I searched for this, but I was not able to find it.

> > Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:461
> >      if (!parameters.maximumIOSurfaceSize.isEmpty())
> >          WebCore::IOSurface::setMaximumSize(parameters.maximumIOSurfaceSize);
> >  
> > +    WebCore::IOSurface::setBytesPerRowAlignment(parameters.bytesPerRowIOSurfaceAlignment);
> 
> We should probably do both of these for the GPU Process too, right? Also
> maybe we need to revisit bug 235526 now that I see we already send over
> maximumIOSurfaceSize.

I revised the original patch to catch (with an assert) when the value is being queried before being set.

I will revisit bug 235526 in a separate bug, if you're OK with that. I think we can avoid the launch time regression by sending the value in the WebPage creation parameters.

Thanks for reviewing!
Comment 8 Per Arne Vollan 2022-01-26 16:04:58 PST
(In reply to Simon Fraser (smfr) from comment #5)
> Comment on attachment 450062 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=450062&action=review
> 
> > Source/WebKit/Shared/cg/ShareableBitmapCG.cpp:97
> > +    return (bytesPerRow + alignmentMask) & ~alignmentMask;
> 
> Pretty sure we have a macro for this.
> 
> > Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:461
> >      if (!parameters.maximumIOSurfaceSize.isEmpty())
> >          WebCore::IOSurface::setMaximumSize(parameters.maximumIOSurfaceSize);
> >  
> > +    WebCore::IOSurface::setBytesPerRowAlignment(parameters.bytesPerRowIOSurfaceAlignment);
> 
> We should probably do both of these for the GPU Process too, right? Also
> maybe we need to revisit bug 235526 now that I see we already send over
> maximumIOSurfaceSize.

For the GPU process, I don't think it is strictly needed to do this, since the IOSurface calls will succeed there.
Comment 9 Per Arne Vollan 2022-01-26 19:37:59 PST
Comment on attachment 450080 [details]
Patch

Thanks for reviewing!
Comment 10 Per Arne Vollan 2022-01-26 19:40:44 PST
<rdar://88024079>
Comment 11 EWS 2022-01-26 20:13:48 PST
Committed r288662 (246470@main): <https://commits.webkit.org/246470@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 450080 [details].