VRGPUParent.cpp (2718B)
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/. */ 6 7 #include "VRGPUParent.h" 8 #include "VRPuppetCommandBuffer.h" 9 10 #include "mozilla/ipc/Endpoint.h" 11 #include "mozilla/ipc/ProcessChild.h" 12 #include "mozilla/StaticPrefs_dom.h" 13 14 namespace mozilla { 15 namespace gfx { 16 17 using namespace ipc; 18 19 VRGPUParent::VRGPUParent(EndpointProcInfo aChildProcess) : mClosed(false) { 20 MOZ_ASSERT(NS_IsMainThread()); 21 22 SetOtherEndpointProcInfo(aChildProcess); 23 } 24 25 VRGPUParent::~VRGPUParent() = default; 26 27 void VRGPUParent::ActorDestroy(ActorDestroyReason aWhy) { 28 #if !defined(MOZ_WIDGET_ANDROID) 29 if (mVRService) { 30 mVRService->Stop(); 31 mVRService = nullptr; 32 } 33 #endif 34 35 mClosed = true; 36 } 37 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; 43 } 44 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))); 50 51 return vcp; 52 } 53 54 void VRGPUParent::Bind(Endpoint<PVRGPUParent>&& aEndpoint) { 55 if (!aEndpoint.Bind(this)) { 56 return; 57 } 58 } 59 60 mozilla::ipc::IPCResult VRGPUParent::RecvStartVRService() { 61 #if !defined(MOZ_WIDGET_ANDROID) 62 mVRService = VRService::Create(); 63 MOZ_ASSERT(mVRService); 64 65 mVRService->Start(); 66 #endif 67 68 return IPC_OK(); 69 } 70 71 mozilla::ipc::IPCResult VRGPUParent::RecvStopVRService() { 72 #if !defined(MOZ_WIDGET_ANDROID) 73 if (mVRService) { 74 mVRService->Stop(); 75 mVRService = nullptr; 76 } 77 #endif 78 79 return IPC_OK(); 80 } 81 82 mozilla::ipc::IPCResult VRGPUParent::RecvPuppetReset() { 83 #if !defined(MOZ_WIDGET_ANDROID) 84 VRPuppetCommandBuffer::Get().Reset(); 85 #endif 86 return IPC_OK(); 87 } 88 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(); 95 } 96 97 mozilla::ipc::IPCResult VRGPUParent::RecvPuppetCheckForCompletion() { 98 #if !defined(MOZ_WIDGET_ANDROID) 99 if (VRPuppetCommandBuffer::Get().HasEnded()) { 100 (void)SendNotifyPuppetComplete(); 101 } 102 #endif 103 return IPC_OK(); 104 } 105 106 bool VRGPUParent::IsClosed() { return mClosed; } 107 108 } // namespace gfx 109 } // namespace mozilla