Index: chrome/browser/android/vr_shell/vr_controller.h |
diff --git a/chrome/browser/android/vr_shell/vr_controller.h b/chrome/browser/android/vr_shell/vr_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..65a8e56cc38ad1b5932950849aa2b00973e1e6b6 |
--- /dev/null |
+++ b/chrome/browser/android/vr_shell/vr_controller.h |
@@ -0,0 +1,149 @@ |
+// Copyright 2016 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_SHELL_VR_CONTROLLER_H_ |
+#define CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ |
+ |
+#include "base/memory/ref_counted.h" |
+#include "base/task_runner_util.h" |
+#include "chrome/browser/android/vr_shell/vr_gesture.h" |
+#include "content/public/browser/android/content_view_core.h" |
+#include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/gvr.h" |
+#include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/gvr_controller.h" |
+#include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/gvr_types.h" |
+ |
+namespace vr_shell { |
+ |
+class VrController { |
+ public: |
+ // Controller API entry point. |
+ explicit VrController(gvr_context_* gvr_context); |
mthiesse
2016/09/22 16:20:11
gvr_context*
asimjour
2016/09/22 22:55:16
Done.
|
+ ~VrController(); |
+ |
+ // Must be called when the Activity gets OnResume(). |
+ void OnResume(); |
+ |
+ // Must be called when the Activity gets OnPause(). |
+ void OnPause(); |
+ |
+ // Must be called when the GL renderer gets OnSurfaceCreated(). |
+ void Initialize(gvr_context_* gvr_context); |
mthiesse
2016/09/22 16:20:11
gvr_context*
asimjour
2016/09/22 22:55:16
Done.
|
+ |
+ // Must be called when the GL renderer gets OnDrawFrame(). |
+ void UpdateState(); |
+ VrGesture DetectGesture(); |
+ |
+ bool IsTouching(); |
+ |
+ float TouchPosX(); |
+ |
+ float TouchPosY(); |
+ |
+ const gvr_quatf Orientation(); |
+ |
+ bool IsTouchDown(); |
+ |
+ bool IsTouchUp(); |
+ |
+ bool ButtonUp(const int32_t button); |
+ bool ButtonDown(const int32_t button); |
+ |
+ bool IsConnected(); |
+ |
+ private: |
+ enum gesture_detector_state { |
+ WAITING, // waiting for user to touch down |
+ TOUCHING, // touching the touch pad but not scrolling |
+ SCROLLING // scrolling on the touch pad |
+ }; |
+ |
+ struct TouchPoint { |
+ gvr_vec2f position; |
mthiesse
2016/09/22 16:20:11
gvr::Vec2f
asimjour
2016/09/22 22:55:16
Done.
|
+ int64_t timestamp; |
+ }; |
+ |
+ struct TouchInfo { |
+ TouchPoint touch_point; |
+ bool touch_up; |
+ bool touch_down; |
+ bool is_touching; |
+ }; |
+ |
+ struct ButtonInfo { |
+ gvr_controller_button button; |
+ bool button_up; |
+ bool button_down; |
+ bool button_state; |
+ int64_t timestamp; |
+ }; |
+ |
+ void UpdateGestureFromTouchInfo(); |
+ |
+ bool GetButtonLongPressFromButtonInfo(); |
+ |
+ // Handle the waiting state. |
+ void HandleWaitingState(); |
+ |
+ // Handle the detecting state. |
+ void HandleDetectingState(); |
+ |
+ // Handle the scrolling state. |
+ void HandleScrollingState(); |
+ void Update(const gvr_controller_state* controller_state); |
+ void Update(bool touch_up, |
+ bool touch_down, |
+ bool is_touching, |
+ const gvr_vec2f position, |
+ int64_t timestamp); |
+ |
+ // Returns true if the touch position is with in the slop of the initial touch |
+ // point, |
+ // false otherwise. |
+ bool InSlop(const gvr_vec2f touch_position); |
mthiesse
2016/09/22 16:20:11
gvr::Vec2f
asimjour
2016/09/22 22:55:15
Replaced gvr_vec2f with gvr::Vec2f in this file an
|
+ |
+ void Reset(); |
+ |
+ int GetGestureListSize() { return static_cast<int>(gesture_list_.size()); } |
mthiesse
2016/09/22 16:20:11
Return a size_t and let the callsite decide if the
asimjour
2016/09/22 22:55:15
Done.
|
+ |
+ const VrGesture* GetGesturePtr(const size_t index); |
+ |
+ // Update gesture parameters, |
+ void UpdateGesture(VrGesture* gesture); |
+ |
+ // If the user is touching the touch pad and the touch point is different from |
+ // before, update the touch point and return true. Otherwise, return false. |
+ bool UpdateCurrentTouchpoint(); |
+ |
+ // State of gesture detector. |
+ gesture_detector_state state_; |
+ |
+ std::unique_ptr<gvr::ControllerApi> controller_api_; |
+ |
+ // The last controller state (updated once per frame). |
+ gvr::ControllerState controller_state_; |
+ |
+ float last_qx_; |
+ float last_qz_; |
+ bool pinch_started_; |
+ bool zoom_in_progress_ = false; |
+ |
+ std::vector<VrGesture> gesture_list_; |
+ std::unique_ptr<TouchInfo> touch_info_; |
+ |
+ // A pointer storing the touch point from previous frame. |
+ std::unique_ptr<TouchPoint> prev_touch_point_; |
+ |
+ // A pointer storing the touch point from current frame. |
+ std::unique_ptr<TouchPoint> cur_touch_point_; |
+ |
+ // Initial touch point. |
+ std::unique_ptr<TouchPoint> init_touch_point_; |
+ |
+ // Overall velocity |
+ gvr_vec2f overall_velocity_; |
mthiesse
2016/09/22 16:20:11
gvr::Vec2f
asimjour
2016/09/22 22:55:16
Done.
|
+}; |
+ |
+} // namespace vr_shell |
+ |
+#endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ |