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_orientation/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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "content/browser/device_orientation/inertial_sensor_consts.h" | 12 #include "content/browser/device_sensors/inertial_sensor_consts.h" |
13 #include "jni/DeviceMotionAndOrientation_jni.h" | 13 #include "jni/DeviceSensors_jni.h" |
14 | 14 |
15 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 static void updateRotationVectorHistogram(bool value) { | 19 static void updateRotationVectorHistogram(bool value) { |
20 UMA_HISTOGRAM_BOOLEAN("InertialSensor.RotationVectorAndroidAvailable", value); | 20 UMA_HISTOGRAM_BOOLEAN("InertialSensor.RotationVectorAndroidAvailable", value); |
21 } | 21 } |
22 | 22 |
23 } | 23 } |
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_motion_buffer_(NULL), | 29 device_motion_buffer_(NULL), |
30 device_orientation_buffer_(NULL), | 30 device_orientation_buffer_(NULL), |
31 is_motion_buffer_ready_(false), | 31 is_motion_buffer_ready_(false), |
32 is_orientation_buffer_ready_(false) { | 32 is_orientation_buffer_ready_(false) { |
33 memset(received_motion_data_, 0, sizeof(received_motion_data_)); | 33 memset(received_motion_data_, 0, sizeof(received_motion_data_)); |
34 device_orientation_.Reset( | 34 device_orientation_.Reset( |
35 Java_DeviceMotionAndOrientation_getInstance( | 35 Java_DeviceSensors_getInstance( |
36 AttachCurrentThread(), | 36 AttachCurrentThread(), |
37 base::android::GetApplicationContext())); | 37 base::android::GetApplicationContext())); |
38 } | 38 } |
39 | 39 |
40 SensorManagerAndroid::~SensorManagerAndroid() { | 40 SensorManagerAndroid::~SensorManagerAndroid() { |
41 } | 41 } |
42 | 42 |
43 bool SensorManagerAndroid::Register(JNIEnv* env) { | 43 bool SensorManagerAndroid::Register(JNIEnv* env) { |
44 return RegisterNativesImpl(env); | 44 return RegisterNativesImpl(env); |
45 } | 45 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 device_motion_buffer_->seqlock.WriteEnd(); | 132 device_motion_buffer_->seqlock.WriteEnd(); |
133 | 133 |
134 if (!is_motion_buffer_ready_) { | 134 if (!is_motion_buffer_ready_) { |
135 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] = 1; | 135 received_motion_data_[RECEIVED_MOTION_DATA_ROTATION_RATE] = 1; |
136 CheckMotionBufferReadyToRead(); | 136 CheckMotionBufferReadyToRead(); |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 bool SensorManagerAndroid::Start(EventType event_type) { | 140 bool SensorManagerAndroid::Start(EventType event_type) { |
141 DCHECK(!device_orientation_.is_null()); | 141 DCHECK(!device_orientation_.is_null()); |
142 return Java_DeviceMotionAndOrientation_start( | 142 return Java_DeviceSensors_start( |
143 AttachCurrentThread(), device_orientation_.obj(), | 143 AttachCurrentThread(), device_orientation_.obj(), |
144 reinterpret_cast<intptr_t>(this), static_cast<jint>(event_type), | 144 reinterpret_cast<intptr_t>(this), static_cast<jint>(event_type), |
145 kInertialSensorIntervalMillis); | 145 kInertialSensorIntervalMillis); |
146 } | 146 } |
147 | 147 |
148 void SensorManagerAndroid::Stop(EventType event_type) { | 148 void SensorManagerAndroid::Stop(EventType event_type) { |
149 DCHECK(!device_orientation_.is_null()); | 149 DCHECK(!device_orientation_.is_null()); |
150 Java_DeviceMotionAndOrientation_stop( | 150 Java_DeviceSensors_stop( |
151 AttachCurrentThread(), device_orientation_.obj(), | 151 AttachCurrentThread(), device_orientation_.obj(), |
152 static_cast<jint>(event_type)); | 152 static_cast<jint>(event_type)); |
153 } | 153 } |
154 | 154 |
155 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() { | 155 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() { |
156 DCHECK(!device_orientation_.is_null()); | 156 DCHECK(!device_orientation_.is_null()); |
157 return Java_DeviceMotionAndOrientation_getNumberActiveDeviceMotionSensors( | 157 return Java_DeviceSensors_getNumberActiveDeviceMotionSensors( |
158 AttachCurrentThread(), device_orientation_.obj()); | 158 AttachCurrentThread(), device_orientation_.obj()); |
159 } | 159 } |
160 | 160 |
161 | 161 |
162 // ----- Shared memory API methods | 162 // ----- Shared memory API methods |
163 | 163 |
164 // --- Device Motion | 164 // --- Device Motion |
165 | 165 |
166 bool SensorManagerAndroid::StartFetchingDeviceMotionData( | 166 bool SensorManagerAndroid::StartFetchingDeviceMotionData( |
167 DeviceMotionHardwareBuffer* buffer) { | 167 DeviceMotionHardwareBuffer* buffer) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 { | 267 { |
268 base::AutoLock autolock(orientation_buffer_lock_); | 268 base::AutoLock autolock(orientation_buffer_lock_); |
269 if (device_orientation_buffer_) { | 269 if (device_orientation_buffer_) { |
270 SetOrientationBufferReadyStatus(false); | 270 SetOrientationBufferReadyStatus(false); |
271 device_orientation_buffer_ = NULL; | 271 device_orientation_buffer_ = NULL; |
272 } | 272 } |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 } // namespace content | 276 } // namespace content |
OLD | NEW |