Commit 3cf5434d authored by Lachlan Ford's avatar Lachlan Ford Committed by Commit Bot

OpenXR HP Revergb G2 and Samsung Odyssey interaction profiles

Implemented the HP Revergb G2 and Samsung Odyssey interaction profiles
for WebXR.

Change-Id: Icb80280e5c68e90aadd0f8dda033a41712a18306
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2398917
Commit-Queue: Lachlan Ford <laford@microsoft.com>
Reviewed-by: default avatarRafael Cintron <rafael.cintron@microsoft.com>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805536}
parent ee49bcdf
...@@ -68,6 +68,7 @@ XrResult OpenXrController::Initialize( ...@@ -68,6 +68,7 @@ XrResult OpenXrController::Initialize(
XrInstance instance, XrInstance instance,
XrSession session, XrSession session,
const OpenXRPathHelper* path_helper, const OpenXRPathHelper* path_helper,
const OpenXrExtensionHelper& extension_helper,
std::map<XrPath, std::vector<XrActionSuggestedBinding>>* bindings) { std::map<XrPath, std::vector<XrActionSuggestedBinding>>* bindings) {
DCHECK(bindings); DCHECK(bindings);
type_ = type; type_ = type;
...@@ -95,7 +96,7 @@ XrResult OpenXrController::Initialize( ...@@ -95,7 +96,7 @@ XrResult OpenXrController::Initialize(
RETURN_IF_XR_FAILED(InitializeControllerActions()); RETURN_IF_XR_FAILED(InitializeControllerActions());
SuggestBindings(bindings); SuggestBindings(extension_helper, bindings);
RETURN_IF_XR_FAILED(InitializeControllerSpaces()); RETURN_IF_XR_FAILED(InitializeControllerSpaces());
return XR_SUCCESS; return XR_SUCCESS;
...@@ -132,10 +133,23 @@ XrResult OpenXrController::InitializeControllerActions() { ...@@ -132,10 +133,23 @@ XrResult OpenXrController::InitializeControllerActions() {
} }
XrResult OpenXrController::SuggestBindings( XrResult OpenXrController::SuggestBindings(
const OpenXrExtensionHelper& extension_helper,
std::map<XrPath, std::vector<XrActionSuggestedBinding>>* bindings) const { std::map<XrPath, std::vector<XrActionSuggestedBinding>>* bindings) const {
const std::string binding_prefix = GetTopLevelUserPath(type_); const std::string binding_prefix = GetTopLevelUserPath(type_);
for (auto interaction_profile : kOpenXrControllerInteractionProfiles) { for (auto interaction_profile : kOpenXrControllerInteractionProfiles) {
// If the interaction profile is defined by an extension, check it here,
// otherwise continue
const bool extension_required =
interaction_profile.required_extension != nullptr;
if (extension_required) {
const bool extension_enabled = extension_helper.ExtensionSupported(
interaction_profile.required_extension);
if (!extension_enabled) {
continue;
}
}
XrPath interaction_profile_path = XrPath interaction_profile_path =
path_helper_->GetInteractionProfileXrPath(interaction_profile.type); path_helper_->GetInteractionProfileXrPath(interaction_profile.type);
RETURN_IF_XR_FAILED(SuggestActionBinding( RETURN_IF_XR_FAILED(SuggestActionBinding(
......
...@@ -34,6 +34,7 @@ class OpenXrController { ...@@ -34,6 +34,7 @@ class OpenXrController {
XrInstance instance, XrInstance instance,
XrSession session, XrSession session,
const OpenXRPathHelper* path_helper, const OpenXRPathHelper* path_helper,
const OpenXrExtensionHelper& extension_helper,
std::map<XrPath, std::vector<XrActionSuggestedBinding>>* bindings); std::map<XrPath, std::vector<XrActionSuggestedBinding>>* bindings);
XrActionSet action_set() const { return action_set_; } XrActionSet action_set() const { return action_set_; }
...@@ -61,6 +62,7 @@ class OpenXrController { ...@@ -61,6 +62,7 @@ class OpenXrController {
XrResult InitializeControllerSpaces(); XrResult InitializeControllerSpaces();
XrResult SuggestBindings( XrResult SuggestBindings(
const OpenXrExtensionHelper& extension_helper,
std::map<XrPath, std::vector<XrActionSuggestedBinding>>* bindings) const; std::map<XrPath, std::vector<XrActionSuggestedBinding>>* bindings) const;
XrResult CreateActionsForButton(OpenXrButtonType button_type); XrResult CreateActionsForButton(OpenXrButtonType button_type);
......
...@@ -9,6 +9,11 @@ namespace device { ...@@ -9,6 +9,11 @@ namespace device {
constexpr char kWin32AppcontainerCompatibleExtensionName[] = constexpr char kWin32AppcontainerCompatibleExtensionName[] =
"XR_EXT_win32_appcontainer_compatible"; "XR_EXT_win32_appcontainer_compatible";
constexpr char kExtSamsungOdysseyControllerExtensionName[] =
"XR_EXT_samsung_odyssey_controller";
constexpr char kExtHPMixedRealityControllerExtensionName[] =
"XR_EXT_hp_mixed_reality_controller";
} // namespace device } // namespace device
#endif // DEVICE_VR_OPENXR_OPENXR_DEFS_H_ #endif // DEVICE_VR_OPENXR_OPENXR_DEFS_H_
...@@ -122,10 +122,11 @@ XrResult OpenXRInputHelper::Initialize(XrInstance instance) { ...@@ -122,10 +122,11 @@ XrResult OpenXRInputHelper::Initialize(XrInstance instance) {
// on availability. // on availability.
std::map<XrPath, std::vector<XrActionSuggestedBinding>> bindings; std::map<XrPath, std::vector<XrActionSuggestedBinding>> bindings;
OpenXrExtensionHelper extension_helper;
for (size_t i = 0; i < controller_states_.size(); i++) { for (size_t i = 0; i < controller_states_.size(); i++) {
RETURN_IF_XR_FAILED(controller_states_[i].controller.Initialize( RETURN_IF_XR_FAILED(controller_states_[i].controller.Initialize(
static_cast<OpenXrHandednessType>(i), instance, session_, static_cast<OpenXrHandednessType>(i), instance, session_,
path_helper_.get(), &bindings)); path_helper_.get(), extension_helper, &bindings));
controller_states_[i].primary_button_pressed = false; controller_states_[i].primary_button_pressed = false;
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "device/gamepad/public/cpp/gamepad.h" #include "device/gamepad/public/cpp/gamepad.h"
#include "device/vr/openxr/openxr_defs.h"
#include "third_party/openxr/src/include/openxr/openxr.h" #include "third_party/openxr/src/include/openxr/openxr.h"
namespace device { namespace device {
...@@ -25,7 +26,9 @@ enum class OpenXrInteractionProfileType { ...@@ -25,7 +26,9 @@ enum class OpenXrInteractionProfileType {
kOculusTouch = 2, kOculusTouch = 2,
kValveIndex = 3, kValveIndex = 3,
kHTCVive = 4, kHTCVive = 4,
kCount = 5, kSamsungOdyssey = 5,
kHPReverbG2 = 6,
kCount = 7,
}; };
enum class OpenXrButtonType { enum class OpenXrButtonType {
...@@ -71,6 +74,7 @@ struct OpenXrAxisPathMap { ...@@ -71,6 +74,7 @@ struct OpenXrAxisPathMap {
struct OpenXrControllerInteractionProfile { struct OpenXrControllerInteractionProfile {
OpenXrInteractionProfileType type; OpenXrInteractionProfileType type;
const char* const path; const char* const path;
const char* const required_extension;
GamepadMapping mapping; GamepadMapping mapping;
const char* const* const input_profiles; const char* const* const input_profiles;
const size_t profile_size; const size_t profile_size;
...@@ -82,13 +86,14 @@ struct OpenXrControllerInteractionProfile { ...@@ -82,13 +86,14 @@ struct OpenXrControllerInteractionProfile {
size_t axis_map_size; size_t axis_map_size;
}; };
// TODO(crbug.com/1017513)
// Currently Supports: // Currently Supports:
// Microsoft motion controller. // Microsoft motion controller.
// Samsung Odyssey controller
// Khronos simple controller. // Khronos simple controller.
// Oculus touch controller. // Oculus touch controller.
// Valve index controller. // Valve index controller.
// HTC vive controller // HTC vive controller
// HP Reverb G2 controller
// Declare OpenXR input profile bindings for other runtimes when they become // Declare OpenXR input profile bindings for other runtimes when they become
// available. // available.
constexpr const char* kMicrosoftMotionInputProfiles[] = { constexpr const char* kMicrosoftMotionInputProfiles[] = {
...@@ -105,6 +110,13 @@ constexpr const char* kValveIndexInputProfiles[] = { ...@@ -105,6 +110,13 @@ constexpr const char* kValveIndexInputProfiles[] = {
constexpr const char* kHTCViveInputProfiles[] = { constexpr const char* kHTCViveInputProfiles[] = {
"htc-vive", "generic-trigger-squeeze-touchpad"}; "htc-vive", "generic-trigger-squeeze-touchpad"};
constexpr const char* kSamsungOdysseyInputProfiles[] = {
"samsung-odyssey", "windows-mixed-reality",
"generic-trigger-squeeze-touchpad-thumbstick"};
constexpr const char* kHPReverbG2InputProfiles[] = {
"hp-mixed-reality", "oculus-touch", "generic-trigger-squeeze"};
constexpr OpenXrButtonPathMap kMicrosoftMotionControllerButtonPathMaps[] = { constexpr OpenXrButtonPathMap kMicrosoftMotionControllerButtonPathMaps[] = {
{OpenXrButtonType::kTrigger, {OpenXrButtonType::kTrigger,
{ {
...@@ -205,7 +217,7 @@ constexpr OpenXrButtonPathMap kValveIndexControllerButtonPathMaps[] = { ...@@ -205,7 +217,7 @@ constexpr OpenXrButtonPathMap kValveIndexControllerButtonPathMaps[] = {
{{OpenXrButtonActionType::kPress, "/input/a/click"}, {{OpenXrButtonActionType::kPress, "/input/a/click"},
{OpenXrButtonActionType::kTouch, "/input/a/touch"}}, {OpenXrButtonActionType::kTouch, "/input/a/touch"}},
2}, 2},
}; // namespace device };
constexpr OpenXrButtonPathMap kHTCViveControllerButtonPathMaps[] = { constexpr OpenXrButtonPathMap kHTCViveControllerButtonPathMaps[] = {
{OpenXrButtonType::kTrigger, {OpenXrButtonType::kTrigger,
...@@ -222,6 +234,46 @@ constexpr OpenXrButtonPathMap kHTCViveControllerButtonPathMaps[] = { ...@@ -222,6 +234,46 @@ constexpr OpenXrButtonPathMap kHTCViveControllerButtonPathMaps[] = {
{OpenXrButtonActionType::kTouch, "/input/trackpad/touch"}}, {OpenXrButtonActionType::kTouch, "/input/trackpad/touch"}},
2}}; 2}};
constexpr OpenXrButtonPathMap kHPReverbG2LeftControllerButtonPathMaps[] = {
{OpenXrButtonType::kTrigger,
{{OpenXrButtonActionType::kPress, "/input/trigger/value"},
{OpenXrButtonActionType::kValue, "/input/trigger/value"}},
2},
{OpenXrButtonType::kSqueeze,
{{OpenXrButtonActionType::kPress, "/input/squeeze/value"},
{OpenXrButtonActionType::kValue, "/input/squeeze/value"}},
2},
{OpenXrButtonType::kThumbstick,
{{OpenXrButtonActionType::kPress, "/input/thumbstick/click"}},
1},
{OpenXrButtonType::kButton1,
{{OpenXrButtonActionType::kPress, "/input/x/click"}},
1},
{OpenXrButtonType::kButton2,
{{OpenXrButtonActionType::kPress, "/input/y/click"}},
1},
};
constexpr OpenXrButtonPathMap kHPReverbG2RightControllerButtonPathMaps[] = {
{OpenXrButtonType::kTrigger,
{{OpenXrButtonActionType::kPress, "/input/trigger/value"},
{OpenXrButtonActionType::kValue, "/input/trigger/value"}},
2},
{OpenXrButtonType::kSqueeze,
{{OpenXrButtonActionType::kPress, "/input/squeeze/value"},
{OpenXrButtonActionType::kValue, "/input/squeeze/value"}},
2},
{OpenXrButtonType::kThumbstick,
{{OpenXrButtonActionType::kPress, "/input/thumbstick/click"}},
1},
{OpenXrButtonType::kButton1,
{{OpenXrButtonActionType::kPress, "/input/a/click"}},
1},
{OpenXrButtonType::kButton2,
{{OpenXrButtonActionType::kPress, "/input/b/click"}},
1},
};
constexpr OpenXrAxisPathMap kMicrosoftMotionControllerAxisPathMaps[] = { constexpr OpenXrAxisPathMap kMicrosoftMotionControllerAxisPathMaps[] = {
{OpenXrAxisType::kTrackpad, "/input/trackpad"}, {OpenXrAxisType::kTrackpad, "/input/trackpad"},
{OpenXrAxisType::kThumbstick, "/input/thumbstick"}, {OpenXrAxisType::kThumbstick, "/input/thumbstick"},
...@@ -240,10 +292,15 @@ constexpr OpenXrAxisPathMap kHTCViveControllerAxisPathMaps[] = { ...@@ -240,10 +292,15 @@ constexpr OpenXrAxisPathMap kHTCViveControllerAxisPathMaps[] = {
{OpenXrAxisType::kTrackpad, "/input/trackpad"}, {OpenXrAxisType::kTrackpad, "/input/trackpad"},
}; };
constexpr OpenXrAxisPathMap kHPReverbG2ControllerAxisPathMaps[] = {
{OpenXrAxisType::kThumbstick, "/input/thumbstick"},
};
constexpr OpenXrControllerInteractionProfile constexpr OpenXrControllerInteractionProfile
kMicrosoftMotionInteractionProfile = { kMicrosoftMotionInteractionProfile = {
OpenXrInteractionProfileType::kMicrosoftMotion, OpenXrInteractionProfileType::kMicrosoftMotion,
"/interaction_profiles/microsoft/motion_controller", "/interaction_profiles/microsoft/motion_controller",
nullptr,
GamepadMapping::kXrStandard, GamepadMapping::kXrStandard,
kMicrosoftMotionInputProfiles, kMicrosoftMotionInputProfiles,
base::size(kMicrosoftMotionInputProfiles), base::size(kMicrosoftMotionInputProfiles),
...@@ -257,6 +314,7 @@ constexpr OpenXrControllerInteractionProfile ...@@ -257,6 +314,7 @@ constexpr OpenXrControllerInteractionProfile
constexpr OpenXrControllerInteractionProfile kKHRSimpleInteractionProfile = { constexpr OpenXrControllerInteractionProfile kKHRSimpleInteractionProfile = {
OpenXrInteractionProfileType::kKHRSimple, OpenXrInteractionProfileType::kKHRSimple,
"/interaction_profiles/khr/simple_controller", "/interaction_profiles/khr/simple_controller",
nullptr,
GamepadMapping::kNone, GamepadMapping::kNone,
kGenericButtonInputProfiles, kGenericButtonInputProfiles,
base::size(kGenericButtonInputProfiles), base::size(kGenericButtonInputProfiles),
...@@ -270,6 +328,7 @@ constexpr OpenXrControllerInteractionProfile kKHRSimpleInteractionProfile = { ...@@ -270,6 +328,7 @@ constexpr OpenXrControllerInteractionProfile kKHRSimpleInteractionProfile = {
constexpr OpenXrControllerInteractionProfile kOculusTouchInteractionProfile = { constexpr OpenXrControllerInteractionProfile kOculusTouchInteractionProfile = {
OpenXrInteractionProfileType::kOculusTouch, OpenXrInteractionProfileType::kOculusTouch,
"/interaction_profiles/oculus/touch_controller", "/interaction_profiles/oculus/touch_controller",
nullptr,
GamepadMapping::kXrStandard, GamepadMapping::kXrStandard,
kOculusTouchInputProfiles, kOculusTouchInputProfiles,
base::size(kOculusTouchInputProfiles), base::size(kOculusTouchInputProfiles),
...@@ -283,6 +342,7 @@ constexpr OpenXrControllerInteractionProfile kOculusTouchInteractionProfile = { ...@@ -283,6 +342,7 @@ constexpr OpenXrControllerInteractionProfile kOculusTouchInteractionProfile = {
constexpr OpenXrControllerInteractionProfile kValveIndexInteractionProfile = { constexpr OpenXrControllerInteractionProfile kValveIndexInteractionProfile = {
OpenXrInteractionProfileType::kValveIndex, OpenXrInteractionProfileType::kValveIndex,
"/interaction_profiles/valve/index_controller", "/interaction_profiles/valve/index_controller",
nullptr,
GamepadMapping::kXrStandard, GamepadMapping::kXrStandard,
kValveIndexInputProfiles, kValveIndexInputProfiles,
base::size(kValveIndexInputProfiles), base::size(kValveIndexInputProfiles),
...@@ -296,6 +356,7 @@ constexpr OpenXrControllerInteractionProfile kValveIndexInteractionProfile = { ...@@ -296,6 +356,7 @@ constexpr OpenXrControllerInteractionProfile kValveIndexInteractionProfile = {
constexpr OpenXrControllerInteractionProfile kHTCViveInteractionProfile = { constexpr OpenXrControllerInteractionProfile kHTCViveInteractionProfile = {
OpenXrInteractionProfileType::kHTCVive, OpenXrInteractionProfileType::kHTCVive,
"/interaction_profiles/htc/vive_controller", "/interaction_profiles/htc/vive_controller",
nullptr,
GamepadMapping::kXrStandard, GamepadMapping::kXrStandard,
kHTCViveInputProfiles, kHTCViveInputProfiles,
base::size(kHTCViveInputProfiles), base::size(kHTCViveInputProfiles),
...@@ -306,11 +367,40 @@ constexpr OpenXrControllerInteractionProfile kHTCViveInteractionProfile = { ...@@ -306,11 +367,40 @@ constexpr OpenXrControllerInteractionProfile kHTCViveInteractionProfile = {
kHTCViveControllerAxisPathMaps, kHTCViveControllerAxisPathMaps,
base::size(kHTCViveControllerAxisPathMaps)}; base::size(kHTCViveControllerAxisPathMaps)};
constexpr OpenXrControllerInteractionProfile kSamsungOdysseyInteractionProfile =
{OpenXrInteractionProfileType::kSamsungOdyssey,
"/interaction_profiles/samsung/odyssey_controller",
kExtSamsungOdysseyControllerExtensionName,
GamepadMapping::kXrStandard,
kSamsungOdysseyInputProfiles,
base::size(kSamsungOdysseyInputProfiles),
kMicrosoftMotionControllerButtonPathMaps,
base::size(kMicrosoftMotionControllerButtonPathMaps),
kMicrosoftMotionControllerButtonPathMaps,
base::size(kMicrosoftMotionControllerButtonPathMaps),
kMicrosoftMotionControllerAxisPathMaps,
base::size(kMicrosoftMotionControllerAxisPathMaps)};
constexpr OpenXrControllerInteractionProfile kHPReverbG2InteractionProfile = {
OpenXrInteractionProfileType::kHPReverbG2,
"/interaction_profiles/hp/mixed_reality_controller",
kExtHPMixedRealityControllerExtensionName,
GamepadMapping::kXrStandard,
kHPReverbG2InputProfiles,
base::size(kHPReverbG2InputProfiles),
kHPReverbG2LeftControllerButtonPathMaps,
base::size(kHPReverbG2LeftControllerButtonPathMaps),
kHPReverbG2RightControllerButtonPathMaps,
base::size(kHPReverbG2RightControllerButtonPathMaps),
kHPReverbG2ControllerAxisPathMaps,
base::size(kHPReverbG2ControllerAxisPathMaps)};
constexpr OpenXrControllerInteractionProfile constexpr OpenXrControllerInteractionProfile
kOpenXrControllerInteractionProfiles[] = { kOpenXrControllerInteractionProfiles[] = {
kMicrosoftMotionInteractionProfile, kKHRSimpleInteractionProfile, kMicrosoftMotionInteractionProfile, kKHRSimpleInteractionProfile,
kOculusTouchInteractionProfile, kValveIndexInteractionProfile, kOculusTouchInteractionProfile, kValveIndexInteractionProfile,
kHTCViveInteractionProfile}; kHTCViveInteractionProfile, kSamsungOdysseyInteractionProfile,
kHPReverbG2InteractionProfile};
} // namespace device } // namespace device
......
...@@ -70,7 +70,8 @@ OpenXrExtensionHelper::OpenXrExtensionHelper() { ...@@ -70,7 +70,8 @@ OpenXrExtensionHelper::OpenXrExtensionHelper() {
OpenXrExtensionHelper::~OpenXrExtensionHelper() = default; OpenXrExtensionHelper::~OpenXrExtensionHelper() = default;
bool OpenXrExtensionHelper::ExtensionSupported(const char* extension_name) { bool OpenXrExtensionHelper::ExtensionSupported(
const char* extension_name) const {
return std::find_if( return std::find_if(
extension_properties_.begin(), extension_properties_.end(), extension_properties_.begin(), extension_properties_.end(),
[&extension_name](const XrExtensionProperties& properties) { [&extension_name](const XrExtensionProperties& properties) {
...@@ -134,6 +135,22 @@ XrResult CreateInstance(XrInstance* instance) { ...@@ -134,6 +135,22 @@ XrResult CreateInstance(XrInstance* instance) {
extensions.push_back(XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME); extensions.push_back(XR_MSFT_UNBOUNDED_REFERENCE_SPACE_EXTENSION_NAME);
} }
// Input extensions. These enable interaction profiles not defined in the core
// spec
const bool samsungInteractionProfileExtensionSupported =
extension_helper.ExtensionSupported(
kExtSamsungOdysseyControllerExtensionName);
if (samsungInteractionProfileExtensionSupported) {
extensions.push_back(kExtSamsungOdysseyControllerExtensionName);
}
const bool hpControllerExtensionSupported =
extension_helper.ExtensionSupported(
kExtHPMixedRealityControllerExtensionName);
if (hpControllerExtensionSupported) {
extensions.push_back(kExtHPMixedRealityControllerExtensionName);
}
instance_create_info.enabledExtensionCount = instance_create_info.enabledExtensionCount =
static_cast<uint32_t>(extensions.size()); static_cast<uint32_t>(extensions.size());
instance_create_info.enabledExtensionNames = extensions.data(); instance_create_info.enabledExtensionNames = extensions.data();
......
...@@ -16,7 +16,7 @@ class OpenXrExtensionHelper { ...@@ -16,7 +16,7 @@ class OpenXrExtensionHelper {
OpenXrExtensionHelper(); OpenXrExtensionHelper();
~OpenXrExtensionHelper(); ~OpenXrExtensionHelper();
bool ExtensionSupported(const char* extension_name); bool ExtensionSupported(const char* extension_name) const;
private: private:
std::vector<XrExtensionProperties> extension_properties_; std::vector<XrExtensionProperties> extension_properties_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment