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

Side by Side Diff: device/sensors/sensor_manager_android.cc

Issue 2845763002: Remove DeviceLightEvent implementation (Closed)
Patch Set: same as previous patch Created 3 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/sensors/sensor_manager_android.h" 5 #include "device/sensors/sensor_manager_android.h"
6 6
7 #include <string.h> 7 #include <string.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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 buffer->data.all_available_sensors_are_active = ready; 48 buffer->data.all_available_sensors_are_active = ready;
49 buffer->seqlock.WriteEnd(); 49 buffer->seqlock.WriteEnd();
50 } 50 }
51 51
52 } // namespace 52 } // namespace
53 53
54 namespace device { 54 namespace device {
55 55
56 SensorManagerAndroid::SensorManagerAndroid() 56 SensorManagerAndroid::SensorManagerAndroid()
57 : number_active_device_motion_sensors_(0), 57 : number_active_device_motion_sensors_(0),
58 device_light_buffer_(nullptr),
59 device_motion_buffer_(nullptr), 58 device_motion_buffer_(nullptr),
60 device_orientation_buffer_(nullptr), 59 device_orientation_buffer_(nullptr),
61 motion_buffer_initialized_(false), 60 motion_buffer_initialized_(false),
62 orientation_buffer_initialized_(false), 61 orientation_buffer_initialized_(false),
63 is_shutdown_(false) { 62 is_shutdown_(false) {
64 DCHECK(thread_checker_.CalledOnValidThread()); 63 DCHECK(thread_checker_.CalledOnValidThread());
65 memset(received_motion_data_, 0, sizeof(received_motion_data_)); 64 memset(received_motion_data_, 0, sizeof(received_motion_data_));
66 device_sensors_.Reset(Java_DeviceSensors_getInstance( 65 device_sensors_.Reset(Java_DeviceSensors_getInstance(
67 AttachCurrentThread(), base::android::GetApplicationContext())); 66 AttachCurrentThread(), base::android::GetApplicationContext()));
68 } 67 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 device_motion_buffer_->data.rotation_rate_gamma = gamma; 189 device_motion_buffer_->data.rotation_rate_gamma = gamma;
191 device_motion_buffer_->data.has_rotation_rate_gamma = true; 190 device_motion_buffer_->data.has_rotation_rate_gamma = true;
192 device_motion_buffer_->seqlock.WriteEnd(); 191 device_motion_buffer_->seqlock.WriteEnd();
193 192
194 if (!motion_buffer_initialized_) { 193 if (!motion_buffer_initialized_) {
195 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] = 1; 194 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] = 1;
196 CheckMotionBufferReadyToRead(); 195 CheckMotionBufferReadyToRead();
197 } 196 }
198 } 197 }
199 198
200 void SensorManagerAndroid::GotLight(JNIEnv*,
201 const JavaParamRef<jobject>&,
202 double value) {
203 base::AutoLock autolock(light_buffer_lock_);
204
205 if (!device_light_buffer_)
206 return;
207
208 device_light_buffer_->seqlock.WriteBegin();
209 device_light_buffer_->data.value = value;
210 device_light_buffer_->seqlock.WriteEnd();
211 }
212
213 bool SensorManagerAndroid::Start(ConsumerType consumer_type) { 199 bool SensorManagerAndroid::Start(ConsumerType consumer_type) {
214 DCHECK(thread_checker_.CalledOnValidThread()); 200 DCHECK(thread_checker_.CalledOnValidThread());
215 DCHECK(!device_sensors_.is_null()); 201 DCHECK(!device_sensors_.is_null());
216 int rate_in_microseconds = (consumer_type == CONSUMER_TYPE_LIGHT)
217 ? kLightSensorIntervalMicroseconds
218 : kDeviceSensorIntervalMicroseconds;
219 return Java_DeviceSensors_start( 202 return Java_DeviceSensors_start(
220 AttachCurrentThread(), device_sensors_, reinterpret_cast<intptr_t>(this), 203 AttachCurrentThread(), device_sensors_, reinterpret_cast<intptr_t>(this),
221 static_cast<jint>(consumer_type), rate_in_microseconds); 204 static_cast<jint>(consumer_type), kDeviceSensorIntervalMicroseconds);
222 } 205 }
223 206
224 void SensorManagerAndroid::Stop(ConsumerType consumer_type) { 207 void SensorManagerAndroid::Stop(ConsumerType consumer_type) {
225 DCHECK(thread_checker_.CalledOnValidThread()); 208 DCHECK(thread_checker_.CalledOnValidThread());
226 DCHECK(!device_sensors_.is_null()); 209 DCHECK(!device_sensors_.is_null());
227 Java_DeviceSensors_stop(AttachCurrentThread(), device_sensors_, 210 Java_DeviceSensors_stop(AttachCurrentThread(), device_sensors_,
228 static_cast<jint>(consumer_type)); 211 static_cast<jint>(consumer_type));
229 } 212 }
230 213
231 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() { 214 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() {
232 DCHECK(thread_checker_.CalledOnValidThread()); 215 DCHECK(thread_checker_.CalledOnValidThread());
233 DCHECK(!device_sensors_.is_null()); 216 DCHECK(!device_sensors_.is_null());
234 return Java_DeviceSensors_getNumberActiveDeviceMotionSensors( 217 return Java_DeviceSensors_getNumberActiveDeviceMotionSensors(
235 AttachCurrentThread(), device_sensors_); 218 AttachCurrentThread(), device_sensors_);
236 } 219 }
237 220
238 SensorManagerAndroid::OrientationSensorType 221 SensorManagerAndroid::OrientationSensorType
239 SensorManagerAndroid::GetOrientationSensorTypeUsed() { 222 SensorManagerAndroid::GetOrientationSensorTypeUsed() {
240 DCHECK(!device_sensors_.is_null()); 223 DCHECK(!device_sensors_.is_null());
241 return static_cast<SensorManagerAndroid::OrientationSensorType>( 224 return static_cast<SensorManagerAndroid::OrientationSensorType>(
242 Java_DeviceSensors_getOrientationSensorTypeUsed(AttachCurrentThread(), 225 Java_DeviceSensors_getOrientationSensorTypeUsed(AttachCurrentThread(),
243 device_sensors_)); 226 device_sensors_));
244 } 227 }
245 228
246 // ----- Shared memory API methods 229 // ----- Shared memory API methods
247 230
248 // --- Device Light
249
250 void SensorManagerAndroid::StartFetchingDeviceLightData(
251 DeviceLightHardwareBuffer* buffer) {
252 DCHECK(thread_checker_.CalledOnValidThread());
253 DCHECK(buffer);
254 if (is_shutdown_)
255 return;
256
257 {
258 base::AutoLock autolock(light_buffer_lock_);
259 device_light_buffer_ = buffer;
260 SetLightBufferValue(-1);
261 }
262 bool success = Start(CONSUMER_TYPE_LIGHT);
263 if (!success) {
264 base::AutoLock autolock(light_buffer_lock_);
265 SetLightBufferValue(std::numeric_limits<double>::infinity());
266 }
267 }
268
269 void SensorManagerAndroid::StopFetchingDeviceLightData() {
270 DCHECK(thread_checker_.CalledOnValidThread());
271 if (is_shutdown_)
272 return;
273
274 Stop(CONSUMER_TYPE_LIGHT);
275 {
276 base::AutoLock autolock(light_buffer_lock_);
277 if (device_light_buffer_) {
278 SetLightBufferValue(-1);
279 device_light_buffer_ = nullptr;
280 }
281 }
282 }
283
284 void SensorManagerAndroid::SetLightBufferValue(double lux) {
285 device_light_buffer_->seqlock.WriteBegin();
286 device_light_buffer_->data.value = lux;
287 device_light_buffer_->seqlock.WriteEnd();
288 }
289
290 // --- Device Motion 231 // --- Device Motion
291 232
292 void SensorManagerAndroid::StartFetchingDeviceMotionData( 233 void SensorManagerAndroid::StartFetchingDeviceMotionData(
293 DeviceMotionHardwareBuffer* buffer) { 234 DeviceMotionHardwareBuffer* buffer) {
294 DCHECK(thread_checker_.CalledOnValidThread()); 235 DCHECK(thread_checker_.CalledOnValidThread());
295 DCHECK(buffer); 236 DCHECK(buffer);
296 if (is_shutdown_) 237 if (is_shutdown_)
297 return; 238 return;
298 239
299 { 240 {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 390 }
450 } 391 }
451 } 392 }
452 393
453 void SensorManagerAndroid::Shutdown() { 394 void SensorManagerAndroid::Shutdown() {
454 DCHECK(thread_checker_.CalledOnValidThread()); 395 DCHECK(thread_checker_.CalledOnValidThread());
455 is_shutdown_ = true; 396 is_shutdown_ = true;
456 } 397 }
457 398
458 } // namespace device 399 } // namespace device
OLDNEW
« no previous file with comments | « device/sensors/sensor_manager_android.h ('k') | device/sensors/sensor_manager_android_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698