commit c19fcf010e8d31dbdc4990f8fb15efc675d2d69c
parent cbe021867d387eb143f9a57eff6bdd88a3e8774e
Author: Jamie Nicol <jnicol@mozilla.com>
Date: Mon, 24 Nov 2025 09:00:18 +0000
Bug 2001152 - Make PCompositorBridge::Initialize async. r=aosmond,ipc-reviewers,mccr8
This call being synchronous currently ensures that
CompositorBridgeParent::RecvInitialize() has completed prior to
GPUParent::RecvInitAPZInputBridge() or
GPUParent::RecvInitUiCompositorController() being called. These both
require that the LayerTreeState corresponding to their aRootLayersId
has already been added to the map.
By moving these messages from PGPU to PCompositorBridge we can
guarantee this ordering while making Initialize() asynchronous.
Differential Revision: https://phabricator.services.mozilla.com/D273239
Diffstat:
10 files changed, 48 insertions(+), 42 deletions(-)
diff --git a/gfx/ipc/GPUParent.cpp b/gfx/ipc/GPUParent.cpp
@@ -46,7 +46,6 @@
#include "mozilla/ipc/CrashReporterClient.h"
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/ipc/ProcessUtils.h"
-#include "mozilla/layers/APZInputBridgeParent.h"
#include "mozilla/layers/APZPublicUtils.h" // for apz::InitializeGlobalState
#include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/CompositorBridgeParent.h"
@@ -55,7 +54,6 @@
#include "mozilla/layers/ImageBridgeParent.h"
#include "mozilla/layers/LayerTreeOwnerTracker.h"
#include "mozilla/layers/RemoteTextureMap.h"
-#include "mozilla/layers/UiCompositorControllerParent.h"
#include "mozilla/layers/VideoBridgeParent.h"
#include "mozilla/webrender/RenderThread.h"
#include "mozilla/webrender/WebRenderAPI.h"
@@ -472,20 +470,6 @@ mozilla::ipc::IPCResult GPUParent::RecvInitVR(
return IPC_OK();
}
-mozilla::ipc::IPCResult GPUParent::RecvInitUiCompositorController(
- const LayersId& aRootLayerTreeId,
- Endpoint<PUiCompositorControllerParent>&& aEndpoint) {
- UiCompositorControllerParent::Start(aRootLayerTreeId, std::move(aEndpoint));
- return IPC_OK();
-}
-
-mozilla::ipc::IPCResult GPUParent::RecvInitAPZInputBridge(
- const LayersId& aRootLayerTreeId,
- Endpoint<PAPZInputBridgeParent>&& aEndpoint) {
- APZInputBridgeParent::Create(aRootLayerTreeId, std::move(aEndpoint));
- return IPC_OK();
-}
-
mozilla::ipc::IPCResult GPUParent::RecvInitProfiler(
Endpoint<PProfilerChild>&& aEndpoint) {
mProfilerController = ChildProfilerController::Create(std::move(aEndpoint));
diff --git a/gfx/ipc/GPUParent.h b/gfx/ipc/GPUParent.h
@@ -66,12 +66,6 @@ class GPUParent final : public PGPUParent {
mozilla::ipc::IPCResult RecvInitVRManager(
Endpoint<PVRManagerParent>&& aEndpoint);
mozilla::ipc::IPCResult RecvInitVR(Endpoint<PVRGPUChild>&& aVRGPUChild);
- mozilla::ipc::IPCResult RecvInitUiCompositorController(
- const LayersId& aRootLayerTreeId,
- Endpoint<PUiCompositorControllerParent>&& aEndpoint);
- mozilla::ipc::IPCResult RecvInitAPZInputBridge(
- const LayersId& aRootLayerTreeId,
- Endpoint<PAPZInputBridgeParent>&& aEndpoint);
mozilla::ipc::IPCResult RecvInitProfiler(
Endpoint<PProfilerChild>&& aEndpoint);
mozilla::ipc::IPCResult RecvUpdateVar(const nsTArray<GfxVarUpdate>& var);
diff --git a/gfx/ipc/GPUProcessManager.cpp b/gfx/ipc/GPUProcessManager.cpp
@@ -1303,12 +1303,12 @@ RefPtr<CompositorSession> GPUProcessManager::CreateRemoteSession(
ipc::Endpoint<PAPZInputBridgeParent> parentPipe;
ipc::Endpoint<PAPZInputBridgeChild> childPipe;
nsresult rv = PAPZInputBridge::CreateEndpoints(
- mGPUChild->OtherEndpointProcInfo(), ipc::EndpointProcInfo::Current(),
+ child->OtherEndpointProcInfo(), ipc::EndpointProcInfo::Current(),
&parentPipe, &childPipe);
if (NS_FAILED(rv)) {
return nullptr;
}
- mGPUChild->SendInitAPZInputBridge(aRootLayerTreeId, std::move(parentPipe));
+ child->SendInitAPZInputBridge(std::move(parentPipe));
RefPtr<APZInputBridgeChild> inputBridge =
APZInputBridgeChild::Create(mProcessToken, std::move(childPipe));
@@ -1325,13 +1325,12 @@ RefPtr<CompositorSession> GPUProcessManager::CreateRemoteSession(
ipc::Endpoint<PUiCompositorControllerParent> parentPipe;
ipc::Endpoint<PUiCompositorControllerChild> childPipe;
nsresult rv = PUiCompositorController::CreateEndpoints(
- mGPUChild->OtherEndpointProcInfo(), ipc::EndpointProcInfo::Current(),
+ child->OtherEndpointProcInfo(), ipc::EndpointProcInfo::Current(),
&parentPipe, &childPipe);
if (NS_FAILED(rv)) {
return nullptr;
}
- mGPUChild->SendInitUiCompositorController(aRootLayerTreeId,
- std::move(parentPipe));
+ child->SendInitUiCompositorController(std::move(parentPipe));
uiController = UiCompositorControllerChild::CreateForGPUProcess(
mProcessToken, std::move(childPipe), aWidget);
MOZ_ASSERT(uiController);
diff --git a/gfx/ipc/PGPU.ipdl b/gfx/ipc/PGPU.ipdl
@@ -8,7 +8,6 @@ include GraphicsMessages;
include MemoryReportTypes;
include HangTypes;
include PrefsTypes;
-include protocol PAPZInputBridge;
include protocol PCompositorManager;
include protocol PImageBridge;
include protocol PProfiler;
@@ -16,7 +15,6 @@ include protocol PVRGPU;
include protocol PVRManager;
include protocol PVideoBridge;
include protocol PVsyncBridge;
-include protocol PUiCompositorController;
include protocol PRemoteMediaManager;
#if defined(MOZ_SANDBOX) && defined(MOZ_DEBUG) && defined(ENABLE_TESTS)
@@ -73,9 +71,6 @@ parent:
async InitImageBridge(Endpoint<PImageBridgeParent> endpoint);
async InitVideoBridge(Endpoint<PVideoBridgeParent> endpoint, VideoBridgeSource aSource);
async InitVRManager(Endpoint<PVRManagerParent> endpoint);
- async InitUiCompositorController(LayersId rootLayerTreeId, Endpoint<PUiCompositorControllerParent> endpoint);
- async InitAPZInputBridge(LayersId layersId,
- Endpoint<PAPZInputBridgeParent> endpoint);
async InitProfiler(Endpoint<PProfilerChild> endpoint);
// Forward GPU process its endpoints to the VR process.
async InitVR(Endpoint<PVRGPUChild> endpoint);
diff --git a/gfx/layers/ipc/CompositorBridgeParent.cpp b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -32,6 +32,7 @@
#include "mozilla/gfx/GPUParent.h"
#include "mozilla/gfx/GPUProcessManager.h"
#include "mozilla/layers/APZCTreeManagerParent.h" // for APZCTreeManagerParent
+#include "mozilla/layers/APZInputBridgeParent.h" // for APZInputBridgeParent
#include "mozilla/layers/APZSampler.h" // for APZSampler
#include "mozilla/layers/APZThreadUtils.h" // for APZThreadUtils
#include "mozilla/layers/APZUpdater.h" // for APZUpdater
@@ -383,6 +384,20 @@ void CompositorBridgeParent::StopAndClearResources() {
mAnimationStorage = nullptr;
}
+mozilla::ipc::IPCResult CompositorBridgeParent::RecvInitAPZInputBridge(
+ Endpoint<PAPZInputBridgeParent>&& aEndpoint) {
+ NS_DispatchToMainThread(NewRunnableFunction(
+ "APZInputBridgeParent::Create", &APZInputBridgeParent::Create,
+ mRootLayerTreeID, std::move(aEndpoint)));
+ return IPC_OK();
+}
+
+mozilla::ipc::IPCResult CompositorBridgeParent::RecvInitUiCompositorController(
+ Endpoint<PUiCompositorControllerParent>&& aEndpoint) {
+ UiCompositorControllerParent::Start(mRootLayerTreeID, std::move(aEndpoint));
+ return IPC_OK();
+}
+
mozilla::ipc::IPCResult CompositorBridgeParent::RecvWillClose() {
StopAndClearResources();
// Once we get the WillClose message, the client side is going to go away
diff --git a/gfx/layers/ipc/CompositorBridgeParent.h b/gfx/layers/ipc/CompositorBridgeParent.h
@@ -188,6 +188,10 @@ class CompositorBridgeParentBase : public PCompositorBridgeParent,
EndRecordingResolver&& aResolve) = 0;
virtual mozilla::ipc::IPCResult RecvInitialize(
const LayersId& rootLayerTreeId) = 0;
+ virtual mozilla::ipc::IPCResult RecvInitAPZInputBridge(
+ Endpoint<PAPZInputBridgeParent>&& aEndpoint) = 0;
+ virtual mozilla::ipc::IPCResult RecvInitUiCompositorController(
+ Endpoint<PUiCompositorControllerParent>&& aEndpoint) = 0;
virtual mozilla::ipc::IPCResult RecvWillClose() = 0;
virtual mozilla::ipc::IPCResult RecvPause() = 0;
virtual mozilla::ipc::IPCResult RecvRequestFxrOutput() = 0;
@@ -259,6 +263,10 @@ class CompositorBridgeParent final : public CompositorBridgeParentBase,
#endif
mozilla::ipc::IPCResult RecvInitialize(
const LayersId& aRootLayerTreeId) override;
+ mozilla::ipc::IPCResult RecvInitAPZInputBridge(
+ Endpoint<PAPZInputBridgeParent>&& aEndpoint) override;
+ mozilla::ipc::IPCResult RecvInitUiCompositorController(
+ Endpoint<PUiCompositorControllerParent>&& aEndpoint) override;
mozilla::ipc::IPCResult RecvWillClose() override;
mozilla::ipc::IPCResult RecvPause() override;
mozilla::ipc::IPCResult RecvRequestFxrOutput() override;
diff --git a/gfx/layers/ipc/ContentCompositorBridgeParent.h b/gfx/layers/ipc/ContentCompositorBridgeParent.h
@@ -36,6 +36,14 @@ class ContentCompositorBridgeParent final : public CompositorBridgeParentBase {
const LayersId& aRootLayerTreeId) override {
return IPC_FAIL_NO_REASON(this);
}
+ mozilla::ipc::IPCResult RecvInitAPZInputBridge(
+ Endpoint<PAPZInputBridgeParent>&& aEndpoint) override {
+ return IPC_FAIL(this, "Must only be called for top-level compositors");
+ }
+ mozilla::ipc::IPCResult RecvInitUiCompositorController(
+ Endpoint<PUiCompositorControllerParent>&& aEndpoint) override {
+ return IPC_FAIL(this, "Must only be called for top-level compositors");
+ }
mozilla::ipc::IPCResult RecvWillClose() override { return IPC_OK(); }
mozilla::ipc::IPCResult RecvPause() override { return IPC_OK(); }
mozilla::ipc::IPCResult RecvRequestFxrOutput() override {
diff --git a/gfx/layers/ipc/PCompositorBridge.ipdl b/gfx/layers/ipc/PCompositorBridge.ipdl
@@ -11,10 +11,12 @@ include PlatformWidgetTypes;
include PCompositorBridgeTypes;
include protocol PAPZ;
include protocol PAPZCTreeManager;
+include protocol PAPZInputBridge;
include protocol PBrowser;
include protocol PCompositorManager;
include protocol PCompositorWidget;
include protocol PTexture;
+include protocol PUiCompositorController;
include protocol PWebRenderBridge;
include "mozilla/GfxMessageUtils.h";
include "mozilla/layers/LayersMessageUtils.h";
@@ -126,8 +128,16 @@ parent:
async PCompositorWidget(CompositorWidgetInitData aInitData);
// When out-of-process, this must be called to finish initialization.
- sync Initialize(LayersId rootLayerTreeId);
+ async Initialize(LayersId rootLayerTreeId);
+ // Must be called after Initialize(), and only for top-level compositors and
+ // when using a GPU process.
+ async InitAPZInputBridge(Endpoint<PAPZInputBridgeParent> endpoint);
+
+ // Must be called after Initialize(), and only for top-level compositors.
+ async InitUiCompositorController(
+ Endpoint<PUiCompositorControllerParent> endpoint);
+
// Must be called after Initialize(), and only succeeds if AsyncPanZoomEnabled() is true.
async PAPZ(LayersId layersId);
async PAPZCTreeManager(LayersId layersId);
diff --git a/gfx/layers/ipc/UiCompositorControllerParent.cpp b/gfx/layers/ipc/UiCompositorControllerParent.cpp
@@ -42,15 +42,10 @@ UiCompositorControllerParent::GetFromRootLayerTreeId(
RefPtr<UiCompositorControllerParent> UiCompositorControllerParent::Start(
const LayersId& aRootLayerTreeId,
Endpoint<PUiCompositorControllerParent>&& aEndpoint) {
+ MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
RefPtr<UiCompositorControllerParent> parent =
new UiCompositorControllerParent(aRootLayerTreeId);
-
- RefPtr<Runnable> task =
- NewRunnableMethod<Endpoint<PUiCompositorControllerParent>&&>(
- "layers::UiCompositorControllerParent::Open", parent,
- &UiCompositorControllerParent::Open, std::move(aEndpoint));
- CompositorThread()->Dispatch(task.forget());
-
+ parent->Open(std::move(aEndpoint));
return parent;
}
diff --git a/ipc/ipdl/sync-messages.ini b/ipc/ipdl/sync-messages.ini
@@ -206,8 +206,6 @@ description = legacy sync IPC - please add detailed description
description = legacy sync IPC - please add detailed description
[PCanvasManager::GetSnapshot]
description = Retrieving canvas contents is synchronous (see also, PWebGL::GetFrontBufferSnapshot).
-[PCompositorBridge::Initialize]
-description = legacy sync IPC - please add detailed description
[PCompositorBridge::WillClose]
description = legacy sync IPC - please add detailed description
[PCompositorBridge::Pause]