| Index: content/browser/device_orientation/data_fetcher_impl_android.cc
|
| diff --git a/content/browser/device_orientation/data_fetcher_impl_android.cc b/content/browser/device_orientation/data_fetcher_impl_android.cc
|
| index c7a066f221fd6f99c497d4841fcf4758813af58e..fe9883363ebc12ef9d61536cbdacb0895f4da284 100644
|
| --- a/content/browser/device_orientation/data_fetcher_impl_android.cc
|
| +++ b/content/browser/device_orientation/data_fetcher_impl_android.cc
|
| @@ -7,6 +7,7 @@
|
| #include "base/android/jni_android.h"
|
| #include "base/logging.h"
|
| #include "content/browser/device_orientation/orientation.h"
|
| +#include "content/common/device_motion_hardware_buffer.h"
|
| #include "jni/DeviceMotionAndOrientation_jni.h"
|
|
|
| using base::android::AttachCurrentThread;
|
| @@ -21,7 +22,9 @@ const int kPeriodInMilliseconds = 100;
|
|
|
| } // namespace
|
|
|
| -DataFetcherImplAndroid::DataFetcherImplAndroid() {
|
| +DataFetcherImplAndroid::DataFetcherImplAndroid()
|
| + : device_motion_buffer_(0),
|
| + is_buffer_ready_(false) {
|
| device_orientation_.Reset(
|
| Java_DeviceMotionAndOrientation_getInstance(AttachCurrentThread()));
|
| }
|
| @@ -80,35 +83,121 @@ void DataFetcherImplAndroid::GotOrientation(
|
| next_orientation_ = orientation;
|
| }
|
|
|
| +bool DataFetcherImplAndroid::Start(
|
| + DeviceData::Type event_type, int rate_in_milliseconds) {
|
| + DCHECK(!device_orientation_.is_null());
|
| + return Java_DeviceMotionAndOrientation_start(
|
| + AttachCurrentThread(), device_orientation_.obj(),
|
| + reinterpret_cast<jint>(this), static_cast<jint>(event_type),
|
| + rate_in_milliseconds);
|
| +}
|
| +
|
| +void DataFetcherImplAndroid::Stop(DeviceData::Type event_type) {
|
| + DCHECK(!device_orientation_.is_null());
|
| + Java_DeviceMotionAndOrientation_stop(
|
| + AttachCurrentThread(), device_orientation_.obj(),
|
| + static_cast<jint>(event_type));
|
| +}
|
| +
|
| +// ----- New shared memory API methods
|
| +
|
| void DataFetcherImplAndroid::GotAcceleration(
|
| JNIEnv*, jobject, double x, double y, double z) {
|
| - NOTIMPLEMENTED();
|
| + device_motion_buffer_->sequence.WriteBegin();
|
| + device_motion_buffer_->buffer.accelerationX = x;
|
| + device_motion_buffer_->buffer.hasAccelerationX = true;
|
| + device_motion_buffer_->buffer.accelerationY = y;
|
| + device_motion_buffer_->buffer.hasAccelerationY = true;
|
| + device_motion_buffer_->buffer.accelerationZ = z;
|
| + device_motion_buffer_->buffer.hasAccelerationZ = true;
|
| + device_motion_buffer_->sequence.WriteEnd();
|
| + LOG(INFO) << "ACTIVE GotAcceleration" << x << "," << y << "," << z;
|
| +
|
| + if (!is_buffer_ready_) {
|
| + receivedMotionData[0] = 1;
|
| + CheckBufferReadyToRead();
|
| + }
|
| }
|
|
|
| void DataFetcherImplAndroid::GotAccelerationIncludingGravity(
|
| JNIEnv*, jobject, double x, double y, double z) {
|
| - NOTIMPLEMENTED();
|
| + device_motion_buffer_->sequence.WriteBegin();
|
| + device_motion_buffer_->buffer.accelerationIncludingGravityX = x;
|
| + device_motion_buffer_->buffer.hasAccelerationIncludingGravityX = true;
|
| + device_motion_buffer_->buffer.accelerationIncludingGravityY = y;
|
| + device_motion_buffer_->buffer.hasAccelerationIncludingGravityY = true;
|
| + device_motion_buffer_->buffer.accelerationIncludingGravityZ = z;
|
| + device_motion_buffer_->buffer.hasAccelerationIncludingGravityZ = true;
|
| + device_motion_buffer_->sequence.WriteEnd();
|
| +
|
| + if (!is_buffer_ready_) {
|
| + receivedMotionData[1] = 1;
|
| + CheckBufferReadyToRead();
|
| + }
|
| }
|
|
|
| void DataFetcherImplAndroid::GotRotationRate(
|
| JNIEnv*, jobject, double alpha, double beta, double gamma) {
|
| - NOTIMPLEMENTED();
|
| + device_motion_buffer_->sequence.WriteBegin();
|
| + device_motion_buffer_->buffer.rotationRateAlpha = alpha;
|
| + device_motion_buffer_->buffer.hasRotationRateAlpha = true;
|
| + device_motion_buffer_->buffer.rotationRateBeta = beta;
|
| + device_motion_buffer_->buffer.hasRotationRateBeta = true;
|
| + device_motion_buffer_->buffer.rotationRateGamma = gamma;
|
| + device_motion_buffer_->buffer.hasRotationRateGamma = true;
|
| + device_motion_buffer_->sequence.WriteEnd();
|
| +
|
| + if (!is_buffer_ready_) {
|
| + receivedMotionData[2] = 1;
|
| + CheckBufferReadyToRead();
|
| + }
|
| }
|
|
|
| -bool DataFetcherImplAndroid::Start(
|
| - DeviceData::Type event_type, int rate_in_milliseconds) {
|
| +int DataFetcherImplAndroid::GetNumberActiveDeviceMotionSensors() {
|
| DCHECK(!device_orientation_.is_null());
|
| - return Java_DeviceMotionAndOrientation_start(
|
| - AttachCurrentThread(), device_orientation_.obj(),
|
| - reinterpret_cast<jint>(this), static_cast<jint>(event_type),
|
| - rate_in_milliseconds);
|
| + return Java_DeviceMotionAndOrientation_getNumberActiveDeviceMotionSensors(
|
| + AttachCurrentThread(), device_orientation_.obj());
|
| }
|
|
|
| -void DataFetcherImplAndroid::Stop(DeviceData::Type event_type) {
|
| - DCHECK(!device_orientation_.is_null());
|
| - Java_DeviceMotionAndOrientation_stop(
|
| - AttachCurrentThread(), device_orientation_.obj(),
|
| - static_cast<jint>(event_type));
|
| +bool DataFetcherImplAndroid::FetchDeviceMotionDataIntoBuffer() {
|
| + // This method should not be called because it is a push based fetcher.
|
| + DCHECK(needsPolling());
|
| + return false;
|
| +}
|
| +
|
| +void DataFetcherImplAndroid::CheckBufferReadyToRead() {
|
| + if (receivedMotionData[0] + receivedMotionData[1] + receivedMotionData[2] ==
|
| + number_active_device_motion_sensors_) {
|
| + device_motion_buffer_->sequence.WriteBegin();
|
| + device_motion_buffer_->is_ready_for_read = true;
|
| + device_motion_buffer_->sequence.WriteEnd();
|
| + is_buffer_ready_ = true;
|
| + LOG(INFO)<<"ACTIVE BUFFER READY TO READ";
|
| + }
|
| +}
|
| +
|
| +bool DataFetcherImplAndroid::StartFetchingDeviceMotionData(
|
| + DeviceMotionHardwareBuffer* buffer) {
|
| + device_motion_buffer_ = buffer;
|
| + receivedMotionData[0] = receivedMotionData[1] = receivedMotionData[2] = 0;
|
| + number_active_device_motion_sensors_ = 0;
|
| + is_buffer_ready_ = false;
|
| + bool success = Start(DeviceData::kTypeMotion, kPeriodInMilliseconds);
|
| +
|
| + // If no motion data can ever be provided, the number of active device motion
|
| + // sensors will be zero. In that case flag the shared memory buffer
|
| + // as ready to read, as it will not change anyway.
|
| + number_active_device_motion_sensors_ = GetNumberActiveDeviceMotionSensors();
|
| + LOG(INFO)<< "ACTIVE SENSORS :"<<number_active_device_motion_sensors_;
|
| + CheckBufferReadyToRead();
|
| + return success;
|
| +}
|
| +
|
| +void DataFetcherImplAndroid::StopFetchingDeviceMotionData() {
|
| + Stop(DeviceData::kTypeMotion);
|
| + number_active_device_motion_sensors_ = 0;
|
| + receivedMotionData[0] = receivedMotionData[1] = receivedMotionData[2] = 0;
|
| + is_buffer_ready_ = false;
|
| }
|
|
|
| } // namespace content
|
|
|