| OLD | NEW |
| 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 "device/vr/android/gvr/gvr_device_provider.h" | 5 #include "device/vr/android/gvr/gvr_device_provider.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 if (!delegate_provider) | 49 if (!delegate_provider) |
| 50 return; | 50 return; |
| 51 | 51 |
| 52 if (!vr_device_) { | 52 if (!vr_device_) { |
| 53 vr_device_.reset( | 53 vr_device_.reset( |
| 54 new GvrDevice(this, delegate_provider->GetNonPresentingDelegate())); | 54 new GvrDevice(this, delegate_provider->GetNonPresentingDelegate())); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool GvrDeviceProvider::RequestPresent() { | 58 bool GvrDeviceProvider::RequestPresent() { |
| 59 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
| 59 device::GvrDelegateProvider* delegate_provider = | 60 device::GvrDelegateProvider* delegate_provider = |
| 60 device::GvrDelegateProvider::GetInstance(); | 61 device::GvrDelegateProvider::GetInstance(); |
| 61 if (!delegate_provider) | 62 if (!delegate_provider) |
| 62 return false; | 63 return false; |
| 63 | 64 |
| 64 // RequestWebVRPresent is async as a render thread may be created. | 65 // RequestWebVRPresent is async as a render thread may be created. |
| 65 return delegate_provider->RequestWebVRPresent(this); | 66 return delegate_provider->RequestWebVRPresent(this); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void GvrDeviceProvider::ExitPresent() { | 69 void GvrDeviceProvider::ExitPresent() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 79 vr_device_->SetDelegate(delegate_provider->GetNonPresentingDelegate()); | 80 vr_device_->SetDelegate(delegate_provider->GetNonPresentingDelegate()); |
| 80 | 81 |
| 81 GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( | 82 GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( |
| 82 GAMEPAD_SOURCE_GVR); | 83 GAMEPAD_SOURCE_GVR); |
| 83 | 84 |
| 84 delegate_provider->ExitWebVRPresent(); | 85 delegate_provider->ExitWebVRPresent(); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void GvrDeviceProvider::OnGvrDelegateReady(GvrDelegate* delegate) { | 88 void GvrDeviceProvider::OnGvrDelegateReady(GvrDelegate* delegate) { |
| 88 main_thread_task_runner_->PostTask( | 89 main_thread_task_runner_->PostTask( |
| 89 FROM_HERE, | 90 FROM_HERE, base::Bind(&GvrDeviceProvider::GvrDelegateReady, this, |
| 90 base::Bind(&GvrDeviceProvider::GvrDelegateReady, base::Unretained(this), | 91 base::Unretained(delegate))); |
| 91 base::Unretained(delegate))); | |
| 92 } | 92 } |
| 93 | 93 |
| 94 void GvrDeviceProvider::OnGvrDelegateRemoved() { | 94 void GvrDeviceProvider::OnGvrDelegateRemoved() { |
| 95 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 95 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
| 96 if (!vr_device_) | 96 if (!vr_device_) |
| 97 return; | 97 return; |
| 98 ExitPresent(); | 98 ExitPresent(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void GvrDeviceProvider::OnDisplayBlur() { |
| 102 if (!main_thread_task_runner_->BelongsToCurrentThread()) { |
| 103 main_thread_task_runner_->PostTask( |
| 104 FROM_HERE, base::Bind(&GvrDeviceProvider::OnDisplayBlur, this)); |
| 105 return; |
| 106 } |
| 107 if (!vr_device_) |
| 108 return; |
| 109 vr_device_->OnDisplayBlur(); |
| 110 } |
| 111 |
| 112 void GvrDeviceProvider::OnDisplayFocus() { |
| 113 if (!main_thread_task_runner_->BelongsToCurrentThread()) { |
| 114 main_thread_task_runner_->PostTask( |
| 115 FROM_HERE, base::Bind(&GvrDeviceProvider::OnDisplayFocus, this)); |
| 116 return; |
| 117 } |
| 118 if (!vr_device_) |
| 119 return; |
| 120 vr_device_->OnDisplayFocus(); |
| 121 } |
| 122 |
| 101 void GvrDeviceProvider::GvrDelegateReady(GvrDelegate* delegate) { | 123 void GvrDeviceProvider::GvrDelegateReady(GvrDelegate* delegate) { |
| 102 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 124 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
| 103 | 125 |
| 104 vr_device_->SetDelegate(delegate); | 126 vr_device_->SetDelegate(delegate); |
| 105 GamepadDataFetcherManager::GetInstance()->AddFactory( | 127 GamepadDataFetcherManager::GetInstance()->AddFactory( |
| 106 new GvrGamepadDataFetcher::Factory(delegate, vr_device_->id())); | 128 new GvrGamepadDataFetcher::Factory(delegate, vr_device_->id())); |
| 107 } | 129 } |
| 108 | 130 |
| 109 } // namespace device | 131 } // namespace device |
| OLD | NEW |