Merge lp:~abreu-alexandre/oxide/accelerometer-support into lp:~oxide-developers/oxide/oxide.trunk
- accelerometer-support
- Merge into oxide.trunk
Proposed by
Alexandre Abreu
Status: | Work in progress | ||||
---|---|---|---|---|---|
Proposed branch: | lp:~abreu-alexandre/oxide/accelerometer-support | ||||
Merge into: | lp:~oxide-developers/oxide/oxide.trunk | ||||
Diff against target: |
573 lines (+487/-1) 8 files modified
qt/build/system.gyp (+17/-0) qt/core/browser/oxide_data_fetcher_shared_memory.cc (+215/-0) qt/core/browser/oxide_data_fetcher_shared_memory.h (+54/-0) qt/core/browser/oxide_qt_accelerometer.cc (+91/-0) qt/core/browser/oxide_qt_accelerometer.h (+39/-0) qt/core/browser/oxide_qt_accelerometer_p.h (+53/-0) qt/core/browser/oxide_qt_browser_startup.cc (+6/-1) qt/core/core.gyp (+12/-0) |
||||
To merge this branch: | bzr merge lp:~abreu-alexandre/oxide/accelerometer-support | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Coulson | Pending | ||
Review via email: mp+277483@code.launchpad.net |
Commit message
Description of the change
WIP
To post a comment you must log in.
Unmerged revisions
- 1276. By Alexandre Abreu
-
simple port to trunk
- 1275. By Alexandre Abreu
-
pull trunk
- 1274. By Alexandre Abreu
-
back to trunk
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'qt/build/system.gyp' | |||
2 | --- qt/build/system.gyp 2015-10-28 19:09:39 +0000 | |||
3 | +++ qt/build/system.gyp 2015-11-13 20:15:31 +0000 | |||
4 | @@ -91,6 +91,23 @@ | |||
5 | 91 | }, | 91 | }, |
6 | 92 | }, | 92 | }, |
7 | 93 | { | 93 | { |
8 | 94 | 'target_name': 'Qt5Sensors', | ||
9 | 95 | 'type': 'none', | ||
10 | 96 | 'direct_dependent_settings': { | ||
11 | 97 | 'cflags_cc': [ | ||
12 | 98 | '<!@(<(pkg_config) --cflags Qt5Sensors)' | ||
13 | 99 | ] | ||
14 | 100 | }, | ||
15 | 101 | 'link_settings': { | ||
16 | 102 | 'ldflags': [ | ||
17 | 103 | '<!@(<(pkg_config) --libs-only-L --libs-only-other Qt5Sensors)', | ||
18 | 104 | ], | ||
19 | 105 | 'libraries': [ | ||
20 | 106 | '<!@(<(pkg_config) --libs-only-l Qt5Sensors)', | ||
21 | 107 | ], | ||
22 | 108 | }, | ||
23 | 109 | }, | ||
24 | 110 | { | ||
25 | 94 | 'target_name': 'Qt5Positioning', | 111 | 'target_name': 'Qt5Positioning', |
26 | 95 | 'type': 'none', | 112 | 'type': 'none', |
27 | 96 | 'direct_dependent_settings': { | 113 | 'direct_dependent_settings': { |
28 | 97 | 114 | ||
29 | === added file 'qt/core/browser/oxide_data_fetcher_shared_memory.cc' | |||
30 | --- qt/core/browser/oxide_data_fetcher_shared_memory.cc 1970-01-01 00:00:00 +0000 | |||
31 | +++ qt/core/browser/oxide_data_fetcher_shared_memory.cc 2015-11-13 20:15:31 +0000 | |||
32 | @@ -0,0 +1,215 @@ | |||
33 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
34 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
35 | 3 | |||
36 | 4 | // This library is free software; you can redistribute it and/or | ||
37 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
38 | 6 | // License as published by the Free Software Foundation; either | ||
39 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
40 | 8 | |||
41 | 9 | // This library is distributed in the hope that it will be useful, | ||
42 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
43 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
44 | 12 | // Lesser General Public License for more details. | ||
45 | 13 | |||
46 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
47 | 15 | // License along with this library; if not, write to the Free Software | ||
48 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
49 | 17 | |||
50 | 18 | #include "oxide_data_fetcher_shared_memory.h" | ||
51 | 19 | |||
52 | 20 | #include "base/logging.h" | ||
53 | 21 | #include "base/metrics/histogram.h" | ||
54 | 22 | |||
55 | 23 | #include "qt/core/browser/oxide_qt_accelerometer.h" | ||
56 | 24 | |||
57 | 25 | namespace { | ||
58 | 26 | |||
59 | 27 | static bool SetMotionBuffer(content::DeviceMotionHardwareBuffer* buffer, | ||
60 | 28 | bool enabled) { | ||
61 | 29 | if (!buffer) | ||
62 | 30 | return false; | ||
63 | 31 | buffer->seqlock.WriteBegin(); | ||
64 | 32 | buffer->data.allAvailableSensorsAreActive = enabled; | ||
65 | 33 | buffer->seqlock.WriteEnd(); | ||
66 | 34 | return true; | ||
67 | 35 | } | ||
68 | 36 | |||
69 | 37 | static bool SetOrientationBuffer( | ||
70 | 38 | content::DeviceOrientationHardwareBuffer* buffer, bool enabled) { | ||
71 | 39 | if (!buffer) | ||
72 | 40 | return false; | ||
73 | 41 | buffer->seqlock.WriteBegin(); | ||
74 | 42 | buffer->data.allAvailableSensorsAreActive = enabled; | ||
75 | 43 | buffer->seqlock.WriteEnd(); | ||
76 | 44 | return true; | ||
77 | 45 | } | ||
78 | 46 | |||
79 | 47 | static bool SetLightBuffer(content::DeviceLightHardwareBuffer* buffer, | ||
80 | 48 | double lux) { | ||
81 | 49 | if (!buffer) | ||
82 | 50 | return false; | ||
83 | 51 | buffer->seqlock.WriteBegin(); | ||
84 | 52 | buffer->data.value = lux; | ||
85 | 53 | buffer->seqlock.WriteEnd(); | ||
86 | 54 | return true; | ||
87 | 55 | } | ||
88 | 56 | |||
89 | 57 | } // namespace | ||
90 | 58 | |||
91 | 59 | namespace oxide { | ||
92 | 60 | |||
93 | 61 | OxideDataFetcherSharedMemory::OxideDataFetcherSharedMemory() | ||
94 | 62 | : motion_buffer_(nullptr), | ||
95 | 63 | orientation_buffer_(nullptr), | ||
96 | 64 | light_buffer_(nullptr) { | ||
97 | 65 | } | ||
98 | 66 | |||
99 | 67 | OxideDataFetcherSharedMemory::~OxideDataFetcherSharedMemory() { | ||
100 | 68 | } | ||
101 | 69 | |||
102 | 70 | void FetchOrientation( | ||
103 | 71 | oxide::qt::AccelerometerSensorReader *sensor, | ||
104 | 72 | content::DeviceOrientationHardwareBuffer* buffer) { | ||
105 | 73 | DCHECK(buffer); | ||
106 | 74 | DCHECK(sensor); | ||
107 | 75 | |||
108 | 76 | double axis_value[3]; | ||
109 | 77 | if (!sensor->GetData(axis_value)) { | ||
110 | 78 | return; | ||
111 | 79 | } | ||
112 | 80 | |||
113 | 81 | const double kRad2deg = 180.0 / M_PI; | ||
114 | 82 | double beta = kRad2deg * atan2(-axis_value[1], axis_value[2]); | ||
115 | 83 | double gamma = kRad2deg * asin(axis_value[0]); | ||
116 | 84 | |||
117 | 85 | if (beta == 180.0) { | ||
118 | 86 | beta = -180; | ||
119 | 87 | } | ||
120 | 88 | if (gamma == 90.0) { | ||
121 | 89 | gamma = nextafter(90, 0); | ||
122 | 90 | } | ||
123 | 91 | |||
124 | 92 | DCHECK_GE(beta, -180.0); | ||
125 | 93 | DCHECK_LT(beta, 180.0); | ||
126 | 94 | DCHECK_GE(gamma, -90.0); | ||
127 | 95 | DCHECK_LT(gamma, 90.0); | ||
128 | 96 | |||
129 | 97 | buffer->seqlock.WriteBegin(); | ||
130 | 98 | buffer->data.beta = beta; | ||
131 | 99 | buffer->data.hasBeta = true; | ||
132 | 100 | buffer->data.gamma = gamma; | ||
133 | 101 | buffer->data.hasGamma = true; | ||
134 | 102 | buffer->data.allAvailableSensorsAreActive = true; | ||
135 | 103 | buffer->seqlock.WriteEnd(); | ||
136 | 104 | } | ||
137 | 105 | |||
138 | 106 | void FetchMotion( | ||
139 | 107 | oxide::qt::AccelerometerSensorReader* sensor, | ||
140 | 108 | content::DeviceMotionHardwareBuffer* buffer) { | ||
141 | 109 | DCHECK(buffer); | ||
142 | 110 | DCHECK(sensor); | ||
143 | 111 | |||
144 | 112 | double axis_value[3]; | ||
145 | 113 | if (!sensor->GetData(axis_value)) { | ||
146 | 114 | return; | ||
147 | 115 | } | ||
148 | 116 | |||
149 | 117 | buffer->seqlock.WriteBegin(); | ||
150 | 118 | buffer->data.accelerationIncludingGravityX = axis_value[0]; | ||
151 | 119 | buffer->data.hasAccelerationIncludingGravityX = true; | ||
152 | 120 | buffer->data.accelerationIncludingGravityY = axis_value[1]; | ||
153 | 121 | buffer->data.hasAccelerationIncludingGravityY = true; | ||
154 | 122 | buffer->data.accelerationIncludingGravityZ = axis_value[2]; | ||
155 | 123 | buffer->data.hasAccelerationIncludingGravityZ = true; | ||
156 | 124 | buffer->data.allAvailableSensorsAreActive = true; | ||
157 | 125 | buffer->seqlock.WriteEnd(); | ||
158 | 126 | } | ||
159 | 127 | |||
160 | 128 | void OxideDataFetcherSharedMemory::Fetch(unsigned consumer_bitmask) { | ||
161 | 129 | DCHECK(base::MessageLoop::current() == GetPollingMessageLoop()); | ||
162 | 130 | DCHECK(consumer_bitmask & content::CONSUMER_TYPE_ORIENTATION || | ||
163 | 131 | consumer_bitmask & content::CONSUMER_TYPE_MOTION || | ||
164 | 132 | consumer_bitmask & content::CONSUMER_TYPE_LIGHT); | ||
165 | 133 | |||
166 | 134 | if (consumer_bitmask & content::CONSUMER_TYPE_ORIENTATION) { | ||
167 | 135 | FetchOrientation(orientation_sensor_.get(), orientation_buffer_); | ||
168 | 136 | } | ||
169 | 137 | if (consumer_bitmask & content::CONSUMER_TYPE_MOTION) { | ||
170 | 138 | FetchMotion(motion_sensor_.get(), motion_buffer_); | ||
171 | 139 | } | ||
172 | 140 | } | ||
173 | 141 | |||
174 | 142 | content::DataFetcherSharedMemoryBase::FetcherType | ||
175 | 143 | OxideDataFetcherSharedMemory::GetType() const { | ||
176 | 144 | return content::DataFetcherSharedMemoryBase::FETCHER_TYPE_POLLING_CALLBACK; | ||
177 | 145 | } | ||
178 | 146 | |||
179 | 147 | bool OxideDataFetcherSharedMemory::Start( | ||
180 | 148 | content::ConsumerType consumer_type, | ||
181 | 149 | void* buffer) { | ||
182 | 150 | DCHECK(buffer); | ||
183 | 151 | |||
184 | 152 | switch (consumer_type) { | ||
185 | 153 | case content::CONSUMER_TYPE_MOTION: | ||
186 | 154 | { | ||
187 | 155 | if (!motion_sensor_.get()) { | ||
188 | 156 | motion_sensor_.reset( | ||
189 | 157 | new oxide::qt::AccelerometerSensorReader()); | ||
190 | 158 | } | ||
191 | 159 | |||
192 | 160 | motion_buffer_ = | ||
193 | 161 | static_cast<content::DeviceMotionHardwareBuffer*>(buffer); | ||
194 | 162 | |||
195 | 163 | UMA_HISTOGRAM_BOOLEAN("InertialSensor.MotionDefaultAvailable", false); | ||
196 | 164 | |||
197 | 165 | return SetMotionBuffer(motion_buffer_, true); | ||
198 | 166 | } | ||
199 | 167 | case content::CONSUMER_TYPE_ORIENTATION: | ||
200 | 168 | { | ||
201 | 169 | if (!orientation_sensor_.get()) { | ||
202 | 170 | orientation_sensor_.reset( | ||
203 | 171 | new oxide::qt::AccelerometerSensorReader()); | ||
204 | 172 | } | ||
205 | 173 | |||
206 | 174 | orientation_buffer_ = | ||
207 | 175 | static_cast<content::DeviceOrientationHardwareBuffer*>(buffer); | ||
208 | 176 | |||
209 | 177 | UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationDefaultAvailable", | ||
210 | 178 | false); | ||
211 | 179 | |||
212 | 180 | return SetOrientationBuffer(orientation_buffer_, true); | ||
213 | 181 | } | ||
214 | 182 | case content::CONSUMER_TYPE_LIGHT: | ||
215 | 183 | { | ||
216 | 184 | light_buffer_ = | ||
217 | 185 | static_cast<content::DeviceLightHardwareBuffer*>(buffer); | ||
218 | 186 | |||
219 | 187 | return SetLightBuffer( | ||
220 | 188 | light_buffer_, | ||
221 | 189 | std::numeric_limits<double>::infinity()); | ||
222 | 190 | } | ||
223 | 191 | default: | ||
224 | 192 | NOTREACHED(); | ||
225 | 193 | } | ||
226 | 194 | return false; | ||
227 | 195 | } | ||
228 | 196 | |||
229 | 197 | bool OxideDataFetcherSharedMemory::Stop(content::ConsumerType consumer_type) { | ||
230 | 198 | switch (consumer_type) { | ||
231 | 199 | case content::CONSUMER_TYPE_MOTION: | ||
232 | 200 | motion_sensor_.reset(nullptr); | ||
233 | 201 | |||
234 | 202 | return SetMotionBuffer(motion_buffer_, false); | ||
235 | 203 | case content::CONSUMER_TYPE_ORIENTATION: | ||
236 | 204 | orientation_sensor_.reset(nullptr); | ||
237 | 205 | |||
238 | 206 | return SetOrientationBuffer(orientation_buffer_, false); | ||
239 | 207 | case content::CONSUMER_TYPE_LIGHT: | ||
240 | 208 | return SetLightBuffer(light_buffer_, -1); | ||
241 | 209 | default: | ||
242 | 210 | NOTREACHED(); | ||
243 | 211 | } | ||
244 | 212 | return false; | ||
245 | 213 | } | ||
246 | 214 | |||
247 | 215 | } // namespace oxide | ||
248 | 0 | 216 | ||
249 | === added file 'qt/core/browser/oxide_data_fetcher_shared_memory.h' | |||
250 | --- qt/core/browser/oxide_data_fetcher_shared_memory.h 1970-01-01 00:00:00 +0000 | |||
251 | +++ qt/core/browser/oxide_data_fetcher_shared_memory.h 2015-11-13 20:15:31 +0000 | |||
252 | @@ -0,0 +1,54 @@ | |||
253 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
254 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
255 | 3 | |||
256 | 4 | // This library is free software; you can redistribute it and/or | ||
257 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
258 | 6 | // License as published by the Free Software Foundation; either | ||
259 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
260 | 8 | |||
261 | 9 | // This library is distributed in the hope that it will be useful, | ||
262 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
263 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
264 | 12 | // Lesser General Public License for more details. | ||
265 | 13 | |||
266 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
267 | 15 | // License along with this library; if not, write to the Free Software | ||
268 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
269 | 17 | |||
270 | 18 | #ifndef _OXIDE_DEVICE_SENSORS_DATA_FETCHER_SHARED_MEMORY_H_ | ||
271 | 19 | #define _OXIDE_DEVICE_SENSORS_DATA_FETCHER_SHARED_MEMORY_H_ | ||
272 | 20 | |||
273 | 21 | #include "content/browser/device_sensors/data_fetcher_shared_memory.h" | ||
274 | 22 | |||
275 | 23 | namespace oxide { | ||
276 | 24 | |||
277 | 25 | namespace qt { | ||
278 | 26 | class AccelerometerSensorReader; | ||
279 | 27 | } | ||
280 | 28 | |||
281 | 29 | class CONTENT_EXPORT OxideDataFetcherSharedMemory | ||
282 | 30 | : public content::DataFetcherSharedMemory { | ||
283 | 31 | |||
284 | 32 | public: | ||
285 | 33 | OxideDataFetcherSharedMemory(); | ||
286 | 34 | ~OxideDataFetcherSharedMemory() override; | ||
287 | 35 | |||
288 | 36 | private: | ||
289 | 37 | bool Start(content::ConsumerType consumer_type, void* buffer) override; | ||
290 | 38 | bool Stop(content::ConsumerType consumer_type) override; | ||
291 | 39 | |||
292 | 40 | void Fetch(unsigned consumer_bitmask) override; | ||
293 | 41 | content::DataFetcherSharedMemoryBase::FetcherType GetType() const override; | ||
294 | 42 | scoped_ptr<oxide::qt::AccelerometerSensorReader> motion_sensor_; | ||
295 | 43 | scoped_ptr<oxide::qt::AccelerometerSensorReader> orientation_sensor_; | ||
296 | 44 | |||
297 | 45 | content::DeviceMotionHardwareBuffer* motion_buffer_; | ||
298 | 46 | content::DeviceOrientationHardwareBuffer* orientation_buffer_; | ||
299 | 47 | content::DeviceLightHardwareBuffer* light_buffer_; | ||
300 | 48 | |||
301 | 49 | DISALLOW_COPY_AND_ASSIGN(OxideDataFetcherSharedMemory); | ||
302 | 50 | }; | ||
303 | 51 | |||
304 | 52 | } | ||
305 | 53 | |||
306 | 54 | #endif // _OXIDE_DEVICE_SENSORS_DATA_FETCHER_SHARED_MEMORY_H_ | ||
307 | 0 | 55 | ||
308 | === added file 'qt/core/browser/oxide_qt_accelerometer.cc' | |||
309 | --- qt/core/browser/oxide_qt_accelerometer.cc 1970-01-01 00:00:00 +0000 | |||
310 | +++ qt/core/browser/oxide_qt_accelerometer.cc 2015-11-13 20:15:31 +0000 | |||
311 | @@ -0,0 +1,91 @@ | |||
312 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
313 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
314 | 3 | |||
315 | 4 | // This library is free software; you can redistribute it and/or | ||
316 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
317 | 6 | // License as published by the Free Software Foundation; either | ||
318 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
319 | 8 | |||
320 | 9 | // This library is distributed in the hope that it will be useful, | ||
321 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
322 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
323 | 12 | // Lesser General Public License for more details. | ||
324 | 13 | |||
325 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
326 | 15 | // License along with this library; if not, write to the Free Software | ||
327 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
328 | 17 | |||
329 | 18 | #include "oxide_qt_accelerometer.h" | ||
330 | 19 | #include "oxide_qt_accelerometer_p.h" | ||
331 | 20 | |||
332 | 21 | |||
333 | 22 | namespace oxide { | ||
334 | 23 | namespace qt { | ||
335 | 24 | |||
336 | 25 | AccelerometerSensorReader::AccelerometerSensorReader() | ||
337 | 26 | : instance_(AccelerometerSensorReaderImpl::GetInstance()) { | ||
338 | 27 | } | ||
339 | 28 | |||
340 | 29 | bool AccelerometerSensorReader::GetData(double buf[3]) { | ||
341 | 30 | return instance_->GetData(buf); | ||
342 | 31 | } | ||
343 | 32 | |||
344 | 33 | QWeakPointer<AccelerometerSensorReaderImpl> AccelerometerSensorReaderImpl::instance_; | ||
345 | 34 | |||
346 | 35 | QSharedPointer<AccelerometerSensorReaderImpl> AccelerometerSensorReaderImpl::GetInstance() { | ||
347 | 36 | QSharedPointer<AccelerometerSensorReaderImpl> instance = | ||
348 | 37 | instance_.toStrongRef(); | ||
349 | 38 | |||
350 | 39 | if (!instance.data()) { | ||
351 | 40 | instance = | ||
352 | 41 | QSharedPointer<AccelerometerSensorReaderImpl>( | ||
353 | 42 | new AccelerometerSensorReaderImpl()); | ||
354 | 43 | |||
355 | 44 | instance->accelerometer_.moveToThread(&instance->thread_); | ||
356 | 45 | instance->connect( | ||
357 | 46 | &instance->accelerometer_, | ||
358 | 47 | SIGNAL(readingChanged()), | ||
359 | 48 | SLOT(updateSensor()), | ||
360 | 49 | Qt::DirectConnection); | ||
361 | 50 | instance->thread_.start(); | ||
362 | 51 | QMetaObject::invokeMethod(&instance->accelerometer_, "start", Qt::QueuedConnection); | ||
363 | 52 | |||
364 | 53 | instance_ = instance; | ||
365 | 54 | } | ||
366 | 55 | return instance; | ||
367 | 56 | } | ||
368 | 57 | |||
369 | 58 | bool AccelerometerSensorReaderImpl::GetData(double buf[3]) { | ||
370 | 59 | if (!initialized_) { | ||
371 | 60 | return false; | ||
372 | 61 | } | ||
373 | 62 | |||
374 | 63 | mutex_.lock(); | ||
375 | 64 | buf[0] = x_; | ||
376 | 65 | buf[1] = y_; | ||
377 | 66 | buf[2] = z_; | ||
378 | 67 | mutex_.unlock(); | ||
379 | 68 | |||
380 | 69 | return true; | ||
381 | 70 | } | ||
382 | 71 | |||
383 | 72 | void AccelerometerSensorReaderImpl::updateSensor() { | ||
384 | 73 | QAccelerometerReading *accelerometer = accelerometer_.reading(); | ||
385 | 74 | if (!accelerometer) { | ||
386 | 75 | return; | ||
387 | 76 | } | ||
388 | 77 | |||
389 | 78 | mutex_.lock(); | ||
390 | 79 | x_ = accelerometer->x(); | ||
391 | 80 | y_ = accelerometer->y(); | ||
392 | 81 | z_ = accelerometer->z(); | ||
393 | 82 | initialized_ = true; | ||
394 | 83 | mutex_.unlock(); | ||
395 | 84 | } | ||
396 | 85 | |||
397 | 86 | AccelerometerSensorReaderImpl::AccelerometerSensorReaderImpl() | ||
398 | 87 | : initialized_(false) { | ||
399 | 88 | } | ||
400 | 89 | |||
401 | 90 | } // namespace qt | ||
402 | 91 | } // namespace oxide | ||
403 | 0 | 92 | ||
404 | === added file 'qt/core/browser/oxide_qt_accelerometer.h' | |||
405 | --- qt/core/browser/oxide_qt_accelerometer.h 1970-01-01 00:00:00 +0000 | |||
406 | +++ qt/core/browser/oxide_qt_accelerometer.h 2015-11-13 20:15:31 +0000 | |||
407 | @@ -0,0 +1,39 @@ | |||
408 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
409 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
410 | 3 | |||
411 | 4 | // This library is free software; you can redistribute it and/or | ||
412 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
413 | 6 | // License as published by the Free Software Foundation; either | ||
414 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
415 | 8 | |||
416 | 9 | // This library is distributed in the hope that it will be useful, | ||
417 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
418 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
419 | 12 | // Lesser General Public License for more details. | ||
420 | 13 | |||
421 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
422 | 15 | // License along with this library; if not, write to the Free Software | ||
423 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
424 | 17 | |||
425 | 18 | #ifndef _OXIDE_QT_CORE_BROWSER_ACCELEROMETER_H_ | ||
426 | 19 | #define _OXIDE_QT_CORE_BROWSER_ACCELEROMETER_H_ | ||
427 | 20 | |||
428 | 21 | #include <QtCore> | ||
429 | 22 | |||
430 | 23 | namespace oxide { | ||
431 | 24 | namespace qt { | ||
432 | 25 | |||
433 | 26 | class AccelerometerSensorReaderImpl; | ||
434 | 27 | |||
435 | 28 | class AccelerometerSensorReader { | ||
436 | 29 | public: | ||
437 | 30 | AccelerometerSensorReader(); | ||
438 | 31 | bool GetData(double buf[3]); | ||
439 | 32 | private: | ||
440 | 33 | QSharedPointer<AccelerometerSensorReaderImpl> instance_; | ||
441 | 34 | }; | ||
442 | 35 | |||
443 | 36 | } // namespace qt | ||
444 | 37 | } // namespace oxide | ||
445 | 38 | |||
446 | 39 | #endif // _OXIDE_QT_CORE_BROWSER_ACCELEROMETER_H_ | ||
447 | 0 | 40 | ||
448 | === added file 'qt/core/browser/oxide_qt_accelerometer_p.h' | |||
449 | --- qt/core/browser/oxide_qt_accelerometer_p.h 1970-01-01 00:00:00 +0000 | |||
450 | +++ qt/core/browser/oxide_qt_accelerometer_p.h 2015-11-13 20:15:31 +0000 | |||
451 | @@ -0,0 +1,53 @@ | |||
452 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
453 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
454 | 3 | |||
455 | 4 | // This library is free software; you can redistribute it and/or | ||
456 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
457 | 6 | // License as published by the Free Software Foundation; either | ||
458 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
459 | 8 | |||
460 | 9 | // This library is distributed in the hope that it will be useful, | ||
461 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
462 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
463 | 12 | // Lesser General Public License for more details. | ||
464 | 13 | |||
465 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
466 | 15 | // License along with this library; if not, write to the Free Software | ||
467 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
468 | 17 | |||
469 | 18 | #ifndef _OXIDE_QT_CORE_BROWSER_ACCELEROMETER_P_H_ | ||
470 | 19 | #define _OXIDE_QT_CORE_BROWSER_ACCELEROMETER_P_H_ | ||
471 | 20 | |||
472 | 21 | #include <QtCore> | ||
473 | 22 | #include <QAccelerometer> | ||
474 | 23 | |||
475 | 24 | namespace oxide { | ||
476 | 25 | namespace qt { | ||
477 | 26 | |||
478 | 27 | class AccelerometerSensorReaderImpl: public QObject { | ||
479 | 28 | Q_OBJECT | ||
480 | 29 | public: | ||
481 | 30 | static QSharedPointer<AccelerometerSensorReaderImpl> GetInstance(); | ||
482 | 31 | |||
483 | 32 | bool GetData(double buf[3]); | ||
484 | 33 | |||
485 | 34 | protected Q_SLOTS: | ||
486 | 35 | void updateSensor(); | ||
487 | 36 | |||
488 | 37 | private: | ||
489 | 38 | AccelerometerSensorReaderImpl(); | ||
490 | 39 | |||
491 | 40 | double x_, y_, z_; | ||
492 | 41 | bool initialized_; | ||
493 | 42 | QAccelerometer accelerometer_; | ||
494 | 43 | QThread thread_; | ||
495 | 44 | QMutex mutex_; | ||
496 | 45 | |||
497 | 46 | //TODO: to QWeakPointer | ||
498 | 47 | static QWeakPointer<AccelerometerSensorReaderImpl> instance_; | ||
499 | 48 | }; | ||
500 | 49 | |||
501 | 50 | } // namespace qt | ||
502 | 51 | } // namespace oxide | ||
503 | 52 | |||
504 | 53 | #endif // _OXIDE_QT_CORE_BROWSER_ACCELEROMETER_P_H_ | ||
505 | 0 | 54 | ||
506 | === modified file 'qt/core/browser/oxide_qt_browser_startup.cc' | |||
507 | --- qt/core/browser/oxide_qt_browser_startup.cc 2015-04-20 19:22:23 +0000 | |||
508 | +++ qt/core/browser/oxide_qt_browser_startup.cc 2015-11-13 20:15:31 +0000 | |||
509 | @@ -30,6 +30,8 @@ | |||
510 | 30 | #include "qt/core/app/oxide_qt_platform_delegate.h" | 30 | #include "qt/core/app/oxide_qt_platform_delegate.h" |
511 | 31 | #include "qt/core/gpu/oxide_qt_gl_context_dependent.h" | 31 | #include "qt/core/gpu/oxide_qt_gl_context_dependent.h" |
512 | 32 | 32 | ||
513 | 33 | #include "content/browser/device_sensors/device_inertial_sensor_service.h" | ||
514 | 34 | #include "oxide_data_fetcher_shared_memory.h" | ||
515 | 33 | #include "oxide_qt_web_context.h" | 35 | #include "oxide_qt_web_context.h" |
516 | 34 | 36 | ||
517 | 35 | namespace oxide { | 37 | namespace oxide { |
518 | @@ -48,7 +50,10 @@ | |||
519 | 48 | 50 | ||
520 | 49 | BrowserStartup::BrowserStartup() | 51 | BrowserStartup::BrowserStartup() |
521 | 50 | : process_model_is_from_env_(false), | 52 | : process_model_is_from_env_(false), |
523 | 51 | process_model_(oxide::PROCESS_MODEL_UNDEFINED) {} | 53 | process_model_(oxide::PROCESS_MODEL_UNDEFINED) { |
524 | 54 | content::DeviceInertialSensorService::GetInstance()->SetDataFetcherForTesting( | ||
525 | 55 | new OxideDataFetcherSharedMemory()); | ||
526 | 56 | } | ||
527 | 52 | 57 | ||
528 | 53 | // static | 58 | // static |
529 | 54 | BrowserStartup* BrowserStartup::GetInstance() { | 59 | BrowserStartup* BrowserStartup::GetInstance() { |
530 | 55 | 60 | ||
531 | === modified file 'qt/core/core.gyp' | |||
532 | --- qt/core/core.gyp 2015-10-28 19:09:39 +0000 | |||
533 | +++ qt/core/core.gyp 2015-11-13 20:15:31 +0000 | |||
534 | @@ -30,6 +30,7 @@ | |||
535 | 30 | '../build/system.gyp:Qt5Gui-private', | 30 | '../build/system.gyp:Qt5Gui-private', |
536 | 31 | '../build/system.gyp:Qt5Positioning', | 31 | '../build/system.gyp:Qt5Positioning', |
537 | 32 | '../build/system.gyp:Qt5Network', | 32 | '../build/system.gyp:Qt5Network', |
538 | 33 | '../build/system.gyp:Qt5Sensors', | ||
539 | 33 | '../../shared/shared.gyp:oxide_shared', | 34 | '../../shared/shared.gyp:oxide_shared', |
540 | 34 | '<(DEPTH)/base/base.gyp:base', | 35 | '<(DEPTH)/base/base.gyp:base', |
541 | 35 | '<(DEPTH)/content/content.gyp:content_browser', | 36 | '<(DEPTH)/content/content.gyp:content_browser', |
542 | @@ -60,6 +61,7 @@ | |||
543 | 60 | 'sources': [ | 61 | 'sources': [ |
544 | 61 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_browser_platform_integration.cc', | 62 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_browser_platform_integration.cc', |
545 | 62 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_input_method_context.cc', | 63 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_input_method_context.cc', |
546 | 64 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_accelerometer_p.cc', | ||
547 | 63 | 'api/internal/oxideqmediacapturedevices_p.cc', | 65 | 'api/internal/oxideqmediacapturedevices_p.cc', |
548 | 64 | 'api/internal/oxideqwebpreferences_p.cc', | 66 | 'api/internal/oxideqwebpreferences_p.cc', |
549 | 65 | 'app/oxide_qt_main.cc', | 67 | 'app/oxide_qt_main.cc', |
550 | @@ -69,6 +71,11 @@ | |||
551 | 69 | 'browser/input/oxide_qt_input_method_context.cc', | 71 | 'browser/input/oxide_qt_input_method_context.cc', |
552 | 70 | 'browser/input/oxide_qt_input_method_context.h', | 72 | 'browser/input/oxide_qt_input_method_context.h', |
553 | 71 | 'browser/input/oxide_qt_input_method_context_client.h', | 73 | 'browser/input/oxide_qt_input_method_context_client.h', |
554 | 74 | 'browser/oxide_qt_accelerometer_p.h', | ||
555 | 75 | 'browser/oxide_qt_accelerometer.h', | ||
556 | 76 | 'browser/oxide_qt_accelerometer.cc', | ||
557 | 77 | 'browser/oxide_data_fetcher_shared_memory.cc', | ||
558 | 78 | 'browser/oxide_data_fetcher_shared_memory.h', | ||
559 | 72 | 'browser/oxide_qt_browser_platform_integration.cc', | 79 | 'browser/oxide_qt_browser_platform_integration.cc', |
560 | 73 | 'browser/oxide_qt_browser_platform_integration.h', | 80 | 'browser/oxide_qt_browser_platform_integration.h', |
561 | 74 | 'browser/oxide_qt_browser_startup.cc', | 81 | 'browser/oxide_qt_browser_startup.cc', |
562 | @@ -151,6 +158,11 @@ | |||
563 | 151 | ], | 158 | ], |
564 | 152 | 'actions': [ | 159 | 'actions': [ |
565 | 153 | { | 160 | { |
566 | 161 | 'action_name': 'moc_oxide_qt_accelerometer_p.cc', | ||
567 | 162 | 'moc_input': 'browser/oxide_qt_accelerometer_p.h', | ||
568 | 163 | 'includes': [ 'moc.gypi' ] | ||
569 | 164 | }, | ||
570 | 165 | { | ||
571 | 154 | 'action_name': 'oxide_qt_clipboard.moc', | 166 | 'action_name': 'oxide_qt_clipboard.moc', |
572 | 155 | 'moc_input': 'browser/oxide_qt_clipboard.cc', | 167 | 'moc_input': 'browser/oxide_qt_clipboard.cc', |
573 | 156 | 'includes': [ 'moc.gypi' ] | 168 | 'includes': [ 'moc.gypi' ] |