| OLD | NEW |
| 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 "content/browser/device_sensors/sensor_manager_android.h" | 5 #include "content/browser/device_sensors/sensor_manager_android.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 | 26 |
| 27 SensorManagerAndroid::SensorManagerAndroid() | 27 SensorManagerAndroid::SensorManagerAndroid() |
| 28 : number_active_device_motion_sensors_(0), | 28 : number_active_device_motion_sensors_(0), |
| 29 device_light_buffer_(NULL), | 29 device_light_buffer_(NULL), |
| 30 device_motion_buffer_(NULL), | 30 device_motion_buffer_(NULL), |
| 31 device_orientation_buffer_(NULL), | 31 device_orientation_buffer_(NULL), |
| 32 is_light_buffer_ready_(false), | 32 is_light_buffer_ready_(false), |
| 33 is_motion_buffer_ready_(false), | 33 is_motion_buffer_ready_(false), |
| 34 is_orientation_buffer_ready_(false) { | 34 is_orientation_buffer_ready_(false), |
| 35 is_using_backup_sensors_for_orientation_(false) { |
| 35 memset(received_motion_data_, 0, sizeof(received_motion_data_)); | 36 memset(received_motion_data_, 0, sizeof(received_motion_data_)); |
| 36 device_sensors_.Reset(Java_DeviceSensors_getInstance( | 37 device_sensors_.Reset(Java_DeviceSensors_getInstance( |
| 37 AttachCurrentThread(), base::android::GetApplicationContext())); | 38 AttachCurrentThread(), base::android::GetApplicationContext())); |
| 38 } | 39 } |
| 39 | 40 |
| 40 SensorManagerAndroid::~SensorManagerAndroid() { | 41 SensorManagerAndroid::~SensorManagerAndroid() { |
| 41 } | 42 } |
| 42 | 43 |
| 43 bool SensorManagerAndroid::Register(JNIEnv* env) { | 44 bool SensorManagerAndroid::Register(JNIEnv* env) { |
| 44 return RegisterNativesImpl(env); | 45 return RegisterNativesImpl(env); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 60 device_orientation_buffer_->data.alpha = alpha; | 61 device_orientation_buffer_->data.alpha = alpha; |
| 61 device_orientation_buffer_->data.hasAlpha = true; | 62 device_orientation_buffer_->data.hasAlpha = true; |
| 62 device_orientation_buffer_->data.beta = beta; | 63 device_orientation_buffer_->data.beta = beta; |
| 63 device_orientation_buffer_->data.hasBeta = true; | 64 device_orientation_buffer_->data.hasBeta = true; |
| 64 device_orientation_buffer_->data.gamma = gamma; | 65 device_orientation_buffer_->data.gamma = gamma; |
| 65 device_orientation_buffer_->data.hasGamma = true; | 66 device_orientation_buffer_->data.hasGamma = true; |
| 66 device_orientation_buffer_->seqlock.WriteEnd(); | 67 device_orientation_buffer_->seqlock.WriteEnd(); |
| 67 | 68 |
| 68 if (!is_orientation_buffer_ready_) { | 69 if (!is_orientation_buffer_ready_) { |
| 69 SetOrientationBufferReadyStatus(true); | 70 SetOrientationBufferReadyStatus(true); |
| 70 updateRotationVectorHistogram(true); | 71 updateRotationVectorHistogram(!is_using_backup_sensors_for_orientation_); |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 | 74 |
| 74 void SensorManagerAndroid::GotAcceleration( | 75 void SensorManagerAndroid::GotAcceleration( |
| 75 JNIEnv*, jobject, double x, double y, double z) { | 76 JNIEnv*, jobject, double x, double y, double z) { |
| 76 base::AutoLock autolock(motion_buffer_lock_); | 77 base::AutoLock autolock(motion_buffer_lock_); |
| 77 | 78 |
| 78 if (!device_motion_buffer_) | 79 if (!device_motion_buffer_) |
| 79 return; | 80 return; |
| 80 | 81 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 device_sensors_.obj(), | 167 device_sensors_.obj(), |
| 167 static_cast<jint>(event_type)); | 168 static_cast<jint>(event_type)); |
| 168 } | 169 } |
| 169 | 170 |
| 170 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() { | 171 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() { |
| 171 DCHECK(!device_sensors_.is_null()); | 172 DCHECK(!device_sensors_.is_null()); |
| 172 return Java_DeviceSensors_getNumberActiveDeviceMotionSensors( | 173 return Java_DeviceSensors_getNumberActiveDeviceMotionSensors( |
| 173 AttachCurrentThread(), device_sensors_.obj()); | 174 AttachCurrentThread(), device_sensors_.obj()); |
| 174 } | 175 } |
| 175 | 176 |
| 177 bool SensorManagerAndroid::isUsingBackupSensorsForOrientation() { |
| 178 DCHECK(!device_sensors_.is_null()); |
| 179 return Java_DeviceSensors_isUsingBackupSensorsForOrientation( |
| 180 AttachCurrentThread(), device_sensors_.obj()); |
| 181 } |
| 176 | 182 |
| 177 // ----- Shared memory API methods | 183 // ----- Shared memory API methods |
| 178 | 184 |
| 179 // --- Device Light | 185 // --- Device Light |
| 180 | 186 |
| 181 bool SensorManagerAndroid::StartFetchingDeviceLightData( | 187 bool SensorManagerAndroid::StartFetchingDeviceLightData( |
| 182 DeviceLightHardwareBuffer* buffer) { | 188 DeviceLightHardwareBuffer* buffer) { |
| 183 DCHECK(buffer); | 189 DCHECK(buffer); |
| 184 { | 190 { |
| 185 base::AutoLock autolock(light_buffer_lock_); | 191 base::AutoLock autolock(light_buffer_lock_); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 307 |
| 302 { | 308 { |
| 303 base::AutoLock autolock(orientation_buffer_lock_); | 309 base::AutoLock autolock(orientation_buffer_lock_); |
| 304 // If Start() was unsuccessful then set the buffer ready flag to true | 310 // If Start() was unsuccessful then set the buffer ready flag to true |
| 305 // to start firing all-null events. | 311 // to start firing all-null events. |
| 306 SetOrientationBufferReadyStatus(!success); | 312 SetOrientationBufferReadyStatus(!success); |
| 307 } | 313 } |
| 308 | 314 |
| 309 if (!success) | 315 if (!success) |
| 310 updateRotationVectorHistogram(false); | 316 updateRotationVectorHistogram(false); |
| 317 else |
| 318 is_using_backup_sensors_for_orientation_ = |
| 319 isUsingBackupSensorsForOrientation(); |
| 311 | 320 |
| 312 return success; | 321 return success; |
| 313 } | 322 } |
| 314 | 323 |
| 315 void SensorManagerAndroid::StopFetchingDeviceOrientationData() { | 324 void SensorManagerAndroid::StopFetchingDeviceOrientationData() { |
| 316 Stop(kTypeOrientation); | 325 Stop(kTypeOrientation); |
| 317 { | 326 { |
| 318 base::AutoLock autolock(orientation_buffer_lock_); | 327 base::AutoLock autolock(orientation_buffer_lock_); |
| 319 if (device_orientation_buffer_) { | 328 if (device_orientation_buffer_) { |
| 320 SetOrientationBufferReadyStatus(false); | 329 SetOrientationBufferReadyStatus(false); |
| 321 device_orientation_buffer_ = NULL; | 330 device_orientation_buffer_ = NULL; |
| 322 } | 331 } |
| 323 } | 332 } |
| 324 } | 333 } |
| 325 | 334 |
| 326 } // namespace content | 335 } // namespace content |
| OLD | NEW |