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

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

Issue 2420743003: mojo VR interface simplified (Closed)
Patch Set: Address bajones@ comments and some clean up Created 4 years, 2 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 "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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 ExitPresent(); 83 ExitPresent();
84 } 84 }
85 85
86 void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) { 86 void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) {
87 Initialize(); 87 Initialize();
88 88
89 if (vr_device_) 89 if (vr_device_)
90 devices->push_back(vr_device_.get()); 90 devices->push_back(vr_device_.get());
91 } 91 }
92 92
93 void GvrDeviceProvider::SetClient(VRClientDispatcher* client) {
94 if (!client_)
95 client_.reset(client);
96 }
97
98 void GvrDeviceProvider::Initialize() { 93 void GvrDeviceProvider::Initialize() {
99 if (!vr_device_) { 94 if (!vr_device_) {
100 vr_device_.reset(new GvrDevice(this, nullptr)); 95 vr_device_.reset(new GvrDevice(this, nullptr));
101 client_->OnDeviceConnectionStatusChanged(vr_device_.get(), true); 96
97 // TODO(Shaobo) : call event here in this way is not proper,
98 // need to find another way.
99 // vr_device_->OnDisplayConnected();
102 } 100 }
103 } 101 }
104 102
105 bool GvrDeviceProvider::RequestPresent() { 103 bool GvrDeviceProvider::RequestPresent() {
106 GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance(); 104 GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance();
107 if (!delegate_provider) 105 if (!delegate_provider)
108 return false; 106 return false;
109 107
110 return delegate_provider->RequestWebVRPresent(this); 108 return delegate_provider->RequestWebVRPresent(this);
111 } 109 }
112 110
113 void GvrDeviceProvider::ExitPresent() { 111 void GvrDeviceProvider::ExitPresent() {
114 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); 112 DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
115 113
116 if (!vr_device_) 114 if (!vr_device_)
117 return; 115 return;
118 116
119 vr_device_->SetDelegate(nullptr); 117 vr_device_->SetDelegate(nullptr);
120 118
121 GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( 119 GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory(
122 GAMEPAD_SOURCE_GVR); 120 GAMEPAD_SOURCE_GVR);
123 121
124 GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance(); 122 GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance();
125 if (delegate_provider) 123 if (delegate_provider)
126 delegate_provider->ExitWebVRPresent(); 124 delegate_provider->ExitWebVRPresent();
127
128 if (client_)
129 client_->OnPresentEnded(vr_device_.get());
130 } 125 }
131 126
132 void GvrDeviceProvider::OnGvrDelegateReady(GvrDelegate* delegate) { 127 void GvrDeviceProvider::OnGvrDelegateReady(GvrDelegate* delegate) {
133 main_thread_task_runner_->PostTask( 128 main_thread_task_runner_->PostTask(
134 FROM_HERE, 129 FROM_HERE,
135 base::Bind(&GvrDeviceProvider::GvrDelegateReady, base::Unretained(this), 130 base::Bind(&GvrDeviceProvider::GvrDelegateReady, base::Unretained(this),
136 base::Unretained(delegate))); 131 base::Unretained(delegate)));
137 } 132 }
138 133
139 void GvrDeviceProvider::OnGvrDelegateRemoved() { 134 void GvrDeviceProvider::OnGvrDelegateRemoved() {
140 if (!vr_device_) 135 if (!vr_device_)
141 return; 136 return;
142 137
143 main_thread_task_runner_->PostTask( 138 main_thread_task_runner_->PostTask(
144 FROM_HERE, 139 FROM_HERE,
145 base::Bind(&GvrDeviceProvider::ExitPresent, base::Unretained(this))); 140 base::Bind(&GvrDeviceProvider::ExitPresent, base::Unretained(this)));
146 } 141 }
147 142
148 void GvrDeviceProvider::GvrDelegateReady(GvrDelegate* delegate) { 143 void GvrDeviceProvider::GvrDelegateReady(GvrDelegate* delegate) {
149 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); 144 DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
150 145
151 vr_device_->SetDelegate(delegate); 146 vr_device_->SetDelegate(delegate);
152 GamepadDataFetcherManager::GetInstance()->AddFactory( 147 GamepadDataFetcherManager::GetInstance()->AddFactory(
153 new GvrGamepadDataFetcher::Factory(delegate, vr_device_->id())); 148 new GvrGamepadDataFetcher::Factory(delegate, vr_device_->id()));
154 } 149 }
155 150
156 } // namespace device 151 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698