| 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 "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 14 matching lines...) Expand all Loading... |
| 25 "InertialSensor.DeviceOrientationSensorAndroid", type, | 25 "InertialSensor.DeviceOrientationSensorAndroid", type, |
| 26 device::SensorManagerAndroid::ORIENTATION_SENSOR_MAX); | 26 device::SensorManagerAndroid::ORIENTATION_SENSOR_MAX); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void SetOrientation(device::DeviceOrientationHardwareBuffer* buffer, | 29 void SetOrientation(device::DeviceOrientationHardwareBuffer* buffer, |
| 30 double alpha, | 30 double alpha, |
| 31 double beta, | 31 double beta, |
| 32 double gamma) { | 32 double gamma) { |
| 33 buffer->seqlock.WriteBegin(); | 33 buffer->seqlock.WriteBegin(); |
| 34 buffer->data.alpha = alpha; | 34 buffer->data.alpha = alpha; |
| 35 buffer->data.hasAlpha = true; | 35 buffer->data.has_alpha = true; |
| 36 buffer->data.beta = beta; | 36 buffer->data.beta = beta; |
| 37 buffer->data.hasBeta = true; | 37 buffer->data.has_beta = true; |
| 38 buffer->data.gamma = gamma; | 38 buffer->data.gamma = gamma; |
| 39 buffer->data.hasGamma = true; | 39 buffer->data.has_gamma = true; |
| 40 buffer->seqlock.WriteEnd(); | 40 buffer->seqlock.WriteEnd(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void SetOrientationBufferStatus(device::DeviceOrientationHardwareBuffer* buffer, | 43 void SetOrientationBufferStatus(device::DeviceOrientationHardwareBuffer* buffer, |
| 44 bool ready, | 44 bool ready, |
| 45 bool absolute) { | 45 bool absolute) { |
| 46 buffer->seqlock.WriteBegin(); | 46 buffer->seqlock.WriteBegin(); |
| 47 buffer->data.absolute = absolute; | 47 buffer->data.absolute = absolute; |
| 48 buffer->data.allAvailableSensorsAreActive = 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), | 58 device_light_buffer_(nullptr), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 const JavaParamRef<jobject>&, | 125 const JavaParamRef<jobject>&, |
| 126 double x, | 126 double x, |
| 127 double y, | 127 double y, |
| 128 double z) { | 128 double z) { |
| 129 base::AutoLock autolock(motion_buffer_lock_); | 129 base::AutoLock autolock(motion_buffer_lock_); |
| 130 | 130 |
| 131 if (!device_motion_buffer_) | 131 if (!device_motion_buffer_) |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 device_motion_buffer_->seqlock.WriteBegin(); | 134 device_motion_buffer_->seqlock.WriteBegin(); |
| 135 device_motion_buffer_->data.accelerationX = x; | 135 device_motion_buffer_->data.acceleration_x = x; |
| 136 device_motion_buffer_->data.hasAccelerationX = true; | 136 device_motion_buffer_->data.has_acceleration_x = true; |
| 137 device_motion_buffer_->data.accelerationY = y; | 137 device_motion_buffer_->data.acceleration_y = y; |
| 138 device_motion_buffer_->data.hasAccelerationY = true; | 138 device_motion_buffer_->data.has_acceleration_y = true; |
| 139 device_motion_buffer_->data.accelerationZ = z; | 139 device_motion_buffer_->data.acceleration_z = z; |
| 140 device_motion_buffer_->data.hasAccelerationZ = true; | 140 device_motion_buffer_->data.has_acceleration_z = true; |
| 141 device_motion_buffer_->seqlock.WriteEnd(); | 141 device_motion_buffer_->seqlock.WriteEnd(); |
| 142 | 142 |
| 143 if (!motion_buffer_initialized_) { | 143 if (!motion_buffer_initialized_) { |
| 144 received_motion_data_[RECEIVED_MOTION_DATA_ACCELERATION] = 1; | 144 received_motion_data_[RECEIVED_MOTION_DATA_ACCELERATION] = 1; |
| 145 CheckMotionBufferReadyToRead(); | 145 CheckMotionBufferReadyToRead(); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 void SensorManagerAndroid::GotAccelerationIncludingGravity( | 149 void SensorManagerAndroid::GotAccelerationIncludingGravity( |
| 150 JNIEnv*, | 150 JNIEnv*, |
| 151 const JavaParamRef<jobject>&, | 151 const JavaParamRef<jobject>&, |
| 152 double x, | 152 double x, |
| 153 double y, | 153 double y, |
| 154 double z) { | 154 double z) { |
| 155 base::AutoLock autolock(motion_buffer_lock_); | 155 base::AutoLock autolock(motion_buffer_lock_); |
| 156 | 156 |
| 157 if (!device_motion_buffer_) | 157 if (!device_motion_buffer_) |
| 158 return; | 158 return; |
| 159 | 159 |
| 160 device_motion_buffer_->seqlock.WriteBegin(); | 160 device_motion_buffer_->seqlock.WriteBegin(); |
| 161 device_motion_buffer_->data.accelerationIncludingGravityX = x; | 161 device_motion_buffer_->data.acceleration_including_gravity_x = x; |
| 162 device_motion_buffer_->data.hasAccelerationIncludingGravityX = true; | 162 device_motion_buffer_->data.has_acceleration_including_gravity_x = true; |
| 163 device_motion_buffer_->data.accelerationIncludingGravityY = y; | 163 device_motion_buffer_->data.acceleration_including_gravity_y = y; |
| 164 device_motion_buffer_->data.hasAccelerationIncludingGravityY = true; | 164 device_motion_buffer_->data.has_acceleration_including_gravity_y = true; |
| 165 device_motion_buffer_->data.accelerationIncludingGravityZ = z; | 165 device_motion_buffer_->data.acceleration_including_gravity_z = z; |
| 166 device_motion_buffer_->data.hasAccelerationIncludingGravityZ = true; | 166 device_motion_buffer_->data.has_acceleration_including_gravity_z = true; |
| 167 device_motion_buffer_->seqlock.WriteEnd(); | 167 device_motion_buffer_->seqlock.WriteEnd(); |
| 168 | 168 |
| 169 if (!motion_buffer_initialized_) { | 169 if (!motion_buffer_initialized_) { |
| 170 received_motion_data_[RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY] = 1; | 170 received_motion_data_[RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY] = 1; |
| 171 CheckMotionBufferReadyToRead(); | 171 CheckMotionBufferReadyToRead(); |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 void SensorManagerAndroid::GotRotationRate(JNIEnv*, | 175 void SensorManagerAndroid::GotRotationRate(JNIEnv*, |
| 176 const JavaParamRef<jobject>&, | 176 const JavaParamRef<jobject>&, |
| 177 double alpha, | 177 double alpha, |
| 178 double beta, | 178 double beta, |
| 179 double gamma) { | 179 double gamma) { |
| 180 base::AutoLock autolock(motion_buffer_lock_); | 180 base::AutoLock autolock(motion_buffer_lock_); |
| 181 | 181 |
| 182 if (!device_motion_buffer_) | 182 if (!device_motion_buffer_) |
| 183 return; | 183 return; |
| 184 | 184 |
| 185 device_motion_buffer_->seqlock.WriteBegin(); | 185 device_motion_buffer_->seqlock.WriteBegin(); |
| 186 device_motion_buffer_->data.rotationRateAlpha = alpha; | 186 device_motion_buffer_->data.rotation_rate_alpha = alpha; |
| 187 device_motion_buffer_->data.hasRotationRateAlpha = true; | 187 device_motion_buffer_->data.has_rotation_rate_alpha = true; |
| 188 device_motion_buffer_->data.rotationRateBeta = beta; | 188 device_motion_buffer_->data.rotation_rate_beta = beta; |
| 189 device_motion_buffer_->data.hasRotationRateBeta = true; | 189 device_motion_buffer_->data.has_rotation_rate_beta = true; |
| 190 device_motion_buffer_->data.rotationRateGamma = gamma; | 190 device_motion_buffer_->data.rotation_rate_gamma = gamma; |
| 191 device_motion_buffer_->data.hasRotationRateGamma = true; | 191 device_motion_buffer_->data.has_rotation_rate_gamma = true; |
| 192 device_motion_buffer_->seqlock.WriteEnd(); | 192 device_motion_buffer_->seqlock.WriteEnd(); |
| 193 | 193 |
| 194 if (!motion_buffer_initialized_) { | 194 if (!motion_buffer_initialized_) { |
| 195 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] = 1; | 195 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] = 1; |
| 196 CheckMotionBufferReadyToRead(); | 196 CheckMotionBufferReadyToRead(); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 void SensorManagerAndroid::GotLight(JNIEnv*, | 200 void SensorManagerAndroid::GotLight(JNIEnv*, |
| 201 const JavaParamRef<jobject>&, | 201 const JavaParamRef<jobject>&, |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 received_motion_data_[RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY] > | 348 received_motion_data_[RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY] > |
| 349 0); | 349 0); |
| 350 UMA_HISTOGRAM_BOOLEAN( | 350 UMA_HISTOGRAM_BOOLEAN( |
| 351 "InertialSensor.GyroscopeAndroidAvailable", | 351 "InertialSensor.GyroscopeAndroidAvailable", |
| 352 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] > 0); | 352 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] > 0); |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| 356 void SensorManagerAndroid::SetMotionBufferReadyStatus(bool ready) { | 356 void SensorManagerAndroid::SetMotionBufferReadyStatus(bool ready) { |
| 357 device_motion_buffer_->seqlock.WriteBegin(); | 357 device_motion_buffer_->seqlock.WriteBegin(); |
| 358 device_motion_buffer_->data.allAvailableSensorsAreActive = ready; | 358 device_motion_buffer_->data.all_available_sensors_are_active = ready; |
| 359 device_motion_buffer_->seqlock.WriteEnd(); | 359 device_motion_buffer_->seqlock.WriteEnd(); |
| 360 motion_buffer_initialized_ = ready; | 360 motion_buffer_initialized_ = ready; |
| 361 } | 361 } |
| 362 | 362 |
| 363 void SensorManagerAndroid::ClearInternalMotionBuffers() { | 363 void SensorManagerAndroid::ClearInternalMotionBuffers() { |
| 364 memset(received_motion_data_, 0, sizeof(received_motion_data_)); | 364 memset(received_motion_data_, 0, sizeof(received_motion_data_)); |
| 365 number_active_device_motion_sensors_ = 0; | 365 number_active_device_motion_sensors_ = 0; |
| 366 SetMotionBufferReadyStatus(false); | 366 SetMotionBufferReadyStatus(false); |
| 367 } | 367 } |
| 368 | 368 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 | 452 |
| 453 void SensorManagerAndroid::Shutdown() { | 453 void SensorManagerAndroid::Shutdown() { |
| 454 DCHECK(thread_checker_.CalledOnValidThread()); | 454 DCHECK(thread_checker_.CalledOnValidThread()); |
| 455 is_shutdown_ = true; | 455 is_shutdown_ = true; |
| 456 } | 456 } |
| 457 | 457 |
| 458 } // namespace device | 458 } // namespace device |
| OLD | NEW |