| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "data_fetcher_shared_memory.h" | 5 #include "data_fetcher_shared_memory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "third_party/sudden_motion_sensor/sudden_motion_sensor_mac.h" | 9 #include "third_party/sudden_motion_sensor/sudden_motion_sensor_mac.h" |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // After that the rest is just a bit of trigonometry. | 57 // After that the rest is just a bit of trigonometry. |
| 58 // | 58 // |
| 59 // Also note that alpha can't be provided but it's assumed to be always zero. | 59 // Also note that alpha can't be provided but it's assumed to be always zero. |
| 60 // This is necessary in order to provide enough information to solve | 60 // This is necessary in order to provide enough information to solve |
| 61 // the equations. | 61 // the equations. |
| 62 // | 62 // |
| 63 const double kRad2deg = 180.0 / M_PI; | 63 const double kRad2deg = 180.0 / M_PI; |
| 64 double beta = kRad2deg * atan2(-axis_value[1], axis_value[2]); | 64 double beta = kRad2deg * atan2(-axis_value[1], axis_value[2]); |
| 65 double gamma = kRad2deg * asin(axis_value[0]); | 65 double gamma = kRad2deg * asin(axis_value[0]); |
| 66 | 66 |
| 67 // TODO(aousterh): should absolute_ be set to false here? | |
| 68 // See crbug.com/136010. | |
| 69 | |
| 70 // Make sure that the interval boundaries comply with the specification. At | 67 // Make sure that the interval boundaries comply with the specification. At |
| 71 // this point, beta is [-180, 180] and gamma is [-90, 90], but the spec has | 68 // this point, beta is [-180, 180] and gamma is [-90, 90], but the spec has |
| 72 // the upper bound open on both. | 69 // the upper bound open on both. |
| 73 if (beta == 180.0) | 70 if (beta == 180.0) |
| 74 beta = -180; // -180 == 180 (upside-down) | 71 beta = -180; // -180 == 180 (upside-down) |
| 75 if (gamma == 90.0) | 72 if (gamma == 90.0) |
| 76 gamma = nextafter(90, 0); | 73 gamma = nextafter(90, 0); |
| 77 | 74 |
| 78 // At this point, DCHECKing is paranoia. Never hurts. | 75 // At this point, DCHECKing is paranoia. Never hurts. |
| 79 DCHECK_GE(beta, -180.0); | 76 DCHECK_GE(beta, -180.0); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 110 } |
| 114 | 111 |
| 115 DataFetcherSharedMemory::FetcherType DataFetcherSharedMemory::GetType() const { | 112 DataFetcherSharedMemory::FetcherType DataFetcherSharedMemory::GetType() const { |
| 116 return FETCHER_TYPE_POLLING_CALLBACK; | 113 return FETCHER_TYPE_POLLING_CALLBACK; |
| 117 } | 114 } |
| 118 | 115 |
| 119 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { | 116 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { |
| 120 DCHECK(base::MessageLoop::current() == GetPollingMessageLoop()); | 117 DCHECK(base::MessageLoop::current() == GetPollingMessageLoop()); |
| 121 DCHECK(buffer); | 118 DCHECK(buffer); |
| 122 | 119 |
| 120 if (!sudden_motion_sensor_) |
| 121 sudden_motion_sensor_.reset(SuddenMotionSensor::Create()); |
| 122 bool sudden_motion_sensor_available = sudden_motion_sensor_.get() != NULL; |
| 123 |
| 123 switch (consumer_type) { | 124 switch (consumer_type) { |
| 124 case CONSUMER_TYPE_MOTION: | 125 case CONSUMER_TYPE_MOTION: |
| 125 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer); | 126 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer); |
| 126 if (!sudden_motion_sensor_) | |
| 127 sudden_motion_sensor_.reset(SuddenMotionSensor::Create()); | |
| 128 UMA_HISTOGRAM_BOOLEAN("InertialSensor.MotionMacAvailable", | 127 UMA_HISTOGRAM_BOOLEAN("InertialSensor.MotionMacAvailable", |
| 129 sudden_motion_sensor_.get() != NULL); | 128 sudden_motion_sensor_available); |
| 130 return sudden_motion_sensor_.get() != NULL; | 129 if (!sudden_motion_sensor_available) { |
| 130 // No motion sensor available, fire an all-null event. |
| 131 motion_buffer_->seqlock.WriteBegin(); |
| 132 motion_buffer_->data.allAvailableSensorsAreActive = true; |
| 133 motion_buffer_->seqlock.WriteEnd(); |
| 134 } |
| 135 return sudden_motion_sensor_available; |
| 131 case CONSUMER_TYPE_ORIENTATION: | 136 case CONSUMER_TYPE_ORIENTATION: |
| 132 orientation_buffer_ = | 137 orientation_buffer_ = |
| 133 static_cast<DeviceOrientationHardwareBuffer*>(buffer); | 138 static_cast<DeviceOrientationHardwareBuffer*>(buffer); |
| 134 if (!sudden_motion_sensor_) | |
| 135 sudden_motion_sensor_.reset(SuddenMotionSensor::Create()); | |
| 136 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationMacAvailable", | 139 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationMacAvailable", |
| 137 sudden_motion_sensor_.get() != NULL); | 140 sudden_motion_sensor_available); |
| 138 return sudden_motion_sensor_.get() != NULL; | 141 if (sudden_motion_sensor_available) { |
| 142 // On Mac we cannot provide absolute orientation. |
| 143 orientation_buffer_->seqlock.WriteBegin(); |
| 144 orientation_buffer_->data.absolute = false; |
| 145 orientation_buffer_->data.hasAbsolute = true; |
| 146 orientation_buffer_->seqlock.WriteEnd(); |
| 147 } else { |
| 148 // No motion sensor available, fire an all-null event. |
| 149 orientation_buffer_->seqlock.WriteBegin(); |
| 150 orientation_buffer_->data.allAvailableSensorsAreActive = true; |
| 151 orientation_buffer_->seqlock.WriteEnd(); |
| 152 } |
| 153 return sudden_motion_sensor_available; |
| 139 default: | 154 default: |
| 140 NOTREACHED(); | 155 NOTREACHED(); |
| 141 } | 156 } |
| 142 return false; | 157 return false; |
| 143 } | 158 } |
| 144 | 159 |
| 145 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { | 160 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { |
| 146 DCHECK(base::MessageLoop::current() == GetPollingMessageLoop()); | 161 DCHECK(base::MessageLoop::current() == GetPollingMessageLoop()); |
| 147 | 162 |
| 148 switch (consumer_type) { | 163 switch (consumer_type) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 162 orientation_buffer_ = NULL; | 177 orientation_buffer_ = NULL; |
| 163 } | 178 } |
| 164 return true; | 179 return true; |
| 165 default: | 180 default: |
| 166 NOTREACHED(); | 181 NOTREACHED(); |
| 167 } | 182 } |
| 168 return false; | 183 return false; |
| 169 } | 184 } |
| 170 | 185 |
| 171 } // namespace content | 186 } // namespace content |
| OLD | NEW |