[webkit-changes] [WebKit/WebKit] a1a9b4: [Site isolation] Snapshotting should be composited...
Said Abou-Hallawa
noreply at github.com
Thu Dec 19 12:24:24 PST 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: a1a9b4a3de6f7f09d36158119cc13563d0478bc2
https://github.com/WebKit/WebKit/commit/a1a9b4a3de6f7f09d36158119cc13563d0478bc2
Author: Said Abou-Hallawa <said at apple.com>
Date: 2024-12-19 (Thu, 19 Dec 2024)
Changed paths:
M Source/WebCore/Headers.cmake
M Source/WebCore/WebCore.xcodeproj/project.pbxproj
M Source/WebCore/platform/graphics/ImageBuffer.cpp
M Source/WebCore/platform/graphics/ImageBuffer.h
M Source/WebCore/platform/graphics/ImageBufferBackend.cpp
M Source/WebCore/platform/graphics/ImageBufferBackend.h
M Source/WebCore/platform/graphics/NullImageBufferBackend.h
A Source/WebCore/platform/graphics/SnapshotIdentifier.h
M Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp
M Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h
M Source/WebCore/platform/graphics/cg/ImageBufferCGPDFDocumentBackend.cpp
M Source/WebCore/platform/graphics/cg/ImageBufferCGPDFDocumentBackend.h
M Source/WebCore/platform/graphics/displaylists/DisplayListItem.h
M Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp
M Source/WebCore/platform/graphics/displaylists/DisplayListItems.h
M Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.cpp
M Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.h
M Source/WebKit/GPUProcess/GPUProcess.cpp
M Source/WebKit/GPUProcess/GPUProcess.h
M Source/WebKit/GPUProcess/graphics/RemoteDisplayListRecorder.cpp
M Source/WebKit/GPUProcess/graphics/RemoteDisplayListRecorder.h
M Source/WebKit/GPUProcess/graphics/RemoteDisplayListRecorder.messages.in
M Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp
M Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h
M Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in
M Source/WebKit/Platform/IPC/ObjectIdentifierReference.serialization.in
M Source/WebKit/Scripts/webkit/messages.py
M Source/WebKit/Scripts/webkit/tests/MessageArgumentDescriptions.cpp
M Source/WebKit/Shared/DisplayListArgumentCoders.serialization.in
M Source/WebKit/Shared/WTFArgumentCoders.serialization.in
M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
M Source/WebKit/Sources.txt
M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
M Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp
M Source/WebKit/UIProcess/GPU/GPUProcessProxy.h
M Source/WebKit/UIProcess/GPU/GPUProcessProxy.messages.in
M Source/WebKit/UIProcess/WebPageProxy.cpp
M Source/WebKit/UIProcess/WebPageProxy.h
M Source/WebKit/WebKit.xcodeproj/project.pbxproj
A Source/WebKit/WebProcess/GPU/graphics/ImageBufferRemotePDFDocumentBackend.cpp
A Source/WebKit/WebProcess/GPU/graphics/ImageBufferRemotePDFDocumentBackend.h
M Source/WebKit/WebProcess/GPU/graphics/RemoteDisplayListRecorderProxy.cpp
M Source/WebKit/WebProcess/GPU/graphics/RemoteDisplayListRecorderProxy.h
M Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.cpp
M Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp
M Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h
M Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm
M Source/WebKit/WebProcess/WebPage/WebPage.cpp
M Source/WebKit/WebProcess/WebPage/WebPage.h
M Source/WebKit/WebProcess/WebPage/WebPage.messages.in
M Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Log Message:
-----------
[Site isolation] Snapshotting should be composited in GPUProcess and sent directly to UIProcess
https://bugs.webkit.org/show_bug.cgi?id=284427
rdar://141254954
Reviewed by Matt Woodrow.
Site isolation puts a hard restriction on snapshotting. No WebContent process
is allowed to see the drawing of another remote frame drawing including the main
frame WebContent process. So the drawing of all frames will happen in GPUProcess
and the result will be sent directly to UIProcess.
The plan is to make all the remote frames draw their contents asynchronously into
separate DisplayLists in GPUProcess and then composite all these DisplayLists to
a PDFDocument or to an ShareableBitmap. This final result will sent directly to
UIProcess.
This PR is a step towards achieving this plan for site-isolation. In this PR the
main frame will be only snapshotted in GPUProcess and the result PDF SharedBuffer
will be sent to UIProcess.
The current workflow for PDF snapshotting when site-isolation = off is:
1. [WKWebView createPDFWithConfiguration] calls WebPageProxy::drawToPDF and sends
a callback to be executed once WebProcess replies back.
2. WebPageProxy::drawToPDF sends the message WebPage::DrawToPDF to the main frame
WebProcess.
3. WebPage::drawToPDF creates a local ImageBuffer with PDFDocument backend. Then
it draws the main frame into this ImageBuffer.
4. Once the drawing is finished, the ImageBuffer is sunk into a SharedBuffer which
holds the PDFDocument. The SharedBuffer is sent back to UIProcess through the
completion handler.
5. UIProcess receives the ShareBuffer back from WebProcess and runs the callback
which saves the returned buffer to an external file.
The new workflow for PDF snapshotting when site-isolation = on is:
1. [WKWebView createPDFWithConfiguration] calls WebPageProxy::drawCompositedToPDF()
and sends a callback to be executed once WebProcess replies back.
2. WebPageProxy::drawCompositedToPDF() generates a new SnapshotIdentifier and adds
the callback into the HashMap `m_pdfSnapshots` which is indexed by SnapshotIdentifier.
Then it sends the message WebPage::DrawCompositedToPDF with SnapshotIdentifier.
3. WebPage::drawCompositedToPDF() creates a RemoteImageBufferProxy with PDFDocument
backend. Then it draws the main frame into this ImageBuffer.
4. Once the drawing is finished, it sends RemoteRenderingBackend::DidDrawCompositedToPDF
along with RenderingResourceIdentifier of the RemoteImageBuffer, the
SnapshotIdentifier and the PageIdentifier
5. RemoteRenderingBackend::didDrawCompositedToPDF() gets the specified ImageBuffer
and sinks to a PDFDocument. Then it calls GPUProcess::didDrawCompositedToPDF()
6. GPUProcess::didDrawCompositedToPDF() sends GPUProcessProxy::DidDrawCompositedToPDF
with the SharedBuffer, the SnapshotIdentifier and the PageIdentifier.
7. GPUProcessProxy::didDrawCompositedToPDF() uses the PageIdentifier to find the
sender WebPageProxy. Then it calls WebPageProxy::didDrawCompositedToPDF().
8. WebPageProxy::didDrawCompositedToPDF() gets the associated callback using the
SnapshotIdentifier and runs it which saves the SharedBuffer into a file.
Drawing to PDF context in GPUProcess is done by:
1. The new backend ImageBufferRemotePDFDocumentBackend is added to act like a null
backend for PDF snapshotting in the WebProcess.
2 RemoteRenderingBackendProxy will create an RemoteImageBufferProxy with this
backend if renderingMode is PDFDocument.
3. The DisplayList items BeginPage and EndPage are added to record beginPage()
and endPage() of GraphicsContext.
4. The RemoteDisplayListRecorder messages BeginPage and EndPage are added to
record beginPage() and endPage() of GraphicsContext in GPUProcess.
5. The new message RemoteImageBuffer::SinkToPDFDocument is added which returns
the PDF document as SharedBuffer.
6. Make RemoteImageBufferProxy implement the virtual method sinkToPDFDocument
and make it send the sync message RemoteImageBuffer::SinkToPDFDocument.
* Source/WebCore/Headers.cmake:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::sinkIntoPDFDocument):
(WebCore::ImageBuffer::sinkToPDFDocument): Deleted.
* Source/WebCore/platform/graphics/ImageBuffer.h:
* Source/WebCore/platform/graphics/ImageBufferBackend.cpp:
(WebCore::ImageBufferBackend::calculateSafeBackendSize):
(WebCore::ImageBufferBackend::sinkIntoPDFDocument):
(WebCore::ImageBufferBackend::sinkToPDFDocument): Deleted.
* Source/WebCore/platform/graphics/ImageBufferBackend.h:
* Source/WebCore/platform/graphics/NullImageBufferBackend.h:
* Source/WebCore/platform/graphics/SnapshotIdentifier.h: Added.
* Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.cpp:
(WebCore::ImageBufferCGBitmapBackend::calculateSafeBackendSize): Deleted.
* Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h:
* Source/WebCore/platform/graphics/cg/ImageBufferCGPDFDocumentBackend.cpp:
(WebCore::ImageBufferCGPDFDocumentBackend::sinkIntoPDFDocument):
(WebCore::ImageBufferCGPDFDocumentBackend::sinkToPDFDocument): Deleted.
* Source/WebCore/platform/graphics/cg/ImageBufferCGPDFDocumentBackend.h:
* Source/WebCore/platform/graphics/displaylists/DisplayListItem.h:
* Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp:
(WebCore::DisplayList::ClipToImageBuffer::apply const):
(WebCore::DisplayList::DrawImageBuffer::apply const):
(WebCore::DisplayList::BeginPage::apply const):
(WebCore::DisplayList::BeginPage::dump const):
(WebCore::DisplayList::EndPage::apply const):
* Source/WebCore/platform/graphics/displaylists/DisplayListItems.h:
(WebCore::DisplayList::BeginPage::BeginPage):
(WebCore::DisplayList::BeginPage::pageSize const):
(WebCore::DisplayList::EndPage::dump const):
* Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.cpp:
(WebCore::DisplayList::RecorderImpl::beginPage):
(WebCore::DisplayList::RecorderImpl::endPage):
* Source/WebCore/platform/graphics/displaylists/DisplayListRecorderImpl.h:
* Source/WebKit/GPUProcess/GPUProcess.cpp:
(WebKit::GPUProcess::didDrawCompositedToPDF):
* Source/WebKit/GPUProcess/GPUProcess.h:
* Source/WebKit/GPUProcess/graphics/RemoteDisplayListRecorder.cpp:
(WebKit::RemoteDisplayListRecorder::beginPage):
(WebKit::RemoteDisplayListRecorder::endPage):
* Source/WebKit/GPUProcess/graphics/RemoteDisplayListRecorder.h:
* Source/WebKit/GPUProcess/graphics/RemoteDisplayListRecorder.messages.in:
* Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp:
(WebKit::RemoteRenderingBackend::didCreateImageBuffer):
(WebKit::RemoteRenderingBackend::didDrawCompositedToPDF):
(WebKit::allocateImageBufferInternal):
* Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h:
* Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in:
* Source/WebKit/Platform/IPC/ObjectIdentifierReference.serialization.in:
* Source/WebKit/Scripts/webkit/messages.py:
(serialized_identifiers):
* Source/WebKit/Scripts/webkit/tests/MessageArgumentDescriptions.cpp:
(IPC::serializedIdentifiers):
* Source/WebKit/Shared/DisplayListArgumentCoders.serialization.in:
* Source/WebKit/Shared/WTFArgumentCoders.serialization.in:
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/Sources.txt:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView createPDFWithConfiguration:completionHandler:]):
* Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp:
(WebKit::GPUProcessProxy::didDrawCompositedToPDF):
* Source/WebKit/UIProcess/GPU/GPUProcessProxy.h:
* Source/WebKit/UIProcess/GPU/GPUProcessProxy.messages.in:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::drawCompositedToPDF):
(WebKit::WebPageProxy::didDrawCompositedToPDF):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/GPU/graphics/ImageBufferRemotePDFDocumentBackend.cpp: Added.
(WebKit::ImageBufferRemotePDFDocumentBackend::calculateBytesPerRow):
(WebKit::ImageBufferRemotePDFDocumentBackend::calculateMemoryCost):
(WebKit::ImageBufferRemotePDFDocumentBackend::create):
(WebKit::ImageBufferRemotePDFDocumentBackend::debugDescription const):
* Source/WebKit/WebProcess/GPU/graphics/ImageBufferRemotePDFDocumentBackend.h: Copied from Source/WebCore/platform/graphics/cg/ImageBufferCGBitmapBackend.h.
* Source/WebKit/WebProcess/GPU/graphics/RemoteDisplayListRecorderProxy.cpp:
(WebKit::RemoteDisplayListRecorderProxy::beginPage):
(WebKit::RemoteDisplayListRecorderProxy::endPage):
* Source/WebKit/WebProcess/GPU/graphics/RemoteDisplayListRecorderProxy.h:
* Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.cpp:
(WebKit::RemoteImageBufferProxy::didCreateBackend):
* Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
(WebKit::RemoteRenderingBackendProxy::createImageBuffer):
(WebKit::RemoteRenderingBackendProxy::didDrawCompositedToPDF):
* Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:
* Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::pdfSnapshotAtSize):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::drawMainFrameToPDF):
(WebKit::WebPage::drawToPDF):
(WebKit::WebPage::drawCompositedToPDF):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::drawToPDFiOS):
Canonical link: https://commits.webkit.org/288113@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list