diff options
| -rw-r--r-- | libs/gui/Surface.cpp | 15 | ||||
| -rw-r--r-- | libs/gui/include/gui/Surface.h | 8 | ||||
| -rw-r--r-- | services/inputflinger/reader/include/TouchVideoDevice.h | 2 | ||||
| -rw-r--r-- | services/sensorservice/SensorEventConnection.cpp | 28 | ||||
| -rw-r--r-- | services/sensorservice/SensorEventConnection.h | 5 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 3 |
6 files changed, 47 insertions, 14 deletions
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index c3323fefb2..d6f9e635f3 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -732,6 +732,8 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { mSharedBufferHasBeenQueued = false; } + mDequeuedSlots.insert(buf); + return OK; } @@ -760,6 +762,8 @@ int Surface::cancelBuffer(android_native_buffer_t* buffer, mSharedBufferHasBeenQueued = true; } + mDequeuedSlots.erase(i); + return OK; } @@ -895,6 +899,8 @@ int Surface::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err); } + mDequeuedSlots.erase(i); + if (mEnableFrameTimestamps) { mFrameEventHistory->applyDelta(output.frameTimestamps); // Update timestamps with the local acquire fence. @@ -1660,6 +1666,7 @@ int Surface::attachBuffer(ANativeWindowBuffer* buffer) mRemovedBuffers.push_back(mSlots[attachedSlot].buffer); } mSlots[attachedSlot].buffer = graphicBuffer; + mDequeuedSlots.insert(attachedSlot); return NO_ERROR; } @@ -1926,6 +1933,10 @@ Dataspace Surface::getBuffersDataSpace() { } void Surface::freeAllBuffers() { + if (!mDequeuedSlots.empty()) { + ALOGE("%s: %zu buffers were freed while being dequeued!", + __FUNCTION__, mDequeuedSlots.size()); + } for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { mSlots[i].buffer = nullptr; } @@ -1947,6 +1958,10 @@ status_t Surface::getAndFlushBuffersFromSlots(const std::vector<int32_t>& slots, ALOGW("%s: Discarded slot %d doesn't contain buffer!", __FUNCTION__, i); continue; } + // Don't flush currently dequeued buffers + if (mDequeuedSlots.count(i) > 0) { + continue; + } outBuffers->push_back(mSlots[i].buffer); mSlots[i].buffer = nullptr; } diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h index 49c83da319..55b4101908 100644 --- a/libs/gui/include/gui/Surface.h +++ b/libs/gui/include/gui/Surface.h @@ -30,6 +30,7 @@ #include <utils/RefBase.h> #include <shared_mutex> +#include <unordered_set> namespace android { @@ -543,8 +544,15 @@ protected: int mMaxBufferCount; sp<IProducerListener> mListenerProxy; + + // Get and flush the buffers of given slots, if the buffer in the slot + // is currently dequeued then it won't be flushed and won't be returned + // in outBuffers. status_t getAndFlushBuffersFromSlots(const std::vector<int32_t>& slots, std::vector<sp<GraphicBuffer>>* outBuffers); + + // Buffers that are successfully dequeued/attached and handed to clients + std::unordered_set<int> mDequeuedSlots; }; } // namespace android diff --git a/services/inputflinger/reader/include/TouchVideoDevice.h b/services/inputflinger/reader/include/TouchVideoDevice.h index 5a32443f29..7de9b830b2 100644 --- a/services/inputflinger/reader/include/TouchVideoDevice.h +++ b/services/inputflinger/reader/include/TouchVideoDevice.h @@ -102,7 +102,7 @@ private: * How many buffers to keep for the internal queue. When the internal buffer * exceeds this capacity, oldest frames will be dropped. */ - static constexpr size_t MAX_QUEUE_SIZE = 10; + static constexpr size_t MAX_QUEUE_SIZE = 20; std::vector<TouchVideoFrame> mFrames; /** diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp index b4b5f98609..6c8671289d 100644 --- a/services/sensorservice/SensorEventConnection.cpp +++ b/services/sensorservice/SensorEventConnection.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include <log/log.h> #include <sys/socket.h> #include <utils/threads.h> @@ -47,20 +48,13 @@ SensorService::SensorEventConnection::SensorEventConnection( SensorService::SensorEventConnection::~SensorEventConnection() { ALOGD_IF(DEBUG_CONNECTIONS, "~SensorEventConnection(%p)", this); destroy(); -} - -void SensorService::SensorEventConnection::destroy() { - Mutex::Autolock _l(mDestroyLock); - - // destroy once only - if (mDestroyed) { - return; - } - mService->cleanupConnection(this); if (mEventCache != nullptr) { delete[] mEventCache; } +} + +void SensorService::SensorEventConnection::destroy() { mDestroyed = true; } @@ -665,6 +659,11 @@ status_t SensorService::SensorEventConnection::enableDisable( int handle, bool enabled, nsecs_t samplingPeriodNs, nsecs_t maxBatchReportLatencyNs, int reservedFlags) { + if (mDestroyed) { + android_errorWriteLog(0x534e4554, "168211968"); + return DEAD_OBJECT; + } + status_t err; if (enabled) { err = mService->enable(this, handle, samplingPeriodNs, maxBatchReportLatencyNs, @@ -679,10 +678,19 @@ status_t SensorService::SensorEventConnection::enableDisable( status_t SensorService::SensorEventConnection::setEventRate( int handle, nsecs_t samplingPeriodNs) { + if (mDestroyed) { + android_errorWriteLog(0x534e4554, "168211968"); + return DEAD_OBJECT; + } + return mService->setEventRate(this, handle, samplingPeriodNs, mOpPackageName); } status_t SensorService::SensorEventConnection::flush() { + if (mDestroyed) { + return DEAD_OBJECT; + } + return mService->flushSensor(this, mOpPackageName); } diff --git a/services/sensorservice/SensorEventConnection.h b/services/sensorservice/SensorEventConnection.h index 8f2d5db28f..9487a39a92 100644 --- a/services/sensorservice/SensorEventConnection.h +++ b/services/sensorservice/SensorEventConnection.h @@ -17,6 +17,7 @@ #ifndef ANDROID_SENSOR_EVENT_CONNECTION_H #define ANDROID_SENSOR_EVENT_CONNECTION_H +#include <atomic> #include <stdint.h> #include <sys/types.h> #include <unordered_map> @@ -182,8 +183,8 @@ private: int mTotalAcksNeeded, mTotalAcksReceived; #endif - mutable Mutex mDestroyLock; - bool mDestroyed; + // Used to track if this object was inappropriately used after destroy(). + std::atomic_bool mDestroyed; // Store a mapping of sensor handles to required AppOp for a sensor. This map only contains a // valid mapping for sensors that require a permission in order to reduce the lookup time. diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 1342cfcb6e..9d65f2f2af 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2122,7 +2122,8 @@ void SurfaceFlinger::onMessageRefresh() { mTimeStats->incrementCompositionStrategyChanges(); } - mVSyncModulator->onRefreshed(mHadClientComposition); + // TODO: b/160583065 Enable skip validation when SF caches all client composition layers + mVSyncModulator->onRefreshed(mHadClientComposition || mReusedClientComposition); mLayersWithQueuedFrames.clear(); if (mVisibleRegionsDirty) { |