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

Side by Side Diff: content/browser/device_sensors/sensor_manager_android.cc

Issue 292693004: [DeviceLight] Browser+java part (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Forgot some light bits removal from device_inertial_sensor_diagnostics.html Created 6 years, 3 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 "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"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "content/browser/device_sensors/inertial_sensor_consts.h" 12 #include "content/browser/device_sensors/inertial_sensor_consts.h"
13 #include "jni/DeviceSensors_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_light_buffer_(NULL),
29 device_motion_buffer_(NULL), 30 device_motion_buffer_(NULL),
30 device_orientation_buffer_(NULL), 31 device_orientation_buffer_(NULL),
32 is_light_buffer_ready_(false),
31 is_motion_buffer_ready_(false), 33 is_motion_buffer_ready_(false),
32 is_orientation_buffer_ready_(false) { 34 is_orientation_buffer_ready_(false) {
33 memset(received_motion_data_, 0, sizeof(received_motion_data_)); 35 memset(received_motion_data_, 0, sizeof(received_motion_data_));
34 device_orientation_.Reset( 36 device_sensors_.Reset(Java_DeviceSensors_getInstance(
35 Java_DeviceSensors_getInstance( 37 AttachCurrentThread(), base::android::GetApplicationContext()));
36 AttachCurrentThread(),
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 }
46 46
47 SensorManagerAndroid* SensorManagerAndroid::GetInstance() { 47 SensorManagerAndroid* SensorManagerAndroid::GetInstance() {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 device_motion_buffer_->data.rotationRateGamma = gamma; 130 device_motion_buffer_->data.rotationRateGamma = gamma;
131 device_motion_buffer_->data.hasRotationRateGamma = true; 131 device_motion_buffer_->data.hasRotationRateGamma = true;
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 void SensorManagerAndroid::GotLight(JNIEnv*, jobject, double value) {
141 base::AutoLock autolock(light_buffer_lock_);
142
143 if (!device_light_buffer_)
144 return;
145
146 device_light_buffer_->seqlock.WriteBegin();
147 device_light_buffer_->data.value = value;
148 device_light_buffer_->seqlock.WriteEnd();
149 }
150
140 bool SensorManagerAndroid::Start(EventType event_type) { 151 bool SensorManagerAndroid::Start(EventType event_type) {
141 DCHECK(!device_orientation_.is_null()); 152 DCHECK(!device_sensors_.is_null());
142 return Java_DeviceSensors_start( 153 int rate_in_milliseconds = (event_type == kTypeLight)
143 AttachCurrentThread(), device_orientation_.obj(), 154 ? kInertialLightSensorIntervalMillis
144 reinterpret_cast<intptr_t>(this), static_cast<jint>(event_type), 155 : kInertialSensorIntervalMillis;
145 kInertialSensorIntervalMillis); 156 return Java_DeviceSensors_start(AttachCurrentThread(),
157 device_sensors_.obj(),
158 reinterpret_cast<intptr_t>(this),
159 static_cast<jint>(event_type),
160 rate_in_milliseconds);
146 } 161 }
147 162
148 void SensorManagerAndroid::Stop(EventType event_type) { 163 void SensorManagerAndroid::Stop(EventType event_type) {
149 DCHECK(!device_orientation_.is_null()); 164 DCHECK(!device_sensors_.is_null());
150 Java_DeviceSensors_stop( 165 Java_DeviceSensors_stop(AttachCurrentThread(),
151 AttachCurrentThread(), device_orientation_.obj(), 166 device_sensors_.obj(),
152 static_cast<jint>(event_type)); 167 static_cast<jint>(event_type));
153 } 168 }
154 169
155 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() { 170 int SensorManagerAndroid::GetNumberActiveDeviceMotionSensors() {
156 DCHECK(!device_orientation_.is_null()); 171 DCHECK(!device_sensors_.is_null());
157 return Java_DeviceSensors_getNumberActiveDeviceMotionSensors( 172 return Java_DeviceSensors_getNumberActiveDeviceMotionSensors(
158 AttachCurrentThread(), device_orientation_.obj()); 173 AttachCurrentThread(), device_sensors_.obj());
159 } 174 }
160 175
161 176
162 // ----- Shared memory API methods 177 // ----- Shared memory API methods
163 178
179 // --- Device Light
180
181 bool SensorManagerAndroid::StartFetchingDeviceLightData(
182 DeviceLightHardwareBuffer* buffer) {
183 DCHECK(buffer);
184 {
185 base::AutoLock autolock(light_buffer_lock_);
186 device_light_buffer_ = buffer;
187 SetInternalLightBuffers(-1);
timvolodine 2014/09/08 15:20:19 the name is confusing, maybe call it SetLightBuffe
riju_ 2014/09/09 14:01:18 Done.
188 }
189 bool success = Start(kTypeLight);
190 if (!success) {
191 base::AutoLock autolock(light_buffer_lock_);
192 SetInternalLightBuffers(std::numeric_limits<double>::infinity());
193 }
194 return success;
195 }
196
197 void SensorManagerAndroid::StopFetchingDeviceLightData() {
198 Stop(kTypeLight);
199 {
200 base::AutoLock autolock(light_buffer_lock_);
201 if (device_light_buffer_) {
202 SetInternalLightBuffers(-1);
203 device_light_buffer_ = NULL;
204 }
205 }
206 }
207
208 void SensorManagerAndroid::SetInternalLightBuffers(double lux) {
209 device_light_buffer_->seqlock.WriteBegin();
210 device_light_buffer_->data.value = lux;
211 device_light_buffer_->seqlock.WriteEnd();
212 }
164 // --- Device Motion 213 // --- Device Motion
165 214
166 bool SensorManagerAndroid::StartFetchingDeviceMotionData( 215 bool SensorManagerAndroid::StartFetchingDeviceMotionData(
167 DeviceMotionHardwareBuffer* buffer) { 216 DeviceMotionHardwareBuffer* buffer) {
168 DCHECK(buffer); 217 DCHECK(buffer);
169 { 218 {
170 base::AutoLock autolock(motion_buffer_lock_); 219 base::AutoLock autolock(motion_buffer_lock_);
171 device_motion_buffer_ = buffer; 220 device_motion_buffer_ = buffer;
172 ClearInternalMotionBuffers(); 221 ClearInternalMotionBuffers();
173 } 222 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 { 316 {
268 base::AutoLock autolock(orientation_buffer_lock_); 317 base::AutoLock autolock(orientation_buffer_lock_);
269 if (device_orientation_buffer_) { 318 if (device_orientation_buffer_) {
270 SetOrientationBufferReadyStatus(false); 319 SetOrientationBufferReadyStatus(false);
271 device_orientation_buffer_ = NULL; 320 device_orientation_buffer_ = NULL;
272 } 321 }
273 } 322 }
274 } 323 }
275 324
276 } // namespace content 325 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698