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

Side by Side Diff: content/public/browser/sensor_manager.cc

Issue 680383007: DeviceOrientation API on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
timvolodine 2014/11/06 02:53:47 can you call this file sensor_manager_chromeos.cc?
timvolodine 2014/11/06 02:53:47 also I don't understand why this needs to be in co
jonross 2014/11/06 18:18:52 This file is also called from the ash library. So
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/public/browser/sensor_manager.h"
6
7 #include "base/logging.h"
8 #include "base/memory/singleton.h"
9
10 namespace {
11 // Conversion ratio from radians to degrees.
12 const double kRad2deg = 180.0 / M_PI;
13 }
14
15 namespace content {
16
17 SensorManager* SensorManager::GetInstance() {
18 return Singleton<SensorManager, LeakySingletonTraits<SensorManager>>::get();
19 }
20
21 void SensorManager::OnAccelerationIncludingGravity(double x,
22 double y,
23 double z) {
timvolodine 2014/11/06 02:53:47 on which thread is this method called? do you need
jonross 2014/11/06 18:18:52 This will be called from the UI thread. I'm adding
24 if (!orientation_buffer_)
25 return;
26
27 // Create a unit vector to remove gravity.
28 // TODO(jonross): Stop reversing signs for vector components once
29 // accelerometer values have been reversed.
30 gfx::Vector3dF data(x, y ? -y : 0.0f, z ? -z : 0.0f);
31 data.Scale(1.0f / data.Length());
32
33 // Transform accelerometer to W3C angles, using the Z-X-Y Eulerangles matrix.
34 // x = sin(gamma)
35 // y = -cos(gamma) * sin(beta)
36 // z = cos(beta) * cos(gamma)
37 // With only accelerometer alpha cannot be provided.
38 double beta = kRad2deg * atan2(data.y(), data.z());
39 double gamma = kRad2deg * asin(data.x());
40
41 // Have the interval boundaries comply with the specification. Beta is
42 // [-180,180) and gamma is [-90, 90).
43 if (beta >= 180.0f)
44 beta = -180.0f;
45 if (gamma >= 90.0f)
46 gamma = -90.0f;
47
48 orientation_buffer_->seqlock.WriteBegin();
49 orientation_buffer_->data.beta = beta;
50 orientation_buffer_->data.hasBeta = true;
51 orientation_buffer_->data.gamma = gamma;
52 orientation_buffer_->data.hasGamma = true;
53 orientation_buffer_->data.allAvailableSensorsAreActive = true;
54 orientation_buffer_->seqlock.WriteEnd();
55 }
56
57 void SensorManager::StartFetchingDeviceOrientationData(
58 DeviceOrientationHardwareBuffer* buffer) {
59 DCHECK(buffer);
60 base::AutoLock autolock(orientation_buffer_lock_);
61 orientation_buffer_ = buffer;
62
63 // No compass information, so we cannot provide absolute orientation.
64 orientation_buffer_->seqlock.WriteBegin();
65 orientation_buffer_->data.absolute = false;
66 orientation_buffer_->data.hasAbsolute = true;
67 orientation_buffer_->seqlock.WriteEnd();
68 }
69
70 void SensorManager::StopFetchingDeviceOrientationData() {
71 base::AutoLock autolock(orientation_buffer_lock_);
72 if (!orientation_buffer_)
73 return;
74 // Null message to signify that sensora are no longer available.
timvolodine 2014/11/06 02:53:47 sensora -> sensors
jonross 2014/11/06 18:18:52 Done.
75 orientation_buffer_->seqlock.WriteBegin();
76 orientation_buffer_->data.allAvailableSensorsAreActive = false;
77 orientation_buffer_->seqlock.WriteEnd();
78 orientation_buffer_ = nullptr;
79 }
80
81 SensorManager::SensorManager() : orientation_buffer_(nullptr) {
82 }
83
84 SensorManager::~SensorManager() {
85 }
86
87 } // namespace content
OLDNEW
« content/public/browser/DEPS ('K') | « content/public/browser/sensor_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698