1 | /*
|
---|
2 | * Copyright (C) 2020 Igalia S.L. All rights reserved.
|
---|
3 | *
|
---|
4 | * Redistribution and use in source and binary forms, with or without
|
---|
5 | * modification, are permitted provided that the following conditions
|
---|
6 | * are met:
|
---|
7 | * 1. Redistributions of source code must retain the above copyright
|
---|
8 | * notice, this list of conditions and the following disclaimer.
|
---|
9 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer in the
|
---|
11 | * documentation and/or other materials provided with the distribution.
|
---|
12 | *
|
---|
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
---|
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
---|
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
---|
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
---|
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
---|
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
---|
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
---|
23 | * THE POSSIBILITY OF SUCH DAMAGE.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #pragma once
|
---|
27 |
|
---|
28 | #if ENABLE(WEBXR)
|
---|
29 |
|
---|
30 | #include "FakeXRButtonStateInit.h"
|
---|
31 | #include "FakeXRInputSourceInit.h"
|
---|
32 | #include "FakeXRRigidTransformInit.h"
|
---|
33 | #include "PlatformXR.h"
|
---|
34 | #include "XRHandedness.h"
|
---|
35 | #include "XRTargetRayMode.h"
|
---|
36 | #include <wtf/HashMap.h>
|
---|
37 | #include <wtf/RefCounted.h>
|
---|
38 | #include <wtf/Vector.h>
|
---|
39 |
|
---|
40 | #if ENABLE(WEBXR_HANDS)
|
---|
41 | #include "FakeXRJointStateInit.h"
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | namespace WebCore {
|
---|
45 |
|
---|
46 | class WebFakeXRInputController final : public RefCounted<WebFakeXRInputController> {
|
---|
47 | public:
|
---|
48 | static Ref<WebFakeXRInputController> create(PlatformXR::InputSourceHandle, const FakeXRInputSourceInit&);
|
---|
49 |
|
---|
50 | void setHandedness(XRHandedness handeness) { m_handeness = handeness; }
|
---|
51 | void setTargetRayMode(XRTargetRayMode mode) { m_targetRayMode = mode; }
|
---|
52 | void setProfiles(Vector<String>&& profiles) { m_profiles = WTFMove(profiles); }
|
---|
53 | void setGripOrigin(FakeXRRigidTransformInit gripOrigin, bool emulatedPosition = false);
|
---|
54 | void clearGripOrigin() { m_gripOrigin = std::nullopt; }
|
---|
55 | void setPointerOrigin(FakeXRRigidTransformInit pointerOrigin, bool emulatedPosition = false);
|
---|
56 | void disconnect();
|
---|
57 | void reconnect();
|
---|
58 | void startSelection() { m_primarySelected = true; }
|
---|
59 | void endSelection() { m_primarySelected = false; }
|
---|
60 | void simulateSelect() { m_simulateSelect = true; }
|
---|
61 | void setSupportedButtons(const Vector<FakeXRButtonStateInit>&);
|
---|
62 | void updateButtonState(const FakeXRButtonStateInit&);
|
---|
63 | bool isConnected() const { return m_connected; }
|
---|
64 |
|
---|
65 | #if ENABLE(WEBXR_HANDS)
|
---|
66 | void updateHandJoints(const Vector<FakeXRJointStateInit>&);
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | PlatformXR::Device::FrameData::InputSource getFrameData();
|
---|
70 |
|
---|
71 | private:
|
---|
72 | WebFakeXRInputController(PlatformXR::InputSourceHandle, const FakeXRInputSourceInit&);
|
---|
73 |
|
---|
74 | struct ButtonOrPlaceholder {
|
---|
75 | std::optional<PlatformXR::Device::FrameData::InputSourceButton> button;
|
---|
76 | std::optional<Vector<float>> axes;
|
---|
77 | };
|
---|
78 | ButtonOrPlaceholder getButtonOrPlaceholder(FakeXRButtonStateInit::Type) const;
|
---|
79 |
|
---|
80 | PlatformXR::InputSourceHandle m_handle { 0 };
|
---|
81 | XRHandedness m_handeness { XRHandedness::None };
|
---|
82 | XRTargetRayMode m_targetRayMode { XRTargetRayMode::Gaze };
|
---|
83 | Vector<String> m_profiles;
|
---|
84 | PlatformXR::Device::FrameData::InputSourcePose m_pointerOrigin;
|
---|
85 | std::optional<PlatformXR::Device::FrameData::InputSourcePose> m_gripOrigin;
|
---|
86 | HashMap<FakeXRButtonStateInit::Type, FakeXRButtonStateInit, IntHash<FakeXRButtonStateInit::Type>, WTF::StrongEnumHashTraits<FakeXRButtonStateInit::Type>> m_buttons;
|
---|
87 | bool m_connected { true };
|
---|
88 | bool m_primarySelected { false };
|
---|
89 | bool m_simulateSelect { false };
|
---|
90 | #if ENABLE(WEBXR_HANDS)
|
---|
91 | std::optional<PlatformXR::Device::FrameData::HandJointsVector> m_handJoints;
|
---|
92 | #endif
|
---|
93 | };
|
---|
94 |
|
---|
95 | } // namespace WebCore
|
---|
96 |
|
---|
97 | #endif // ENABLE(WEBXR)
|
---|