diff options
-rw-r--r-- | include/ui/Fence.h | 5 | ||||
-rw-r--r-- | libs/gui/BufferItemConsumer.cpp | 2 | ||||
-rw-r--r-- | libs/gui/CpuConsumer.cpp | 2 | ||||
-rw-r--r-- | libs/gui/GLConsumer.cpp | 2 | ||||
-rw-r--r-- | libs/gui/Surface.cpp | 4 | ||||
-rw-r--r-- | libs/ui/Fence.cpp | 3 | ||||
-rw-r--r-- | services/sensorservice/CorrectedGyroSensor.cpp | 2 | ||||
-rw-r--r-- | services/sensorservice/GravitySensor.cpp | 2 | ||||
-rw-r--r-- | services/sensorservice/LinearAccelerationSensor.cpp | 2 | ||||
-rw-r--r-- | services/sensorservice/OrientationSensor.cpp | 5 | ||||
-rw-r--r-- | services/sensorservice/RotationVectorSensor.cpp | 4 | ||||
-rw-r--r-- | services/sensorservice/SensorFusion.cpp | 20 | ||||
-rw-r--r-- | services/sensorservice/SensorService.cpp | 76 | ||||
-rw-r--r-- | services/sensorservice/SensorService.h | 4 | ||||
-rw-r--r-- | services/surfaceflinger/DisplayHardware/HWComposer.cpp | 2 |
15 files changed, 72 insertions, 63 deletions
diff --git a/include/ui/Fence.h b/include/ui/Fence.h index 81d5d09..60156e7 100644 --- a/include/ui/Fence.h +++ b/include/ui/Fence.h @@ -70,9 +70,10 @@ public: // waitForever is a convenience function for waiting forever for a fence to // signal (just like wait(TIMEOUT_NEVER)), but issuing an error to the // system log and fence state to the kernel log if the wait lasts longer - // than warningTimeout. The logname argument should be a string identifying + // than a warning timeout. + // The logname argument should be a string identifying // the caller and will be included in the log message. - status_t waitForever(unsigned int warningTimeout, const char* logname); + status_t waitForever(const char* logname); // merge combines two Fence objects, creating a new Fence object that // becomes signaled when both f1 and f2 are signaled (even if f1 or f2 is diff --git a/libs/gui/BufferItemConsumer.cpp b/libs/gui/BufferItemConsumer.cpp index 90619ab..7db1b84 100644 --- a/libs/gui/BufferItemConsumer.cpp +++ b/libs/gui/BufferItemConsumer.cpp @@ -63,7 +63,7 @@ status_t BufferItemConsumer::acquireBuffer(BufferItem *item, bool waitForFence) } if (waitForFence) { - err = item->mFence->waitForever(1000, "BufferItemConsumer::acquireBuffer"); + err = item->mFence->waitForever("BufferItemConsumer::acquireBuffer"); if (err != OK) { BI_LOGE("Failed to wait for fence of acquired buffer: %s (%d)", strerror(-err), err); diff --git a/libs/gui/CpuConsumer.cpp b/libs/gui/CpuConsumer.cpp index 91af78d..0543649 100644 --- a/libs/gui/CpuConsumer.cpp +++ b/libs/gui/CpuConsumer.cpp @@ -80,7 +80,7 @@ status_t CpuConsumer::lockNextBuffer(LockedBuffer *nativeBuffer) { int buf = b.mBuf; if (b.mFence.get()) { - err = b.mFence->waitForever(1000, "CpuConsumer::lockNextBuffer"); + err = b.mFence->waitForever("CpuConsumer::lockNextBuffer"); if (err != OK) { CC_LOGE("Failed to wait for fence of acquired buffer: %s (%d)", strerror(-err), err); diff --git a/libs/gui/GLConsumer.cpp b/libs/gui/GLConsumer.cpp index 7487612..344a93a 100644 --- a/libs/gui/GLConsumer.cpp +++ b/libs/gui/GLConsumer.cpp @@ -821,7 +821,7 @@ status_t GLConsumer::doGLFenceWaitLocked() const { return UNKNOWN_ERROR; } } else { - status_t err = mCurrentFence->waitForever(1000, + status_t err = mCurrentFence->waitForever( "GLConsumer::doGLFenceWaitLocked"); if (err != NO_ERROR) { ST_LOGE("doGLFenceWait: error waiting for fence: %d", err); diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 4a58023..a616c1e 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -113,7 +113,7 @@ int Surface::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window, int fenceFd = -1; int result = c->dequeueBuffer(&buf, &fenceFd); sp<Fence> fence(new Fence(fenceFd)); - int waitResult = fence->waitForever(1000, "dequeueBuffer_DEPRECATED"); + int waitResult = fence->waitForever("dequeueBuffer_DEPRECATED"); if (waitResult != OK) { ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an error: %d", waitResult); @@ -734,7 +734,7 @@ status_t Surface::lock( sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out)); sp<Fence> fence(new Fence(fenceFd)); - err = fence->waitForever(1000, "Surface::lock"); + err = fence->waitForever("Surface::lock"); if (err != OK) { ALOGE("Fence::wait failed (%s)", strerror(-err)); cancelBuffer(out, fenceFd); diff --git a/libs/ui/Fence.cpp b/libs/ui/Fence.cpp index b9e0f00..464ee86 100644 --- a/libs/ui/Fence.cpp +++ b/libs/ui/Fence.cpp @@ -54,11 +54,12 @@ status_t Fence::wait(unsigned int timeout) { return err < 0 ? -errno : status_t(NO_ERROR); } -status_t Fence::waitForever(unsigned int warningTimeout, const char* logname) { +status_t Fence::waitForever(const char* logname) { ATRACE_CALL(); if (mFenceFd == -1) { return NO_ERROR; } + unsigned int warningTimeout = 3000; int err = sync_wait(mFenceFd, warningTimeout); if (err < 0 && errno == ETIME) { ALOGE("%s: fence %d didn't signal in %u ms", logname, mFenceFd, diff --git a/services/sensorservice/CorrectedGyroSensor.cpp b/services/sensorservice/CorrectedGyroSensor.cpp index 1857443..09f60a9 100644 --- a/services/sensorservice/CorrectedGyroSensor.cpp +++ b/services/sensorservice/CorrectedGyroSensor.cpp @@ -69,7 +69,7 @@ status_t CorrectedGyroSensor::setDelay(void* ident, int handle, int64_t ns) { Sensor CorrectedGyroSensor::getSensor() const { sensor_t hwSensor; hwSensor.name = "Corrected Gyroscope Sensor"; - hwSensor.vendor = "Google Inc."; + hwSensor.vendor = "AOSP"; hwSensor.version = 1; hwSensor.handle = '_cgy'; hwSensor.type = SENSOR_TYPE_GYROSCOPE; diff --git a/services/sensorservice/GravitySensor.cpp b/services/sensorservice/GravitySensor.cpp index c57715f..0bf20db 100644 --- a/services/sensorservice/GravitySensor.cpp +++ b/services/sensorservice/GravitySensor.cpp @@ -77,7 +77,7 @@ status_t GravitySensor::setDelay(void* ident, int handle, int64_t ns) { Sensor GravitySensor::getSensor() const { sensor_t hwSensor; hwSensor.name = "Gravity Sensor"; - hwSensor.vendor = "Google Inc."; + hwSensor.vendor = "AOSP"; hwSensor.version = 3; hwSensor.handle = '_grv'; hwSensor.type = SENSOR_TYPE_GRAVITY; diff --git a/services/sensorservice/LinearAccelerationSensor.cpp b/services/sensorservice/LinearAccelerationSensor.cpp index f0054f2..25ae473 100644 --- a/services/sensorservice/LinearAccelerationSensor.cpp +++ b/services/sensorservice/LinearAccelerationSensor.cpp @@ -62,7 +62,7 @@ Sensor LinearAccelerationSensor::getSensor() const { Sensor gsensor(mGravitySensor.getSensor()); sensor_t hwSensor; hwSensor.name = "Linear Acceleration Sensor"; - hwSensor.vendor = "Google Inc."; + hwSensor.vendor = "AOSP"; hwSensor.version = gsensor.getVersion(); hwSensor.handle = '_lin'; hwSensor.type = SENSOR_TYPE_LINEAR_ACCELERATION; diff --git a/services/sensorservice/OrientationSensor.cpp b/services/sensorservice/OrientationSensor.cpp index 037adaa..b146332 100644 --- a/services/sensorservice/OrientationSensor.cpp +++ b/services/sensorservice/OrientationSensor.cpp @@ -33,6 +33,9 @@ OrientationSensor::OrientationSensor() : mSensorDevice(SensorDevice::getInstance()), mSensorFusion(SensorFusion::getInstance()) { + // FIXME: instead of using the SensorFusion code, we should use + // the SENSOR_TYPE_ROTATION_VECTOR instead. This way we could use the + // HAL's implementation. } bool OrientationSensor::process(sensors_event_t* outEvent, @@ -73,7 +76,7 @@ status_t OrientationSensor::setDelay(void* ident, int handle, int64_t ns) { Sensor OrientationSensor::getSensor() const { sensor_t hwSensor; hwSensor.name = "Orientation Sensor"; - hwSensor.vendor = "Google Inc."; + hwSensor.vendor = "AOSP"; hwSensor.version = 1; hwSensor.handle = '_ypr'; hwSensor.type = SENSOR_TYPE_ORIENTATION; diff --git a/services/sensorservice/RotationVectorSensor.cpp b/services/sensorservice/RotationVectorSensor.cpp index 5ea9568..725deb4 100644 --- a/services/sensorservice/RotationVectorSensor.cpp +++ b/services/sensorservice/RotationVectorSensor.cpp @@ -63,7 +63,7 @@ status_t RotationVectorSensor::setDelay(void* ident, int handle, int64_t ns) { Sensor RotationVectorSensor::getSensor() const { sensor_t hwSensor; hwSensor.name = "Rotation Vector Sensor"; - hwSensor.vendor = "Google Inc."; + hwSensor.vendor = "AOSP"; hwSensor.version = 3; hwSensor.handle = '_rov'; hwSensor.type = SENSOR_TYPE_ROTATION_VECTOR; @@ -112,7 +112,7 @@ status_t GyroDriftSensor::setDelay(void* ident, int handle, int64_t ns) { Sensor GyroDriftSensor::getSensor() const { sensor_t hwSensor; hwSensor.name = "Gyroscope Bias (debug)"; - hwSensor.vendor = "Google Inc."; + hwSensor.vendor = "AOSP"; hwSensor.version = 1; hwSensor.handle = '_gbs'; hwSensor.type = SENSOR_TYPE_ACCELEROMETER; diff --git a/services/sensorservice/SensorFusion.cpp b/services/sensorservice/SensorFusion.cpp index d23906d..4837b97 100644 --- a/services/sensorservice/SensorFusion.cpp +++ b/services/sensorservice/SensorFusion.cpp @@ -28,6 +28,7 @@ SensorFusion::SensorFusion() mEnabled(false), mGyroTime(0) { sensor_t const* list; + Sensor uncalibratedGyro; ssize_t count = mSensorDevice.getSensorList(&list); if (count > 0) { for (size_t i=0 ; i<size_t(count) ; i++) { @@ -39,18 +40,27 @@ SensorFusion::SensorFusion() } if (list[i].type == SENSOR_TYPE_GYROSCOPE) { mGyro = Sensor(list + i); - // 200 Hz for gyro events is a good compromise between precision - // and power/cpu usage. - mGyroRate = 200; - mTargetDelayNs = 1000000000LL/mGyroRate; } + if (list[i].type == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED) { + uncalibratedGyro = Sensor(list + i); + } + } + + // Use the uncalibrated gyroscope for sensor fusion when available + if (uncalibratedGyro.getType() == SENSOR_TYPE_GYROSCOPE_UNCALIBRATED) { + mGyro = uncalibratedGyro; } + + // 200 Hz for gyro events is a good compromise between precision + // and power/cpu usage. + mGyroRate = 200; + mTargetDelayNs = 1000000000LL/mGyroRate; mFusion.init(); } } void SensorFusion::process(const sensors_event_t& event) { - if (event.type == SENSOR_TYPE_GYROSCOPE) { + if (event.type == mGyro.getType()) { if (mGyroTime != 0) { const float dT = (event.timestamp - mGyroTime) / 1000000000.0f; const float freq = 1 / dT; diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp index ebf5cf0..4718447 100644 --- a/services/sensorservice/SensorService.cpp +++ b/services/sensorservice/SensorService.cpp @@ -93,6 +93,7 @@ void SensorService::onFirstRef() orientationIndex = i; break; case SENSOR_TYPE_GYROSCOPE: + case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED: hasGyro = true; break; case SENSOR_TYPE_GRAVITY: @@ -108,54 +109,44 @@ void SensorService::onFirstRef() // registered) const SensorFusion& fusion(SensorFusion::getInstance()); + // build the sensor list returned to users + mUserSensorList = mSensorList; + if (hasGyro) { - // Always instantiate Android's virtual sensors. Since they are - // instantiated behind sensors from the HAL, they won't - // interfere with applications, unless they looks specifically - // for them (by name). + Sensor aSensor; - registerVirtualSensor( new RotationVectorSensor() ); - registerVirtualSensor( new GravitySensor(list, count) ); - registerVirtualSensor( new LinearAccelerationSensor(list, count) ); + // Add Android virtual sensors if they're not already + // available in the HAL - // these are optional - registerVirtualSensor( new OrientationSensor() ); - registerVirtualSensor( new CorrectedGyroSensor(list, count) ); - } + aSensor = registerVirtualSensor( new RotationVectorSensor() ); + if (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR)) { + mUserSensorList.add(aSensor); + } - // build the sensor list returned to users - mUserSensorList = mSensorList; + aSensor = registerVirtualSensor( new GravitySensor(list, count) ); + if (virtualSensorsNeeds & (1<<SENSOR_TYPE_GRAVITY)) { + mUserSensorList.add(aSensor); + } - if (hasGyro) { - // virtual debugging sensors are not added to mUserSensorList - registerVirtualSensor( new GyroDriftSensor() ); - } + aSensor = registerVirtualSensor( new LinearAccelerationSensor(list, count) ); + if (virtualSensorsNeeds & (1<<SENSOR_TYPE_LINEAR_ACCELERATION)) { + mUserSensorList.add(aSensor); + } - if (hasGyro && - (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR))) { - // if we have the fancy sensor fusion, and it's not provided by the - // HAL, use our own (fused) orientation sensor by removing the - // HAL supplied one form the user list. - if (orientationIndex >= 0) { - mUserSensorList.removeItemsAt(orientationIndex); + aSensor = registerVirtualSensor( new OrientationSensor() ); + if (virtualSensorsNeeds & (1<<SENSOR_TYPE_ROTATION_VECTOR)) { + // if we are doing our own rotation-vector, also add + // the orientation sensor and remove the HAL provided one. + mUserSensorList.replaceAt(aSensor, orientationIndex); } + + // virtual debugging sensors are not added to mUserSensorList + registerVirtualSensor( new CorrectedGyroSensor(list, count) ); + registerVirtualSensor( new GyroDriftSensor() ); } // debugging sensor list - for (size_t i=0 ; i<mSensorList.size() ; i++) { - switch (mSensorList[i].getType()) { - case SENSOR_TYPE_GRAVITY: - case SENSOR_TYPE_LINEAR_ACCELERATION: - case SENSOR_TYPE_ROTATION_VECTOR: - if (strstr(mSensorList[i].getVendor().string(), "Google")) { - mUserSensorListDebug.add(mSensorList[i]); - } - break; - default: - mUserSensorListDebug.add(mSensorList[i]); - break; - } - } + mUserSensorListDebug = mSensorList; run("SensorService", PRIORITY_URGENT_DISPLAY); mInitCheck = NO_ERROR; @@ -163,7 +154,7 @@ void SensorService::onFirstRef() } } -void SensorService::registerSensor(SensorInterface* s) +Sensor SensorService::registerSensor(SensorInterface* s) { sensors_event_t event; memset(&event, 0, sizeof(event)); @@ -175,12 +166,15 @@ void SensorService::registerSensor(SensorInterface* s) mSensorMap.add(sensor.getHandle(), s); // create an entry in the mLastEventSeen array mLastEventSeen.add(sensor.getHandle(), event); + + return sensor; } -void SensorService::registerVirtualSensor(SensorInterface* s) +Sensor SensorService::registerVirtualSensor(SensorInterface* s) { - registerSensor(s); + Sensor sensor = registerSensor(s); mVirtualSensorList.add( s ); + return sensor; } SensorService::~SensorService() diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h index ff3b555..67489cc 100644 --- a/services/sensorservice/SensorService.h +++ b/services/sensorservice/SensorService.h @@ -114,8 +114,8 @@ class SensorService : int getSensorType(int handle) const; void recordLastValue(sensors_event_t const * buffer, size_t count); static void sortEventBuffer(sensors_event_t* buffer, size_t count); - void registerSensor(SensorInterface* sensor); - void registerVirtualSensor(SensorInterface* sensor); + Sensor registerSensor(SensorInterface* sensor); + Sensor registerVirtualSensor(SensorInterface* sensor); status_t cleanupWithoutDisable(const sp<SensorEventConnection>& connection, int handle); void cleanupAutoDisabledSensor(const sp<SensorEventConnection>& connection, diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 4e6dde5..5082192 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -747,7 +747,7 @@ int HWComposer::fbPost(int32_t id, if (mHwc && hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) { return setFramebufferTarget(id, acquireFence, buffer); } else { - acquireFence->waitForever(1000, "HWComposer::fbPost"); + acquireFence->waitForever("HWComposer::fbPost"); return mFbDev->post(mFbDev, buffer->handle); } } |