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

Unified Diff: content/browser/device_orientation/data_fetcher_impl_android.cc

Issue 18572014: Implement Android shared memory data fetcher for Device Motion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@renderer-sync-12June-tryASYNC-2-bis-tryRebase-6
Patch Set: added OWNERS file Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
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..8e1c47bd7b2c008713fbe5ed2585aba7e68be75c 100644
--- a/content/browser/device_orientation/data_fetcher_impl_android.cc
+++ b/content/browser/device_orientation/data_fetcher_impl_android.cc
@@ -21,7 +21,9 @@ const int kPeriodInMilliseconds = 100;
} // namespace
-DataFetcherImplAndroid::DataFetcherImplAndroid() {
+DataFetcherImplAndroid::DataFetcherImplAndroid()
+ : device_motion_buffer_(0),
bulach 2013/07/04 08:23:36 nit: s/0/NULL/
timvolodine 2013/07/04 12:02:52 Done.
+ is_buffer_ready_(false) {
device_orientation_.Reset(
Java_DeviceMotionAndOrientation_getInstance(AttachCurrentThread()));
}
@@ -31,14 +33,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 also 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 +53,7 @@ DataFetcherImplAndroid::~DataFetcherImplAndroid() {
// TODO(timvolodine): Support device motion as well. Only stop
// the active event type(s).
bulach 2013/07/04 08:23:36 the first part of the TODO seem done :)
timvolodine 2013/07/04 12:02:52 Done.
Stop(DeviceData::kTypeOrientation);
+ Stop(DeviceData::kTypeMotion);
}
const DeviceData* DataFetcherImplAndroid::GetDeviceData(
@@ -82,17 +90,53 @@ void DataFetcherImplAndroid::GotOrientation(
void DataFetcherImplAndroid::GotAcceleration(
JNIEnv*, jobject, double x, double y, double z) {
- NOTIMPLEMENTED();
+ device_motion_buffer_->seqlock.WriteBegin();
+ device_motion_buffer_->data.accelerationX = x;
+ device_motion_buffer_->data.hasAccelerationX = true;
+ device_motion_buffer_->data.accelerationY = y;
+ device_motion_buffer_->data.hasAccelerationY = true;
+ device_motion_buffer_->data.accelerationZ = z;
+ device_motion_buffer_->data.hasAccelerationZ = true;
+ device_motion_buffer_->seqlock.WriteEnd();
+
+ if (!is_buffer_ready_) {
+ receivedMotionData[0] = 1;
+ CheckBufferReadyToRead();
+ }
}
void DataFetcherImplAndroid::GotAccelerationIncludingGravity(
JNIEnv*, jobject, double x, double y, double z) {
- NOTIMPLEMENTED();
+ device_motion_buffer_->seqlock.WriteBegin();
+ device_motion_buffer_->data.accelerationIncludingGravityX = x;
+ device_motion_buffer_->data.hasAccelerationIncludingGravityX = true;
+ device_motion_buffer_->data.accelerationIncludingGravityY = y;
+ device_motion_buffer_->data.hasAccelerationIncludingGravityY = true;
+ device_motion_buffer_->data.accelerationIncludingGravityZ = z;
+ device_motion_buffer_->data.hasAccelerationIncludingGravityZ = true;
+ device_motion_buffer_->seqlock.WriteEnd();
+
+ if (!is_buffer_ready_) {
+ receivedMotionData[1] = 1;
+ CheckBufferReadyToRead();
+ }
}
void DataFetcherImplAndroid::GotRotationRate(
JNIEnv*, jobject, double alpha, double beta, double gamma) {
- NOTIMPLEMENTED();
+ device_motion_buffer_->seqlock.WriteBegin();
+ device_motion_buffer_->data.rotationRateAlpha = alpha;
+ device_motion_buffer_->data.hasRotationRateAlpha = true;
+ device_motion_buffer_->data.rotationRateBeta = beta;
+ device_motion_buffer_->data.hasRotationRateBeta = true;
+ device_motion_buffer_->data.rotationRateGamma = gamma;
+ device_motion_buffer_->data.hasRotationRateGamma = true;
+ device_motion_buffer_->seqlock.WriteEnd();
+
+ if (!is_buffer_ready_) {
+ receivedMotionData[2] = 1;
+ CheckBufferReadyToRead();
+ }
}
bool DataFetcherImplAndroid::Start(
@@ -117,4 +161,46 @@ int DataFetcherImplAndroid::GetNumberActiveDeviceMotionSensors() {
AttachCurrentThread(), device_orientation_.obj());
}
+
+// ----- New shared memory API methods
+
+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_->seqlock.WriteBegin();
+ device_motion_buffer_->data.allAvailableSensorsAreActive = true;
bulach 2013/07/04 08:23:36 just checking: once it has all three datatypes, th
timvolodine 2013/07/04 12:02:52 This flag is actually intended for the cases where
+ device_motion_buffer_->seqlock.WriteEnd();
+ is_buffer_ready_ = true;
+ }
+}
+
+bool DataFetcherImplAndroid::StartFetchingDeviceMotionData(
+ DeviceMotionHardwareBuffer* buffer) {
+ device_motion_buffer_ = buffer;
+ receivedMotionData[0] = receivedMotionData[1] = receivedMotionData[2] = 0;
bulach 2013/07/04 08:23:36 nit: memset(received_motion_data, 0, sizeof(receiv
timvolodine 2013/07/04 12:02:52 Done.
+ 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;
bulach 2013/07/04 08:23:36 nit: memset
timvolodine 2013/07/04 12:02:52 Done.
+ is_buffer_ready_ = false;
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698