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

Side by Side Diff: device/sensors/data_fetcher_shared_memory_mac.cc

Issue 2763333002: Convert device sensors structs from Blink to Chromium naming (Closed)
Patch Set: Rebase Created 3 years, 9 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 "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"
(...skipping 25 matching lines...) Expand all
36 void FetchMotion(SuddenMotionSensor* sensor, 36 void FetchMotion(SuddenMotionSensor* sensor,
37 DeviceMotionHardwareBuffer* buffer) { 37 DeviceMotionHardwareBuffer* buffer) {
38 DCHECK(sensor); 38 DCHECK(sensor);
39 DCHECK(buffer); 39 DCHECK(buffer);
40 40
41 float axis_value[3]; 41 float axis_value[3];
42 if (!sensor->ReadSensorValues(axis_value)) 42 if (!sensor->ReadSensorValues(axis_value))
43 return; 43 return;
44 44
45 buffer->seqlock.WriteBegin(); 45 buffer->seqlock.WriteBegin();
46 buffer->data.accelerationIncludingGravityX = axis_value[0] * kMeanGravity; 46 buffer->data.acceleration_including_gravity_x = axis_value[0] * kMeanGravity;
47 buffer->data.hasAccelerationIncludingGravityX = true; 47 buffer->data.has_acceleration_including_gravity_x = true;
48 buffer->data.accelerationIncludingGravityY = axis_value[1] * kMeanGravity; 48 buffer->data.acceleration_including_gravity_y = axis_value[1] * kMeanGravity;
49 buffer->data.hasAccelerationIncludingGravityY = true; 49 buffer->data.has_acceleration_including_gravity_y = true;
50 buffer->data.accelerationIncludingGravityZ = axis_value[2] * kMeanGravity; 50 buffer->data.acceleration_including_gravity_z = axis_value[2] * kMeanGravity;
51 buffer->data.hasAccelerationIncludingGravityZ = true; 51 buffer->data.has_acceleration_including_gravity_z = true;
52 buffer->data.allAvailableSensorsAreActive = true; 52 buffer->data.all_available_sensors_are_active = true;
53 buffer->seqlock.WriteEnd(); 53 buffer->seqlock.WriteEnd();
54 } 54 }
55 55
56 void FetchOrientation(SuddenMotionSensor* sensor, 56 void FetchOrientation(SuddenMotionSensor* sensor,
57 DeviceOrientationHardwareBuffer* buffer) { 57 DeviceOrientationHardwareBuffer* buffer) {
58 DCHECK(sensor); 58 DCHECK(sensor);
59 DCHECK(buffer); 59 DCHECK(buffer);
60 60
61 // Retrieve per-axis calibrated values. 61 // Retrieve per-axis calibrated values.
62 float axis_value[3]; 62 float axis_value[3];
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 gamma = nextafter(90, 0); 96 gamma = nextafter(90, 0);
97 97
98 // At this point, DCHECKing is paranoia. Never hurts. 98 // At this point, DCHECKing is paranoia. Never hurts.
99 DCHECK_GE(beta, -180.0); 99 DCHECK_GE(beta, -180.0);
100 DCHECK_LT(beta, 180.0); 100 DCHECK_LT(beta, 180.0);
101 DCHECK_GE(gamma, -90.0); 101 DCHECK_GE(gamma, -90.0);
102 DCHECK_LT(gamma, 90.0); 102 DCHECK_LT(gamma, 90.0);
103 103
104 buffer->seqlock.WriteBegin(); 104 buffer->seqlock.WriteBegin();
105 buffer->data.beta = beta; 105 buffer->data.beta = beta;
106 buffer->data.hasBeta = true; 106 buffer->data.has_beta = true;
107 buffer->data.gamma = gamma; 107 buffer->data.gamma = gamma;
108 buffer->data.hasGamma = true; 108 buffer->data.has_gamma = true;
109 buffer->data.allAvailableSensorsAreActive = true; 109 buffer->data.all_available_sensors_are_active = true;
110 buffer->seqlock.WriteEnd(); 110 buffer->seqlock.WriteEnd();
111 } 111 }
112 112
113 DataFetcherSharedMemory::DataFetcherSharedMemory() {} 113 DataFetcherSharedMemory::DataFetcherSharedMemory() {}
114 114
115 DataFetcherSharedMemory::~DataFetcherSharedMemory() {} 115 DataFetcherSharedMemory::~DataFetcherSharedMemory() {}
116 116
117 void DataFetcherSharedMemory::Fetch(unsigned consumer_bitmask) { 117 void DataFetcherSharedMemory::Fetch(unsigned consumer_bitmask) {
118 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread()); 118 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread());
119 DCHECK(consumer_bitmask & CONSUMER_TYPE_ORIENTATION || 119 DCHECK(consumer_bitmask & CONSUMER_TYPE_ORIENTATION ||
(...skipping 22 matching lines...) Expand all
142 sudden_motion_sensor_.reset(SuddenMotionSensor::Create()); 142 sudden_motion_sensor_.reset(SuddenMotionSensor::Create());
143 bool sudden_motion_sensor_available = 143 bool sudden_motion_sensor_available =
144 sudden_motion_sensor_.get() != nullptr; 144 sudden_motion_sensor_.get() != nullptr;
145 145
146 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer); 146 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer);
147 UMA_HISTOGRAM_BOOLEAN("InertialSensor.MotionMacAvailable", 147 UMA_HISTOGRAM_BOOLEAN("InertialSensor.MotionMacAvailable",
148 sudden_motion_sensor_available); 148 sudden_motion_sensor_available);
149 if (!sudden_motion_sensor_available) { 149 if (!sudden_motion_sensor_available) {
150 // No motion sensor available, fire an all-null event. 150 // No motion sensor available, fire an all-null event.
151 motion_buffer_->seqlock.WriteBegin(); 151 motion_buffer_->seqlock.WriteBegin();
152 motion_buffer_->data.allAvailableSensorsAreActive = true; 152 motion_buffer_->data.all_available_sensors_are_active = true;
153 motion_buffer_->seqlock.WriteEnd(); 153 motion_buffer_->seqlock.WriteEnd();
154 } 154 }
155 return sudden_motion_sensor_available; 155 return sudden_motion_sensor_available;
156 } 156 }
157 case CONSUMER_TYPE_ORIENTATION: { 157 case CONSUMER_TYPE_ORIENTATION: {
158 if (!sudden_motion_sensor_) 158 if (!sudden_motion_sensor_)
159 sudden_motion_sensor_.reset(SuddenMotionSensor::Create()); 159 sudden_motion_sensor_.reset(SuddenMotionSensor::Create());
160 bool sudden_motion_sensor_available = 160 bool sudden_motion_sensor_available =
161 sudden_motion_sensor_.get() != nullptr; 161 sudden_motion_sensor_.get() != nullptr;
162 162
163 orientation_buffer_ = 163 orientation_buffer_ =
164 static_cast<DeviceOrientationHardwareBuffer*>(buffer); 164 static_cast<DeviceOrientationHardwareBuffer*>(buffer);
165 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationMacAvailable", 165 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationMacAvailable",
166 sudden_motion_sensor_available); 166 sudden_motion_sensor_available);
167 if (sudden_motion_sensor_available) { 167 if (sudden_motion_sensor_available) {
168 // On Mac we cannot provide absolute orientation. 168 // On Mac we cannot provide absolute orientation.
169 orientation_buffer_->seqlock.WriteBegin(); 169 orientation_buffer_->seqlock.WriteBegin();
170 orientation_buffer_->data.absolute = false; 170 orientation_buffer_->data.absolute = false;
171 orientation_buffer_->seqlock.WriteEnd(); 171 orientation_buffer_->seqlock.WriteEnd();
172 } else { 172 } else {
173 // No motion sensor available, fire an all-null event. 173 // No motion sensor available, fire an all-null event.
174 orientation_buffer_->seqlock.WriteBegin(); 174 orientation_buffer_->seqlock.WriteBegin();
175 orientation_buffer_->data.allAvailableSensorsAreActive = true; 175 orientation_buffer_->data.all_available_sensors_are_active = true;
176 orientation_buffer_->seqlock.WriteEnd(); 176 orientation_buffer_->seqlock.WriteEnd();
177 } 177 }
178 return sudden_motion_sensor_available; 178 return sudden_motion_sensor_available;
179 } 179 }
180 case CONSUMER_TYPE_ORIENTATION_ABSOLUTE: { 180 case CONSUMER_TYPE_ORIENTATION_ABSOLUTE: {
181 orientation_absolute_buffer_ = 181 orientation_absolute_buffer_ =
182 static_cast<DeviceOrientationHardwareBuffer*>(buffer); 182 static_cast<DeviceOrientationHardwareBuffer*>(buffer);
183 // Absolute device orientation not available on Mac, let the 183 // Absolute device orientation not available on Mac, let the
184 // implementation fire an all-null event to signal this to blink. 184 // implementation fire an all-null event to signal this to blink.
185 orientation_absolute_buffer_->seqlock.WriteBegin(); 185 orientation_absolute_buffer_->seqlock.WriteBegin();
186 orientation_absolute_buffer_->data.absolute = true; 186 orientation_absolute_buffer_->data.absolute = true;
187 orientation_absolute_buffer_->data.allAvailableSensorsAreActive = true; 187 orientation_absolute_buffer_->data.all_available_sensors_are_active =
188 true;
188 orientation_absolute_buffer_->seqlock.WriteEnd(); 189 orientation_absolute_buffer_->seqlock.WriteEnd();
189 return false; 190 return false;
190 } 191 }
191 case CONSUMER_TYPE_LIGHT: { 192 case CONSUMER_TYPE_LIGHT: {
192 if (!ambient_light_sensor_) 193 if (!ambient_light_sensor_)
193 ambient_light_sensor_ = AmbientLightSensor::Create(); 194 ambient_light_sensor_ = AmbientLightSensor::Create();
194 bool ambient_light_sensor_available = 195 bool ambient_light_sensor_available =
195 ambient_light_sensor_.get() != nullptr; 196 ambient_light_sensor_.get() != nullptr;
196 197
197 light_buffer_ = static_cast<DeviceLightHardwareBuffer*>(buffer); 198 light_buffer_ = static_cast<DeviceLightHardwareBuffer*>(buffer);
(...skipping 10 matching lines...) Expand all
208 return false; 209 return false;
209 } 210 }
210 211
211 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { 212 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) {
212 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread()); 213 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread());
213 214
214 switch (consumer_type) { 215 switch (consumer_type) {
215 case CONSUMER_TYPE_MOTION: 216 case CONSUMER_TYPE_MOTION:
216 if (motion_buffer_) { 217 if (motion_buffer_) {
217 motion_buffer_->seqlock.WriteBegin(); 218 motion_buffer_->seqlock.WriteBegin();
218 motion_buffer_->data.allAvailableSensorsAreActive = false; 219 motion_buffer_->data.all_available_sensors_are_active = false;
219 motion_buffer_->seqlock.WriteEnd(); 220 motion_buffer_->seqlock.WriteEnd();
220 motion_buffer_ = nullptr; 221 motion_buffer_ = nullptr;
221 } 222 }
222 return true; 223 return true;
223 case CONSUMER_TYPE_ORIENTATION: 224 case CONSUMER_TYPE_ORIENTATION:
224 if (orientation_buffer_) { 225 if (orientation_buffer_) {
225 orientation_buffer_->seqlock.WriteBegin(); 226 orientation_buffer_->seqlock.WriteBegin();
226 orientation_buffer_->data.allAvailableSensorsAreActive = false; 227 orientation_buffer_->data.all_available_sensors_are_active = false;
227 orientation_buffer_->seqlock.WriteEnd(); 228 orientation_buffer_->seqlock.WriteEnd();
228 orientation_buffer_ = nullptr; 229 orientation_buffer_ = nullptr;
229 } 230 }
230 return true; 231 return true;
231 case CONSUMER_TYPE_ORIENTATION_ABSOLUTE: 232 case CONSUMER_TYPE_ORIENTATION_ABSOLUTE:
232 if (orientation_absolute_buffer_) { 233 if (orientation_absolute_buffer_) {
233 orientation_absolute_buffer_->seqlock.WriteBegin(); 234 orientation_absolute_buffer_->seqlock.WriteBegin();
234 orientation_absolute_buffer_->data.allAvailableSensorsAreActive = false; 235 orientation_absolute_buffer_->data.all_available_sensors_are_active =
236 false;
235 orientation_absolute_buffer_->seqlock.WriteEnd(); 237 orientation_absolute_buffer_->seqlock.WriteEnd();
236 orientation_absolute_buffer_ = nullptr; 238 orientation_absolute_buffer_ = nullptr;
237 } 239 }
238 return true; 240 return true;
239 case CONSUMER_TYPE_LIGHT: 241 case CONSUMER_TYPE_LIGHT:
240 if (light_buffer_) { 242 if (light_buffer_) {
241 light_buffer_->seqlock.WriteBegin(); 243 light_buffer_->seqlock.WriteBegin();
242 light_buffer_->data.value = -1; 244 light_buffer_->data.value = -1;
243 light_buffer_->seqlock.WriteEnd(); 245 light_buffer_->seqlock.WriteEnd();
244 light_buffer_ = nullptr; 246 light_buffer_ = nullptr;
245 } 247 }
246 return true; 248 return true;
247 default: 249 default:
248 NOTREACHED(); 250 NOTREACHED();
249 } 251 }
250 return false; 252 return false;
251 } 253 }
252 254
253 } // namespace device 255 } // namespace device
OLDNEW
« no previous file with comments | « device/sensors/data_fetcher_shared_memory_default.cc ('k') | device/sensors/data_fetcher_shared_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698