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 #ifndef CHROME_BROWSER_DEVICE_ORIENTATION_SENSOR_MANAGER_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_DEVICE_ORIENTATION_SENSOR_MANAGER_ANDROID_H_ |
6 #define CHROME_BROWSER_DEVICE_ORIENTATION_SENSOR_MANAGER_ANDROID_H_ | 6 #define CONTENT_BROWSER_DEVICE_ORIENTATION_SENSOR_MANAGER_ANDROID_H_ |
7 | 7 |
8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "content/common/device_light/device_light_hardware_buffer.h" |
12 #include "content/common/device_orientation/device_motion_hardware_buffer.h" | 13 #include "content/common/device_orientation/device_motion_hardware_buffer.h" |
13 #include "content/common/device_orientation/device_orientation_hardware_buffer.h
" | 14 #include "content/common/device_orientation/device_orientation_hardware_buffer.h
" |
14 | 15 |
15 template<typename T> struct DefaultSingletonTraits; | 16 template<typename T> struct DefaultSingletonTraits; |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 // Android implementation of Device Orientation API. | 20 // Android implementation of Device Orientation API. |
20 // | 21 // |
21 // Android's SensorManager has a push API, so when Got*() methods are called | 22 // Android's SensorManager has a push API, so when Got*() methods are called |
22 // by the system the browser process puts the received data into a shared | 23 // by the system the browser process puts the received data into a shared |
23 // memory buffer, which is read by the renderer processes. | 24 // memory buffer, which is read by the renderer processes. |
24 class CONTENT_EXPORT SensorManagerAndroid { | 25 class CONTENT_EXPORT SensorManagerAndroid { |
25 public: | 26 public: |
26 // Must be called at startup, before GetInstance(). | 27 // Must be called at startup, before GetInstance(). |
27 static bool Register(JNIEnv* env); | 28 static bool Register(JNIEnv* env); |
28 | 29 |
29 // Needs to be thread-safe, because accessed from different threads. | 30 // Needs to be thread-safe, because accessed from different threads. |
30 static SensorManagerAndroid* GetInstance(); | 31 static SensorManagerAndroid* GetInstance(); |
31 | 32 |
32 // Called from Java via JNI. | 33 // Called from Java via JNI. |
| 34 void GotLight(JNIEnv*, jobject, |
| 35 double value); |
33 void GotOrientation(JNIEnv*, jobject, | 36 void GotOrientation(JNIEnv*, jobject, |
34 double alpha, double beta, double gamma); | 37 double alpha, double beta, double gamma); |
35 void GotAcceleration(JNIEnv*, jobject, | 38 void GotAcceleration(JNIEnv*, jobject, |
36 double x, double y, double z); | 39 double x, double y, double z); |
37 void GotAccelerationIncludingGravity(JNIEnv*, jobject, | 40 void GotAccelerationIncludingGravity(JNIEnv*, jobject, |
38 double x, double y, double z); | 41 double x, double y, double z); |
39 void GotRotationRate(JNIEnv*, jobject, | 42 void GotRotationRate(JNIEnv*, jobject, |
40 double alpha, double beta, double gamma); | 43 double alpha, double beta, double gamma); |
41 | 44 |
42 // Shared memory related methods. | 45 // Shared memory related methods. |
| 46 bool StartFetchingDeviceLightData(DeviceLightHardwareBuffer* buffer); |
| 47 void StopFetchingDeviceLightData(); |
| 48 |
43 bool StartFetchingDeviceMotionData(DeviceMotionHardwareBuffer* buffer); | 49 bool StartFetchingDeviceMotionData(DeviceMotionHardwareBuffer* buffer); |
44 void StopFetchingDeviceMotionData(); | 50 void StopFetchingDeviceMotionData(); |
45 | 51 |
46 bool StartFetchingDeviceOrientationData( | 52 bool StartFetchingDeviceOrientationData( |
47 DeviceOrientationHardwareBuffer* buffer); | 53 DeviceOrientationHardwareBuffer* buffer); |
48 void StopFetchingDeviceOrientationData(); | 54 void StopFetchingDeviceOrientationData(); |
49 | 55 |
50 protected: | 56 protected: |
51 enum EventType { | 57 enum EventType { |
52 // These constants should match DEVICE_ORIENTATION and DEVICE_MOTION | 58 // These constants should match DEVICE_ORIENTATION, DEVICE_MOTION and |
53 // constants in content/public/android/java/src/org/chromium/content/ | 59 // DEVICE_LIGHT constants in content/public/android/java/src/org/chromium/ |
54 // browser/DeviceMotionAndOrientation.java | 60 // content/browser/DeviceMotionAndOrientation.java |
55 kTypeOrientation = 0, | 61 kTypeOrientation = 0, |
56 kTypeMotion = 1 | 62 kTypeMotion = 1, |
| 63 kTypeLight = 2 |
57 }; | 64 }; |
58 | 65 |
59 SensorManagerAndroid(); | 66 SensorManagerAndroid(); |
60 virtual ~SensorManagerAndroid(); | 67 virtual ~SensorManagerAndroid(); |
61 | 68 |
62 virtual bool Start(EventType event_type); | 69 virtual bool Start(EventType event_type); |
63 virtual void Stop(EventType event_type); | 70 virtual void Stop(EventType event_type); |
64 virtual int GetNumberActiveDeviceMotionSensors(); | 71 virtual int GetNumberActiveDeviceMotionSensors(); |
65 | 72 |
66 private: | 73 private: |
67 friend struct DefaultSingletonTraits<SensorManagerAndroid>; | 74 friend struct DefaultSingletonTraits<SensorManagerAndroid>; |
68 | 75 |
69 enum { | 76 enum { |
70 RECEIVED_MOTION_DATA_ACCELERATION = 0, | 77 RECEIVED_MOTION_DATA_ACCELERATION = 0, |
71 RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY = 1, | 78 RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY = 1, |
72 RECEIVED_MOTION_DATA_ROTATION_RATE = 2, | 79 RECEIVED_MOTION_DATA_ROTATION_RATE = 2, |
73 RECEIVED_MOTION_DATA_MAX = 3, | 80 RECEIVED_MOTION_DATA_MAX = 3, |
74 }; | 81 }; |
75 | 82 |
76 void CheckMotionBufferReadyToRead(); | 83 void CheckMotionBufferReadyToRead(); |
77 void SetMotionBufferReadyStatus(bool ready); | 84 void SetMotionBufferReadyStatus(bool ready); |
78 void ClearInternalMotionBuffers(); | 85 void ClearInternalMotionBuffers(); |
79 | 86 |
| 87 void SetLightBufferReadyStatus(bool ready); |
| 88 void ClearInternalLightBuffers(); |
| 89 |
80 void SetOrientationBufferReadyStatus(bool ready); | 90 void SetOrientationBufferReadyStatus(bool ready); |
81 | 91 |
82 // The Java provider of orientation info. | 92 // The Java provider of orientation info. |
83 base::android::ScopedJavaGlobalRef<jobject> device_orientation_; | 93 base::android::ScopedJavaGlobalRef<jobject> device_orientation_; |
84 int number_active_device_motion_sensors_; | 94 int number_active_device_motion_sensors_; |
85 int received_motion_data_[RECEIVED_MOTION_DATA_MAX]; | 95 int received_motion_data_[RECEIVED_MOTION_DATA_MAX]; |
| 96 DeviceLightHardwareBuffer* device_light_buffer_; |
86 DeviceMotionHardwareBuffer* device_motion_buffer_; | 97 DeviceMotionHardwareBuffer* device_motion_buffer_; |
87 DeviceOrientationHardwareBuffer* device_orientation_buffer_; | 98 DeviceOrientationHardwareBuffer* device_orientation_buffer_; |
| 99 bool is_light_buffer_ready_; |
88 bool is_motion_buffer_ready_; | 100 bool is_motion_buffer_ready_; |
89 bool is_orientation_buffer_ready_; | 101 bool is_orientation_buffer_ready_; |
90 | 102 |
| 103 base::Lock light_buffer_lock_; |
91 base::Lock motion_buffer_lock_; | 104 base::Lock motion_buffer_lock_; |
92 base::Lock orientation_buffer_lock_; | 105 base::Lock orientation_buffer_lock_; |
93 | 106 |
94 DISALLOW_COPY_AND_ASSIGN(SensorManagerAndroid); | 107 DISALLOW_COPY_AND_ASSIGN(SensorManagerAndroid); |
95 }; | 108 }; |
96 | 109 |
97 } // namespace content | 110 } // namespace content |
98 | 111 |
99 #endif // CHROME_BROWSER_DEVICE_ORIENTATION_SENSOR_MANAGER_ANDROID_H_ | 112 #endif // CONTENT_BROWSER_DEVICE_ORIENTATION_SENSOR_MANAGER_ANDROID_H_ |
OLD | NEW |