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

Side by Side Diff: device/vr/android/gvr/gvr_device_provider.cc

Issue 2420743003: mojo VR interface simplified (Closed)
Patch Set: address leon@ comments about name Created 4 years, 1 month 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 "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 18 matching lines...) Expand all
29 29
30 GvrDeviceProvider::~GvrDeviceProvider() { 30 GvrDeviceProvider::~GvrDeviceProvider() {
31 device::GvrDelegateProvider* delegate_provider = 31 device::GvrDelegateProvider* delegate_provider =
32 device::GvrDelegateProvider::GetInstance(); 32 device::GvrDelegateProvider::GetInstance();
33 if (delegate_provider) 33 if (delegate_provider)
34 delegate_provider->DestroyNonPresentingDelegate(); 34 delegate_provider->DestroyNonPresentingDelegate();
35 35
36 ExitPresent(); 36 ExitPresent();
37 } 37 }
38 38
39 void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) { 39 void GvrDeviceProvider::GetDevices(std::vector<VRServiceImpl*>* clients,
40 Initialize(); 40 std::vector<VRDevice*>* devices) {
41 Initialize(clients);
41 42
42 if (vr_device_) 43 if (vr_device_)
43 devices->push_back(vr_device_.get()); 44 devices->push_back(vr_device_.get());
44 } 45 }
45 46
46 void GvrDeviceProvider::SetClient(VRClientDispatcher* client) { 47 void GvrDeviceProvider::Initialize(std::vector<VRServiceImpl*>* clients) {
47 if (!client_)
48 client_.reset(client);
49 }
50
51 void GvrDeviceProvider::Initialize() {
52 device::GvrDelegateProvider* delegate_provider = 48 device::GvrDelegateProvider* delegate_provider =
53 device::GvrDelegateProvider::GetInstance(); 49 device::GvrDelegateProvider::GetInstance();
54 if (!delegate_provider) 50 if (!delegate_provider)
55 return; 51 return;
56 52
57 if (!vr_device_) { 53 if (!vr_device_) {
58 vr_device_.reset( 54 vr_device_.reset(
59 new GvrDevice(this, delegate_provider->GetNonPresentingDelegate())); 55 new GvrDevice(this, delegate_provider->GetNonPresentingDelegate()));
60 client_->OnDeviceConnectionStatusChanged(vr_device_.get(), true); 56 vr_device_->SetClient(clients);
57 vr_device_->OnDisplayConnected();
61 } 58 }
62 } 59 }
63 60
64 bool GvrDeviceProvider::RequestPresent() { 61 bool GvrDeviceProvider::RequestPresent() {
65 device::GvrDelegateProvider* delegate_provider = 62 device::GvrDelegateProvider* delegate_provider =
66 device::GvrDelegateProvider::GetInstance(); 63 device::GvrDelegateProvider::GetInstance();
67 if (!delegate_provider) 64 if (!delegate_provider)
68 return false; 65 return false;
69 66
70 // RequestWebVRPresent is async as a render thread may be created. 67 // RequestWebVRPresent is async as a render thread may be created.
(...skipping 10 matching lines...) Expand all
81 device::GvrDelegateProvider::GetInstance(); 78 device::GvrDelegateProvider::GetInstance();
82 if (!delegate_provider) 79 if (!delegate_provider)
83 return; 80 return;
84 81
85 vr_device_->SetDelegate(delegate_provider->GetNonPresentingDelegate()); 82 vr_device_->SetDelegate(delegate_provider->GetNonPresentingDelegate());
86 83
87 GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( 84 GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory(
88 GAMEPAD_SOURCE_GVR); 85 GAMEPAD_SOURCE_GVR);
89 86
90 delegate_provider->ExitWebVRPresent(); 87 delegate_provider->ExitWebVRPresent();
91
92 if (client_)
93 client_->OnPresentEnded(vr_device_.get());
94 } 88 }
95 89
96 void GvrDeviceProvider::OnGvrDelegateReady(GvrDelegate* delegate) { 90 void GvrDeviceProvider::OnGvrDelegateReady(GvrDelegate* delegate) {
97 main_thread_task_runner_->PostTask( 91 main_thread_task_runner_->PostTask(
98 FROM_HERE, 92 FROM_HERE,
99 base::Bind(&GvrDeviceProvider::GvrDelegateReady, base::Unretained(this), 93 base::Bind(&GvrDeviceProvider::GvrDelegateReady, base::Unretained(this),
100 base::Unretained(delegate))); 94 base::Unretained(delegate)));
101 } 95 }
102 96
103 void GvrDeviceProvider::OnGvrDelegateRemoved() { 97 void GvrDeviceProvider::OnGvrDelegateRemoved() {
104 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); 98 DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
105 if (!vr_device_) 99 if (!vr_device_)
106 return; 100 return;
107 ExitPresent(); 101 ExitPresent();
108 } 102 }
109 103
110 void GvrDeviceProvider::GvrDelegateReady(GvrDelegate* delegate) { 104 void GvrDeviceProvider::GvrDelegateReady(GvrDelegate* delegate) {
111 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); 105 DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
112 106
113 vr_device_->SetDelegate(delegate); 107 vr_device_->SetDelegate(delegate);
114 GamepadDataFetcherManager::GetInstance()->AddFactory( 108 GamepadDataFetcherManager::GetInstance()->AddFactory(
115 new GvrGamepadDataFetcher::Factory(delegate, vr_device_->id())); 109 new GvrGamepadDataFetcher::Factory(delegate, vr_device_->id()));
116 } 110 }
117 111
118 } // namespace device 112 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698