Skip to content
Permalink
Browse files
Rename SharedBufferCopy to SharedBufferReference
https://bugs.webkit.org/show_bug.cgi?id=240796
rdar://problem/93754681

Patch by Jean-Yves Avenard <jyavenard@gmail.com> on 2022-05-24
Reviewed by Jer Noble.

1. SharedBufferCopy doesn't perform a copy, but passes SharedMemory and return a SharedBuffer that wraps such SharedMemory.
Rename it to SharedBufferReference to more accurately reflect what it actually does.

2. Remove SharedBufferCopy::safeBuffer() and rename
 SharedBufferCopy::buffer with SharedBufferCopy::unsafeBuffer. This gives
 better clarity that accessing SharedBufferCopy should be treated with care.

3. Add SharedBufferCopy::isNull() method
4. When passing a SharedBufferReferal across multiple processes, we remove the need for a new allocation and copy of the content; instead we move the underlying SharedMemory.

No change of observable behaviour.

* Source/WebKit/GPUProcess/media/RemoteCDMInstanceProxy.h:
* Source/WebKit/GPUProcess/media/RemoteImageDecoderAVFProxy.cpp:
(WebKit::RemoteImageDecoderAVFProxy::createDecoder):
(WebKit::RemoteImageDecoderAVFProxy::setData):
* Source/WebKit/GPUProcess/media/RemoteImageDecoderAVFProxy.h:
* Source/WebKit/GPUProcess/media/RemoteImageDecoderAVFProxy.messages.in:
* Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::bufferingTimerFired):
(WebKit::NetworkResourceLoader::sendBuffer):
(WebKit::NetworkResourceLoader::dataReceivedThroughContentFilter):
* Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.cpp:
(WebKit::ServiceWorkerDownloadTask::didReceiveData):
* Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.h:
* Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerDownloadTask.messages.in:
* Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp:
(WebKit::ServiceWorkerFetchTask::didReceiveData):
(WebKit::ServiceWorkerFetchTask::loadBodyFromPreloader):
* Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.h:
* Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.messages.in:
* Source/WebKit/Platform/IPC/SharedBufferCopy.cpp: Removed.
* Source/WebKit/Platform/IPC/SharedBufferCopy.h: Removed.
* Source/WebKit/Platform/IPC/SharedBufferReference.cpp: Added.
(IPC::SharedBufferReference::encode const):
(IPC::SharedBufferReference::decode):
(IPC::SharedBufferReference::unsafeBuffer const):
(IPC::SharedBufferReference::data const):
* Source/WebKit/Platform/IPC/SharedBufferReference.h: Added.
(IPC::SharedBufferReference::SharedBufferReference):
(IPC::SharedBufferReference::size const):
(IPC::SharedBufferReference::isEmpty const):
(IPC::SharedBufferReference::isNull const):
* Source/WebKit/Shared/RemoteLayerTree/CGDisplayListImageBufferBackend.cpp:
(WebKit::CGDisplayListImageBufferBackend::createBackendHandle const):
* Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::applyBackingStoreToLayer):
* Source/WebKit/Sources.txt:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView createPDFWithConfiguration:completionHandler:]):
* Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::platformRegisterAttachment):
* Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm:
(WebKit::WebProcessProxy::sendAudioComponentRegistrations):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::CompletionHandler<void):
(WebKit::WebPageProxy::drawToPDF):
(WebKit::WebPageProxy::getLoadDecisionForIcon):
(WebKit::WebPageProxy::updateAttachmentAttributes):
(WebKit::WebPageProxy::registerAttachmentIdentifierFromData):
(WebKit::WebPageProxy::platformRegisterAttachment):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/WebPageProxy.messages.in:
* Source/WebKit/UIProcess/WebPasteboardProxy.h:
* Source/WebKit/UIProcess/WebPasteboardProxy.messages.in:
* Source/WebKit/UIProcess/WebURLSchemeTask.cpp:
(WebKit::WebURLSchemeTask::didReceiveData):
* Source/WebKit/UIProcess/gtk/WebPasteboardProxyGtk.cpp:
(WebKit::WebPasteboardProxy::readBuffer):
* Source/WebKit/UIProcess/ios/WKContentView.mm:
(-[WKContentView _wk_pageCountForPrintFormatter:]):
* Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::drawToPDFiOS):
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/GPU/graphics/ImageBufferBackendHandle.h:
* Source/WebKit/WebProcess/GPU/media/RemoteImageDecoderAVF.cpp:
(WebKit::RemoteImageDecoderAVF::setData):
* Source/WebKit/WebProcess/GPU/media/RemoteImageDecoderAVFManager.cpp:
(WebKit::RemoteImageDecoderAVFManager::createImageDecoder):
* Source/WebKit/WebProcess/Network/WebResourceLoader.cpp:
(WebKit::WebResourceLoader::didReceiveData):
* Source/WebKit/WebProcess/Network/WebResourceLoader.h:
* Source/WebKit/WebProcess/Network/WebResourceLoader.messages.in:
* Source/WebKit/WebProcess/Storage/WebServiceWorkerFetchTaskClient.cpp:
(WebKit::WebServiceWorkerFetchTaskClient::didReceiveData):
(WebKit::WebServiceWorkerFetchTaskClient::didReceiveBlobChunk):
* Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp:
* Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::registerAttachmentIdentifier):
* Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::readBufferFromClipboard):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::getContentsAsMHTMLData):
(WebKit::WebPage::getSelectionAsWebArchiveData):
(WebKit::WebPage::getMainResourceDataOfFrame):
(WebKit::WebPage::getResourceDataFromFrame):
(WebKit::WebPage::getWebArchiveOfFrame):
(WebKit::WebPage::getAccessibilityTreeData):
(WebKit::WebPage::drawToPDF):
(WebKit::WebPage::drawPagesToPDF):
(WebKit::WebPage::didGetLoadDecisionForIcon):
(WebKit::WebPage::urlSchemeTaskDidReceiveData):
(WebKit::WebPage::updateAttachmentAttributes):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::drawToPDFiOS):
* Source/WebKit/WebProcess/WebProcess.h:
* Source/WebKit/WebProcess/WebProcess.messages.in:
* Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::consumeAudioComponentRegistrations):

Canonical link: https://commits.webkit.org/250949@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294790 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
jyavenard authored and webkit-commit-queue committed May 25, 2022
1 parent a867a9a commit 7003d0d99c34a2ad46faa61c444ef26d8db513f4
Showing 48 changed files with 370 additions and 286 deletions.
@@ -42,7 +42,7 @@ struct CDMKeySystemConfiguration;
}

namespace IPC {
class SharedBufferCopy;
class SharedBufferReference;
}

namespace WebKit {
@@ -32,7 +32,7 @@
#include "GPUProcess.h"
#include "RemoteImageDecoderAVFManagerMessages.h"
#include "RemoteImageDecoderAVFProxyMessages.h"
#include "SharedBufferCopy.h"
#include "SharedBufferReference.h"
#include "WebCoreArgumentCoders.h"
#include <WebCore/IOSurface.h>
#include <WebCore/ImageDecoderAVFObjC.h>
@@ -46,9 +46,9 @@ RemoteImageDecoderAVFProxy::RemoteImageDecoderAVFProxy(GPUConnectionToWebProcess
{
}

void RemoteImageDecoderAVFProxy::createDecoder(const IPC::SharedBufferCopy& data, const String& mimeType, CompletionHandler<void(std::optional<ImageDecoderIdentifier>&&)>&& completionHandler)
void RemoteImageDecoderAVFProxy::createDecoder(const IPC::SharedBufferReference& data, const String& mimeType, CompletionHandler<void(std::optional<ImageDecoderIdentifier>&&)>&& completionHandler)
{
auto imageDecoder = ImageDecoderAVFObjC::create(data.safeBuffer(), mimeType, AlphaOption::Premultiplied, GammaAndColorProfileOption::Ignored);
auto imageDecoder = ImageDecoderAVFObjC::create(data.isNull() ? SharedBuffer::create() : data.unsafeBuffer().releaseNonNull(), mimeType, AlphaOption::Premultiplied, GammaAndColorProfileOption::Ignored);

std::optional<ImageDecoderIdentifier> imageDecoderIdentifier;
if (!imageDecoder)
@@ -94,7 +94,7 @@ void RemoteImageDecoderAVFProxy::setExpectedContentSize(ImageDecoderIdentifier i
m_imageDecoders.get(identifier)->setExpectedContentSize(expectedContentSize);
}

void RemoteImageDecoderAVFProxy::setData(ImageDecoderIdentifier identifier, const IPC::SharedBufferCopy& data, bool allDataReceived, CompletionHandler<void(size_t frameCount, const IntSize& size, bool hasTrack, std::optional<Vector<ImageDecoder::FrameInfo>>&&)>&& completionHandler)
void RemoteImageDecoderAVFProxy::setData(ImageDecoderIdentifier identifier, const IPC::SharedBufferReference& data, bool allDataReceived, CompletionHandler<void(size_t frameCount, const IntSize& size, bool hasTrack, std::optional<Vector<ImageDecoder::FrameInfo>>&&)>&& completionHandler)
{
ASSERT(m_imageDecoders.contains(identifier));
if (!m_imageDecoders.contains(identifier)) {
@@ -103,7 +103,7 @@ void RemoteImageDecoderAVFProxy::setData(ImageDecoderIdentifier identifier, cons
}

auto imageDecoder = m_imageDecoders.get(identifier);
imageDecoder->setData(data.safeBuffer(), allDataReceived);
imageDecoder->setData(data.isNull() ? SharedBuffer::create() : data.unsafeBuffer().releaseNonNull(), allDataReceived);

auto frameCount = imageDecoder->frameCount();

@@ -37,7 +37,7 @@
#include <wtf/WeakPtr.h>

namespace IPC {
class SharedBufferCopy;
class SharedBufferReference;
}

namespace WebKit {
@@ -56,10 +56,10 @@ class RemoteImageDecoderAVFProxy : private IPC::MessageReceiver {
bool allowsExitUnderMemoryPressure() const;

private:
void createDecoder(const IPC::SharedBufferCopy&, const String& mimeType, CompletionHandler<void(std::optional<WebCore::ImageDecoderIdentifier>&&)>&&);
void createDecoder(const IPC::SharedBufferReference&, const String& mimeType, CompletionHandler<void(std::optional<WebCore::ImageDecoderIdentifier>&&)>&&);
void deleteDecoder(WebCore::ImageDecoderIdentifier);
void setExpectedContentSize(WebCore::ImageDecoderIdentifier, long long expectedContentSize);
void setData(WebCore::ImageDecoderIdentifier, const IPC::SharedBufferCopy&, bool allDataReceived, CompletionHandler<void(size_t frameCount, const WebCore::IntSize& size, bool hasTrack, std::optional<Vector<WebCore::ImageDecoder::FrameInfo>>&&)>&&);
void setData(WebCore::ImageDecoderIdentifier, const IPC::SharedBufferReference&, bool allDataReceived, CompletionHandler<void(size_t frameCount, const WebCore::IntSize& size, bool hasTrack, std::optional<Vector<WebCore::ImageDecoder::FrameInfo>>&&)>&&);
void createFrameImageAtIndex(WebCore::ImageDecoderIdentifier, size_t index, CompletionHandler<void(std::optional<WTF::MachSendRight>&&, std::optional<WebCore::DestinationColorSpace>&&)>&&);
void clearFrameBufferCache(WebCore::ImageDecoderIdentifier, size_t index);

@@ -28,10 +28,10 @@
#if ENABLE(GPU_PROCESS) && HAVE(AVASSETREADER)

messages -> RemoteImageDecoderAVFProxy NotRefCounted {
CreateDecoder(IPC::SharedBufferCopy data, String mimeType) -> (std::optional<WebCore::ImageDecoderIdentifier> identifier) Synchronous
CreateDecoder(IPC::SharedBufferReference data, String mimeType) -> (std::optional<WebCore::ImageDecoderIdentifier> identifier) Synchronous
DeleteDecoder(WebCore::ImageDecoderIdentifier identifier)
SetExpectedContentSize(WebCore::ImageDecoderIdentifier identifier, long long expectedContentSize)
SetData(WebCore::ImageDecoderIdentifier identifier, IPC::SharedBufferCopy data, bool allDataReceived) -> (size_t frameCount, WebCore::IntSize size, bool hasTrack, std::optional<Vector<WebCore::ImageDecoder::FrameInfo>> frameInfos) Synchronous
SetData(WebCore::ImageDecoderIdentifier identifier, IPC::SharedBufferReference data, bool allDataReceived) -> (size_t frameCount, WebCore::IntSize size, bool hasTrack, std::optional<Vector<WebCore::ImageDecoder::FrameInfo>> frameInfos) Synchronous
CreateFrameImageAtIndex(WebCore::ImageDecoderIdentifier identifier, size_t index) -> (std::optional<MachSendRight> sendRight, std::optional<WebCore::DestinationColorSpace> colorSpace) Synchronous
ClearFrameBufferCache(WebCore::ImageDecoderIdentifier identifier, size_t index)
}
@@ -1346,9 +1346,9 @@ void NetworkResourceLoader::bufferingTimerFired()
auto sharedBuffer = m_bufferedData.takeAsContiguous();
bool shouldFilter = m_contentFilter && !m_contentFilter->continueAfterDataReceived(sharedBuffer, m_bufferedDataEncodedDataLength);
if (!shouldFilter)
send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferCopy(sharedBuffer.get()), m_bufferedDataEncodedDataLength));
send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferReference(sharedBuffer.get()), m_bufferedDataEncodedDataLength));
#else
send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferCopy(*m_bufferedData.get()), m_bufferedDataEncodedDataLength));
send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferReference(*m_bufferedData.get()), m_bufferedDataEncodedDataLength));
#endif
m_bufferedData.empty();
m_bufferedDataEncodedDataLength = 0;
@@ -1363,7 +1363,7 @@ void NetworkResourceLoader::sendBuffer(const FragmentedSharedBuffer& buffer, siz
return;
#endif

send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferCopy(buffer), encodedDataLength));
send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferReference(buffer), encodedDataLength));
}

void NetworkResourceLoader::tryStoreAsCacheEntry()
@@ -1820,7 +1820,7 @@ bool NetworkResourceLoader::isAppInitiated()
#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS)
void NetworkResourceLoader::dataReceivedThroughContentFilter(const SharedBuffer& buffer, size_t encodedDataLength)
{
send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferCopy(buffer), encodedDataLength));
send(Messages::WebResourceLoader::DidReceiveData(IPC::SharedBufferReference(buffer), encodedDataLength));
}

WebCore::ResourceError NetworkResourceLoader::contentFilterDidBlock(WebCore::ContentFilterUnblockHandler unblockHandler, String&& unblockRequestDeniedScript)
@@ -32,7 +32,7 @@
#include "Logging.h"
#include "NetworkProcess.h"
#include "ServiceWorkerDownloadTaskMessages.h"
#include "SharedBufferCopy.h"
#include "SharedBufferReference.h"
#include "WebErrors.h"
#include "WebSWContextManagerConnectionMessages.h"
#include "WebSWServerToContextConnection.h"
@@ -181,7 +181,7 @@ void ServiceWorkerDownloadTask::start()
downloadPtr->didCreateDestination(m_pendingDownloadLocation);
}

void ServiceWorkerDownloadTask::didReceiveData(const IPC::SharedBufferCopy& data, int64_t encodedDataLength)
void ServiceWorkerDownloadTask::didReceiveData(const IPC::SharedBufferReference& data, int64_t encodedDataLength)
{
ASSERT(!isMainRunLoop());

@@ -37,7 +37,7 @@

namespace IPC {
class FormDataReference;
class SharedBufferCopy;
class SharedBufferReference;
}

namespace WebKit {
@@ -73,7 +73,7 @@ class ServiceWorkerDownloadTask : public NetworkDataTask, public IPC::Connection
void startListeningForIPC();

// IPC Message
void didReceiveData(const IPC::SharedBufferCopy&, int64_t encodedDataLength);
void didReceiveData(const IPC::SharedBufferReference&, int64_t encodedDataLength);
void didReceiveFormData(const IPC::FormDataReference&);
void didFinish();
void didFail(WebCore::ResourceError&&);
@@ -24,7 +24,7 @@

messages -> ServiceWorkerDownloadTask NotRefCounted {
DidFail(WebCore::ResourceError error)
DidReceiveData(IPC::SharedBufferCopy data, int64_t encodedDataLength)
DidReceiveData(IPC::SharedBufferReference data, int64_t encodedDataLength)
DidReceiveFormData(IPC::FormDataReference data)
DidFinish()
}
@@ -37,7 +37,7 @@
#include "NetworkSession.h"
#include "PrivateRelayed.h"
#include "ServiceWorkerNavigationPreloader.h"
#include "SharedBufferCopy.h"
#include "SharedBufferReference.h"
#include "WebCoreArgumentCoders.h"
#include "WebResourceLoaderMessages.h"
#include "WebSWContextManagerConnectionMessages.h"
@@ -232,7 +232,7 @@ void ServiceWorkerFetchTask::processResponse(ResourceResponse&& response, bool n
m_loader.setResponse(WTFMove(response));
}

void ServiceWorkerFetchTask::didReceiveData(const IPC::SharedBufferCopy& data, int64_t encodedDataLength)
void ServiceWorkerFetchTask::didReceiveData(const IPC::SharedBufferReference& data, int64_t encodedDataLength)
{
if (m_isDone)
return;
@@ -416,7 +416,7 @@ void ServiceWorkerFetchTask::loadBodyFromPreloader()
didFinish(m_preloader->networkLoadMetrics());
return;
}
didReceiveData(IPC::SharedBufferCopy(const_cast<WebCore::FragmentedSharedBuffer&>(*chunk)), length);
didReceiveData(IPC::SharedBufferReference(const_cast<WebCore::FragmentedSharedBuffer&>(*chunk)), length);
});
}

@@ -48,7 +48,7 @@ namespace IPC {
class Connection;
class Decoder;
class FormDataReference;
class SharedBufferCopy;
class SharedBufferReference;
}

namespace WebCore {
@@ -94,7 +94,7 @@ class ServiceWorkerFetchTask : public CanMakeWeakPtr<ServiceWorkerFetchTask> {
enum class ShouldSetSource : bool { No, Yes };
void didReceiveRedirectResponse(WebCore::ResourceResponse&&);
void didReceiveResponse(WebCore::ResourceResponse&&, bool needsContinueDidReceiveResponseMessage);
void didReceiveData(const IPC::SharedBufferCopy&, int64_t encodedDataLength);
void didReceiveData(const IPC::SharedBufferReference&, int64_t encodedDataLength);
void didReceiveFormData(const IPC::FormDataReference&);
void didFinish(const WebCore::NetworkLoadMetrics&);
void didFail(const WebCore::ResourceError&);
@@ -27,7 +27,7 @@ messages -> ServiceWorkerFetchTask NotRefCounted {
DidFail(WebCore::ResourceError error)
DidReceiveRedirectResponse(WebCore::ResourceResponse response)
DidReceiveResponse(WebCore::ResourceResponse response, bool needsContinueDidReceiveResponseMessage)
DidReceiveData(IPC::SharedBufferCopy data, int64_t encodedDataLength)
DidReceiveData(IPC::SharedBufferReference data, int64_t encodedDataLength)
DidReceiveFormData(IPC::FormDataReference data)
DidFinish(WebCore::NetworkLoadMetrics metrics)
}

This file was deleted.

This file was deleted.

0 comments on commit 7003d0d

Please sign in to comment.