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

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell_delegate.cc

Issue 2762003002: Refactor GVR controller gamepad API integration (Closed)
Patch Set: Fix comment, include gvr_types only for data provider Created 3 years, 9 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 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h" 5 #include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h" 10 #include "chrome/browser/android/vr_shell/non_presenting_gvr_delegate.h"
11 #include "device/vr/android/gvr/gvr_device.h" 11 #include "device/vr/android/gvr/gvr_device.h"
12 #include "device/vr/android/gvr/gvr_device_provider.h" 12 #include "device/vr/android/gvr/gvr_device_provider.h"
13 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h"
14 #include "jni/VrShellDelegate_jni.h" 13 #include "jni/VrShellDelegate_jni.h"
15 14
16 using base::android::JavaParamRef; 15 using base::android::JavaParamRef;
17 using base::android::AttachCurrentThread; 16 using base::android::AttachCurrentThread;
18 17
19 namespace vr_shell { 18 namespace vr_shell {
20 19
21 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj) 20 VrShellDelegate::VrShellDelegate(JNIEnv* env, jobject obj)
22 : weak_ptr_factory_(this) { 21 : weak_ptr_factory_(this) {
23 j_vr_shell_delegate_.Reset(env, obj); 22 j_vr_shell_delegate_.Reset(env, obj);
(...skipping 25 matching lines...) Expand all
49 delegate_ = delegate; 48 delegate_ = delegate;
50 // Clean up the non-presenting delegate. 49 // Clean up the non-presenting delegate.
51 if (delegate_ && non_presenting_delegate_) { 50 if (delegate_ && non_presenting_delegate_) {
52 non_presenting_delegate_ = nullptr; 51 non_presenting_delegate_ = nullptr;
53 JNIEnv* env = AttachCurrentThread(); 52 JNIEnv* env = AttachCurrentThread();
54 Java_VrShellDelegate_shutdownNonPresentingNativeContext( 53 Java_VrShellDelegate_shutdownNonPresentingNativeContext(
55 env, j_vr_shell_delegate_.obj()); 54 env, j_vr_shell_delegate_.obj());
56 } 55 }
57 if (device_provider_) { 56 if (device_provider_) {
58 device::GvrDevice* device = device_provider_->Device(); 57 device::GvrDevice* device = device_provider_->Device();
59 device::GamepadDataFetcherManager::GetInstance()->AddFactory(
60 new device::GvrGamepadDataFetcher::Factory(context, device->id()));
61 device->OnDelegateChanged(); 58 device->OnDelegateChanged();
62 } 59 }
63 60
64 delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_); 61 delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_);
65 } 62 }
66 63
67 void VrShellDelegate::RemoveDelegate() { 64 void VrShellDelegate::RemoveDelegate() {
68 delegate_ = nullptr; 65 delegate_ = nullptr;
69 device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory(
70 device::GAMEPAD_SOURCE_GVR);
71 if (device_provider_) { 66 if (device_provider_) {
72 CreateNonPresentingDelegate(); 67 CreateNonPresentingDelegate();
73 device_provider_->Device()->OnDelegateChanged(); 68 device_provider_->Device()->OnDelegateChanged();
74 } 69 }
75 } 70 }
76 71
77 void VrShellDelegate::SetPresentResult(JNIEnv* env, 72 void VrShellDelegate::SetPresentResult(JNIEnv* env,
78 const JavaParamRef<jobject>& obj, 73 const JavaParamRef<jobject>& obj,
79 jboolean result) { 74 jboolean result) {
80 CHECK(!present_callback_.is_null()); 75 CHECK(!present_callback_.is_null());
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 214 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
220 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); 215 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
221 } 216 }
222 217
223 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { 218 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
224 device::GvrDelegateProvider::SetInstance( 219 device::GvrDelegateProvider::SetInstance(
225 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); 220 base::Bind(&VrShellDelegate::CreateVrShellDelegate));
226 } 221 }
227 222
228 } // namespace vr_shell 223 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698