Skip to content

Commit

Permalink
Use smart pointers to store references to ObjectHeap
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270892
rdar://124497369

Reviewed by Mike Wyrzykowski.

We expect the objects to never outlive the ObjectHeap, so use WeakRef
instead of WeakPtr.  However, the objects are ThreadSafeRefCounted,
so if something does happen and something keeps a strong reference to
the objects to keep them alive beyond the lifetime of the ObjectHeap,
we want to dereference null and crash safely instead of using a C++
reference to a freed object.

While I was at it, I did the same with all stored C++ references in
Source/WebKit/GPUProcess, and made withDisplayBufferAsNativeImage
always call its completion handler.

* Source/WebKit/GPUProcess/ShapeDetection/RemoteBarcodeDetector.h:
* Source/WebKit/GPUProcess/ShapeDetection/RemoteFaceDetector.h:
* Source/WebKit/GPUProcess/ShapeDetection/RemoteTextDetector.h:
* Source/WebKit/GPUProcess/ShapeDetection/ShapeDetectionObjectHeap.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteAdapter.cpp:
(WebKit::RemoteAdapter::destruct):
(WebKit::RemoteAdapter::requestDevice):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteAdapter.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteBindGroup.cpp:
(WebKit::RemoteBindGroup::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteBindGroup.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteBindGroupLayout.cpp:
(WebKit::RemoteBindGroupLayout::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteBindGroupLayout.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteBuffer.cpp:
(WebKit::RemoteBuffer::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteBuffer.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCommandBuffer.cpp:
(WebKit::RemoteCommandBuffer::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCommandBuffer.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCommandEncoder.cpp:
(WebKit::RemoteCommandEncoder::destruct):
(WebKit::RemoteCommandEncoder::beginRenderPass):
(WebKit::RemoteCommandEncoder::beginComputePass):
(WebKit::RemoteCommandEncoder::copyBufferToBuffer):
(WebKit::RemoteCommandEncoder::copyBufferToTexture):
(WebKit::RemoteCommandEncoder::copyTextureToBuffer):
(WebKit::RemoteCommandEncoder::copyTextureToTexture):
(WebKit::RemoteCommandEncoder::clearBuffer):
(WebKit::RemoteCommandEncoder::writeTimestamp):
(WebKit::RemoteCommandEncoder::resolveQuerySet):
(WebKit::RemoteCommandEncoder::finish):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCommandEncoder.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCompositorIntegration.cpp:
(WebKit::RemoteCompositorIntegration::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteCompositorIntegration.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteComputePassEncoder.cpp:
(WebKit::RemoteComputePassEncoder::destruct):
(WebKit::RemoteComputePassEncoder::setPipeline):
(WebKit::RemoteComputePassEncoder::dispatchIndirect):
(WebKit::RemoteComputePassEncoder::setBindGroup):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteComputePassEncoder.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteComputePipeline.cpp:
(WebKit::RemoteComputePipeline::destruct):
(WebKit::RemoteComputePipeline::getBindGroupLayout):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteComputePipeline.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteDevice.cpp:
(WebKit::RemoteDevice::destruct):
(WebKit::RemoteDevice::createBuffer):
(WebKit::RemoteDevice::createTexture):
(WebKit::RemoteDevice::createSampler):
(WebKit::RemoteDevice::importExternalTextureFromVideoFrame):
(WebKit::RemoteDevice::createBindGroupLayout):
(WebKit::RemoteDevice::createPipelineLayout):
(WebKit::RemoteDevice::createBindGroup):
(WebKit::RemoteDevice::createShaderModule):
(WebKit::RemoteDevice::createComputePipeline):
(WebKit::RemoteDevice::createRenderPipeline):
(WebKit::RemoteDevice::createComputePipelineAsync):
(WebKit::RemoteDevice::createRenderPipelineAsync):
(WebKit::RemoteDevice::createCommandEncoder):
(WebKit::RemoteDevice::createRenderBundleEncoder):
(WebKit::RemoteDevice::createQuerySet):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteDevice.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteExternalTexture.cpp:
(WebKit::RemoteExternalTexture::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteExternalTexture.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemotePipelineLayout.cpp:
(WebKit::RemotePipelineLayout::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemotePipelineLayout.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemotePresentationContext.cpp:
(WebKit::RemotePresentationContext::configure):
(WebKit::RemotePresentationContext::getCurrentTexture):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemotePresentationContext.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteQuerySet.cpp:
(WebKit::RemoteQuerySet::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteQuerySet.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteQueue.cpp:
(WebKit::RemoteQueue::destruct):
(WebKit::RemoteQueue::submit):
(WebKit::RemoteQueue::writeBuffer):
(WebKit::RemoteQueue::writeTexture):
(WebKit::RemoteQueue::copyExternalImageToTexture):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteQueue.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteRenderBundle.cpp:
(WebKit::RemoteRenderBundle::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteRenderBundle.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteRenderBundleEncoder.cpp:
(WebKit::RemoteRenderBundleEncoder::destruct):
(WebKit::RemoteRenderBundleEncoder::setPipeline):
(WebKit::RemoteRenderBundleEncoder::setIndexBuffer):
(WebKit::RemoteRenderBundleEncoder::setVertexBuffer):
(WebKit::RemoteRenderBundleEncoder::drawIndirect):
(WebKit::RemoteRenderBundleEncoder::drawIndexedIndirect):
(WebKit::RemoteRenderBundleEncoder::setBindGroup):
(WebKit::RemoteRenderBundleEncoder::finish):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteRenderBundleEncoder.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteRenderPassEncoder.cpp:
(WebKit::RemoteRenderPassEncoder::destruct):
(WebKit::RemoteRenderPassEncoder::setPipeline):
(WebKit::RemoteRenderPassEncoder::setIndexBuffer):
(WebKit::RemoteRenderPassEncoder::setVertexBuffer):
(WebKit::RemoteRenderPassEncoder::drawIndirect):
(WebKit::RemoteRenderPassEncoder::drawIndexedIndirect):
(WebKit::RemoteRenderPassEncoder::setBindGroup):
(WebKit::RemoteRenderPassEncoder::setBlendConstant):
(WebKit::RemoteRenderPassEncoder::executeBundles):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteRenderPassEncoder.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteRenderPipeline.cpp:
(WebKit::RemoteRenderPipeline::destruct):
(WebKit::RemoteRenderPipeline::getBindGroupLayout):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteRenderPipeline.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteSampler.cpp:
(WebKit::RemoteSampler::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteSampler.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteShaderModule.cpp:
(WebKit::RemoteShaderModule::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteShaderModule.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteTexture.cpp:
(WebKit::RemoteTexture::createView):
(WebKit::RemoteTexture::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteTexture.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteTextureView.cpp:
(WebKit::RemoteTextureView::destruct):
* Source/WebKit/GPUProcess/graphics/WebGPU/RemoteTextureView.h:
* Source/WebKit/GPUProcess/graphics/WebGPU/WebGPUObjectHeap.h:

Canonical link: https://commits.webkit.org/276036@main
  • Loading branch information
achristensen07 committed Mar 13, 2024
1 parent d83537a commit 60aeffa
Show file tree
Hide file tree
Showing 82 changed files with 268 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ Vector<MachSendRight> CompositorIntegrationImpl::recreateRenderBuffers(int width
}
#endif

void CompositorIntegrationImpl::withDisplayBufferAsNativeImage(uint32_t bufferIndex, Function<void(WebCore::NativeImage&)> completion)
void CompositorIntegrationImpl::withDisplayBufferAsNativeImage(uint32_t bufferIndex, Function<void(WebCore::NativeImage*)> completion)
{
if (!m_renderBuffers.size() || bufferIndex >= m_renderBuffers.size())
return;
return completion(nullptr);

RefPtr<NativeImage> displayImage;

Expand All @@ -98,10 +98,10 @@ void CompositorIntegrationImpl::withDisplayBufferAsNativeImage(uint32_t bufferIn
displayImage = NativeImage::create(renderBuffer->createImage(cgContext.get()));

if (!displayImage)
return;
return completion(nullptr);

CGImageSetCachingFlags(displayImage->platformImage().get(), kCGImageCachingTransient);
completion(*displayImage);
completion(displayImage.get());
}

void CompositorIntegrationImpl::paintCompositedResultsToCanvas(WebCore::ImageBuffer&, uint32_t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CompositorIntegrationImpl final : public CompositorIntegration {
m_onSubmittedWorkScheduledCallback = WTFMove(onSubmittedWorkScheduledCallback);
}

void withDisplayBufferAsNativeImage(uint32_t bufferIndex, Function<void(WebCore::NativeImage&)>) final;
void withDisplayBufferAsNativeImage(uint32_t bufferIndex, Function<void(WebCore::NativeImage*)>) final;
void paintCompositedResultsToCanvas(WebCore::ImageBuffer&, uint32_t) final;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CompositorIntegration : public RefCounted<CompositorIntegration> {
#endif

virtual void prepareForDisplay(CompletionHandler<void()>&&) = 0;
virtual void withDisplayBufferAsNativeImage(uint32_t bufferIndex, Function<void(WebCore::NativeImage&)>) = 0;
virtual void withDisplayBufferAsNativeImage(uint32_t bufferIndex, Function<void(WebCore::NativeImage*)>) = 0;
virtual void paintCompositedResultsToCanvas(WebCore::ImageBuffer&, uint32_t bufferIndex) = 0;

protected:
Expand Down
28 changes: 14 additions & 14 deletions Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ class GPUProxyForCapture final : public UserMediaCaptureManagerProxy::Connection
}

private:
Logger& logger() final { return m_process.logger(); }
Logger& logger() final { return m_process->logger(); }
void addMessageReceiver(IPC::ReceiverName, IPC::MessageReceiver&) final { }
void removeMessageReceiver(IPC::ReceiverName messageReceiverName) final { }
IPC::Connection& connection() final { return m_process.connection(); }
IPC::Connection& connection() final { return m_process->connection(); }
bool willStartCapture(CaptureDevice::DeviceType type) const final
{
switch (type) {
Expand All @@ -195,38 +195,38 @@ class GPUProxyForCapture final : public UserMediaCaptureManagerProxy::Connection
case CaptureDevice::DeviceType::Speaker:
return false;
case CaptureDevice::DeviceType::Microphone:
return m_process.allowsAudioCapture();
return m_process->allowsAudioCapture();
case CaptureDevice::DeviceType::Camera:
if (!m_process.allowsVideoCapture())
if (!m_process->allowsVideoCapture())
return false;
#if PLATFORM(IOS) || PLATFORM(VISION)
MediaSessionManageriOS::providePresentingApplicationPID();
#endif
return true;
break;
case CaptureDevice::DeviceType::Screen:
return m_process.allowsDisplayCapture();
return m_process->allowsDisplayCapture();
case CaptureDevice::DeviceType::Window:
return m_process.allowsDisplayCapture();
return m_process->allowsDisplayCapture();
}
}

bool setCaptureAttributionString() final
{
return m_process.setCaptureAttributionString();
return m_process->setCaptureAttributionString();
}

#if ENABLE(APP_PRIVACY_REPORT)
void setTCCIdentity() final
{
m_process.setTCCIdentity();
m_process->setTCCIdentity();
}
#endif

#if ENABLE(EXTENSION_CAPABILITIES)
bool setCurrentMediaEnvironment(WebCore::PageIdentifier pageIdentifier) final
{
auto mediaEnvironment = m_process.mediaEnvironment(pageIdentifier);
auto mediaEnvironment = m_process->mediaEnvironment(pageIdentifier);
bool result = !mediaEnvironment.isEmpty();
WebCore::RealtimeMediaSourceCenter::singleton().setCurrentMediaEnvironment(WTFMove(mediaEnvironment));
return result;
Expand All @@ -236,21 +236,21 @@ class GPUProxyForCapture final : public UserMediaCaptureManagerProxy::Connection
void startProducingData(CaptureDevice::DeviceType type) final
{
if (type == CaptureDevice::DeviceType::Microphone)
m_process.startCapturingAudio();
m_process->startCapturingAudio();
#if PLATFORM(IOS)
else if (type == CaptureDevice::DeviceType::Camera)
m_process.overridePresentingApplicationPIDIfNeeded();
m_process->overridePresentingApplicationPIDIfNeeded();
#endif
}

const ProcessIdentity& resourceOwner() const final
{
return m_process.webProcessIdentity();
return m_process->webProcessIdentity();
}

RemoteVideoFrameObjectHeap* remoteVideoFrameObjectHeap() final { return &m_process.videoFrameObjectHeap(); }
RemoteVideoFrameObjectHeap* remoteVideoFrameObjectHeap() final { return &m_process->videoFrameObjectHeap(); }

GPUConnectionToWebProcess& m_process;
WeakRef<GPUConnectionToWebProcess> m_process;
};

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RemoteBarcodeDetector::~RemoteBarcodeDetector() = default;

void RemoteBarcodeDetector::detect(WebCore::RenderingResourceIdentifier renderingResourceIdentifier, CompletionHandler<void(Vector<WebCore::ShapeDetection::DetectedBarcode>&&)>&& completionHandler)
{
auto sourceImage = m_backend.imageBuffer(renderingResourceIdentifier);
auto sourceImage = m_backend->imageBuffer(renderingResourceIdentifier);
if (!sourceImage) {
completionHandler({ });
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <wtf/CompletionHandler.h>
#include <wtf/Ref.h>
#include <wtf/Vector.h>
#include <wtf/WeakRef.h>

namespace WebCore::ShapeDetection {
class BarcodeDetector;
Expand Down Expand Up @@ -75,8 +76,8 @@ class RemoteBarcodeDetector : public IPC::StreamMessageReceiver {
void detect(WebCore::RenderingResourceIdentifier, CompletionHandler<void(Vector<WebCore::ShapeDetection::DetectedBarcode>&&)>&&);

Ref<WebCore::ShapeDetection::BarcodeDetector> m_backing;
ShapeDetection::ObjectHeap& m_objectHeap;
RemoteRenderingBackend& m_backend;
WeakRef<ShapeDetection::ObjectHeap> m_objectHeap;
WeakRef<RemoteRenderingBackend> m_backend;
const ShapeDetectionIdentifier m_identifier;
const WebCore::ProcessIdentifier m_webProcessIdentifier;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ RemoteFaceDetector::~RemoteFaceDetector() = default;

void RemoteFaceDetector::detect(WebCore::RenderingResourceIdentifier renderingResourceIdentifier, CompletionHandler<void(Vector<WebCore::ShapeDetection::DetectedFace>&&)>&& completionHandler)
{
auto sourceImage = m_backend.imageBuffer(renderingResourceIdentifier);
auto sourceImage = m_backend->imageBuffer(renderingResourceIdentifier);
if (!sourceImage) {
completionHandler({ });
return;
Expand Down
5 changes: 3 additions & 2 deletions Source/WebKit/GPUProcess/ShapeDetection/RemoteFaceDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <wtf/CompletionHandler.h>
#include <wtf/Ref.h>
#include <wtf/Vector.h>
#include <wtf/WeakRef.h>

namespace WebCore::ShapeDetection {
struct DetectedFace;
Expand Down Expand Up @@ -74,8 +75,8 @@ class RemoteFaceDetector : public IPC::StreamMessageReceiver {
void detect(WebCore::RenderingResourceIdentifier, CompletionHandler<void(Vector<WebCore::ShapeDetection::DetectedFace>&&)>&&);

Ref<WebCore::ShapeDetection::FaceDetector> m_backing;
ShapeDetection::ObjectHeap& m_objectHeap;
RemoteRenderingBackend& m_backend;
WeakRef<ShapeDetection::ObjectHeap> m_objectHeap;
WeakRef<RemoteRenderingBackend> m_backend;
const ShapeDetectionIdentifier m_identifier;
const WebCore::ProcessIdentifier m_webProcessIdentifier;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ RemoteTextDetector::~RemoteTextDetector() = default;

void RemoteTextDetector::detect(WebCore::RenderingResourceIdentifier renderingResourceIdentifier, CompletionHandler<void(Vector<WebCore::ShapeDetection::DetectedText>&&)>&& completionHandler)
{
auto imageBuffer = m_backend.imageBuffer(renderingResourceIdentifier);
auto imageBuffer = m_backend->imageBuffer(renderingResourceIdentifier);
if (!imageBuffer) {
completionHandler({ });
return;
Expand Down
5 changes: 3 additions & 2 deletions Source/WebKit/GPUProcess/ShapeDetection/RemoteTextDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <wtf/CompletionHandler.h>
#include <wtf/Ref.h>
#include <wtf/Vector.h>
#include <wtf/WeakRef.h>

namespace WebCore::ShapeDetection {
struct DetectedText;
Expand Down Expand Up @@ -74,8 +75,8 @@ class RemoteTextDetector : public IPC::StreamMessageReceiver {
void detect(WebCore::RenderingResourceIdentifier, CompletionHandler<void(Vector<WebCore::ShapeDetection::DetectedText>&&)>&&);

Ref<WebCore::ShapeDetection::TextDetector> m_backing;
ShapeDetection::ObjectHeap& m_objectHeap;
RemoteRenderingBackend& m_backend;
WeakRef<ShapeDetection::ObjectHeap> m_objectHeap;
WeakRef<RemoteRenderingBackend> m_backend;
const ShapeDetectionIdentifier m_identifier;
const WebCore::ProcessIdentifier m_webProcessIdentifier;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <variant>
#include <wtf/HashMap.h>
#include <wtf/Ref.h>
#include <wtf/WeakPtr.h>

namespace WebCore::ShapeDetection {
class BarcodeDetector;
Expand All @@ -48,7 +49,7 @@ class RemoteTextDetector;

namespace WebKit::ShapeDetection {

class ObjectHeap final : public RefCounted<ObjectHeap> {
class ObjectHeap final : public RefCounted<ObjectHeap>, public CanMakeWeakPtr<ObjectHeap> {
WTF_MAKE_FAST_ALLOCATED;
public:
static Ref<ObjectHeap> create()
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <WebCore/ProcessIdentity.h>
#include <WebCore/RenderingResourceIdentifier.h>
#include <wtf/HashMap.h>
#include <wtf/WeakPtr.h>

namespace WTF {
enum class Critical : bool;
Expand Down Expand Up @@ -88,7 +89,7 @@ namespace ShapeDetection {
class ObjectHeap;
}

class RemoteRenderingBackend : private IPC::MessageSender, public IPC::StreamMessageReceiver {
class RemoteRenderingBackend : private IPC::MessageSender, public IPC::StreamMessageReceiver, public CanMakeWeakPtr<RemoteRenderingBackend> {
public:
static Ref<RemoteRenderingBackend> create(GPUConnectionToWebProcess&, RemoteRenderingBackendCreationParameters&&, Ref<IPC::StreamServerConnection>&&);
virtual ~RemoteRenderingBackend();
Expand Down
6 changes: 3 additions & 3 deletions Source/WebKit/GPUProcess/graphics/WebGPU/RemoteAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ RemoteAdapter::~RemoteAdapter() = default;

void RemoteAdapter::destruct()
{
m_objectHeap.removeObject(m_identifier);
m_objectHeap->removeObject(m_identifier);
}

void RemoteAdapter::stopListeningForIPC()
Expand All @@ -65,14 +65,14 @@ void RemoteAdapter::stopListeningForIPC()

void RemoteAdapter::requestDevice(const WebGPU::DeviceDescriptor& descriptor, WebGPUIdentifier identifier, WebGPUIdentifier queueIdentifier, CompletionHandler<void(WebGPU::SupportedFeatures&&, WebGPU::SupportedLimits&&)>&& callback)
{
auto convertedDescriptor = m_objectHeap.convertFromBacking(descriptor);
auto convertedDescriptor = m_objectHeap->convertFromBacking(descriptor);
ASSERT(convertedDescriptor);
if (!convertedDescriptor) {
callback({ { } }, { });
return;
}

m_backing->requestDevice(*convertedDescriptor, [callback = WTFMove(callback), objectHeap = Ref { m_objectHeap }, streamConnection = m_streamConnection.copyRef(), identifier, queueIdentifier, &gpuConnectionToWebProcess = m_gpuConnectionToWebProcess] (RefPtr<WebCore::WebGPU::Device>&& devicePtr) mutable {
m_backing->requestDevice(*convertedDescriptor, [callback = WTFMove(callback), objectHeap = Ref { m_objectHeap.get() }, streamConnection = m_streamConnection.copyRef(), identifier, queueIdentifier, &gpuConnectionToWebProcess = m_gpuConnectionToWebProcess] (RefPtr<WebCore::WebGPU::Device>&& devicePtr) mutable {
if (!devicePtr.get()) {
callback({ }, { });
return;
Expand Down
5 changes: 3 additions & 2 deletions Source/WebKit/GPUProcess/graphics/WebGPU/RemoteAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "WebGPUIdentifier.h"
#include <wtf/CompletionHandler.h>
#include <wtf/Ref.h>
#include <wtf/WeakRef.h>

namespace WebCore::WebGPU {
class Adapter;
Expand Down Expand Up @@ -80,9 +81,9 @@ class RemoteAdapter final : public IPC::StreamMessageReceiver {
void destruct();

Ref<WebCore::WebGPU::Adapter> m_backing;
WebGPU::ObjectHeap& m_objectHeap;
WeakRef<WebGPU::ObjectHeap> m_objectHeap;
Ref<IPC::StreamServerConnection> m_streamConnection;
GPUConnectionToWebProcess& m_gpuConnectionToWebProcess;
WeakRef<GPUConnectionToWebProcess> m_gpuConnectionToWebProcess;
WebGPUIdentifier m_identifier;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ RemoteBindGroup::~RemoteBindGroup() = default;

void RemoteBindGroup::destruct()
{
m_objectHeap.removeObject(m_identifier);
m_objectHeap->removeObject(m_identifier);
}

void RemoteBindGroup::stopListeningForIPC()
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/GPUProcess/graphics/WebGPU/RemoteBindGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "StreamMessageReceiver.h"
#include "WebGPUIdentifier.h"
#include <wtf/Ref.h>
#include <wtf/WeakRef.h>
#include <wtf/text/WTFString.h>

namespace WebCore::WebGPU {
Expand Down Expand Up @@ -76,7 +77,7 @@ class RemoteBindGroup final : public IPC::StreamMessageReceiver {
void destruct();

Ref<WebCore::WebGPU::BindGroup> m_backing;
WebGPU::ObjectHeap& m_objectHeap;
WeakRef<WebGPU::ObjectHeap> m_objectHeap;
Ref<IPC::StreamServerConnection> m_streamConnection;
WebGPUIdentifier m_identifier;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ RemoteBindGroupLayout::~RemoteBindGroupLayout() = default;

void RemoteBindGroupLayout::destruct()
{
m_objectHeap.removeObject(m_identifier);
m_objectHeap->removeObject(m_identifier);
}

void RemoteBindGroupLayout::stopListeningForIPC()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "StreamMessageReceiver.h"
#include "WebGPUIdentifier.h"
#include <wtf/Ref.h>
#include <wtf/WeakRef.h>
#include <wtf/text/WTFString.h>

namespace WebCore::WebGPU {
Expand Down Expand Up @@ -76,7 +77,7 @@ class RemoteBindGroupLayout final : public IPC::StreamMessageReceiver {
void destruct();

Ref<WebCore::WebGPU::BindGroupLayout> m_backing;
WebGPU::ObjectHeap& m_objectHeap;
WeakRef<WebGPU::ObjectHeap> m_objectHeap;
Ref<IPC::StreamServerConnection> m_streamConnection;
WebGPUIdentifier m_identifier;
};
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/GPUProcess/graphics/WebGPU/RemoteBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void RemoteBuffer::destroy()

void RemoteBuffer::destruct()
{
m_objectHeap.removeObject(m_identifier);
m_objectHeap->removeObject(m_identifier);
}

void RemoteBuffer::setLabel(String&& label)
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/GPUProcess/graphics/WebGPU/RemoteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <wtf/CompletionHandler.h>
#include <wtf/Ref.h>
#include <wtf/Vector.h>
#include <wtf/WeakRef.h>
#include <wtf/text/WTFString.h>

namespace WebCore::WebGPU {
Expand Down Expand Up @@ -87,7 +88,7 @@ class RemoteBuffer final : public IPC::StreamMessageReceiver {
void setLabel(String&&);

Ref<WebCore::WebGPU::Buffer> m_backing;
WebGPU::ObjectHeap& m_objectHeap;
WeakRef<WebGPU::ObjectHeap> m_objectHeap;
Ref<IPC::StreamServerConnection> m_streamConnection;
WebGPUIdentifier m_identifier;
bool m_isMapped { false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ RemoteCommandBuffer::~RemoteCommandBuffer() = default;

void RemoteCommandBuffer::destruct()
{
m_objectHeap.removeObject(m_identifier);
m_objectHeap->removeObject(m_identifier);
}

void RemoteCommandBuffer::stopListeningForIPC()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "StreamMessageReceiver.h"
#include "WebGPUIdentifier.h"
#include <wtf/Ref.h>
#include <wtf/WeakRef.h>
#include <wtf/text/WTFString.h>

namespace WebCore::WebGPU {
Expand Down Expand Up @@ -76,7 +77,7 @@ class RemoteCommandBuffer final : public IPC::StreamMessageReceiver {
void destruct();

Ref<WebCore::WebGPU::CommandBuffer> m_backing;
WebGPU::ObjectHeap& m_objectHeap;
WeakRef<WebGPU::ObjectHeap> m_objectHeap;
Ref<IPC::StreamServerConnection> m_streamConnection;
WebGPUIdentifier m_identifier;
};
Expand Down
Loading

0 comments on commit 60aeffa

Please sign in to comment.