Backed out changeset 62d0239c5141 (bug 1936381) for causing build bustages @updater...
[gecko.git] / gfx / vr / ipc / VRGPUParent.cpp
blob4a7f91cfcfa3978f3f197381487e3c7471637add
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/. */
7 #include "VRGPUParent.h"
8 #include "VRPuppetCommandBuffer.h"
10 #include "mozilla/ipc/Endpoint.h"
11 #include "mozilla/ipc/ProcessChild.h"
12 #include "mozilla/StaticPrefs_dom.h"
14 namespace mozilla {
15 namespace gfx {
17 using namespace ipc;
19 VRGPUParent::VRGPUParent(EndpointProcInfo aChildProcess) : mClosed(false) {
20 MOZ_ASSERT(NS_IsMainThread());
22 SetOtherEndpointProcInfo(aChildProcess);
25 VRGPUParent::~VRGPUParent() = default;
27 void VRGPUParent::ActorDestroy(ActorDestroyReason aWhy) {
28 #if !defined(MOZ_WIDGET_ANDROID)
29 if (mVRService) {
30 mVRService->Stop();
31 mVRService = nullptr;
33 #endif
35 mClosed = true;
38 /* static */
39 RefPtr<VRGPUParent> VRGPUParent::CreateForGPU(
40 Endpoint<PVRGPUParent>&& aEndpoint) {
41 if (!StaticPrefs::dom_vr_enabled() && !StaticPrefs::dom_vr_webxr_enabled()) {
42 return nullptr;
45 RefPtr<VRGPUParent> vcp = new VRGPUParent(aEndpoint.OtherEndpointProcInfo());
46 GetCurrentSerialEventTarget()->Dispatch(
47 NewRunnableMethod<Endpoint<PVRGPUParent>&&>("gfx::VRGPUParent::Bind", vcp,
48 &VRGPUParent::Bind,
49 std::move(aEndpoint)));
51 return vcp;
54 void VRGPUParent::Bind(Endpoint<PVRGPUParent>&& aEndpoint) {
55 if (!aEndpoint.Bind(this)) {
56 return;
60 mozilla::ipc::IPCResult VRGPUParent::RecvStartVRService() {
61 #if !defined(MOZ_WIDGET_ANDROID)
62 mVRService = VRService::Create();
63 MOZ_ASSERT(mVRService);
65 mVRService->Start();
66 #endif
68 return IPC_OK();
71 mozilla::ipc::IPCResult VRGPUParent::RecvStopVRService() {
72 #if !defined(MOZ_WIDGET_ANDROID)
73 if (mVRService) {
74 mVRService->Stop();
75 mVRService = nullptr;
77 #endif
79 return IPC_OK();
82 mozilla::ipc::IPCResult VRGPUParent::RecvPuppetReset() {
83 #if !defined(MOZ_WIDGET_ANDROID)
84 VRPuppetCommandBuffer::Get().Reset();
85 #endif
86 return IPC_OK();
89 mozilla::ipc::IPCResult VRGPUParent::RecvPuppetSubmit(
90 const nsTArray<uint64_t>& aBuffer) {
91 #if !defined(MOZ_WIDGET_ANDROID)
92 VRPuppetCommandBuffer::Get().Submit(aBuffer);
93 #endif
94 return IPC_OK();
97 mozilla::ipc::IPCResult VRGPUParent::RecvPuppetCheckForCompletion() {
98 #if !defined(MOZ_WIDGET_ANDROID)
99 if (VRPuppetCommandBuffer::Get().HasEnded()) {
100 Unused << SendNotifyPuppetComplete();
102 #endif
103 return IPC_OK();
106 bool VRGPUParent::IsClosed() { return mClosed; }
108 } // namespace gfx
109 } // namespace mozilla