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

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

Issue 2762003002: Refactor GVR controller gamepad API integration (Closed)
Patch Set: Rebase, no changes 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) {
21 DVLOG(1) << __FUNCTION__ << "=" << this;
22 j_vr_shell_delegate_.Reset(env, obj); 22 j_vr_shell_delegate_.Reset(env, obj);
23 } 23 }
24 24
25 VrShellDelegate::~VrShellDelegate() { 25 VrShellDelegate::~VrShellDelegate() {
26 DVLOG(1) << __FUNCTION__ << "=" << this;
26 if (device_provider_) { 27 if (device_provider_) {
27 device_provider_->Device()->OnDelegateChanged(); 28 device_provider_->Device()->OnDelegateChanged();
28 } 29 }
29 } 30 }
30 31
31 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() { 32 device::GvrDelegateProvider* VrShellDelegate::CreateVrShellDelegate() {
32 JNIEnv* env = AttachCurrentThread(); 33 JNIEnv* env = AttachCurrentThread();
33 base::android::ScopedJavaLocalRef<jobject> jdelegate = 34 base::android::ScopedJavaLocalRef<jobject> jdelegate =
34 Java_VrShellDelegate_getInstance(env); 35 Java_VrShellDelegate_getInstance(env);
35 if (!jdelegate.is_null()) 36 if (!jdelegate.is_null())
(...skipping 12 matching lines...) Expand all
48 delegate_ = delegate; 49 delegate_ = delegate;
49 // Clean up the non-presenting delegate. 50 // Clean up the non-presenting delegate.
50 if (delegate_ && non_presenting_delegate_) { 51 if (delegate_ && non_presenting_delegate_) {
51 non_presenting_delegate_ = nullptr; 52 non_presenting_delegate_ = nullptr;
52 JNIEnv* env = AttachCurrentThread(); 53 JNIEnv* env = AttachCurrentThread();
53 Java_VrShellDelegate_shutdownNonPresentingNativeContext( 54 Java_VrShellDelegate_shutdownNonPresentingNativeContext(
54 env, j_vr_shell_delegate_.obj()); 55 env, j_vr_shell_delegate_.obj());
55 } 56 }
56 if (device_provider_) { 57 if (device_provider_) {
57 device::GvrDevice* device = device_provider_->Device(); 58 device::GvrDevice* device = device_provider_->Device();
58 device::GamepadDataFetcherManager::GetInstance()->AddFactory(
59 new device::GvrGamepadDataFetcher::Factory(context, device->id()));
60 device->OnDelegateChanged(); 59 device->OnDelegateChanged();
61 } 60 }
62 61
63 delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_); 62 delegate_->UpdateVSyncInterval(timebase_nanos_, interval_seconds_);
64 } 63 }
65 64
66 void VrShellDelegate::RemoveDelegate() { 65 void VrShellDelegate::RemoveDelegate() {
67 delegate_ = nullptr; 66 delegate_ = nullptr;
68 device::GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory(
69 device::GAMEPAD_SOURCE_GVR);
70 if (device_provider_) { 67 if (device_provider_) {
71 CreateNonPresentingDelegate(); 68 CreateNonPresentingDelegate();
72 device_provider_->Device()->OnDelegateChanged(); 69 device_provider_->Device()->OnDelegateChanged();
73 } 70 }
74 } 71 }
75 72
76 void VrShellDelegate::SetPresentResult(JNIEnv* env, 73 void VrShellDelegate::SetPresentResult(JNIEnv* env,
77 const JavaParamRef<jobject>& obj, 74 const JavaParamRef<jobject>& obj,
78 jboolean result) { 75 jboolean result) {
79 CHECK(!present_callback_.is_null()); 76 CHECK(!present_callback_.is_null());
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 201 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
205 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj)); 202 return reinterpret_cast<intptr_t>(new VrShellDelegate(env, obj));
206 } 203 }
207 204
208 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) { 205 static void OnLibraryAvailable(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
209 device::GvrDelegateProvider::SetInstance( 206 device::GvrDelegateProvider::SetInstance(
210 base::Bind(&VrShellDelegate::CreateVrShellDelegate)); 207 base::Bind(&VrShellDelegate::CreateVrShellDelegate));
211 } 208 }
212 209
213 } // namespace vr_shell 210 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell.cc ('k') | chrome/browser/android/vr_shell/vr_shell_gl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698