Bug 1567650 [wpt PR 17950] - [ElementTiming] Replace responseEnd with loadTime, a...
[gecko.git] / gfx / vr / service / PuppetSession.cpp
blob6d729da33b349e15d02d73fa605244a53249739f
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"
9 #include "nsString.h"
10 #include "VRPuppetCommandBuffer.h"
11 #include "mozilla/StaticPrefs_dom.h"
13 #if defined(XP_WIN)
14 # include <d3d11.h>
15 # include "mozilla/gfx/DeviceManagerDx.h"
16 #elif defined(XP_MACOSX)
17 # include "mozilla/gfx/MacIOSurface.h"
18 #endif
20 using namespace mozilla::gfx;
22 namespace mozilla {
23 namespace 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()) {
31 return false;
33 VRPuppetCommandBuffer::Get().Run(aSystemState);
34 if (!aSystemState.displayState.isConnected) {
35 return false;
37 #if defined(XP_WIN)
38 if (!CreateD3DObjects()) {
39 Shutdown();
40 return false;
42 #endif
44 // Succeeded
45 return true;
48 #if defined(XP_WIN)
49 bool PuppetSession::CreateD3DObjects() {
50 RefPtr<ID3D11Device> device = gfx::DeviceManagerDx::Get()->GetVRDevice();
51 if (!device) {
52 return false;
54 if (!CreateD3DContext(device)) {
55 return false;
57 return true;
59 #endif
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) {
71 mShouldQuit = true;
75 #if defined(XP_WIN)
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();
87 #endif
89 void PuppetSession::StopPresentation() {
90 VRPuppetCommandBuffer::Get().StopPresentation();
93 bool PuppetSession::StartPresentation() {
94 VRPuppetCommandBuffer::Get().StartPresentation();
95 return true;
98 void PuppetSession::VibrateHaptic(uint32_t aControllerIdx,
99 uint32_t aHapticIndex, float aIntensity,
100 float aDuration) {
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();
113 } // namespace gfx
114 } // namespace mozilla