Skip to content

Commit 5b5498b

Browse files
committed
Support running per-thread instances of RemoteGraphicsContextGLProxy
https://bugs.webkit.org/show_bug.cgi?id=248557 Reviewed by Kimmo Kinnunen. This removes the GPUProcessConnection, and instead relies on the StreamClientConnection to receive notifications when the GPUP has gone away. * Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp: (WebKit::RemoteGraphicsContextGLProxy::RemoteGraphicsContextGLProxy): (WebKit::RemoteGraphicsContextGLProxy::paintCompositedResultsToVideoFrame): (WebKit::RemoteGraphicsContextGLProxy::didClose): (WebKit::RemoteGraphicsContextGLProxy::abandonGpuProcess): (WebKit::RemoteGraphicsContextGLProxy::disconnectGpuProcessIfNeeded): (WebKit::RemoteGraphicsContextGLProxy::gpuProcessConnectionDidClose): Deleted. * Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h: (WebKit::RemoteGraphicsContextGLProxy::isContextLost const): * Source/WebKit/WebProcess/GPU/graphics/cocoa/RemoteGraphicsContextGLProxyCocoa.mm: (WebKit::RemoteGraphicsContextGLProxy::create): * Source/WebKit/WebProcess/GPU/graphics/gbm/RemoteGraphicsContextGLProxyGBM.cpp: (WebKit::RemoteGraphicsContextGLProxyGBM::RemoteGraphicsContextGLProxyGBM): (WebKit::RemoteGraphicsContextGLProxy::create): * Source/WebKit/WebProcess/GPU/graphics/wc/RemoteGraphicsContextGLProxyWC.cpp: (WebKit::RemoteGraphicsContextGLProxy::create): * Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::createGraphicsContextGL const): Canonical link: https://commits.webkit.org/257534@main
1 parent 7a91f36 commit 5b5498b

File tree

6 files changed

+34
-36
lines changed

6 files changed

+34
-36
lines changed

Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,14 @@ IPC::ArrayReferenceTuple<Types...> toArrayReferenceTuple(const GCGLSpanTuple<Spa
6666

6767
}
6868

69-
RemoteGraphicsContextGLProxy::RemoteGraphicsContextGLProxy(GPUProcessConnection& gpuProcessConnection, const GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
69+
RemoteGraphicsContextGLProxy::RemoteGraphicsContextGLProxy(IPC::Connection& connection, SerialFunctionDispatcher& dispatcher, const GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
7070
: GraphicsContextGL(attributes)
71-
, m_gpuProcessConnection(&gpuProcessConnection)
7271
{
7372
auto [clientConnection, serverConnectionHandle] = IPC::StreamClientConnection::create(defaultStreamSize);
7473
m_streamConnection = WTFMove(clientConnection);
75-
m_gpuProcessConnection->addClient(*this);
76-
m_gpuProcessConnection->connection().send(Messages::GPUConnectionToWebProcess::CreateGraphicsContextGL(attributes, m_graphicsContextGLIdentifier, renderingBackend, WTFMove(serverConnectionHandle)), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
77-
m_streamConnection->open(*this);
74+
m_connection = &connection;
75+
m_connection->send(Messages::GPUConnectionToWebProcess::CreateGraphicsContextGL(attributes, m_graphicsContextGLIdentifier, renderingBackend, WTFMove(serverConnectionHandle)), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
76+
m_streamConnection->open(*this, dispatcher);
7877
// TODO: We must wait until initialized, because at the moment we cannot receive IPC messages
7978
// during wait while in synchronous stream send. Should be fixed as part of https://bugs.webkit.org/show_bug.cgi?id=217211.
8079
waitUntilInitialized();
@@ -193,6 +192,7 @@ void RemoteGraphicsContextGLProxy::paintCompositedResultsToCanvas(ImageBuffer& b
193192
#if ENABLE(MEDIA_STREAM)
194193
RefPtr<WebCore::VideoFrame> RemoteGraphicsContextGLProxy::paintCompositedResultsToVideoFrame()
195194
{
195+
ASSERT(isMainRunLoop());
196196
if (isContextLost())
197197
return nullptr;
198198
auto sendResult = sendSync(Messages::RemoteGraphicsContextGL::PaintCompositedResultsToVideoFrame());
@@ -203,7 +203,7 @@ RefPtr<WebCore::VideoFrame> RemoteGraphicsContextGLProxy::paintCompositedResults
203203
auto [result] = sendResult.takeReply();
204204
if (!result)
205205
return nullptr;
206-
return RemoteVideoFrameProxy::create(m_gpuProcessConnection->connection(), m_gpuProcessConnection->videoFrameObjectHeapProxy(), WTFMove(*result));
206+
return RemoteVideoFrameProxy::create(WebProcess::singleton().ensureGPUProcessConnection().connection(), WebProcess::singleton().ensureGPUProcessConnection().videoFrameObjectHeapProxy(), WTFMove(*result));
207207
}
208208
#endif
209209

@@ -394,7 +394,7 @@ void RemoteGraphicsContextGLProxy::waitUntilInitialized()
394394
markContextLost();
395395
}
396396

397-
void RemoteGraphicsContextGLProxy::gpuProcessConnectionDidClose(GPUProcessConnection&)
397+
void RemoteGraphicsContextGLProxy::didClose(IPC::Connection&)
398398
{
399399
ASSERT(!isContextLost());
400400
abandonGpuProcess();
@@ -403,17 +403,15 @@ void RemoteGraphicsContextGLProxy::gpuProcessConnectionDidClose(GPUProcessConnec
403403

404404
void RemoteGraphicsContextGLProxy::abandonGpuProcess()
405405
{
406-
auto gpuProcessConnection = std::exchange(m_gpuProcessConnection, nullptr);
407-
gpuProcessConnection->removeClient(*this);
408-
m_gpuProcessConnection = nullptr;
406+
m_connection = nullptr;
409407
}
410408

411409
void RemoteGraphicsContextGLProxy::disconnectGpuProcessIfNeeded()
412410
{
413-
if (auto gpuProcessConnection = std::exchange(m_gpuProcessConnection, nullptr)) {
411+
if (m_connection) {
414412
m_streamConnection->invalidate();
415-
gpuProcessConnection->removeClient(*this);
416-
gpuProcessConnection->connection().send(Messages::GPUConnectionToWebProcess::ReleaseGraphicsContextGL(m_graphicsContextGLIdentifier), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
413+
m_connection->send(Messages::GPUConnectionToWebProcess::ReleaseGraphicsContextGL(m_graphicsContextGLIdentifier), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
414+
m_connection = nullptr;
417415
}
418416
ASSERT(isContextLost());
419417
}

Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ namespace WebKit {
4949
// The implementation is largely generated by running Tools/Scripts/generate-gpup-webgl.
5050
class RemoteGraphicsContextGLProxy
5151
: private IPC::Connection::Client
52-
, private GPUProcessConnection::Client
5352
, public WebCore::GraphicsContextGL {
5453
public:
55-
static RefPtr<RemoteGraphicsContextGLProxy> create(const WebCore::GraphicsContextGLAttributes&, RenderingBackendIdentifier);
54+
static RefPtr<RemoteGraphicsContextGLProxy> create(IPC::Connection&, const WebCore::GraphicsContextGLAttributes&, RemoteRenderingBackendProxy&);
5655
~RemoteGraphicsContextGLProxy();
5756

5857
// IPC::Connection::Client overrides.
5958
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
60-
void didClose(IPC::Connection&) final { }
59+
void didClose(IPC::Connection&) final;
6160
void didReceiveInvalidMessage(IPC::Connection&, IPC::MessageName) final { }
6261

6362
// WebCore::GraphicsContextGL overrides.
@@ -342,9 +341,9 @@ class RemoteGraphicsContextGLProxy
342341

343342
static bool handleMessageToRemovedDestination(IPC::Connection&, IPC::Decoder&);
344343
protected:
345-
RemoteGraphicsContextGLProxy(GPUProcessConnection&, const WebCore::GraphicsContextGLAttributes&, RenderingBackendIdentifier);
344+
RemoteGraphicsContextGLProxy(IPC::Connection&, SerialFunctionDispatcher&, const WebCore::GraphicsContextGLAttributes&, RenderingBackendIdentifier);
346345

347-
bool isContextLost() const { return !m_gpuProcessConnection; }
346+
bool isContextLost() const { return !m_connection; }
348347
void markContextLost();
349348

350349
static inline Seconds defaultSendTimeout = 30_s;
@@ -366,15 +365,12 @@ class RemoteGraphicsContextGLProxy
366365
void wasLost();
367366
void wasChanged();
368367

369-
// GPUProcessConnection::Client overrides.
370-
void gpuProcessConnectionDidClose(GPUProcessConnection&) final;
371-
372368
void initialize(const String& availableExtensions, const String& requestableExtensions);
373369
void waitUntilInitialized();
374370
void disconnectGpuProcessIfNeeded();
375371
void abandonGpuProcess();
376372

377-
GPUProcessConnection* m_gpuProcessConnection;
373+
RefPtr<IPC::Connection> m_connection;
378374
bool m_didInitialize { false };
379375
// Guarded by waitUntilInitialized().
380376
HashSet<String> m_availableExtensions;

Source/WebKit/WebProcess/GPU/graphics/cocoa/RemoteGraphicsContextGLProxyCocoa.mm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#import "config.h"
2727
#import "RemoteGraphicsContextGLProxy.h"
2828

29+
#import "RemoteRenderingBackendProxy.h"
30+
2931
#if ENABLE(GPU_PROCESS) && ENABLE(WEBGL)
3032
#import "GPUConnectionToWebProcess.h"
3133
#import "GPUProcessConnection.h"
@@ -99,8 +101,8 @@ void setDisplayBuffer(const MachSendRight& displayBuffer)
99101
WebCore::GraphicsContextGLCV* asCV() final { return nullptr; }
100102
#endif
101103
private:
102-
RemoteGraphicsContextGLProxyCocoa(GPUProcessConnection& gpuProcessConnection, const WebCore::GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
103-
: RemoteGraphicsContextGLProxy(gpuProcessConnection, attributes, renderingBackend)
104+
RemoteGraphicsContextGLProxyCocoa(IPC::Connection& connection, SerialFunctionDispatcher& dispatcher, const WebCore::GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
105+
: RemoteGraphicsContextGLProxy(connection, dispatcher, attributes, renderingBackend)
104106
, m_layerContentsDisplayDelegate(DisplayBufferDisplayDelegate::create(!attributes.alpha, attributes.devicePixelRatio))
105107
{
106108
}
@@ -129,9 +131,9 @@ void setDisplayBuffer(const MachSendRight& displayBuffer)
129131

130132
}
131133

132-
RefPtr<RemoteGraphicsContextGLProxy> RemoteGraphicsContextGLProxy::create(const WebCore::GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
134+
RefPtr<RemoteGraphicsContextGLProxy> RemoteGraphicsContextGLProxy::create(IPC::Connection& connection, const WebCore::GraphicsContextGLAttributes& attributes, RemoteRenderingBackendProxy& renderingBackend)
133135
{
134-
return adoptRef(new RemoteGraphicsContextGLProxyCocoa(WebProcess::singleton().ensureGPUProcessConnection(), attributes, renderingBackend));
136+
return adoptRef(new RemoteGraphicsContextGLProxyCocoa(connection, renderingBackend.dispatcher(), attributes, renderingBackend.ensureBackendCreated()));
135137
}
136138

137139
}

Source/WebKit/WebProcess/GPU/graphics/gbm/RemoteGraphicsContextGLProxyGBM.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "config.h"
2828
#include "RemoteGraphicsContextGLProxy.h"
29+
#include "RemoteRenderingBackendProxy.h"
2930

3031
#if ENABLE(GPU_PROCESS) && ENABLE(WEBGL) && USE(LIBGBM)
3132

@@ -99,7 +100,7 @@ void NicosiaDisplayDelegate::swapBuffersIfNeeded()
99100

100101
class RemoteGraphicsContextGLProxyGBM final : public RemoteGraphicsContextGLProxy {
101102
public:
102-
RemoteGraphicsContextGLProxyGBM(GPUProcessConnection&, const WebCore::GraphicsContextGLAttributes&, RenderingBackendIdentifier);
103+
RemoteGraphicsContextGLProxyGBM(IPC::Connection&, SerialFunctionDispatcher&, const WebCore::GraphicsContextGLAttributes&, RenderingBackendIdentifier);
103104
virtual ~RemoteGraphicsContextGLProxyGBM() = default;
104105

105106
private:
@@ -110,8 +111,8 @@ class RemoteGraphicsContextGLProxyGBM final : public RemoteGraphicsContextGLProx
110111
Ref<NicosiaDisplayDelegate> m_layerContentsDisplayDelegate;
111112
};
112113

113-
RemoteGraphicsContextGLProxyGBM::RemoteGraphicsContextGLProxyGBM(GPUProcessConnection& processConnection, const WebCore::GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
114-
: RemoteGraphicsContextGLProxy(processConnection, attributes, renderingBackend)
114+
RemoteGraphicsContextGLProxyGBM::RemoteGraphicsContextGLProxyGBM(IPC::Connection& connection, SerialFunctionDispatcher& dispatcher, const WebCore::GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
115+
: RemoteGraphicsContextGLProxy(connection, dispatcher, attributes, renderingBackend)
115116
, m_layerContentsDisplayDelegate(adoptRef(*new NicosiaDisplayDelegate(!attributes.alpha)))
116117
{ }
117118

@@ -136,9 +137,9 @@ void RemoteGraphicsContextGLProxyGBM::prepareForDisplay()
136137
markLayerComposited();
137138
}
138139

139-
RefPtr<RemoteGraphicsContextGLProxy> RemoteGraphicsContextGLProxy::create(const WebCore::GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
140+
RefPtr<RemoteGraphicsContextGLProxy> RemoteGraphicsContextGLProxy::create(IPC::Connection& connection, const WebCore::GraphicsContextGLAttributes& attributes, RemoteRenderingBackendProxy& renderingBackend)
140141
{
141-
return adoptRef(new RemoteGraphicsContextGLProxyGBM(WebProcess::singleton().ensureGPUProcessConnection(), attributes, renderingBackend));
142+
return adoptRef(new RemoteGraphicsContextGLProxyGBM(connection, renderingBackend.dispatcher(), attributes, renderingBackend.ensureBackendCreated()));
142143
}
143144

144145
} // namespace WebKit

Source/WebKit/WebProcess/GPU/graphics/wc/RemoteGraphicsContextGLProxyWC.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "GPUConnectionToWebProcess.h"
3232
#include "GPUProcessConnection.h"
3333
#include "RemoteGraphicsContextGLMessages.h"
34+
#include "RemoteRenderingBackendProxy.h"
3435
#include "WCPlatformLayerGCGL.h"
3536
#include "WebProcess.h"
3637
#include <WebCore/GraphicsLayerContentsDisplayDelegate.h>
@@ -70,8 +71,8 @@ class RemoteGraphicsContextGLProxyWC final : public RemoteGraphicsContextGLProxy
7071
RefPtr<WebCore::VideoFrame> paintCompositedResultsToVideoFrame() final { return nullptr; }
7172
#endif
7273
private:
73-
RemoteGraphicsContextGLProxyWC(GPUProcessConnection& gpuProcessConnection, const WebCore::GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
74-
: RemoteGraphicsContextGLProxy(gpuProcessConnection, attributes, renderingBackend)
74+
RemoteGraphicsContextGLProxyWC(IPC::Connection& connection, SerialFunctionDispatcher& dispatcher, const WebCore::GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
75+
: RemoteGraphicsContextGLProxy(connection, dispatcher, attributes, renderingBackend)
7576
, m_layerContentsDisplayDelegate(PlatformLayerDisplayDelegate::create(makeUnique<WCPlatformLayerGCGL>()))
7677
{
7778
}
@@ -97,9 +98,9 @@ void RemoteGraphicsContextGLProxyWC::prepareForDisplay()
9798

9899
}
99100

100-
RefPtr<RemoteGraphicsContextGLProxy> RemoteGraphicsContextGLProxy::create(const WebCore::GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
101+
RefPtr<RemoteGraphicsContextGLProxy> RemoteGraphicsContextGLProxy::create(IPC::Connection& connection, const WebCore::GraphicsContextGLAttributes& attributes, RemoteRenderingBackendProxy& renderingBackend)
101102
{
102-
return adoptRef(new RemoteGraphicsContextGLProxyWC(WebProcess::singleton().ensureGPUProcessConnection(), attributes, renderingBackend));
103+
return adoptRef(new RemoteGraphicsContextGLProxyWC(connection, renderingBackend.dispatcher(), attributes, renderingBackend.ensureBackendCreated()));
103104
}
104105

105106
}

Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ RefPtr<GraphicsContextGL> WebChromeClient::createGraphicsContextGL(const Graphic
923923
{
924924
#if ENABLE(GPU_PROCESS)
925925
if (WebProcess::singleton().shouldUseRemoteRenderingForWebGL())
926-
return RemoteGraphicsContextGLProxy::create(attributes, m_page.ensureRemoteRenderingBackendProxy().ensureBackendCreated());
926+
return RemoteGraphicsContextGLProxy::create(WebProcess::singleton().ensureGPUProcessConnection().connection(), attributes, m_page.ensureRemoteRenderingBackendProxy());
927927
#endif
928928
return WebCore::createWebProcessGraphicsContextGL(attributes);
929929
}

0 commit comments

Comments
 (0)