Bug 231009

Summary: Cocoa WebGL should support UI side compositing
Product: WebKit Reporter: Kimmo Kinnunen <kkinnunen>
Component: WebGLAssignee: Kimmo Kinnunen <kkinnunen>
Status: RESOLVED FIXED    
Severity: Normal CC: annulen, cdumez, changseok, cmarcelo, dino, esprehn+autocc, ews-watchlist, fred.wang, glenn, gyuyoung.kim, Hironori.Fujii, jonlee, kbr, kkinnunen, kondapallykalyan, luiz, pdr, ryuan.choi, sergio, simon.fraser, tsavell, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=234169
Bug Depends on: 231010, 231427, 231804, 233123    
Bug Blocks: 217211, 233756    
Attachments:
Description Flags
Patch for feedback
none
Patch for feedback
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch for landing
none
Patch for landing
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch for landing
none
Patch for landing none

Description Kimmo Kinnunen 2021-09-30 01:00:02 PDT
Cocoa WebGL support UI side compositing

Currently WebGL needs IOKit in WP
Comment 1 Kimmo Kinnunen 2021-09-30 01:01:08 PDT
<rdar://83437059>
Comment 2 Kimmo Kinnunen 2021-10-14 07:34:42 PDT
Created attachment 441214 [details]
Patch for feedback
Comment 3 Kimmo Kinnunen 2021-10-14 07:42:29 PDT
Created attachment 441215 [details]
Patch for feedback
Comment 4 Simon Fraser (smfr) 2021-10-14 21:23:59 PDT
I like the idea of a "content provider". Can it be a function on GraphicsLayerClient?
Comment 5 Kimmo Kinnunen 2021-10-15 06:29:53 PDT
> I like the idea of a "content provider". Can it be a function on GraphicsLayerClient?

In a way "yes", considering that current GraphicsLayerClient can provide contents via painting via "draws content".

However, in practice "no", as the GraphicsLayerClient is general purpose and closed, the "content provider" is platform-specific and open-ended.

I'd view it the other way, in that eventually GraphicsLayerClient::paintContents could be expressed as a "content provider", and RenderLayerBacking (or RenderLayers?) could be the instance that returns "paintContents content provider".

RenderLayerBacking does now: m_layer->setDrawsContent(true)
Instead it would do: m_layer->setContentFromProvider(this);

RenderLayerBacking does now: m_layer->setDrawsContent(false);
Instead it would do: m_layer->setContentFromProvider(nullptr); (or ->setNoContents());

However, it's probably not within my expertise to implement that part, and it'd be a refactor without much benefit..
Comment 6 Kimmo Kinnunen 2021-11-18 10:51:02 PST
Created attachment 444701 [details]
Patch
Comment 7 Fujii Hironori 2021-11-18 22:35:07 PST
Comment on attachment 444701 [details]
Patch

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

> Source/WebCore/platform/graphics/GraphicsLayer.h:525
>      virtual void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) { }

Do you have a plan to remove setContentsToPlatformLayer?

> Source/WebCore/platform/graphics/GraphicsLayer.h:526
> +    virtual void setContentsFromDisplayDelegate(RefPtr<GraphicsLayerContentsDisplayDelegate>&&, ContentsLayerPurpose);

This name sounds inconsistent to me.
Other methods setting the contents layer are named setContentsTo*.
I prefer setContentsToDisplayDelegate.
Comment 8 Fujii Hironori 2021-11-18 22:39:24 PST
(In reply to Kimmo Kinnunen from comment #5)
> RenderLayerBacking does now: m_layer->setDrawsContent(true)
> Instead it would do: m_layer->setContentFromProvider(this);

setDrawsContent makes the primary layer paintable, not the content layer.
I think it should be setPrimaryProvider or setPrimaryToProvider for the consistency.
Comment 9 Kimmo Kinnunen 2021-11-19 01:36:42 PST
Created attachment 444791 [details]
Patch
Comment 10 Kimmo Kinnunen 2021-11-19 05:10:22 PST
Created attachment 444804 [details]
Patch
Comment 11 Kimmo Kinnunen 2021-11-19 05:31:54 PST
Created attachment 444807 [details]
Patch
Comment 12 Kimmo Kinnunen 2021-11-22 06:09:38 PST
Created attachment 444961 [details]
Patch
Comment 13 Kimmo Kinnunen 2021-11-22 10:36:11 PST
Created attachment 444976 [details]
Patch
Comment 14 Kimmo Kinnunen 2021-11-22 23:44:46 PST
Created attachment 445007 [details]
Patch
Comment 15 Kimmo Kinnunen 2021-11-23 00:50:11 PST
Created attachment 445014 [details]
Patch
Comment 16 Kimmo Kinnunen 2021-11-23 03:32:16 PST
Created attachment 445021 [details]
Patch
Comment 17 Kimmo Kinnunen 2021-11-23 22:34:59 PST
Created attachment 445067 [details]
Patch
Comment 18 Kimmo Kinnunen 2021-11-24 04:57:12 PST
Created attachment 445089 [details]
Patch
Comment 19 Kimmo Kinnunen 2021-12-01 00:30:26 PST
Created attachment 445537 [details]
Patch
Comment 20 Kimmo Kinnunen 2021-12-01 04:24:47 PST
Created attachment 445550 [details]
Patch
Comment 21 Kimmo Kinnunen 2021-12-01 05:04:32 PST
Created attachment 445561 [details]
Patch
Comment 22 Kimmo Kinnunen 2021-12-01 06:26:19 PST
Created attachment 445569 [details]
Patch
Comment 23 Kimmo Kinnunen 2021-12-01 08:22:15 PST
Created attachment 445576 [details]
Patch
Comment 24 Kimmo Kinnunen 2021-12-01 11:20:02 PST
Created attachment 445594 [details]
Patch
Comment 25 Kimmo Kinnunen 2021-12-02 00:43:30 PST
Created attachment 445686 [details]
Patch
Comment 26 Kimmo Kinnunen 2021-12-02 02:10:35 PST
Created attachment 445695 [details]
Patch
Comment 27 Kimmo Kinnunen 2021-12-02 03:56:28 PST
Created attachment 445702 [details]
Patch
Comment 28 Kimmo Kinnunen 2021-12-02 05:07:24 PST
Created attachment 445713 [details]
Patch
Comment 29 Kimmo Kinnunen 2021-12-02 06:41:40 PST
Created attachment 445716 [details]
Patch
Comment 30 Kimmo Kinnunen 2021-12-02 06:45:04 PST
Created attachment 445717 [details]
Patch
Comment 31 Simon Fraser (smfr) 2021-12-02 09:48:57 PST
Comment on attachment 445717 [details]
Patch

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

> Source/WebCore/platform/graphics/GraphicsLayer.h:526
> +    virtual void setContentsToDisplayDelegate(RefPtr<GraphicsLayerContentsDisplayDelegate>&&, ContentsLayerPurpose);

The name is a bit odd. Maybe setContentsDisplayDelegate?

Does calling setContentsToSolidColor() or setContentsToPlatformLayer() remove the delegate?

> Source/WebCore/platform/graphics/GraphicsLayerContentsDisplayDelegate.h:47
> +    virtual void willDelegateDisplay(PlatformCALayer&);

This name is ambiguous. On first reading I expect it to return a bool. Does it mean "prepare to render a frame"?

> Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp:1363
> +        m_contentsLayer = createPlatformCALayer(PlatformCALayer::LayerTypeContentsProvidedLayer, this);

Naively I would expect that the GraphicsLayerContentsDisplayDelegate would do the layer creation?

> Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp:1369
> +        m_contentsLayer->setBackingStoreAttached(true);
> +        m_contentsLayer->setAcceleratesDrawing(true);

I feel like these should be under delegate control too?

> Source/WebCore/platform/graphics/cocoa/WebProcessGraphicsContextGLCocoa.mm:49
> +    }
> +    void display(PlatformCALayer& layer) final

Blank lines between functions please.

> Source/WebCore/platform/graphics/mac/WebLayer.mm:86
> +    if (!layer->owner()->platformCALayerDrawsContent() && !layer->owner()->platformCALayerDelegatesDisplay(layer.get()))

Maybe we should add a function that does both these checks.

> Source/WebKit/WebProcess/GPU/graphics/cocoa/RemoteGraphicsContextGLProxyCocoa.mm:56
> +    }
> +    void display(WebCore::PlatformCALayer& layer) final

Blank lines please
Comment 32 Fujii Hironori 2021-12-02 16:59:46 PST
Comment on attachment 445717 [details]
Patch

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

>> Source/WebCore/platform/graphics/GraphicsLayer.h:526
>> +    virtual void setContentsToDisplayDelegate(RefPtr<GraphicsLayerContentsDisplayDelegate>&&, ContentsLayerPurpose);
> 
> The name is a bit odd. Maybe setContentsDisplayDelegate?
> 
> Does calling setContentsToSolidColor() or setContentsToPlatformLayer() remove the delegate?

Just a idea. What about using overloading for the methods?

    virtual void setContents(Image*) { }
    virtual void setContents(const Color&) { }
    virtual void setContents(RefPtr<GraphicsLayerContentsDisplayDelegate>&&, ContentsLayerPurpose);
    virtual void setContents(RefPtr<Model>&&) { }

> Source/WebKit/WebProcess/GPU/graphics/wc/RemoteGraphicsContextGLProxyWC.cpp:73
> +        , m_layerContentsDisplayDelegate(PlatformLayerDisplayDelegate::create(makeUnique<WCPlatformLayerGCGL>(m_graphicsContextGLIdentifier)))

We no longer need WCPlatformLayerGCGL. I will remove it in follow-up patch.
Comment 33 Kimmo Kinnunen 2021-12-03 05:30:07 PST
Created attachment 445846 [details]
Patch
Comment 34 Kimmo Kinnunen 2021-12-03 10:46:39 PST
Created attachment 445872 [details]
Patch
Comment 35 Fujii Hironori 2021-12-05 13:23:39 PST
Created attachment 445990 [details]
Patch

* Fixed WinCairo build
Comment 36 Kimmo Kinnunen 2021-12-06 10:10:53 PST
Thanks Fujii!
Comment 37 Kimmo Kinnunen 2021-12-07 03:13:12 PST
Created attachment 446150 [details]
Patch for landing
Comment 38 Kimmo Kinnunen 2021-12-07 03:37:10 PST
Created attachment 446151 [details]
Patch for landing
Comment 39 EWS 2021-12-07 04:22:35 PST
Committed r286596 (?): <https://commits.webkit.org/r286596>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 446151 [details].
Comment 40 Truitt Savell 2021-12-08 13:03:28 PST
I believe the changes in https://trac.webkit.org/changeset/286596/webkit

Caused these two tests to timeout on iOS:
compositing/tiling/tiled-reflection-inwindow.html
fast/forms/ios/focus-select-and-switch-tabs.html

I don't think EWS caught this because it was considered flaky during the run. current history shows a very clear regression point though

History:
https://results.webkit.org/?suite=layout-tests&suite=layout-tests&test=editing%2Fpasteboard%2Fdom-paste%2Fdom-paste-requires-user-gesture.html&test=fast%2Fforms%2Fios%2Ffocus-select-and-switch-tabs.html&platform=ios

Tracking in: https://bugs.webkit.org/show_bug.cgi?id=234032
Comment 41 Truitt Savell 2021-12-08 13:07:16 PST
Reverted r286596 for reason:

broke 2 tests on iOS

Committed r286709 (244986@trunk): <https://commits.webkit.org/244986@trunk>
Comment 42 Kimmo Kinnunen 2021-12-10 05:27:24 PST
Created attachment 446713 [details]
Patch
Comment 43 Kimmo Kinnunen 2021-12-10 07:17:31 PST
Created attachment 446723 [details]
Patch
Comment 44 Kimmo Kinnunen 2021-12-10 07:29:00 PST
Created attachment 446726 [details]
Patch
Comment 45 Kimmo Kinnunen 2021-12-10 08:02:20 PST
Created attachment 446730 [details]
Patch
Comment 46 Simon Fraser (smfr) 2021-12-10 08:34:58 PST
Comment on attachment 446730 [details]
Patch

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

> Source/WebCore/platform/graphics/cocoa/WebProcessGraphicsContextGLCocoa.mm:89
> +    const bool m_isOpaque;
> +    const float m_contentsScale;
> +    std::unique_ptr<IOSurface> m_displayBuffer;

Doesn't really matter but I would flip the ordering to avoid padding.

> Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h:140
> +    // FIXME: This should be removed and m_bufferHandle should be used to ref the buffer once ShareableBitmap::Handle
> +    // can be encoded multiple times.

File a bug to track?

> Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:117
> +    // FIXME: For simplicity this should be moved to the end of display() once the buffer handles can be created once
> +    // and stored in m_bufferHandle.

Reference the same bug.

> Source/WebKit/WebProcess/GPU/graphics/cocoa/RemoteGraphicsContextGLProxyCocoa.mm:91
> +    const bool m_isOpaque;
> +    const float m_contentsScale;
> +    MachSendRight m_displayBuffer;

Ditto.
Comment 47 Kimmo Kinnunen 2021-12-10 13:00:38 PST
Created attachment 446789 [details]
Patch for landing
Comment 48 EWS 2021-12-13 01:35:25 PST
Tools/Scripts/svn-apply failed to apply attachment 446789 [details] to trunk.
Please resolve the conflicts and upload a new patch.
Comment 49 Kimmo Kinnunen 2021-12-13 01:38:45 PST
Created attachment 446976 [details]
Patch for landing
Comment 50 EWS 2021-12-13 02:38:52 PST
Committed r286943 (245168@main): <https://commits.webkit.org/245168@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 446976 [details].
Comment 51 Simon Fraser (smfr) 2021-12-14 21:15:33 PST
Comment on attachment 446976 [details]
Patch for landing

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

> Source/WebCore/WebCore.xcodeproj/project.pbxproj:33104
> +				7B582DD82716F55B004B92D0 /* (null) in Headers */,

What?