Commit f532106e authored by Alex Cooper's avatar Alex Cooper Committed by Commit Bot

Remove GvrGamepadData and related dead code

Removes the GvrGamepadData struct in favor of directly using the device
Gamepad struct (used by XRInputSourceState).  While updating this, it
was discovered that one code path was essentially just setting a bool
that was otherwise unused, so that code path was removed.

Fixed: 1017848
Change-Id: I6c45df3c38f277b5452481d03f4fc58e8c1a4be8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1917683Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717772}
parent a19f5a94
...@@ -27,7 +27,6 @@ static_library("vr_android") { ...@@ -27,7 +27,6 @@ static_library("vr_android") {
"gl_browser_interface.h", "gl_browser_interface.h",
"gvr_consent_helper_impl.cc", "gvr_consent_helper_impl.cc",
"gvr_consent_helper_impl.h", "gvr_consent_helper_impl.h",
"gvr_gamepad_data.h",
"gvr_graphics_delegate.cc", "gvr_graphics_delegate.cc",
"gvr_graphics_delegate.h", "gvr_graphics_delegate.h",
"gvr_input_delegate.cc", "gvr_input_delegate.cc",
......
...@@ -70,8 +70,7 @@ std::unique_ptr<BrowserRenderer> BrowserRendererFactory::Create( ...@@ -70,8 +70,7 @@ std::unique_ptr<BrowserRenderer> BrowserRendererFactory::Create(
if (params->cardboard_gamepad) { if (params->cardboard_gamepad) {
input_delegate = std::make_unique<CardboardInputDelegate>(params->gvr_api); input_delegate = std::make_unique<CardboardInputDelegate>(params->gvr_api);
} else { } else {
input_delegate = input_delegate = std::make_unique<GvrInputDelegate>(params->gvr_api);
std::make_unique<GvrInputDelegate>(params->gvr_api, vr_gl_thread);
} }
auto graphics_delegate = std::make_unique<GvrGraphicsDelegate>( auto graphics_delegate = std::make_unique<GvrGraphicsDelegate>(
vr_gl_thread, vr_gl_thread,
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <memory> #include <memory>
#include "base/android/jni_weak_ref.h" #include "base/android/jni_weak_ref.h"
#include "chrome/browser/android/vr/gvr_gamepad_data.h"
#include "chrome/browser/vr/assets_load_status.h" #include "chrome/browser/vr/assets_load_status.h"
#include "chrome/browser/vr/ui_test_input.h" #include "chrome/browser/vr/ui_test_input.h"
#include "device/vr/public/mojom/vr_service.mojom.h" #include "device/vr/public/mojom/vr_service.mojom.h"
...@@ -36,7 +35,6 @@ class GlBrowserInterface { ...@@ -36,7 +35,6 @@ class GlBrowserInterface {
virtual void SendRequestPresentReply(device::mojom::XRSessionPtr) = 0; virtual void SendRequestPresentReply(device::mojom::XRSessionPtr) = 0;
virtual void DialogSurfaceCreated(jobject surface, virtual void DialogSurfaceCreated(jobject surface,
gl::SurfaceTexture* texture) = 0; gl::SurfaceTexture* texture) = 0;
virtual void UpdateGamepadData(GvrGamepadData) = 0;
virtual void ToggleCardboardGamepad(bool enabled) = 0; virtual void ToggleCardboardGamepad(bool enabled) = 0;
}; };
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_VR_GVR_GAMEPAD_DATA_H_
#define CHROME_BROWSER_ANDROID_VR_GVR_GAMEPAD_DATA_H_
#include "ui/gfx/geometry/quaternion.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/geometry/vector3d_f.h"
namespace vr {
// Subset of GVR controller data needed for the gamepad API. Filled in
// by vr_shell's VrController.
struct GvrGamepadData {
GvrGamepadData()
: timestamp(0),
is_touching(false),
controller_button_pressed(false),
right_handed(true),
connected(false) {}
int64_t timestamp;
gfx::Vector2dF touch_pos;
gfx::Quaternion orientation;
gfx::Vector3dF accel;
gfx::Vector3dF gyro;
bool is_touching;
bool controller_button_pressed;
bool right_handed;
bool connected;
};
} // namespace vr
#endif // CHROME_BROWSER_ANDROID_VR_GVR_GAMEPAD_DATA_H_
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/android/vr/gl_browser_interface.h"
#include "chrome/browser/android/vr/vr_controller.h" #include "chrome/browser/android/vr/vr_controller.h"
#include "chrome/browser/vr/input_event.h" #include "chrome/browser/vr/input_event.h"
#include "chrome/browser/vr/model/controller_model.h" #include "chrome/browser/vr/model/controller_model.h"
...@@ -18,51 +17,12 @@ ...@@ -18,51 +17,12 @@
namespace { namespace {
constexpr gfx::Vector3dF kForwardVector = {0.0f, 0.0f, -1.0f}; constexpr gfx::Vector3dF kForwardVector = {0.0f, 0.0f, -1.0f};
device::Gamepad CreateGamepad(const vr::GvrGamepadData& data) {
device::Gamepad gamepad;
// Unless the controller state is updated on a different thread,
// data.connected should always be true when this function is called by
// GvrInputDelegate::GetInputSourceState.
gamepad.connected = data.connected;
gamepad.timestamp = data.timestamp;
gamepad.hand = data.right_handed ? device::GamepadHand::kRight
: device::GamepadHand::kLeft;
bool pressed = data.controller_button_pressed;
bool touched = data.is_touching;
double value = pressed ? 1.0 : 0.0;
gamepad.buttons[gamepad.buttons_length++] =
device::GamepadButton(pressed, touched, value);
if (touched) {
// data.touch_pos values reported by the GVR Android SDK are clamped to
// [0.0, 1.0], with (0, 0) corresponding to the top-left of the touchpad.
// Normalize the values to use X axis range -1 (left) to 1 (right) and Y
// axis range -1 (top) to 1 (bottom).
gamepad.axes[0] = (data.touch_pos.x() * 2.0) - 1.0;
gamepad.axes[1] = (data.touch_pos.y() * 2.0) - 1.0;
} else {
gamepad.axes[0] = 0.0;
gamepad.axes[1] = 0.0;
}
gamepad.axes_length = 2;
return gamepad;
} }
} // namespace
namespace vr { namespace vr {
GvrInputDelegate::GvrInputDelegate(gvr::GvrApi* gvr_api, GvrInputDelegate::GvrInputDelegate(gvr::GvrApi* gvr_api)
GlBrowserInterface* browser) : controller_(std::make_unique<VrController>(gvr_api)), gvr_api_(gvr_api) {}
: controller_(std::make_unique<VrController>(gvr_api)),
gvr_api_(gvr_api),
browser_(browser) {}
GvrInputDelegate::~GvrInputDelegate() = default; GvrInputDelegate::~GvrInputDelegate() = default;
...@@ -80,11 +40,6 @@ void GvrInputDelegate::UpdateController(const gfx::Transform& head_pose, ...@@ -80,11 +40,6 @@ void GvrInputDelegate::UpdateController(const gfx::Transform& head_pose,
base::TimeTicks current_time, base::TimeTicks current_time,
bool is_webxr_frame) { bool is_webxr_frame) {
controller_->UpdateState(head_pose); controller_->UpdateState(head_pose);
GvrGamepadData controller_data = controller_->GetGamepadData();
if (!is_webxr_frame)
controller_data.connected = false;
browser_->UpdateGamepadData(controller_data);
} }
ControllerModel GvrInputDelegate::GetControllerModel( ControllerModel GvrInputDelegate::GetControllerModel(
...@@ -189,7 +144,7 @@ device::mojom::XRInputSourceStatePtr GvrInputDelegate::GetInputSourceState() { ...@@ -189,7 +144,7 @@ device::mojom::XRInputSourceStatePtr GvrInputDelegate::GetInputSourceState() {
state->description->profiles.push_back("google-daydream"); state->description->profiles.push_back("google-daydream");
// This Gamepad data is used to expose touchpad position to WebXR. // This Gamepad data is used to expose touchpad position to WebXR.
state->gamepad = CreateGamepad(controller_->GetGamepadData()); state->gamepad = controller_->GetGamepadData();
} }
return state; return state;
......
...@@ -18,11 +18,10 @@ class GvrApi; ...@@ -18,11 +18,10 @@ class GvrApi;
namespace vr { namespace vr {
class GestureDetector; class GestureDetector;
class GlBrowserInterface;
class GvrInputDelegate : public InputDelegate { class GvrInputDelegate : public InputDelegate {
public: public:
GvrInputDelegate(gvr::GvrApi* gvr_api, GlBrowserInterface* browser); explicit GvrInputDelegate(gvr::GvrApi* gvr_api);
~GvrInputDelegate() override; ~GvrInputDelegate() override;
// InputDelegate implementation. // InputDelegate implementation.
...@@ -41,7 +40,6 @@ class GvrInputDelegate : public InputDelegate { ...@@ -41,7 +40,6 @@ class GvrInputDelegate : public InputDelegate {
std::unique_ptr<VrController> controller_; std::unique_ptr<VrController> controller_;
GestureDetector gesture_detector_; GestureDetector gesture_detector_;
gvr::GvrApi* gvr_api_; gvr::GvrApi* gvr_api_;
GlBrowserInterface* browser_;
bool was_select_button_down_ = false; bool was_select_button_down_ = false;
......
...@@ -62,11 +62,6 @@ VrController::VrController(gvr::GvrApi* gvr_api) ...@@ -62,11 +62,6 @@ VrController::VrController(gvr::GvrApi* gvr_api)
options |= GVR_CONTROLLER_ENABLE_ARM_MODEL; options |= GVR_CONTROLLER_ENABLE_ARM_MODEL;
// Enable non-default options - WebVR needs gyro and linear acceleration, and
// since VrShell implements GvrGamepadDataProvider we need this always.
options |= GVR_CONTROLLER_ENABLE_GYRO;
options |= GVR_CONTROLLER_ENABLE_ACCEL;
CHECK(controller_api_->Init(options, gvr_api_->cobj())); CHECK(controller_api_->Init(options, gvr_api_->cobj()));
controller_api_->Resume(); controller_api_->Resume();
...@@ -93,31 +88,45 @@ void VrController::OnPause() { ...@@ -93,31 +88,45 @@ void VrController::OnPause() {
controller_api_->Pause(); controller_api_->Pause();
} }
GvrGamepadData VrController::GetGamepadData() { device::Gamepad VrController::GetGamepadData() {
GvrGamepadData pad = {}; device::Gamepad gamepad;
pad.connected = IsConnected();
pad.timestamp = controller_state_->GetLastOrientationTimestamp(); gamepad.connected = IsConnected();
gamepad.timestamp = controller_state_->GetLastOrientationTimestamp();
if (pad.connected) {
pad.touch_pos = {GetPositionInTrackpad().x(), GetPositionInTrackpad().y()}; if (!gamepad.connected)
pad.orientation = Orientation(); return gamepad;
// Use orientation to rotate acceleration/gyro into seated space. if (handedness_ == GVR_CONTROLLER_RIGHT_HANDED) {
gfx::Transform pose_mat(Orientation()); gamepad.hand = device::GamepadHand::kRight;
const gvr::Vec3f& accel = controller_state_->GetAccel(); } else {
const gvr::Vec3f& gyro = controller_state_->GetGyro(); gamepad.hand = device::GamepadHand::kLeft;
pad.accel = gfx::Vector3dF(accel.x, accel.y, accel.z);
pose_mat.TransformVector(&pad.accel);
pad.gyro = gfx::Vector3dF(gyro.x, gyro.y, gyro.z);
pose_mat.TransformVector(&pad.gyro);
pad.is_touching = controller_state_->IsTouching();
pad.controller_button_pressed =
controller_state_->GetButtonState(GVR_CONTROLLER_BUTTON_CLICK);
pad.right_handed = handedness_ == GVR_CONTROLLER_RIGHT_HANDED;
} }
return pad; bool touched = controller_state_->IsTouching();
bool pressed = controller_state_->GetButtonState(GVR_CONTROLLER_BUTTON_CLICK);
double value = pressed ? 1.0 : 0.0;
gamepad.buttons[gamepad.buttons_length++] =
device::GamepadButton(pressed, touched, value);
if (touched) {
// Trackpad values reported by the GVR Android SDK are clamped to
// [0.0, 1.0], with (0, 0) corresponding to the top-left of the touchpad.
// Normalize the values to use X axis range -1 (left) to 1 (right) and Y
// axis range -1 (top) to 1 (bottom).
double x = GetPositionInTrackpad().x();
double y = GetPositionInTrackpad().y();
gamepad.axes[0] = (x * 2.0) - 1.0;
gamepad.axes[1] = (y * 2.0) - 1.0;
} else {
gamepad.axes[0] = 0.0;
gamepad.axes[1] = 0.0;
}
gamepad.axes_length = 2;
return gamepad;
} }
bool VrController::IsButtonDown(ButtonType type) const { bool VrController::IsButtonDown(ButtonType type) const {
......
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/android/vr/gvr_gamepad_data.h"
#include "chrome/browser/android/vr/gvr_util.h" #include "chrome/browser/android/vr/gvr_util.h"
#include "chrome/browser/vr/gesture_detector.h" #include "chrome/browser/vr/gesture_detector.h"
#include "chrome/browser/vr/platform_controller.h" #include "chrome/browser/vr/platform_controller.h"
#include "device/gamepad/public/cpp/gamepad.h"
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_types.h" #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_types.h"
#include "ui/gfx/geometry/point3_f.h" #include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/quaternion.h" #include "ui/gfx/geometry/quaternion.h"
...@@ -47,7 +47,7 @@ class VrController : public PlatformController { ...@@ -47,7 +47,7 @@ class VrController : public PlatformController {
// Must be called when the Activity gets OnPause(). // Must be called when the Activity gets OnPause().
void OnPause(); void OnPause();
GvrGamepadData GetGamepadData(); device::Gamepad GetGamepadData();
// Called once per frame to update controller state. // Called once per frame to update controller state.
void UpdateState(const gfx::Transform& head_pose); void UpdateState(const gfx::Transform& head_pose);
......
...@@ -118,13 +118,6 @@ void VrGLThread::SendRequestPresentReply(device::mojom::XRSessionPtr session) { ...@@ -118,13 +118,6 @@ void VrGLThread::SendRequestPresentReply(device::mojom::XRSessionPtr session) {
weak_vr_shell_, std::move(session))); weak_vr_shell_, std::move(session)));
} }
void VrGLThread::UpdateGamepadData(GvrGamepadData pad) {
DCHECK(OnGlThread());
main_thread_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&VrShell::UpdateGamepadData, weak_vr_shell_, pad));
}
void VrGLThread::ForwardEventToContent(std::unique_ptr<InputEvent> event, void VrGLThread::ForwardEventToContent(std::unique_ptr<InputEvent> event,
int content_id) { int content_id) {
DCHECK(OnGlThread()); DCHECK(OnGlThread());
......
...@@ -71,7 +71,6 @@ class VrGLThread : public base::android::JavaHandlerThread, ...@@ -71,7 +71,6 @@ class VrGLThread : public base::android::JavaHandlerThread,
void SendRequestPresentReply(device::mojom::XRSessionPtr) override; void SendRequestPresentReply(device::mojom::XRSessionPtr) override;
void DialogSurfaceCreated(jobject surface, void DialogSurfaceCreated(jobject surface,
gl::SurfaceTexture* texture) override; gl::SurfaceTexture* texture) override;
void UpdateGamepadData(GvrGamepadData) override;
void ToggleCardboardGamepad(bool enabled) override; void ToggleCardboardGamepad(bool enabled) override;
// BrowserRendererBrowserInterface implementation (BrowserRenderer calling to // BrowserRendererBrowserInterface implementation (BrowserRenderer calling to
......
...@@ -413,20 +413,6 @@ void VrShell::ToggleCardboardGamepad(bool enabled) { ...@@ -413,20 +413,6 @@ void VrShell::ToggleCardboardGamepad(bool enabled) {
} }
} }
void VrShell::ToggleGvrGamepad(bool enabled) {
// Enable/disable updating gamepad state.
if (enabled) {
DCHECK(!gvr_gamepad_source_active_);
device::GvrDevice* gvr_device = delegate_provider_->GetGvrDevice();
if (!gvr_device)
return;
gvr_gamepad_source_active_ = true;
} else {
DCHECK(gvr_gamepad_source_active_);
gvr_gamepad_source_active_ = false;
}
}
void VrShell::OnTriggerEvent(JNIEnv* env, void VrShell::OnTriggerEvent(JNIEnv* env,
const JavaParamRef<jobject>& obj, const JavaParamRef<jobject>& obj,
bool touched) { bool touched) {
...@@ -1073,11 +1059,6 @@ void VrShell::ProcessDialogGesture(std::unique_ptr<InputEvent> event) { ...@@ -1073,11 +1059,6 @@ void VrShell::ProcessDialogGesture(std::unique_ptr<InputEvent> event) {
dialog_gesture_target_->DispatchInputEvent(std::move(event)); dialog_gesture_target_->DispatchInputEvent(std::move(event));
} }
void VrShell::UpdateGamepadData(GvrGamepadData pad) {
if (gvr_gamepad_source_active_ != pad.connected)
ToggleGvrGamepad(pad.connected);
}
bool VrShell::HasDaydreamSupport(JNIEnv* env) { bool VrShell::HasDaydreamSupport(JNIEnv* env) {
return Java_VrShell_hasDaydreamSupport(env, j_vr_shell_); return Java_VrShell_hasDaydreamSupport(env, j_vr_shell_);
} }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/browser/android/vr/gvr_gamepad_data.h"
#include "chrome/browser/ui/page_info/page_info_ui.h" #include "chrome/browser/ui/page_info/page_info_ui.h"
#include "chrome/browser/ui/toolbar/chrome_location_bar_model_delegate.h" #include "chrome/browser/ui/toolbar/chrome_location_bar_model_delegate.h"
#include "chrome/browser/vr/assets_load_status.h" #include "chrome/browser/vr/assets_load_status.h"
...@@ -146,7 +145,6 @@ class VrShell : VoiceResultDelegate, ...@@ -146,7 +145,6 @@ class VrShell : VoiceResultDelegate,
void OpenFeedback(); void OpenFeedback();
void CloseHostedDialog(); void CloseHostedDialog();
void ToggleCardboardGamepad(bool enabled); void ToggleCardboardGamepad(bool enabled);
void ToggleGvrGamepad(bool enabled);
void SetHistoryButtonsEnabled(JNIEnv* env, void SetHistoryButtonsEnabled(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
jboolean can_go_back, jboolean can_go_back,
...@@ -254,8 +252,6 @@ class VrShell : VoiceResultDelegate, ...@@ -254,8 +252,6 @@ class VrShell : VoiceResultDelegate,
device::mojom::VRDisplayInfoPtr display_info, device::mojom::VRDisplayInfoPtr display_info,
device::mojom::XRRuntimeSessionOptionsPtr options); device::mojom::XRRuntimeSessionOptionsPtr options);
void UpdateGamepadData(GvrGamepadData);
// ChromeLocationBarModelDelegate implementation. // ChromeLocationBarModelDelegate implementation.
content::WebContents* GetActiveWebContents() const override; content::WebContents* GetActiveWebContents() const override;
bool ShouldDisplayURL() const override; bool ShouldDisplayURL() const override;
...@@ -368,7 +364,6 @@ class VrShell : VoiceResultDelegate, ...@@ -368,7 +364,6 @@ class VrShell : VoiceResultDelegate,
CapturingStateModel potential_capturing_; CapturingStateModel potential_capturing_;
// Are we currently providing a gamepad factory to the gamepad manager? // Are we currently providing a gamepad factory to the gamepad manager?
bool gvr_gamepad_source_active_ = false;
bool cardboard_gamepad_source_active_ = false; bool cardboard_gamepad_source_active_ = false;
bool pending_cardboard_trigger_ = false; bool pending_cardboard_trigger_ = false;
......
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