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

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

Issue 2420743003: mojo VR interface simplified (Closed)
Patch Set: update binding process and update some unittest 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 }; 76 };
77 77
78 GvrDeviceProvider::GvrDeviceProvider() 78 GvrDeviceProvider::GvrDeviceProvider()
79 : VRDeviceProvider(), 79 : VRDeviceProvider(),
80 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 80 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
81 81
82 GvrDeviceProvider::~GvrDeviceProvider() { 82 GvrDeviceProvider::~GvrDeviceProvider() {
83 ExitPresent(); 83 ExitPresent();
84 } 84 }
85 85
86 void GvrDeviceProvider::GetDevices(std::vector<VRDevice*>* devices) { 86 void GvrDeviceProvider::GetDevices(std::vector<VRServiceImpl*>* clients,
87 Initialize(); 87 std::vector<VRDevice*>* devices) {
88 Initialize(clients);
88 89
89 if (vr_device_) 90 if (vr_device_)
90 devices->push_back(vr_device_.get()); 91 devices->push_back(vr_device_.get());
91 } 92 }
92 93
93 void GvrDeviceProvider::SetClient(VRClientDispatcher* client) { 94 void GvrDeviceProvider::Initialize(std::vector<VRServiceImpl*>* clients) {
94 if (!client_)
95 client_.reset(client);
96 }
97
98 void GvrDeviceProvider::Initialize() {
99 if (!vr_device_) { 95 if (!vr_device_) {
100 vr_device_.reset(new GvrDevice(this, nullptr)); 96 vr_device_.reset(new GvrDevice(this, nullptr));
101 client_->OnDeviceConnectionStatusChanged(vr_device_.get(), true); 97 vr_device_->SetClient(clients);
98 vr_device_->OnDisplayConnected();
102 } 99 }
103 } 100 }
104 101
105 bool GvrDeviceProvider::RequestPresent() { 102 bool GvrDeviceProvider::RequestPresent() {
106 GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance(); 103 GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance();
107 if (!delegate_provider) 104 if (!delegate_provider)
108 return false; 105 return false;
109 106
110 return delegate_provider->RequestWebVRPresent(this); 107 return delegate_provider->RequestWebVRPresent(this);
111 } 108 }
112 109
113 void GvrDeviceProvider::ExitPresent() { 110 void GvrDeviceProvider::ExitPresent() {
114 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); 111 DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
115 112
116 if (!vr_device_) 113 if (!vr_device_)
117 return; 114 return;
118 115
119 vr_device_->SetDelegate(nullptr); 116 vr_device_->SetDelegate(nullptr);
120 117
121 GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory( 118 GamepadDataFetcherManager::GetInstance()->RemoveSourceFactory(
122 GAMEPAD_SOURCE_GVR); 119 GAMEPAD_SOURCE_GVR);
123 120
124 GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance(); 121 GvrDelegateProvider* delegate_provider = GvrDelegateProvider::GetInstance();
125 if (delegate_provider) 122 if (delegate_provider)
126 delegate_provider->ExitWebVRPresent(); 123 delegate_provider->ExitWebVRPresent();
127
128 if (client_)
129 client_->OnPresentEnded(vr_device_.get());
130 } 124 }
131 125
132 void GvrDeviceProvider::OnGvrDelegateReady(GvrDelegate* delegate) { 126 void GvrDeviceProvider::OnGvrDelegateReady(GvrDelegate* delegate) {
133 main_thread_task_runner_->PostTask( 127 main_thread_task_runner_->PostTask(
134 FROM_HERE, 128 FROM_HERE,
135 base::Bind(&GvrDeviceProvider::GvrDelegateReady, base::Unretained(this), 129 base::Bind(&GvrDeviceProvider::GvrDelegateReady, base::Unretained(this),
136 base::Unretained(delegate))); 130 base::Unretained(delegate)));
137 } 131 }
138 132
139 void GvrDeviceProvider::OnGvrDelegateRemoved() { 133 void GvrDeviceProvider::OnGvrDelegateRemoved() {
140 if (!vr_device_) 134 if (!vr_device_)
141 return; 135 return;
142 136
143 main_thread_task_runner_->PostTask( 137 main_thread_task_runner_->PostTask(
144 FROM_HERE, 138 FROM_HERE,
145 base::Bind(&GvrDeviceProvider::ExitPresent, base::Unretained(this))); 139 base::Bind(&GvrDeviceProvider::ExitPresent, base::Unretained(this)));
146 } 140 }
147 141
148 void GvrDeviceProvider::GvrDelegateReady(GvrDelegate* delegate) { 142 void GvrDeviceProvider::GvrDelegateReady(GvrDelegate* delegate) {
149 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); 143 DCHECK(main_thread_task_runner_->BelongsToCurrentThread());
150 144
151 vr_device_->SetDelegate(delegate); 145 vr_device_->SetDelegate(delegate);
152 GamepadDataFetcherManager::GetInstance()->AddFactory( 146 GamepadDataFetcherManager::GetInstance()->AddFactory(
153 new GvrGamepadDataFetcher::Factory(delegate, vr_device_->id())); 147 new GvrGamepadDataFetcher::Factory(delegate, vr_device_->id()));
154 } 148 }
155 149
156 } // namespace device 150 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698