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

Side by Side Diff: device/generic_sensor/platform_sensor_android.cc

Issue 2395853003: [Sensors] Improvements in shared buffer managing (Closed)
Patch Set: Test compilation fix + comment from Ken Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/generic_sensor/platform_sensor_android.h" 5 #include "device/generic_sensor/platform_sensor_android.h"
6 6
7 #include "base/android/context_utils.h" 7 #include "base/android/context_utils.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/threading/thread_task_runner_handle.h"
10 #include "jni/PlatformSensor_jni.h" 9 #include "jni/PlatformSensor_jni.h"
11 10
12 using base::android::AttachCurrentThread; 11 using base::android::AttachCurrentThread;
13 using base::android::JavaRef; 12 using base::android::JavaRef;
14 13
15 namespace device { 14 namespace device {
16 15
17 // static 16 // static
18 bool PlatformSensorAndroid::RegisterJNI(JNIEnv* env) { 17 bool PlatformSensorAndroid::RegisterJNI(JNIEnv* env) {
19 return RegisterNativesImpl(env); 18 return RegisterNativesImpl(env);
20 } 19 }
21 20
22 PlatformSensorAndroid::PlatformSensorAndroid( 21 PlatformSensorAndroid::PlatformSensorAndroid(
23 mojom::SensorType type, 22 mojom::SensorType type,
24 mojo::ScopedSharedBufferMapping mapping, 23 mojo::ScopedSharedBufferMapping mapping,
25 uint64_t buffer_size,
26 PlatformSensorProvider* provider, 24 PlatformSensorProvider* provider,
27 const JavaRef<jobject>& java_sensor) 25 const JavaRef<jobject>& java_sensor)
28 : PlatformSensor(type, std::move(mapping), provider), 26 : PlatformSensor(type, std::move(mapping), provider) {
29 task_runner_(base::ThreadTaskRunnerHandle::Get()) {
30 JNIEnv* env = AttachCurrentThread(); 27 JNIEnv* env = AttachCurrentThread();
31 j_object_.Reset(java_sensor); 28 j_object_.Reset(java_sensor);
32 29
33 jobject byte_buffer = 30 Java_PlatformSensor_initPlatformSensorAndroid(env, j_object_.obj(),
34 env->NewDirectByteBuffer(shared_buffer_mapping_.get(), buffer_size); 31 reinterpret_cast<jlong>(this));
35 Java_PlatformSensor_initPlatformSensorAndroid(
36 env, j_object_.obj(), reinterpret_cast<jlong>(this), byte_buffer);
37 } 32 }
38 33
39 PlatformSensorAndroid::~PlatformSensorAndroid() { 34 PlatformSensorAndroid::~PlatformSensorAndroid() {
40 StopSensor(); 35 StopSensor();
41 } 36 }
42 37
43 mojom::ReportingMode PlatformSensorAndroid::GetReportingMode() { 38 mojom::ReportingMode PlatformSensorAndroid::GetReportingMode() {
44 JNIEnv* env = AttachCurrentThread(); 39 JNIEnv* env = AttachCurrentThread();
45 return static_cast<mojom::ReportingMode>( 40 return static_cast<mojom::ReportingMode>(
46 Java_PlatformSensor_getReportingMode(env, j_object_.obj())); 41 Java_PlatformSensor_getReportingMode(env, j_object_.obj()));
(...skipping 18 matching lines...) Expand all
65 Java_PlatformSensor_stopSensor(env, j_object_.obj()); 60 Java_PlatformSensor_stopSensor(env, j_object_.obj());
66 } 61 }
67 62
68 bool PlatformSensorAndroid::CheckSensorConfiguration( 63 bool PlatformSensorAndroid::CheckSensorConfiguration(
69 const PlatformSensorConfiguration& configuration) { 64 const PlatformSensorConfiguration& configuration) {
70 JNIEnv* env = AttachCurrentThread(); 65 JNIEnv* env = AttachCurrentThread();
71 return Java_PlatformSensor_checkSensorConfiguration( 66 return Java_PlatformSensor_checkSensorConfiguration(
72 env, j_object_.obj(), configuration.frequency()); 67 env, j_object_.obj(), configuration.frequency());
73 } 68 }
74 69
75 void PlatformSensorAndroid::NotifyPlatformSensorReadingChanged(
76 JNIEnv*,
77 const JavaRef<jobject>& caller) {
78 task_runner_->PostTask(
79 FROM_HERE,
80 base::Bind(&PlatformSensorAndroid::NotifySensorReadingChanged, this));
81 }
82
83 void PlatformSensorAndroid::NotifyPlatformSensorError( 70 void PlatformSensorAndroid::NotifyPlatformSensorError(
84 JNIEnv*, 71 JNIEnv*,
85 const JavaRef<jobject>& caller) { 72 const JavaRef<jobject>& caller) {
86 task_runner_->PostTask( 73 task_runner_->PostTask(
87 FROM_HERE, base::Bind(&PlatformSensorAndroid::NotifySensorError, this)); 74 FROM_HERE, base::Bind(&PlatformSensorAndroid::NotifySensorError, this));
88 } 75 }
89 76
77 void PlatformSensorAndroid::UpdatePlatformSensorReading(
78 JNIEnv*,
79 const base::android::JavaRef<jobject>& caller,
80 jdouble timestamp,
81 jdouble value1,
82 jdouble value2,
83 jdouble value3) {
84 SensorReading reading;
85 reading.timestamp = timestamp;
86 reading.values[0] = value1;
87 reading.values[1] = value2;
88 reading.values[2] = value3;
89
90 bool needNotify = (GetReportingMode() == mojom::ReportingMode::ON_CHANGE);
91 UpdateSensorReading(reading, needNotify);
92 }
93
90 } // namespace device 94 } // namespace device
OLDNEW
« no previous file with comments | « device/generic_sensor/platform_sensor_android.h ('k') | device/generic_sensor/platform_sensor_provider_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698