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_VRSHMEM_H
8 #define GFX_VR_VRSHMEM_H
10 // This file declares VRShMem, which is used for cross-platform, cross-process
11 // communication between VR components.
12 // A shared memory handle is opened for the struct of type VRExternalShmem, and
13 // different processes write or read members of it to share data. Note that no
14 // process should be reading or writing to the same members, except for the
15 // versioning members used for synchronization.
17 #include "moz_external_vr.h"
18 #include "base/process.h" // for base::ProcessHandle
25 VRShMem(volatile VRExternalShmem
* aShmem
, bool aRequiresMutex
);
28 void CreateShMem(bool aCreateOnSharedMemory
);
29 void CreateShMemForAndroid();
36 void PushBrowserState(VRBrowserState
& aBrowserState
, bool aNotifyCond
);
37 void PullBrowserState(mozilla::gfx::VRBrowserState
& aState
);
39 void PushSystemState(const mozilla::gfx::VRSystemState
& aState
);
41 VRDisplayState
& aDisplayState
, VRHMDSensorState
& aSensorState
,
42 VRControllerState (&aControllerState
)[kVRControllerMaxCount
],
43 bool& aEnumerationCompleted
,
44 const std::function
<bool()>& aWaitCondition
= nullptr);
46 void PushWindowState(VRWindowState
& aState
);
47 void PullWindowState(VRWindowState
& aState
);
49 void PushTelemetryState(VRTelemetryState
& aState
);
50 void PullTelemetryState(VRTelemetryState
& aState
);
52 void SendIMEState(uint64_t aWindowID
, mozilla::gfx::VRFxEventState aImeState
);
53 void SendFullscreenState(uint64_t aWindowID
, bool aFullscreen
);
54 void SendShutdowmState(uint64_t aWindowID
);
56 bool HasExternalShmem() const { return mExternalShmem
!= nullptr; }
57 bool IsSharedExternalShmem() const { return mIsSharedExternalShmem
; }
58 volatile VRExternalShmem
* GetExternalShmem() const;
59 bool IsDisplayStateShutdown() const;
62 bool IsCreatedOnSharedMemory() const;
63 void SendEvent(uint64_t aWindowID
, mozilla::gfx::VRFxEventType aEventType
,
64 mozilla::gfx::VRFxEventState aEventState
);
66 // mExternalShmem can have one of three sources:
67 // - Allocated outside of this class on the heap and passed in via
68 // constructor, or acquired via GeckoVRManager (for GeckoView scenario).
69 // This is usually for scenarios where there is no VR process for cross-
70 // proc communication, and VRService is receiving the object.
71 // --> mIsSharedExternalShmem == true, IsCreatedOnSharedMemory() == false
72 // --> [Windows 7, Mac, Android, Linux]
73 // - Allocated inside this class on the heap. This is usually for scenarios
74 // where there is no VR process, and VRManager is creating the object.
75 // --> mIsSharedExternalShmem == false, IsCreatedOnSharedMemory() == false
76 // --> [Windows 7, Mac, Linux]
77 // - Allocated inside this class on shared memory. This is usually for
78 // scenarios where there is a VR process and cross-process communication
80 // --> mIsSharedExternalShmem == false, IsCreatedOnSharedMemory() == true
81 // --> [Windows 10 with VR process enabled]
82 volatile VRExternalShmem
* mExternalShmem
= nullptr;
83 // This member is true when mExternalShmem was allocated externally, via
84 // being passed into the constructor or accessed via GeckoVRManager
85 bool mIsSharedExternalShmem
;
91 #if defined(XP_MACOSX)
94 base::ProcessHandle mShmemFile
;
95 base::ProcessHandle mMutex
;
98 #if !defined(MOZ_WIDGET_ANDROID)
99 int64_t mBrowserGeneration
= 0;
103 } // namespace mozilla