| 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 069454db1d7faafc243b2bf02287c1148eab600d..453724fb7a7550ae9a23e524e0f26050713bc91d 100644
|
| --- a/content/browser/device_orientation/data_fetcher_impl_android.cc
|
| +++ b/content/browser/device_orientation/data_fetcher_impl_android.cc
|
| @@ -21,7 +21,10 @@ const int kPeriodInMilliseconds = 100;
|
|
|
| } // namespace
|
|
|
| -DataFetcherImplAndroid::DataFetcherImplAndroid() {
|
| +
|
| +DataFetcherImplAndroid::DataFetcherImplAndroid()
|
| + : device_motion_buffer_(0),
|
| + is_buffer_ready_(false) {
|
| device_orientation_.Reset(
|
| Java_DeviceMotionAndOrientation_getInstance(AttachCurrentThread()));
|
| }
|
| @@ -31,14 +34,19 @@ void DataFetcherImplAndroid::Init(JNIEnv* env) {
|
| DCHECK(result);
|
| }
|
|
|
| -// TODO(timvolodine): Modify this method to be able to distinguish
|
| -// device motion from orientation.
|
| +DataFetcherImplAndroid* DataFetcherImplAndroid::instance() {
|
| + CR_DEFINE_STATIC_LOCAL(DataFetcherImplAndroid, s_data_fetcher, ());
|
| + return &s_data_fetcher;
|
| +}
|
| +
|
| +// TODO(timvolodine): Remove this method once orientation switches to shared
|
| +// memory implementation..
|
| DataFetcher* DataFetcherImplAndroid::Create() {
|
| - scoped_ptr<DataFetcherImplAndroid> fetcher(new DataFetcherImplAndroid);
|
| + DataFetcherImplAndroid* fetcher = DataFetcherImplAndroid::instance();
|
| if (fetcher->Start(DeviceData::kTypeOrientation, kPeriodInMilliseconds))
|
| - return fetcher.release();
|
| + return fetcher;
|
|
|
| - LOG(ERROR) << "DataFetcherImplAndroid::Start failed!";
|
| + DVLOG(2) << "DataFetcherImplAndroid::Start failed!";
|
| return NULL;
|
| }
|
|
|
| @@ -46,6 +54,7 @@ DataFetcherImplAndroid::~DataFetcherImplAndroid() {
|
| // TODO(timvolodine): Support device motion as well. Only stop
|
| // the active event type(s).
|
| Stop(DeviceData::kTypeOrientation);
|
| + Stop(DeviceData::kTypeMotion);
|
| }
|
|
|
| const DeviceData* DataFetcherImplAndroid::GetDeviceData(
|
| @@ -80,21 +89,6 @@ void DataFetcherImplAndroid::GotOrientation(
|
| next_orientation_ = orientation;
|
| }
|
|
|
| -void DataFetcherImplAndroid::GotAcceleration(
|
| - JNIEnv*, jobject, double x, double y, double z) {
|
| - NOTIMPLEMENTED();
|
| -}
|
| -
|
| -void DataFetcherImplAndroid::GotAccelerationIncludingGravity(
|
| - JNIEnv*, jobject, double x, double y, double z) {
|
| - NOTIMPLEMENTED();
|
| -}
|
| -
|
| -void DataFetcherImplAndroid::GotRotationRate(
|
| - JNIEnv*, jobject, double alpha, double beta, double gamma) {
|
| - NOTIMPLEMENTED();
|
| -}
|
| -
|
| bool DataFetcherImplAndroid::Start(
|
| DeviceData::Type event_type, int rate_in_milliseconds) {
|
| DCHECK(!device_orientation_.is_null());
|
| @@ -111,10 +105,102 @@ void DataFetcherImplAndroid::Stop(DeviceData::Type event_type) {
|
| static_cast<jint>(event_type));
|
| }
|
|
|
| +// ----- New shared memory API methods
|
| +
|
| +void DataFetcherImplAndroid::GotAcceleration(
|
| + JNIEnv*, jobject, double x, double y, double z) {
|
| + 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();
|
| +
|
| + if (!is_buffer_ready_) {
|
| + receivedMotionData[0] = 1;
|
| + CheckBufferReadyToRead();
|
| + }
|
| +}
|
| +
|
| +void DataFetcherImplAndroid::GotAccelerationIncludingGravity(
|
| + JNIEnv*, jobject, double x, double y, double z) {
|
| + 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) {
|
| + 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();
|
| + }
|
| +}
|
| +
|
| int DataFetcherImplAndroid::GetNumberActiveDeviceMotionSensors() {
|
| DCHECK(!device_orientation_.is_null());
|
| return Java_DeviceMotionAndOrientation_getNumberActiveDeviceMotionSensors(
|
| AttachCurrentThread(), device_orientation_.obj());
|
| }
|
|
|
| +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;
|
| + }
|
| +}
|
| +
|
| +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();
|
| + 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
|
|
|