Commit 87b5f7c6 authored by Jacob DeWitt's avatar Jacob DeWitt Committed by Commit Bot

Remove WebVR support from Oculus runtime.

WebVR had a different way of sending gamepad data to blink than WebXR.
Remove the code that built + sent the WebVR gamepad data.

Bug: 1017852
Change-Id: If4aa86b9a5837c7b6390fdc16404d04c3c34ded8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879991
Commit-Queue: Jacob DeWitt <jacde@chromium.org>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709931}
parent 2b430c40
......@@ -110,11 +110,6 @@ bool OculusDevice::IsApiAvailable() {
return result.IsOculusServiceRunning;
}
mojo::PendingRemote<mojom::IsolatedXRGamepadProviderFactory>
OculusDevice::BindGamepadFactory() {
return gamepad_provider_factory_receiver_.BindNewPipeAndPassRemote();
}
mojo::PendingRemote<mojom::XRCompositorHost>
OculusDevice::BindCompositorHost() {
return compositor_host_receiver_.BindNewPipeAndPassRemote();
......@@ -150,15 +145,6 @@ void OculusDevice::RequestSession(
return;
}
// If we have a pending gamepad provider receiver when starting the render
// loop, post the receiver over to the render loop to be bound.
if (provider_receiver_) {
render_loop_->task_runner()->PostTask(
FROM_HERE, base::BindOnce(&XRCompositorCommon::RequestGamepadProvider,
base::Unretained(render_loop_.get()),
std::move(provider_receiver_)));
}
if (overlay_receiver_) {
render_loop_->task_runner()->PostTask(
FROM_HERE, base::BindOnce(&XRCompositorCommon::RequestOverlay,
......@@ -284,22 +270,6 @@ void OculusDevice::StopOvrSession() {
}
}
void OculusDevice::GetIsolatedXRGamepadProvider(
mojo::PendingReceiver<mojom::IsolatedXRGamepadProvider> provider_receiver) {
// We bind the provider_receiver on the render loop thread, so gamepad data is
// updated at the rendering rate.
// If we haven't started the render loop yet, postpone binding the receiver
// until we do.
if (render_loop_->IsRunning()) {
render_loop_->task_runner()->PostTask(
FROM_HERE, base::BindOnce(&XRCompositorCommon::RequestGamepadProvider,
base::Unretained(render_loop_.get()),
std::move(provider_receiver)));
} else {
provider_receiver_ = std::move(provider_receiver);
}
}
void OculusDevice::CreateImmersiveOverlay(
mojo::PendingReceiver<mojom::ImmersiveOverlay> overlay_receiver) {
if (render_loop_->IsRunning()) {
......
......@@ -23,7 +23,6 @@ class XRCompositorCommon;
class DEVICE_VR_EXPORT OculusDevice
: public VRDeviceBase,
public mojom::XRSessionController,
public mojom::IsolatedXRGamepadProviderFactory,
public mojom::XRCompositorHost {
public:
OculusDevice();
......@@ -43,8 +42,6 @@ class DEVICE_VR_EXPORT OculusDevice
bool IsAvailable();
mojo::PendingRemote<mojom::IsolatedXRGamepadProviderFactory>
BindGamepadFactory();
mojo::PendingRemote<mojom::XRCompositorHost> BindCompositorHost();
private:
......@@ -53,11 +50,6 @@ class DEVICE_VR_EXPORT OculusDevice
void OnPresentingControllerMojoConnectionError();
// mojom::IsolatedXRGamepadProviderFactory
void GetIsolatedXRGamepadProvider(
mojo::PendingReceiver<mojom::IsolatedXRGamepadProvider> provider_receiver)
override;
// XRCompositorHost
void CreateImmersiveOverlay(
mojo::PendingReceiver<mojom::ImmersiveOverlay> overlay_receiver) override;
......@@ -75,9 +67,6 @@ class DEVICE_VR_EXPORT OculusDevice
mojo::Receiver<mojom::XRSessionController> exclusive_controller_receiver_{
this};
mojo::Receiver<mojom::IsolatedXRGamepadProviderFactory>
gamepad_provider_factory_receiver_{this};
mojo::PendingReceiver<mojom::IsolatedXRGamepadProvider> provider_receiver_;
mojo::Receiver<mojom::XRCompositorHost> compositor_host_receiver_{this};
mojo::PendingReceiver<mojom::ImmersiveOverlay> overlay_receiver_;
......
......@@ -19,15 +19,6 @@ namespace device {
namespace {
// TODO(https://crbug.com/953489): This is currently WebVR-only. If it is useful
// for addressing this issue, give it a more meaningful name. Otherwise, remove
// this enum when WebVR support is removed.
enum GamepadIndex : unsigned int {
kLeftTouchController = 0x0,
kRightTouchController = 0x1,
kRemote = 0x2,
};
float ApplyTriggerDeadzone(float value) {
// Trigger value should be between 0 and 1. We apply a deadzone for small
// values so a loose controller still reports a value of 0 when not in use.
......@@ -36,155 +27,6 @@ float ApplyTriggerDeadzone(float value) {
return (value < kTriggerDeadzone) ? 0 : value;
}
mojom::XRGamepadButtonPtr GetGamepadButton(const ovrInputState& input_state,
ovrButton button_id) {
bool pressed = (input_state.Buttons & button_id) != 0;
bool touched = (input_state.Touches & button_id) != 0;
auto button = mojom::XRGamepadButton::New();
button->pressed = pressed;
button->touched = touched;
button->value = pressed ? 1.0f : 0.0f;
return button;
}
mojom::XRGamepadButtonPtr GetGamepadTouchTrigger(
const ovrInputState& input_state,
ovrTouch touch_id,
float value) {
bool touched = (input_state.Touches & touch_id) != 0;
value = ApplyTriggerDeadzone(value);
auto button = mojom::XRGamepadButton::New();
button->pressed = value != 0;
button->touched = touched;
button->value = value;
return button;
}
mojom::XRGamepadButtonPtr GetGamepadTrigger(float value) {
value = ApplyTriggerDeadzone(value);
auto button = mojom::XRGamepadButton::New();
button->pressed = value != 0;
button->touched = value != 0;
button->value = value;
return button;
}
mojom::XRGamepadButtonPtr GetGamepadTouch(const ovrInputState& input_state,
ovrTouch touch_id) {
bool touched = (input_state.Touches & touch_id) != 0;
auto button = mojom::XRGamepadButton::New();
button->pressed = false;
button->touched = touched;
button->value = 0.0f;
return button;
}
void AddTouchData(mojom::XRGamepadDataPtr& data,
const ovrTrackingState& tracking,
const ovrInputState& input_state,
ovrHandType hand) {
auto gamepad = mojom::XRGamepad::New();
// This gamepad layout is the defacto standard, but can be adjusted for WebXR.
switch (hand) {
case ovrHand_Left:
gamepad->hand = device::mojom::XRHandedness::LEFT;
gamepad->controller_id = kLeftTouchController;
gamepad->buttons.push_back(
GetGamepadButton(input_state, ovrButton_LThumb));
break;
case ovrHand_Right:
gamepad->hand = device::mojom::XRHandedness::RIGHT;
gamepad->controller_id = kRightTouchController;
gamepad->buttons.push_back(
GetGamepadButton(input_state, ovrButton_RThumb));
break;
default:
NOTREACHED();
return;
}
gamepad->axes.push_back(input_state.Thumbstick[hand].x);
gamepad->axes.push_back(-input_state.Thumbstick[hand].y);
gamepad->buttons.push_back(GetGamepadTouchTrigger(
input_state,
hand == ovrHand_Left ? ovrTouch_LIndexTrigger : ovrTouch_RIndexTrigger,
input_state.IndexTrigger[hand]));
gamepad->buttons.push_back(GetGamepadTrigger(input_state.HandTrigger[hand]));
switch (hand) {
case ovrHand_Left:
gamepad->buttons.push_back(GetGamepadButton(input_state, ovrButton_X));
gamepad->buttons.push_back(GetGamepadButton(input_state, ovrButton_Y));
gamepad->buttons.push_back(
GetGamepadTouch(input_state, ovrTouch_LThumbRest));
break;
case ovrHand_Right:
gamepad->buttons.push_back(GetGamepadButton(input_state, ovrButton_A));
gamepad->buttons.push_back(GetGamepadButton(input_state, ovrButton_B));
gamepad->buttons.push_back(
GetGamepadTouch(input_state, ovrTouch_RThumbRest));
break;
default:
NOTREACHED();
break;
}
auto dst_pose = mojom::VRPose::New();
const ovrPoseStatef& src_pose = tracking.HandPoses[hand];
dst_pose->orientation = gfx::Quaternion(
src_pose.ThePose.Orientation.x, src_pose.ThePose.Orientation.y,
src_pose.ThePose.Orientation.z, src_pose.ThePose.Orientation.w);
dst_pose->position =
gfx::Point3F(src_pose.ThePose.Position.x, src_pose.ThePose.Position.y,
src_pose.ThePose.Position.z);
dst_pose->angular_velocity =
gfx::Vector3dF(src_pose.AngularVelocity.x, src_pose.AngularVelocity.y,
src_pose.AngularVelocity.z);
dst_pose->linear_velocity =
gfx::Vector3dF(src_pose.LinearVelocity.x, src_pose.LinearVelocity.y,
src_pose.LinearVelocity.z);
dst_pose->angular_acceleration = gfx::Vector3dF(
src_pose.AngularAcceleration.x, src_pose.AngularAcceleration.y,
src_pose.AngularAcceleration.z);
dst_pose->linear_acceleration = gfx::Vector3dF(src_pose.LinearAcceleration.x,
src_pose.LinearAcceleration.y,
src_pose.LinearAcceleration.z);
gamepad->pose = std::move(dst_pose);
gamepad->can_provide_position = true;
gamepad->can_provide_orientation = true;
gamepad->timestamp = base::TimeTicks::Now();
data->gamepads.push_back(std::move(gamepad));
}
void AddRemoteData(mojom::XRGamepadDataPtr& data,
const ovrInputState& input_remote) {
auto remote = mojom::XRGamepad::New();
remote->buttons.push_back(GetGamepadButton(input_remote, ovrButton_Enter));
remote->buttons.push_back(GetGamepadButton(input_remote, ovrButton_Back));
remote->buttons.push_back(GetGamepadButton(input_remote, ovrButton_Up));
remote->buttons.push_back(GetGamepadButton(input_remote, ovrButton_Down));
remote->buttons.push_back(GetGamepadButton(input_remote, ovrButton_Left));
remote->buttons.push_back(GetGamepadButton(input_remote, ovrButton_Right));
remote->controller_id = kRemote;
remote->hand = device::mojom::XRHandedness::NONE;
data->gamepads.push_back(std::move(remote));
}
device::mojom::XRHandedness OculusToMojomHand(ovrHandType hand) {
switch (hand) {
case ovrHand_Left:
......@@ -279,31 +121,6 @@ class OculusGamepadBuilder : public XRStandardGamepadBuilder {
} // namespace
mojom::XRGamepadDataPtr OculusGamepadHelper::GetGamepadData(
ovrSession session) {
ovrInputState input_touch;
bool have_touch = OVR_SUCCESS(
ovr_GetInputState(session, ovrControllerType_Touch, &input_touch));
ovrInputState input_remote;
bool have_remote = OVR_SUCCESS(
ovr_GetInputState(session, ovrControllerType_Remote, &input_remote));
ovrTrackingState tracking = ovr_GetTrackingState(session, 0, false);
mojom::XRGamepadDataPtr data = mojom::XRGamepadData::New();
if (have_touch) {
AddTouchData(data, tracking, input_touch, ovrHand_Left);
AddTouchData(data, tracking, input_touch, ovrHand_Right);
}
if (have_remote)
AddRemoteData(data, input_remote);
return data;
}
// Order of buttons 1-4 is dictated by the xr-standard Gamepad mapping.
// Buttons 5-7 are in order of decreasing importance.
// 1) index trigger (primary trigger/button)
......
......@@ -5,14 +5,14 @@
#ifndef DEVICE_VR_OCULUS_OCULUS_GAMEPAD_HELPER_H_
#define DEVICE_VR_OCULUS_OCULUS_GAMEPAD_HELPER_H_
#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
#include "base/optional.h"
#include "device/gamepad/public/cpp/gamepads.h"
#include "third_party/libovr/src/Include/OVR_CAPI.h"
namespace device {
class OculusGamepadHelper {
public:
static mojom::XRGamepadDataPtr GetGamepadData(ovrSession session);
static base::Optional<Gamepad> CreateGamepad(ovrSession session,
ovrHandType hand);
};
......
......@@ -72,14 +72,6 @@ mojom::XRFrameDataPtr OculusRenderLoop::GetNextFrameData() {
return frame_data;
}
mojom::XRGamepadDataPtr OculusRenderLoop::GetNextGamepadData() {
if (!session_) {
return nullptr;
}
return OculusGamepadHelper::GetGamepadData(session_);
}
bool OculusRenderLoop::StartRuntime() {
if (!session_) {
ovrInitParams initParams = {ovrInit_RequestVersion | ovrInit_MixedRendering,
......
......@@ -32,7 +32,6 @@ class OculusRenderLoop : public XRCompositorCommon {
private:
// XRDeviceAbstraction:
mojom::XRFrameDataPtr GetNextFrameData() override;
mojom::XRGamepadDataPtr GetNextGamepadData() override;
bool StartRuntime() override;
void StopRuntime() override;
void OnSessionStart() override;
......
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