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/data_fetcher_shared_memory.h" | 5 #include "device/sensors/data_fetcher_shared_memory.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "content/browser/device_sensors/ambient_light_mac.h" | 12 #include "device/sensors/ambient_light_mac.h" |
13 #include "device/sensors/public/cpp/device_util_mac.h" | 13 #include "device/sensors/public/cpp/device_util_mac.h" |
14 #include "third_party/sudden_motion_sensor/sudden_motion_sensor_mac.h" | 14 #include "third_party/sudden_motion_sensor/sudden_motion_sensor_mac.h" |
15 | 15 |
16 namespace { | 16 namespace device { |
17 | 17 |
18 const double kMeanGravity = 9.80665; | 18 const double kMeanGravity = 9.80665; |
19 | 19 |
20 void FetchLight(content::AmbientLightSensor* sensor, | 20 void FetchLight(AmbientLightSensor* sensor, DeviceLightHardwareBuffer* buffer) { |
21 content::DeviceLightHardwareBuffer* buffer) { | |
22 DCHECK(sensor); | 21 DCHECK(sensor); |
23 DCHECK(buffer); | 22 DCHECK(buffer); |
24 // Macbook pro has 2 lux values, left and right, we take the average. | 23 // Macbook pro has 2 lux values, left and right, we take the average. |
25 // The raw sensor values are converted to lux using LMUvalueToLux(raw_value) | 24 // The raw sensor values are converted to lux using LMUvalueToLux(raw_value) |
26 // similar to how it is done in Firefox. | 25 // similar to how it is done in Firefox. |
27 uint64_t lux_value[2]; | 26 uint64_t lux_value[2]; |
28 if (!sensor->ReadSensorValue(lux_value)) | 27 if (!sensor->ReadSensorValue(lux_value)) |
29 return; | 28 return; |
30 uint64_t mean = (lux_value[0] + lux_value[1]) / 2; | 29 uint64_t mean = (lux_value[0] + lux_value[1]) / 2; |
31 double lux = device::LMUvalueToLux(mean); | 30 double lux = LMUvalueToLux(mean); |
32 buffer->seqlock.WriteBegin(); | 31 buffer->seqlock.WriteBegin(); |
33 buffer->data.value = lux; | 32 buffer->data.value = lux; |
34 buffer->seqlock.WriteEnd(); | 33 buffer->seqlock.WriteEnd(); |
35 } | 34 } |
36 | 35 |
37 void FetchMotion(SuddenMotionSensor* sensor, | 36 void FetchMotion(SuddenMotionSensor* sensor, |
38 content::DeviceMotionHardwareBuffer* buffer) { | 37 DeviceMotionHardwareBuffer* buffer) { |
39 DCHECK(sensor); | 38 DCHECK(sensor); |
40 DCHECK(buffer); | 39 DCHECK(buffer); |
41 | 40 |
42 float axis_value[3]; | 41 float axis_value[3]; |
43 if (!sensor->ReadSensorValues(axis_value)) | 42 if (!sensor->ReadSensorValues(axis_value)) |
44 return; | 43 return; |
45 | 44 |
46 buffer->seqlock.WriteBegin(); | 45 buffer->seqlock.WriteBegin(); |
47 buffer->data.accelerationIncludingGravityX = axis_value[0] * kMeanGravity; | 46 buffer->data.accelerationIncludingGravityX = axis_value[0] * kMeanGravity; |
48 buffer->data.hasAccelerationIncludingGravityX = true; | 47 buffer->data.hasAccelerationIncludingGravityX = true; |
49 buffer->data.accelerationIncludingGravityY = axis_value[1] * kMeanGravity; | 48 buffer->data.accelerationIncludingGravityY = axis_value[1] * kMeanGravity; |
50 buffer->data.hasAccelerationIncludingGravityY = true; | 49 buffer->data.hasAccelerationIncludingGravityY = true; |
51 buffer->data.accelerationIncludingGravityZ = axis_value[2] * kMeanGravity; | 50 buffer->data.accelerationIncludingGravityZ = axis_value[2] * kMeanGravity; |
52 buffer->data.hasAccelerationIncludingGravityZ = true; | 51 buffer->data.hasAccelerationIncludingGravityZ = true; |
53 buffer->data.allAvailableSensorsAreActive = true; | 52 buffer->data.allAvailableSensorsAreActive = true; |
54 buffer->seqlock.WriteEnd(); | 53 buffer->seqlock.WriteEnd(); |
55 } | 54 } |
56 | 55 |
57 void FetchOrientation(SuddenMotionSensor* sensor, | 56 void FetchOrientation(SuddenMotionSensor* sensor, |
58 content::DeviceOrientationHardwareBuffer* buffer) { | 57 DeviceOrientationHardwareBuffer* buffer) { |
59 DCHECK(sensor); | 58 DCHECK(sensor); |
60 DCHECK(buffer); | 59 DCHECK(buffer); |
61 | 60 |
62 // Retrieve per-axis calibrated values. | 61 // Retrieve per-axis calibrated values. |
63 float axis_value[3]; | 62 float axis_value[3]; |
64 if (!sensor->ReadSensorValues(axis_value)) | 63 if (!sensor->ReadSensorValues(axis_value)) |
65 return; | 64 return; |
66 | 65 |
67 // Transform the accelerometer values to W3C draft angles. | 66 // Transform the accelerometer values to W3C draft angles. |
68 // | 67 // |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 103 |
105 buffer->seqlock.WriteBegin(); | 104 buffer->seqlock.WriteBegin(); |
106 buffer->data.beta = beta; | 105 buffer->data.beta = beta; |
107 buffer->data.hasBeta = true; | 106 buffer->data.hasBeta = true; |
108 buffer->data.gamma = gamma; | 107 buffer->data.gamma = gamma; |
109 buffer->data.hasGamma = true; | 108 buffer->data.hasGamma = true; |
110 buffer->data.allAvailableSensorsAreActive = true; | 109 buffer->data.allAvailableSensorsAreActive = true; |
111 buffer->seqlock.WriteEnd(); | 110 buffer->seqlock.WriteEnd(); |
112 } | 111 } |
113 | 112 |
114 } // namespace | |
115 | |
116 namespace content { | |
117 | |
118 DataFetcherSharedMemory::DataFetcherSharedMemory() { | 113 DataFetcherSharedMemory::DataFetcherSharedMemory() { |
119 } | 114 } |
120 | 115 |
121 DataFetcherSharedMemory::~DataFetcherSharedMemory() { | 116 DataFetcherSharedMemory::~DataFetcherSharedMemory() { |
122 } | 117 } |
123 | 118 |
124 void DataFetcherSharedMemory::Fetch(unsigned consumer_bitmask) { | 119 void DataFetcherSharedMemory::Fetch(unsigned consumer_bitmask) { |
125 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread()); | 120 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread()); |
126 DCHECK(consumer_bitmask & CONSUMER_TYPE_ORIENTATION || | 121 DCHECK(consumer_bitmask & CONSUMER_TYPE_ORIENTATION || |
127 consumer_bitmask & CONSUMER_TYPE_MOTION || | 122 consumer_bitmask & CONSUMER_TYPE_MOTION || |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 light_buffer_->seqlock.WriteEnd(); | 245 light_buffer_->seqlock.WriteEnd(); |
251 light_buffer_ = nullptr; | 246 light_buffer_ = nullptr; |
252 } | 247 } |
253 return true; | 248 return true; |
254 default: | 249 default: |
255 NOTREACHED(); | 250 NOTREACHED(); |
256 } | 251 } |
257 return false; | 252 return false; |
258 } | 253 } |
259 | 254 |
260 } // namespace content | 255 } // namespace device |
OLD | NEW |