1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "VRGPUParent.h"
10 #include "nsDebugImpl.h"
11 #include "nsThreadManager.h"
12 #include "nsPrintfCString.h"
14 #include "mozilla/dom/MemoryReportRequest.h"
15 #include "mozilla/gfx/gfxVars.h"
16 #include "mozilla/ipc/CrashReporterClient.h"
17 #include "mozilla/ipc/ProcessChild.h"
18 #include "mozilla/ipc/ProcessUtils.h"
19 #include "mozilla/Preferences.h"
23 # include "mozilla/gfx/DeviceManagerDx.h"
31 using mozilla::ipc::IPCResult
;
33 VRParent::VRParent() : mVRGPUParent(nullptr) {}
35 IPCResult
VRParent::RecvNewGPUVRManager(Endpoint
<PVRGPUParent
>&& aEndpoint
) {
36 RefPtr
<VRGPUParent
> vrGPUParent
=
37 VRGPUParent::CreateForGPU(std::move(aEndpoint
));
39 return IPC_FAIL_NO_REASON(this);
42 mVRGPUParent
= std::move(vrGPUParent
);
46 IPCResult
VRParent::RecvInit(nsTArray
<GfxVarUpdate
>&& vars
,
47 const DevicePrefs
& devicePrefs
) {
48 Unused
<< SendInitComplete();
50 for (const auto& var
: vars
) {
51 gfxVars::ApplyUpdate(var
);
54 // Inherit device preferences.
55 gfxConfig::Inherit(Feature::HW_COMPOSITING
, devicePrefs
.hwCompositing());
56 gfxConfig::Inherit(Feature::D3D11_COMPOSITING
,
57 devicePrefs
.d3d11Compositing());
58 gfxConfig::Inherit(Feature::OPENGL_COMPOSITING
, devicePrefs
.oglCompositing());
59 gfxConfig::Inherit(Feature::DIRECT2D
, devicePrefs
.useD2D1());
62 if (gfxConfig::IsEnabled(Feature::D3D11_COMPOSITING
)) {
63 DeviceManagerDx::Get()->CreateCompositorDevices();
69 IPCResult
VRParent::RecvUpdateVar(const GfxVarUpdate
& aUpdate
) {
70 gfxVars::ApplyUpdate(aUpdate
);
74 mozilla::ipc::IPCResult
VRParent::RecvPreferenceUpdate(const Pref
& aPref
) {
75 Preferences::SetPreference(aPref
);
79 mozilla::ipc::IPCResult
VRParent::RecvOpenVRControllerActionPathToVR(
80 const nsCString
& aPath
) {
81 mOpenVRControllerAction
= aPath
;
85 mozilla::ipc::IPCResult
VRParent::RecvOpenVRControllerManifestPathToVR(
86 const VRControllerType
& aType
, const nsCString
& aPath
) {
87 mOpenVRControllerManifest
.InsertOrUpdate(static_cast<uint32_t>(aType
), aPath
);
91 mozilla::ipc::IPCResult
VRParent::RecvRequestMemoryReport(
92 const uint32_t& aGeneration
, const bool& aAnonymize
,
93 const bool& aMinimizeMemoryUsage
, const Maybe
<FileDescriptor
>& aDMDFile
,
94 const RequestMemoryReportResolver
& aResolver
) {
95 MOZ_ASSERT(XRE_IsVRProcess());
96 nsPrintfCString
processName("VR (pid %u)", (unsigned)getpid());
98 mozilla::dom::MemoryReportRequestClient::Start(
99 aGeneration
, aAnonymize
, aMinimizeMemoryUsage
, aDMDFile
, processName
,
100 [&](const MemoryReport
& aReport
) {
101 Unused
<< SendAddMemoryReport(aReport
);
107 void VRParent::ActorDestroy(ActorDestroyReason aWhy
) {
108 if (AbnormalShutdown
== aWhy
) {
109 NS_WARNING("Shutting down VR process early due to a crash!");
110 ipc::ProcessChild::QuickExit();
112 if (mVRGPUParent
&& !mVRGPUParent
->IsClosed()) {
113 mVRGPUParent
->Close();
115 mVRGPUParent
= nullptr;
117 #ifndef NS_FREE_PERMANENT_DATA
118 // No point in going through XPCOM shutdown because we don't keep persistent
120 ipc::ProcessChild::QuickExit();
124 DeviceManagerDx::Shutdown();
127 gfxConfig::Shutdown();
128 ipc::CrashReporterClient::DestroySingleton();
129 // Only calling XRE_ShutdownChildProcess() at the child process
130 // instead of the main process. Otherwise, it will close all child processes
131 // that are spawned from the main process.
132 XRE_ShutdownChildProcess();
135 bool VRParent::Init(mozilla::ipc::UntypedEndpoint
&& aEndpoint
,
136 const char* aParentBuildID
) {
137 // Initialize the thread manager before starting IPC. Otherwise, messages
138 // may be posted to the main thread and we won't be able to process them.
139 if (NS_WARN_IF(NS_FAILED(nsThreadManager::get().Init()))) {
143 // Now it's safe to start IPC.
144 if (NS_WARN_IF(!aEndpoint
.Bind(this))) {
148 nsDebugImpl::SetMultiprocessMode("VR");
150 // This must be checked before any IPDL message, which may hit sentinel
151 // errors due to parent and content processes having different
153 MessageChannel
* channel
= GetIPCChannel();
154 if (channel
&& !channel
->SendBuildIDsMatchMessage(aParentBuildID
)) {
155 // We need to quit this process if the buildID doesn't match the parent's.
156 // This can occur when an update occurred in the background.
157 ipc::ProcessChild::QuickExit();
160 // Init crash reporter support.
161 ipc::CrashReporterClient::InitSingleton(this);
164 gfxVars::Initialize();
166 DeviceManagerDx::Init();
168 if (NS_FAILED(NS_InitMinimalXPCOM())) {
172 mozilla::ipc::SetThisProcessName("VR Process");
176 bool VRParent::GetOpenVRControllerActionPath(nsCString
* aPath
) {
177 if (!mOpenVRControllerAction
.IsEmpty()) {
178 *aPath
= mOpenVRControllerAction
;
185 bool VRParent::GetOpenVRControllerManifestPath(VRControllerType aType
,
187 return mOpenVRControllerManifest
.Get(static_cast<uint32_t>(aType
), aPath
);
191 } // namespace mozilla