Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell.h

Issue 2879973002: Expose Gamepad API instance for Cardboard button (Closed)
Patch Set: fix crash in tests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/android/jni_weak_ref.h" 12 #include "base/android/jni_weak_ref.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "chrome/browser/android/vr_shell/ui_interface.h" 17 #include "chrome/browser/android/vr_shell/ui_interface.h"
18 #include "chrome/browser/android/vr_shell/vr_controller_model.h" 18 #include "chrome/browser/android/vr_shell/vr_controller_model.h"
19 #include "content/public/browser/web_contents_observer.h" 19 #include "content/public/browser/web_contents_observer.h"
20 #include "device/vr/android/gvr/cardboard_gamepad_data_provider.h"
20 #include "device/vr/android/gvr/gvr_delegate.h" 21 #include "device/vr/android/gvr/gvr_delegate.h"
21 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" 22 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h"
22 #include "device/vr/vr_service.mojom.h" 23 #include "device/vr/vr_service.mojom.h"
23 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h" 24 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h"
24 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_types.h" 25 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_types.h"
25 26
26 namespace blink { 27 namespace blink {
27 class WebInputEvent; 28 class WebInputEvent;
28 } 29 }
29 30
(...skipping 27 matching lines...) Expand all
57 SHOW_TAB, 58 SHOW_TAB,
58 OPEN_NEW_TAB, 59 OPEN_NEW_TAB,
59 EXIT_PRESENT, 60 EXIT_PRESENT,
60 }; 61 };
61 62
62 class VrMetricsHelper; 63 class VrMetricsHelper;
63 64
64 // The native instance of the Java VrShell. This class is not threadsafe and 65 // The native instance of the Java VrShell. This class is not threadsafe and
65 // must only be used on the UI thread. 66 // must only be used on the UI thread.
66 class VrShell : public device::PresentingGvrDelegate, 67 class VrShell : public device::PresentingGvrDelegate,
67 device::GvrGamepadDataProvider { 68 device::GvrGamepadDataProvider,
69 device::CardboardGamepadDataProvider {
68 public: 70 public:
69 VrShell(JNIEnv* env, 71 VrShell(JNIEnv* env,
70 jobject obj, 72 jobject obj,
71 ui::WindowAndroid* window, 73 ui::WindowAndroid* window,
72 bool for_web_vr, 74 bool for_web_vr,
73 bool in_cct, 75 bool in_cct,
74 VrShellDelegate* delegate, 76 VrShellDelegate* delegate,
75 gvr_context* gvr_api, 77 gvr_context* gvr_api,
76 bool reprojected_rendering); 78 bool reprojected_rendering);
77 void SwapContents( 79 void SwapContents(
78 JNIEnv* env, 80 JNIEnv* env,
79 const base::android::JavaParamRef<jobject>& obj, 81 const base::android::JavaParamRef<jobject>& obj,
80 const base::android::JavaParamRef<jobject>& web_contents, 82 const base::android::JavaParamRef<jobject>& web_contents,
81 const base::android::JavaParamRef<jobject>& touch_event_synthesizer); 83 const base::android::JavaParamRef<jobject>& touch_event_synthesizer);
82 void LoadUIContent(JNIEnv* env, 84 void LoadUIContent(JNIEnv* env,
83 const base::android::JavaParamRef<jobject>& obj); 85 const base::android::JavaParamRef<jobject>& obj);
84 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); 86 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
85 void OnTriggerEvent(JNIEnv* env, 87 void OnTriggerEvent(JNIEnv* env,
86 const base::android::JavaParamRef<jobject>& obj); 88 const base::android::JavaParamRef<jobject>& obj,
89 bool touched);
87 void OnPause(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); 90 void OnPause(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
88 void OnResume(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); 91 void OnResume(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
89 void SetSurface(JNIEnv* env, 92 void SetSurface(JNIEnv* env,
90 const base::android::JavaParamRef<jobject>& obj, 93 const base::android::JavaParamRef<jobject>& obj,
91 const base::android::JavaParamRef<jobject>& surface); 94 const base::android::JavaParamRef<jobject>& surface);
92 void SetWebVrMode(JNIEnv* env, 95 void SetWebVrMode(JNIEnv* env,
93 const base::android::JavaParamRef<jobject>& obj, 96 const base::android::JavaParamRef<jobject>& obj,
94 bool enabled); 97 bool enabled);
95 bool GetWebVrMode(JNIEnv* env, 98 bool GetWebVrMode(JNIEnv* env,
96 const base::android::JavaParamRef<jobject>& obj); 99 const base::android::JavaParamRef<jobject>& obj);
(...skipping 10 matching lines...) Expand all
107 jboolean incognito, 110 jboolean incognito,
108 jint id, 111 jint id,
109 jstring jtitle); 112 jstring jtitle);
110 void OnTabRemoved(JNIEnv* env, 113 void OnTabRemoved(JNIEnv* env,
111 const base::android::JavaParamRef<jobject>& obj, 114 const base::android::JavaParamRef<jobject>& obj,
112 jboolean incognito, 115 jboolean incognito,
113 jint id); 116 jint id);
114 void OnContentPaused(bool paused); 117 void OnContentPaused(bool paused);
115 void NavigateBack(); 118 void NavigateBack();
116 void ExitCct(); 119 void ExitCct();
120 void ToggleCardboardGamepad(bool enabled);
117 base::android::ScopedJavaGlobalRef<jobject> TakeContentSurface( 121 base::android::ScopedJavaGlobalRef<jobject> TakeContentSurface(
118 JNIEnv* env, 122 JNIEnv* env,
119 const base::android::JavaParamRef<jobject>& obj); 123 const base::android::JavaParamRef<jobject>& obj);
120 void RestoreContentSurface(JNIEnv* env, 124 void RestoreContentSurface(JNIEnv* env,
121 const base::android::JavaParamRef<jobject>& obj); 125 const base::android::JavaParamRef<jobject>& obj);
122 void SetHistoryButtonsEnabled(JNIEnv* env, 126 void SetHistoryButtonsEnabled(JNIEnv* env,
123 const base::android::JavaParamRef<jobject>& obj, 127 const base::android::JavaParamRef<jobject>& obj,
124 jboolean can_go_back, 128 jboolean can_go_back,
125 jboolean can_go_forward); 129 jboolean can_go_forward);
126 130
(...skipping 30 matching lines...) Expand all
157 void ForceExitVr(); 161 void ForceExitVr();
158 void ExitPresent(); 162 void ExitPresent();
159 void ExitFullscreen(); 163 void ExitFullscreen();
160 void ExitVrDueToUnsupportedMode(); 164 void ExitVrDueToUnsupportedMode();
161 165
162 void ProcessContentGesture(std::unique_ptr<blink::WebInputEvent> event); 166 void ProcessContentGesture(std::unique_ptr<blink::WebInputEvent> event);
163 void SubmitControllerModel(std::unique_ptr<VrControllerModel> model); 167 void SubmitControllerModel(std::unique_ptr<VrControllerModel> model);
164 168
165 // device::GvrGamepadDataProvider implementation. 169 // device::GvrGamepadDataProvider implementation.
166 void UpdateGamepadData(device::GvrGamepadData) override; 170 void UpdateGamepadData(device::GvrGamepadData) override;
167 void RegisterGamepadDataFetcher(device::GvrGamepadDataFetcher*) override; 171 void RegisterGvrGamepadDataFetcher(device::GvrGamepadDataFetcher*) override;
172
173 // device::CardboardGamepadDataProvider implementation.
174 void RegisterCardboardGamepadDataFetcher(
175 device::CardboardGamepadDataFetcher*) override;
168 176
169 private: 177 private:
170 ~VrShell() override; 178 ~VrShell() override;
171 void WaitForGlThread(); 179 void WaitForGlThread();
172 void PostToGlThread(const tracked_objects::Location& from_here, 180 void PostToGlThread(const tracked_objects::Location& from_here,
173 const base::Closure& task); 181 const base::Closure& task);
174 void SetUiState(); 182 void SetUiState();
175 183
176 // device::GvrDelegate implementation. 184 // device::GvrDelegate implementation.
177 void SetWebVRSecureOrigin(bool secure_origin) override; 185 void SetWebVRSecureOrigin(bool secure_origin) override;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 base::CancelableClosure poll_capturing_media_task_; 237 base::CancelableClosure poll_capturing_media_task_;
230 bool is_capturing_audio_ = false; 238 bool is_capturing_audio_ = false;
231 bool is_capturing_video_ = false; 239 bool is_capturing_video_ = false;
232 bool is_capturing_screen_ = false; 240 bool is_capturing_screen_ = false;
233 241
234 // TODO(mthiesse): Remove the need for this to be stored here. 242 // TODO(mthiesse): Remove the need for this to be stored here.
235 // crbug.com/674594 243 // crbug.com/674594
236 gvr_context* gvr_api_; 244 gvr_context* gvr_api_;
237 245
238 // Are we currently providing a gamepad factory to the gamepad manager? 246 // Are we currently providing a gamepad factory to the gamepad manager?
239 bool gamepad_source_active_ = false; 247 bool gvr_gamepad_source_active_ = false;
240 // Registered fetcher, must remain alive for UpdateGamepadData calls. 248 bool cardboard_gamepad_source_active_ = false;
249
250 // Registered fetchers, must remain alive for UpdateGamepadData calls.
241 // That's ok since the fetcher is only destroyed from VrShell's destructor. 251 // That's ok since the fetcher is only destroyed from VrShell's destructor.
242 device::GvrGamepadDataFetcher* gamepad_data_fetcher_ = nullptr; 252 device::GvrGamepadDataFetcher* gvr_gamepad_data_fetcher_ = nullptr;
253 device::CardboardGamepadDataFetcher* cardboard_gamepad_data_fetcher_ =
254 nullptr;
255 int64_t cardboard_gamepad_timer_ = 0;
243 256
244 base::WeakPtrFactory<VrShell> weak_ptr_factory_; 257 base::WeakPtrFactory<VrShell> weak_ptr_factory_;
245 258
246 DISALLOW_COPY_AND_ASSIGN(VrShell); 259 DISALLOW_COPY_AND_ASSIGN(VrShell);
247 }; 260 };
248 261
249 bool RegisterVrShell(JNIEnv* env); 262 bool RegisterVrShell(JNIEnv* env);
250 263
251 } // namespace vr_shell 264 } // namespace vr_shell
252 265
253 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_ 266 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_gl_thread.cc ('k') | chrome/browser/android/vr_shell/vr_shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698