Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / gfx / vr / VRServiceHost.h
blob0c1a6193cc0095f21296ec40ff23232356d8cf67
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 #ifndef GFX_VR_SERVICE_HOST_H
8 #define GFX_VR_SERVICE_HOST_H
10 #include "mozilla/RefPtr.h"
11 #include "nsISupportsImpl.h"
12 #include "nsTArray.h"
14 #include <cstdint>
16 namespace mozilla {
17 namespace gfx {
19 struct VRExternalShmem;
20 class VRService;
22 /**
23 * VRServiceHost is allocated as a singleton in the GPU process.
24 * It is responsible for allocating VRService either within the GPU process
25 * or in the VR process.
26 * When the VR process is enabled, it maintains the state of the VR process,
27 * starting and stopping it as needed.
28 * VRServiceHost provides an interface that enables communication of the
29 * VRService in the same way regardless of it running within the GPU process
30 * or the VR process.
33 class VRServiceHost {
34 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(mozilla::gfx::VRServiceHost)
35 public:
36 static void Init(bool aEnableVRProcess);
37 static VRServiceHost* Get();
39 void Refresh();
40 void StartService();
41 void StopService();
42 void Shutdown();
43 void CreateService(volatile VRExternalShmem* aShmem);
44 void NotifyVRProcessStarted();
45 void CheckForPuppetCompletion();
47 void PuppetSubmit(const nsTArray<uint64_t>& aBuffer);
48 void PuppetReset();
50 protected:
51 private:
52 explicit VRServiceHost(bool aEnableVRProcess);
53 ~VRServiceHost();
55 void RefreshVRProcess();
56 bool NeedVRProcess();
57 void CreateVRProcess();
58 void ShutdownVRProcess();
59 void SendPuppetResetToVRProcess();
60 void SendPuppetCheckForCompletionToVRProcess();
61 void SendPuppetSubmitToVRProcess(const nsTArray<uint64_t>& aBuffer);
63 // Commands pending to be sent to the puppet device
64 // once the VR service is started.
65 nsTArray<uint64_t> mPuppetPendingCommands;
67 RefPtr<VRService> mVRService;
68 // mVRProcessEnabled indicates that a separate, VR Process, should be used.
69 // This may be false if the VR process is disabled with the
70 // dom.vr.process.enabled preference or when the GPU process is disabled.
71 // mVRProcessEnabled will not change once the browser is started and does not
72 // reflect the started / stopped state of the VR Process.
73 bool mVRProcessEnabled;
74 // mVRProcessStarted is true when the VR Process is running.
75 bool mVRProcessStarted;
76 // mVRServiceReadyInVRProcess is true when the VR Process is running and the
77 // VRService in the VR Process is ready to accept commands.
78 bool mVRServiceReadyInVRProcess;
79 // mVRServiceRequested is true when the VRService is needed. This can be due
80 // to Web API activity (WebXR, WebVR), browser activity (eg, VR Video
81 // Playback), or a request to simulate a VR device with the VRServiceTest /
82 // puppet API. mVRServiceRequested indicates the intended state of the VR
83 // Service and is not an indication that the VR Service is ready to accept
84 // requests or that the VR Process is enabled or running. Toggling the
85 // mVRServiceRequested flag will result in the VR Service and/or the VR
86 // Process either starting or stopping as needed.
87 bool mVRServiceRequested;
90 } // namespace gfx
91 } // namespace mozilla
93 #endif // GFX_VR_SERVICE_HOST_H