Title: [275922] trunk/Source/WebKit
Revision
275922
Author
[email protected]
Date
2021-04-13 18:00:24 -0700 (Tue, 13 Apr 2021)

Log Message

RemoteRenderingBackendProxy should only relaunch the GPUProcess if it actually needs it
https://bugs.webkit.org/show_bug.cgi?id=224516

Reviewed by Geoff Garen.

Previously, RemoteRenderingBackendProxy would launch the GPUProcess as soon as it was
constructed. This went against the goals of r275887 to delay the GPUProcess launch
until it is actually needed. Also, in case a a GPUProcess crash/termination,
RemoteRenderingBackendProxy would relaunch the GPUProcess right away, even if it
did not need it (No live ImageBuffers). This patch addresses both issues.

This patch is a pre-requirement for terminating the GPUProcess on memory pressure when
it is not used by any tabs.

* WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
(WebKit::RemoteRenderingBackendProxy::~RemoteRenderingBackendProxy):
(WebKit::RemoteRenderingBackendProxy::ensureGPUProcessConnection):
(WebKit::RemoteRenderingBackendProxy::gpuProcessConnectionDidClose):
(WebKit::RemoteRenderingBackendProxy::messageSenderConnection const):
(WebKit::RemoteRenderingBackendProxy::waitForDidCreateImageBufferBackend):
(WebKit::RemoteRenderingBackendProxy::waitForDidFlush):
* WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (275921 => 275922)


--- trunk/Source/WebKit/ChangeLog	2021-04-14 00:37:03 UTC (rev 275921)
+++ trunk/Source/WebKit/ChangeLog	2021-04-14 01:00:24 UTC (rev 275922)
@@ -1,5 +1,30 @@
 2021-04-13  Chris Dumez  <[email protected]>
 
+        RemoteRenderingBackendProxy should only relaunch the GPUProcess if it actually needs it
+        https://bugs.webkit.org/show_bug.cgi?id=224516
+
+        Reviewed by Geoff Garen.
+
+        Previously, RemoteRenderingBackendProxy would launch the GPUProcess as soon as it was
+        constructed. This went against the goals of r275887 to delay the GPUProcess launch
+        until it is actually needed. Also, in case a a GPUProcess crash/termination,
+        RemoteRenderingBackendProxy would relaunch the GPUProcess right away, even if it
+        did not need it (No live ImageBuffers). This patch addresses both issues.
+
+        This patch is a pre-requirement for terminating the GPUProcess on memory pressure when
+        it is not used by any tabs.
+
+        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
+        (WebKit::RemoteRenderingBackendProxy::~RemoteRenderingBackendProxy):
+        (WebKit::RemoteRenderingBackendProxy::ensureGPUProcessConnection):
+        (WebKit::RemoteRenderingBackendProxy::gpuProcessConnectionDidClose):
+        (WebKit::RemoteRenderingBackendProxy::messageSenderConnection const):
+        (WebKit::RemoteRenderingBackendProxy::waitForDidCreateImageBufferBackend):
+        (WebKit::RemoteRenderingBackendProxy::waitForDidFlush):
+        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:
+
+2021-04-13  Chris Dumez  <[email protected]>
+
         Stop requiring a RemoteRenderingBackend for visibility propagation views
         https://bugs.webkit.org/show_bug.cgi?id=224513
 

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp (275921 => 275922)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp	2021-04-14 00:37:03 UTC (rev 275921)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp	2021-04-14 01:00:24 UTC (rev 275922)
@@ -55,42 +55,36 @@
         webPage.identifier()
     }
 {
-    connectToGPUProcess();
 }
 
 RemoteRenderingBackendProxy::~RemoteRenderingBackendProxy()
 {
+    if (!m_gpuProcessConnection)
+        return;
+
     // Un-register itself as a MessageReceiver.
-    IPC::MessageReceiverMap& messageReceiverMap = WebProcess::singleton().ensureGPUProcessConnection().messageReceiverMap();
-    messageReceiverMap.removeMessageReceiver(*this);
+    m_gpuProcessConnection->messageReceiverMap().removeMessageReceiver(*this);
 
     // Release the RemoteRenderingBackend.
     send(Messages::GPUConnectionToWebProcess::ReleaseRenderingBackend(renderingBackendIdentifier()), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
 }
 
-void RemoteRenderingBackendProxy::connectToGPUProcess()
+GPUProcessConnection& RemoteRenderingBackendProxy::ensureGPUProcessConnection()
 {
-    auto& connection = WebProcess::singleton().ensureGPUProcessConnection();
-    connection.addClient(*this);
-    connection.messageReceiverMap().addMessageReceiver(Messages::RemoteRenderingBackendProxy::messageReceiverName(), renderingBackendIdentifier().toUInt64(), *this);
-    send(Messages::GPUConnectionToWebProcess::CreateRenderingBackend(m_parameters), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
-}
-
-void RemoteRenderingBackendProxy::reestablishGPUProcessConnection()
-{
-    connectToGPUProcess();
-
-    for (auto& imageBuffer : m_remoteResourceCacheProxy.imageBuffers().values()) {
-        if (!imageBuffer)
-            continue;
-        send(Messages::RemoteRenderingBackend::CreateImageBuffer(imageBuffer->logicalSize(), imageBuffer->renderingMode(), imageBuffer->resolutionScale(), imageBuffer->colorSpace(), imageBuffer->pixelFormat(), imageBuffer->renderingResourceIdentifier()), renderingBackendIdentifier(), IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
-        imageBuffer->clearBackend();
+    if (!m_gpuProcessConnection) {
+        auto& gpuProcessConnection = WebProcess::singleton().ensureGPUProcessConnection();
+        gpuProcessConnection.addClient(*this);
+        gpuProcessConnection.messageReceiverMap().addMessageReceiver(Messages::RemoteRenderingBackendProxy::messageReceiverName(), renderingBackendIdentifier().toUInt64(), *this);
+        gpuProcessConnection.connection().send(Messages::GPUConnectionToWebProcess::CreateRenderingBackend(m_parameters), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
+        m_gpuProcessConnection = makeWeakPtr(gpuProcessConnection);
     }
+    return *m_gpuProcessConnection;
 }
 
 void RemoteRenderingBackendProxy::gpuProcessConnectionDidClose(GPUProcessConnection& previousConnection)
 {
     previousConnection.removeClient(*this);
+    m_gpuProcessConnection = nullptr;
 
     m_identifiersOfReusableHandles.clear();
     m_sharedDisplayListHandles.clear();
@@ -98,12 +92,17 @@
     m_deferredWakeupMessageArguments = WTF::nullopt;
     m_remainingItemsToAppendBeforeSendingWakeup = 0;
 
-    reestablishGPUProcessConnection();
+    for (auto& imageBuffer : m_remoteResourceCacheProxy.imageBuffers().values()) {
+        if (!imageBuffer)
+            continue;
+        send(Messages::RemoteRenderingBackend::CreateImageBuffer(imageBuffer->logicalSize(), imageBuffer->renderingMode(), imageBuffer->resolutionScale(), imageBuffer->colorSpace(), imageBuffer->pixelFormat(), imageBuffer->renderingResourceIdentifier()), renderingBackendIdentifier(), IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
+        imageBuffer->clearBackend();
+    }
 }
 
 IPC::Connection* RemoteRenderingBackendProxy::messageSenderConnection() const
 {
-    return &WebProcess::singleton().ensureGPUProcessConnection().connection();
+    return &const_cast<RemoteRenderingBackendProxy&>(*this).ensureGPUProcessConnection().connection();
 }
 
 uint64_t RemoteRenderingBackendProxy::messageSenderDestinationID() const
@@ -113,7 +112,7 @@
 
 RemoteRenderingBackendProxy::DidReceiveBackendCreationResult RemoteRenderingBackendProxy::waitForDidCreateImageBufferBackend()
 {
-    Ref<IPC::Connection> connection = WebProcess::singleton().ensureGPUProcessConnection().connection();
+    auto connection = makeRefPtr(messageSenderConnection());
     if (!connection->waitForAndDispatchImmediately<Messages::RemoteRenderingBackendProxy::DidCreateImageBufferBackend>(renderingBackendIdentifier(), 1_s, IPC::WaitForOption::InterruptWaitingIfSyncMessageArrives))
         return DidReceiveBackendCreationResult::TimeoutOrIPCFailure;
     return DidReceiveBackendCreationResult::ReceivedAnyResponse;
@@ -121,7 +120,7 @@
 
 bool RemoteRenderingBackendProxy::waitForDidFlush()
 {
-    Ref<IPC::Connection> connection = WebProcess::singleton().ensureGPUProcessConnection().connection();
+    auto connection = makeRefPtr(messageSenderConnection());
     return connection->waitForAndDispatchImmediately<Messages::RemoteRenderingBackendProxy::DidFlush>(renderingBackendIdentifier(), 1_s, IPC::WaitForOption::InterruptWaitingIfSyncMessageArrives);
 }
 

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h (275921 => 275922)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h	2021-04-14 00:37:03 UTC (rev 275921)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h	2021-04-14 01:00:24 UTC (rev 275922)
@@ -116,8 +116,7 @@
     // GPUProcessConnection::Client
     void gpuProcessConnectionDidClose(GPUProcessConnection&) final;
 
-    void connectToGPUProcess();
-    void reestablishGPUProcessConnection();
+    GPUProcessConnection& ensureGPUProcessConnection();
 
     // Messages to be received.
     void didCreateImageBufferBackend(ImageBufferBackendHandle, WebCore::RenderingResourceIdentifier);
@@ -139,6 +138,7 @@
     RefPtr<SharedMemory> m_getImageDataSharedMemory;
     uint64_t m_getImageDataSharedMemoryLength { 0 };
     WebCore::Timer m_destroyGetImageDataSharedMemoryTimer { *this, &RemoteRenderingBackendProxy::destroyGetImageDataSharedMemory };
+    WeakPtr<GPUProcessConnection> m_gpuProcessConnection;
 };
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to