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 "PuppetSession.h"
10 #include "VRPuppetCommandBuffer.h"
11 #include "mozilla/StaticPrefs_dom.h"
15 # include "mozilla/gfx/DeviceManagerDx.h"
16 #elif defined(XP_MACOSX)
17 # include "mozilla/gfx/MacIOSurface.h"
20 using namespace mozilla::gfx
;
25 PuppetSession::PuppetSession() : VRSession() {}
27 PuppetSession::~PuppetSession() { Shutdown(); }
29 bool PuppetSession::Initialize(mozilla::gfx::VRSystemState
& aSystemState
) {
30 if (!StaticPrefs::dom_vr_enabled() || !StaticPrefs::dom_vr_puppet_enabled()) {
33 VRPuppetCommandBuffer::Get().Run(aSystemState
);
34 if (!aSystemState
.displayState
.isConnected
) {
38 if (!CreateD3DObjects()) {
49 bool PuppetSession::CreateD3DObjects() {
50 RefPtr
<ID3D11Device
> device
= gfx::DeviceManagerDx::Get()->GetVRDevice();
54 if (!CreateD3DContext(device
)) {
61 void PuppetSession::Shutdown() {}
63 void PuppetSession::StartFrame(mozilla::gfx::VRSystemState
& aSystemState
) {
64 VRPuppetCommandBuffer::Get().Run(aSystemState
);
67 void PuppetSession::ProcessEvents(mozilla::gfx::VRSystemState
& aSystemState
) {
68 VRPuppetCommandBuffer
& puppet
= VRPuppetCommandBuffer::Get();
69 puppet
.Run(aSystemState
);
70 if (!aSystemState
.displayState
.isConnected
) {
76 bool PuppetSession::SubmitFrame(
77 const mozilla::gfx::VRLayer_Stereo_Immersive
& aLayer
,
78 ID3D11Texture2D
* aTexture
) {
79 return VRPuppetCommandBuffer::Get().SubmitFrame();
81 #elif defined(XP_MACOSX)
82 bool PuppetSession::SubmitFrame(
83 const mozilla::gfx::VRLayer_Stereo_Immersive
& aLayer
,
84 const VRLayerTextureHandle
& aTexture
) {
85 return VRPuppetCommandBuffer::Get().SubmitFrame();
89 void PuppetSession::StopPresentation() {
90 VRPuppetCommandBuffer::Get().StopPresentation();
93 bool PuppetSession::StartPresentation() {
94 VRPuppetCommandBuffer::Get().StartPresentation();
98 void PuppetSession::VibrateHaptic(uint32_t aControllerIdx
,
99 uint32_t aHapticIndex
, float aIntensity
,
101 VRPuppetCommandBuffer::Get().VibrateHaptic(aControllerIdx
, aHapticIndex
,
102 aIntensity
, aDuration
);
105 void PuppetSession::StopVibrateHaptic(uint32_t aControllerIdx
) {
106 VRPuppetCommandBuffer::Get().StopVibrateHaptic(aControllerIdx
);
109 void PuppetSession::StopAllHaptics() {
110 VRPuppetCommandBuffer::Get().StopAllHaptics();
114 } // namespace mozilla