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 { |
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(device::AmbientLightSensor* sensor, |
blundell
2017/01/30 14:06:04
nit: just put the tests in the device namespace.
ke.he
2017/01/30 15:08:56
The fetchLight() function(s) here is not for test.
blundell
2017/01/30 15:12:35
Oops, I misread. Yes, just move the namespace devi
ke.he
2017/01/30 15:26:22
Thanks, Done:)
| |
21 content::DeviceLightHardwareBuffer* buffer) { | 21 device::DeviceLightHardwareBuffer* buffer) { |
22 DCHECK(sensor); | 22 DCHECK(sensor); |
23 DCHECK(buffer); | 23 DCHECK(buffer); |
24 // Macbook pro has 2 lux values, left and right, we take the average. | 24 // 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) | 25 // The raw sensor values are converted to lux using LMUvalueToLux(raw_value) |
26 // similar to how it is done in Firefox. | 26 // similar to how it is done in Firefox. |
27 uint64_t lux_value[2]; | 27 uint64_t lux_value[2]; |
28 if (!sensor->ReadSensorValue(lux_value)) | 28 if (!sensor->ReadSensorValue(lux_value)) |
29 return; | 29 return; |
30 uint64_t mean = (lux_value[0] + lux_value[1]) / 2; | 30 uint64_t mean = (lux_value[0] + lux_value[1]) / 2; |
31 double lux = device::LMUvalueToLux(mean); | 31 double lux = device::LMUvalueToLux(mean); |
32 buffer->seqlock.WriteBegin(); | 32 buffer->seqlock.WriteBegin(); |
33 buffer->data.value = lux; | 33 buffer->data.value = lux; |
34 buffer->seqlock.WriteEnd(); | 34 buffer->seqlock.WriteEnd(); |
35 } | 35 } |
36 | 36 |
37 void FetchMotion(SuddenMotionSensor* sensor, | 37 void FetchMotion(SuddenMotionSensor* sensor, |
38 content::DeviceMotionHardwareBuffer* buffer) { | 38 device::DeviceMotionHardwareBuffer* buffer) { |
39 DCHECK(sensor); | 39 DCHECK(sensor); |
40 DCHECK(buffer); | 40 DCHECK(buffer); |
41 | 41 |
42 float axis_value[3]; | 42 float axis_value[3]; |
43 if (!sensor->ReadSensorValues(axis_value)) | 43 if (!sensor->ReadSensorValues(axis_value)) |
44 return; | 44 return; |
45 | 45 |
46 buffer->seqlock.WriteBegin(); | 46 buffer->seqlock.WriteBegin(); |
47 buffer->data.accelerationIncludingGravityX = axis_value[0] * kMeanGravity; | 47 buffer->data.accelerationIncludingGravityX = axis_value[0] * kMeanGravity; |
48 buffer->data.hasAccelerationIncludingGravityX = true; | 48 buffer->data.hasAccelerationIncludingGravityX = true; |
49 buffer->data.accelerationIncludingGravityY = axis_value[1] * kMeanGravity; | 49 buffer->data.accelerationIncludingGravityY = axis_value[1] * kMeanGravity; |
50 buffer->data.hasAccelerationIncludingGravityY = true; | 50 buffer->data.hasAccelerationIncludingGravityY = true; |
51 buffer->data.accelerationIncludingGravityZ = axis_value[2] * kMeanGravity; | 51 buffer->data.accelerationIncludingGravityZ = axis_value[2] * kMeanGravity; |
52 buffer->data.hasAccelerationIncludingGravityZ = true; | 52 buffer->data.hasAccelerationIncludingGravityZ = true; |
53 buffer->data.allAvailableSensorsAreActive = true; | 53 buffer->data.allAvailableSensorsAreActive = true; |
54 buffer->seqlock.WriteEnd(); | 54 buffer->seqlock.WriteEnd(); |
55 } | 55 } |
56 | 56 |
57 void FetchOrientation(SuddenMotionSensor* sensor, | 57 void FetchOrientation(SuddenMotionSensor* sensor, |
58 content::DeviceOrientationHardwareBuffer* buffer) { | 58 device::DeviceOrientationHardwareBuffer* buffer) { |
59 DCHECK(sensor); | 59 DCHECK(sensor); |
60 DCHECK(buffer); | 60 DCHECK(buffer); |
61 | 61 |
62 // Retrieve per-axis calibrated values. | 62 // Retrieve per-axis calibrated values. |
63 float axis_value[3]; | 63 float axis_value[3]; |
64 if (!sensor->ReadSensorValues(axis_value)) | 64 if (!sensor->ReadSensorValues(axis_value)) |
65 return; | 65 return; |
66 | 66 |
67 // Transform the accelerometer values to W3C draft angles. | 67 // Transform the accelerometer values to W3C draft angles. |
68 // | 68 // |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 buffer->data.beta = beta; | 106 buffer->data.beta = beta; |
107 buffer->data.hasBeta = true; | 107 buffer->data.hasBeta = true; |
108 buffer->data.gamma = gamma; | 108 buffer->data.gamma = gamma; |
109 buffer->data.hasGamma = true; | 109 buffer->data.hasGamma = true; |
110 buffer->data.allAvailableSensorsAreActive = true; | 110 buffer->data.allAvailableSensorsAreActive = true; |
111 buffer->seqlock.WriteEnd(); | 111 buffer->seqlock.WriteEnd(); |
112 } | 112 } |
113 | 113 |
114 } // namespace | 114 } // namespace |
115 | 115 |
116 namespace content { | 116 namespace device { |
117 | 117 |
118 DataFetcherSharedMemory::DataFetcherSharedMemory() { | 118 DataFetcherSharedMemory::DataFetcherSharedMemory() { |
119 } | 119 } |
120 | 120 |
121 DataFetcherSharedMemory::~DataFetcherSharedMemory() { | 121 DataFetcherSharedMemory::~DataFetcherSharedMemory() { |
122 } | 122 } |
123 | 123 |
124 void DataFetcherSharedMemory::Fetch(unsigned consumer_bitmask) { | 124 void DataFetcherSharedMemory::Fetch(unsigned consumer_bitmask) { |
125 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread()); | 125 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread()); |
126 DCHECK(consumer_bitmask & CONSUMER_TYPE_ORIENTATION || | 126 DCHECK(consumer_bitmask & CONSUMER_TYPE_ORIENTATION || |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 light_buffer_->seqlock.WriteEnd(); | 250 light_buffer_->seqlock.WriteEnd(); |
251 light_buffer_ = nullptr; | 251 light_buffer_ = nullptr; |
252 } | 252 } |
253 return true; | 253 return true; |
254 default: | 254 default: |
255 NOTREACHED(); | 255 NOTREACHED(); |
256 } | 256 } |
257 return false; | 257 return false; |
258 } | 258 } |
259 | 259 |
260 } // namespace content | 260 } // namespace device |
OLD | NEW |