source: webkit/trunk/Source/WebCore/testing/WebFakeXRInputController.h

Last change on this file was 292780, checked in by [email protected], 3 years ago

[WebXR] Implement the WebXRFrame methods for getting joints' poses and radii
https://bugs.webkit.org/show_bug.cgi?id=238968

Patch by Ada Chan <[email protected]> on 2022-04-12
Reviewed by Dean Jackson.

Source/WebCore:

Tests: http/wpt/webxr/xrFrame_fillJointRadii.html

http/wpt/webxr/xrFrame_fillJointRadii_missing_joint_pose.html
http/wpt/webxr/xrFrame_fillPoses.html
http/wpt/webxr/xrFrame_fillPoses_missing_joint_pose.html
http/wpt/webxr/xrFrame_getJointPose.html
http/wpt/webxr/xrFrame_getJointPose_missing_joint_pose.html
http/wpt/webxr/xrHand.html

  • Implement the methods in WebXRFrame for getting joints' poses and radii.
  • Add a new InputSourceHandJoint struct to represent joint data, and add

a vector of InputSourceHandJoint in PlatformXR::Device::FrameData::InputSource
to represent the joints data.

  • Implement logic for managing a vector of WebXRJointSpaces in WebXRHand and

updating it with new hand joints data from PlatformXR::Device::FrameData::InputSource.

  • DerivedSources-input.xcfilelist:
  • DerivedSources-output.xcfilelist:
  • DerivedSources.make:
  • Modules/webxr/WebXRFrame+HandInput.idl:
  • Modules/webxr/WebXRFrame.cpp:

(WebCore::WebXRFrame::populatePose):
There are valid cases when the WebXRSpace's effective origin can be null,
for example, a joint pose from a hand that has other missing joint poses.
Just return null and not throw an exception in that case.
(WebCore::WebXRFrame::getJointPose):
Populate the joint's pose, and create a WebXRJointPose with the pose's
transform and the joint's radius.
(WebCore::WebXRFrame::fillJointRadii):
Validate the inputs and fill in the radii array. Fill in with NaN
if the hand has missing joint poses.
(WebCore::WebXRFrame::fillPoses):
Validate the inputs and fill in the transforms array. Fill in with NaN
if the hand has missing joint poses.

  • Modules/webxr/WebXRFrame.h:
  • Modules/webxr/WebXRHand.cpp:

(WebCore::WebXRHand::WebXRHand):
Initialize the m_joints array.
(WebCore::WebXRHand::get):
(WebCore::WebXRHand::Iterator::next):
(WebCore::WebXRHand::session):
(WebCore::WebXRHand::updateFromInputSource):
Update m_joints array based on the latest hands data from InputSource.

  • Modules/webxr/WebXRHand.h:

(WebCore::WebXRHand::size):
(WebCore::WebXRHand::hasMissingPoses const):

  • Modules/webxr/WebXRInputSource.cpp:

(WebCore::WebXRInputSource::update):

  • Modules/webxr/WebXRJointPose.cpp:

(WebCore::WebXRJointPose::create):
(WebCore::WebXRJointPose::WebXRJointPose):
Handle joint radius.

  • Modules/webxr/WebXRJointPose.h:
  • Modules/webxr/WebXRJointPose.idl:
  • Modules/webxr/WebXRJointSpace.cpp:

(WebCore::WebXRJointSpace::create):
(WebCore::WebXRJointSpace::WebXRJointSpace):
Handle joint name and the actual pose data. Keep a weak ptr to the WebXRHand.
(WebCore::WebXRJointSpace::updateFromJoint):
(WebCore::WebXRJointSpace::handHasMissingPoses const):
(WebCore::WebXRJointSpace::session const):
(WebCore::WebXRJointSpace::nativeOrigin const):
Return null pose transforms if there are missing joint poses.

  • Modules/webxr/WebXRJointSpace.h:

(WebCore::WebXRJointSpace::jointName const):
(WebCore::WebXRJointSpace::radius const):

  • Modules/webxr/WebXRJointSpace.idl:
  • Modules/webxr/WebXRSession.cpp:

(WebCore::WebXRSession::isHandTrackingEnabled const):

  • Modules/webxr/WebXRSession.h:
  • WebCore.xcodeproj/project.pbxproj:
  • platform/xr/PlatformXR.h:

(PlatformXR::Device::FrameData::InputSourceHandJoint::encode const):
(PlatformXR::Device::FrameData::InputSourceHandJoint::decode):
(PlatformXR::Device::FrameData::InputSource::encode const):
(PlatformXR::Device::FrameData::InputSource::decode):

  • testing/FakeXRInputSourceInit.h:
  • testing/FakeXRInputSourceInit.idl:

Allow test InputSource to be created with an array of joints.

  • testing/FakeXRJointStateInit.h: Copied from Source/WebCore/Modules/webxr/WebXRJointPose.idl.
  • testing/FakeXRJointStateInit.idl: Copied from Source/WebCore/Modules/webxr/WebXRJointPose.idl.

Define init dictionary for joint data.

  • testing/WebFakeXRInputController.cpp:

(WebCore::WebFakeXRInputController::WebFakeXRInputController):
(WebCore::WebFakeXRInputController::getFrameData):
(WebCore::WebFakeXRInputController::updateHandJoints):
Update m_handJoints based on joint init dictionaries.

  • testing/WebFakeXRInputController.h:
  • testing/WebFakeXRInputController.idl:
  • testing/WebXRTest.cpp:

(WebCore::parseFeatures):
(WebCore::WebXRTest::simulateDeviceConnection):
Allow test device to specify a list of enabled features that don't need
further explicit consent.

  • testing/WebXRTest.h:
  • testing/WebXRTest.idl:

Source/WebKit:

  • Shared/XR/XRDeviceProxy.cpp:

(WebKit::XRDeviceProxy::initializeTrackingAndRendering):
Initialize input sources on session start.

LayoutTests:

Add more constants for a valid joint value and device init dictionary
that represents a device with hand tracking support enabled.

Add new tests for testing hand input related methods in XRFrame.

  • http/wpt/webxr/resources/webxr_test_constants_single_view.js:
  • http/wpt/webxr/xrFrame_fillJointRadii-expected.txt: Added.
  • http/wpt/webxr/xrFrame_fillJointRadii.html: Added.
  • http/wpt/webxr/xrFrame_fillJointRadii_missing_joint_pose-expected.txt: Added.
  • http/wpt/webxr/xrFrame_fillJointRadii_missing_joint_pose.html: Added.
  • http/wpt/webxr/xrFrame_fillPoses-expected.txt: Added.
  • http/wpt/webxr/xrFrame_fillPoses.html: Added.
  • http/wpt/webxr/xrFrame_fillPoses_missing_joint_pose-expected.txt: Added.
  • http/wpt/webxr/xrFrame_fillPoses_missing_joint_pose.html: Added.
  • http/wpt/webxr/xrFrame_getJointPose-expected.txt: Added.
  • http/wpt/webxr/xrFrame_getJointPose.html: Added.
  • http/wpt/webxr/xrFrame_getJointPose_missing_joint_pose-expected.txt: Added.
  • http/wpt/webxr/xrFrame_getJointPose_missing_joint_pose.html: Added.
  • http/wpt/webxr/xrHand-expected.txt: Added.
  • http/wpt/webxr/xrHand.html: Added.
  • http/wpt/webxr/xrHandInput_gc.html:
  • platform/win/TestExpectations: Skip other folders with WebXR tests
  • Property svn:eol-style set to LF
File size: 4.0 KB
Line 
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
44namespace WebCore {
45
46class WebFakeXRInputController final : public RefCounted<WebFakeXRInputController> {
47public:
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
71private:
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)
Note: See TracBrowser for help on using the repository browser.