| 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 15 matching lines...) Expand all Loading... |
| 26 GvrDeviceProvider::~GvrDeviceProvider() { | 26 GvrDeviceProvider::~GvrDeviceProvider() { |
| 27 device::GvrDelegateProvider* delegate_provider = | 27 device::GvrDelegateProvider* delegate_provider = |
| 28 device::GvrDelegateProvider::GetInstance(); | 28 device::GvrDelegateProvider::GetInstance(); |
| 29 if (delegate_provider) { | 29 if (delegate_provider) { |
| 30 delegate_provider->ExitWebVRPresent(); | 30 delegate_provider->ExitWebVRPresent(); |
| 31 delegate_provider->ClearDeviceProvider(); | 31 delegate_provider->ClearDeviceProvider(); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) { | 35 void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) { |
| 36 Initialize(); | 36 devices->push_back(vr_device_.get()); |
| 37 if (initialized_) | 37 } |
| 38 devices->push_back(vr_device_.get()); | 38 |
| 39 device::GvrDelegateProvider* GvrDeviceProvider::GetDelegateProvider() { |
| 40 device::GvrDelegateProvider* provider = |
| 41 device::GvrDelegateProvider::GetInstance(); |
| 42 Initialize(provider); |
| 43 return provider; |
| 39 } | 44 } |
| 40 | 45 |
| 41 void GvrDeviceProvider::Initialize() { | 46 void GvrDeviceProvider::Initialize() { |
| 42 // TODO(mthiesse): Clean up how we connect the GvrDelegateProvider to the | 47 // TODO(mthiesse): Clean up how we connect the GvrDelegateProvider to the |
| 43 // GvrDeviceProvider so we don't have to call this function multiple times. | 48 // GvrDeviceProvider so we don't have to call this function multiple times. |
| 44 // Ideally the DelegateProvider would always be available, and GetInstance() | 49 // Ideally the DelegateProvider would always be available, and GetInstance() |
| 45 // would create it. | 50 // would create it. |
| 46 if (initialized_) | 51 Initialize(device::GvrDelegateProvider::GetInstance()); |
| 52 } |
| 53 |
| 54 void GvrDeviceProvider::Initialize(device::GvrDelegateProvider* provider) { |
| 55 if (!provider) |
| 47 return; | 56 return; |
| 48 device::GvrDelegateProvider* delegate_provider = | 57 provider->SetDeviceProvider(this); |
| 49 device::GvrDelegateProvider::GetInstance(); | |
| 50 if (!delegate_provider) | |
| 51 return; | |
| 52 delegate_provider->SetDeviceProvider(this); | |
| 53 initialized_ = true; | |
| 54 } | 58 } |
| 55 | 59 |
| 56 void GvrDeviceProvider::RequestPresent( | 60 void GvrDeviceProvider::RequestPresent( |
| 61 mojom::VRSubmitFrameClientPtr submit_client, |
| 57 const base::Callback<void(bool)>& callback) { | 62 const base::Callback<void(bool)>& callback) { |
| 58 Initialize(); | 63 device::GvrDelegateProvider* delegate_provider = GetDelegateProvider(); |
| 59 device::GvrDelegateProvider* delegate_provider = | |
| 60 device::GvrDelegateProvider::GetInstance(); | |
| 61 if (!delegate_provider) | 64 if (!delegate_provider) |
| 62 return callback.Run(false); | 65 return callback.Run(false); |
| 63 | 66 |
| 64 // RequestWebVRPresent is async as we may trigger a DON flow that pauses | 67 // RequestWebVRPresent is async as we may trigger a DON flow that pauses |
| 65 // Chrome. | 68 // Chrome. |
| 66 delegate_provider->RequestWebVRPresent(callback); | 69 delegate_provider->RequestWebVRPresent(std::move(submit_client), callback); |
| 67 } | 70 } |
| 68 | 71 |
| 69 // VR presentation exit requested by the API. | 72 // VR presentation exit requested by the API. |
| 70 void GvrDeviceProvider::ExitPresent() { | 73 void GvrDeviceProvider::ExitPresent() { |
| 71 Initialize(); | 74 device::GvrDelegateProvider* delegate_provider = GetDelegateProvider(); |
| 72 GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance(); | |
| 73 if (delegate_provider) | 75 if (delegate_provider) |
| 74 delegate_provider->ExitWebVRPresent(); | 76 delegate_provider->ExitWebVRPresent(); |
| 75 } | 77 } |
| 76 | 78 |
| 77 void GvrDeviceProvider::SetListeningForActivate(bool listening) { | 79 void GvrDeviceProvider::SetListeningForActivate(bool listening) { |
| 78 Initialize(); | 80 device::GvrDelegateProvider* delegate_provider = GetDelegateProvider(); |
| 79 device::GvrDelegateProvider* delegate_provider = | |
| 80 device::GvrDelegateProvider::GetInstance(); | |
| 81 if (!delegate_provider) | 81 if (!delegate_provider) |
| 82 return; | 82 return; |
| 83 | 83 |
| 84 delegate_provider->SetListeningForActivate(listening); | 84 delegate_provider->SetListeningForActivate(listening); |
| 85 } | 85 } |
| 86 | 86 |
| 87 } // namespace device | 87 } // namespace device |
| OLD | NEW |