diff options
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/gui/BufferQueue.cpp | 7 | ||||
| -rw-r--r-- | libs/gui/BufferQueueProducer.cpp | 1 | ||||
| -rw-r--r-- | libs/gui/FrameTimestamps.cpp | 57 | ||||
| -rw-r--r-- | libs/gui/IConsumerListener.cpp | 13 | ||||
| -rw-r--r-- | libs/gui/Surface.cpp | 18 | ||||
| -rw-r--r-- | libs/gui/tests/DummyConsumer.h | 6 | ||||
| -rw-r--r-- | libs/gui/tests/IGraphicBufferProducer_test.cpp | 8 | ||||
| -rw-r--r-- | libs/gui/tests/Surface_test.cpp | 2 | ||||
| -rw-r--r-- | libs/ui/FenceTime.cpp | 18 |
9 files changed, 79 insertions, 51 deletions
diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp index f76a282af6..13692eb982 100644 --- a/libs/gui/BufferQueue.cpp +++ b/libs/gui/BufferQueue.cpp @@ -31,6 +31,13 @@ BufferQueue::ProxyConsumerListener::ProxyConsumerListener( BufferQueue::ProxyConsumerListener::~ProxyConsumerListener() {} +void BufferQueue::ProxyConsumerListener::onDisconnect() { + sp<ConsumerListener> listener(mConsumerListener.promote()); + if (listener != NULL) { + listener->onDisconnect(); + } +} + void BufferQueue::ProxyConsumerListener::onFrameAvailable( const BufferItem& item) { sp<ConsumerListener> listener(mConsumerListener.promote()); diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index 0cbafcf864..27ced6180b 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -1275,6 +1275,7 @@ status_t BufferQueueProducer::disconnect(int api, DisconnectMode mode) { // Call back without lock held if (listener != NULL) { listener->onBuffersReleased(); + listener->onDisconnect(); } return status; diff --git a/libs/gui/FrameTimestamps.cpp b/libs/gui/FrameTimestamps.cpp index a6fa38aae5..019a11e2b3 100644 --- a/libs/gui/FrameTimestamps.cpp +++ b/libs/gui/FrameTimestamps.cpp @@ -16,6 +16,8 @@ #include <gui/FrameTimestamps.h> +#define LOG_TAG "FrameEvents" + #include <cutils/compiler.h> // For CC_[UN]LIKELY #include <inttypes.h> #include <utils/Log.h> @@ -33,19 +35,19 @@ namespace android { // ============================================================================ bool FrameEvents::hasPostedInfo() const { - return Fence::isValidTimestamp(postedTime); + return FrameEvents::isValidTimestamp(postedTime); } bool FrameEvents::hasRequestedPresentInfo() const { - return Fence::isValidTimestamp(requestedPresentTime); + return FrameEvents::isValidTimestamp(requestedPresentTime); } bool FrameEvents::hasLatchInfo() const { - return Fence::isValidTimestamp(latchTime); + return FrameEvents::isValidTimestamp(latchTime); } bool FrameEvents::hasFirstRefreshStartInfo() const { - return Fence::isValidTimestamp(firstRefreshStartTime); + return FrameEvents::isValidTimestamp(firstRefreshStartTime); } bool FrameEvents::hasLastRefreshStartInfo() const { @@ -56,7 +58,7 @@ bool FrameEvents::hasLastRefreshStartInfo() const { } bool FrameEvents::hasDequeueReadyInfo() const { - return Fence::isValidTimestamp(dequeueReadyTime); + return FrameEvents::isValidTimestamp(dequeueReadyTime); } bool FrameEvents::hasAcquireInfo() const { @@ -117,21 +119,21 @@ void FrameEvents::dump(String8& outString) const outString.appendFormat("--- Req. Present\t%" PRId64 "\n", requestedPresentTime); outString.appendFormat("--- Latched \t"); - if (Fence::isValidTimestamp(latchTime)) { + if (FrameEvents::isValidTimestamp(latchTime)) { outString.appendFormat("%" PRId64 "\n", latchTime); } else { outString.appendFormat("Pending\n"); } outString.appendFormat("--- Refresh (First)\t"); - if (Fence::isValidTimestamp(firstRefreshStartTime)) { + if (FrameEvents::isValidTimestamp(firstRefreshStartTime)) { outString.appendFormat("%" PRId64 "\n", firstRefreshStartTime); } else { outString.appendFormat("Pending\n"); } outString.appendFormat("--- Refresh (Last)\t"); - if (Fence::isValidTimestamp(lastRefreshStartTime)) { + if (FrameEvents::isValidTimestamp(lastRefreshStartTime)) { outString.appendFormat("%" PRId64 "\n", lastRefreshStartTime); } else { outString.appendFormat("Pending\n"); @@ -147,7 +149,7 @@ void FrameEvents::dump(String8& outString) const !addRetireCalled, *displayRetireFence); outString.appendFormat("--- DequeueReady \t"); - if (Fence::isValidTimestamp(dequeueReadyTime)) { + if (FrameEvents::isValidTimestamp(dequeueReadyTime)) { outString.appendFormat("%" PRId64 "\n", dequeueReadyTime); } else { outString.appendFormat("Pending\n"); @@ -256,8 +258,7 @@ void ProducerFrameEventHistory::updateAcquireFence( uint64_t frameNumber, std::shared_ptr<FenceTime>&& acquire) { FrameEvents* frame = getFrame(frameNumber, &mAcquireOffset); if (frame == nullptr) { - ALOGE("ProducerFrameEventHistory::updateAcquireFence: " - "Did not find frame."); + ALOGE("updateAcquireFence: Did not find frame."); return; } @@ -277,8 +278,8 @@ void ProducerFrameEventHistory::applyDelta( for (auto& d : delta.mDeltas) { // Avoid out-of-bounds access. - if (d.mIndex >= mFrames.size()) { - ALOGE("ProducerFrameEventHistory::applyDelta: Bad index."); + if (CC_UNLIKELY(d.mIndex >= mFrames.size())) { + ALOGE("applyDelta: Bad index."); return; } @@ -328,7 +329,7 @@ void ProducerFrameEventHistory::updateSignalTimes() { void ProducerFrameEventHistory::applyFenceDelta(FenceTimeline* timeline, std::shared_ptr<FenceTime>* dst, const FenceTime::Snapshot& src) const { - if (CC_UNLIKELY(dst == nullptr)) { + if (CC_UNLIKELY(dst == nullptr || dst->get() == nullptr)) { ALOGE("applyFenceDelta: dst is null."); return; } @@ -337,9 +338,7 @@ void ProducerFrameEventHistory::applyFenceDelta(FenceTimeline* timeline, case FenceTime::Snapshot::State::EMPTY: return; case FenceTime::Snapshot::State::FENCE: - if (CC_UNLIKELY((*dst)->isValid())) { - ALOGE("applyFenceDelta: Unexpected fence."); - } + ALOGE_IF((*dst)->isValid(), "applyFenceDelta: Unexpected fence."); *dst = createFenceTime(src.fence); timeline->push(*dst); return; @@ -365,6 +364,11 @@ std::shared_ptr<FenceTime> ProducerFrameEventHistory::createFenceTime( ConsumerFrameEventHistory::~ConsumerFrameEventHistory() = default; +void ConsumerFrameEventHistory::onDisconnect() { + mCurrentConnectId++; + mProducerWantsEvents = false; +} + void ConsumerFrameEventHistory::initializeCompositorTiming( const CompositorTiming& compositorTiming) { mCompositorTiming = compositorTiming; @@ -373,6 +377,7 @@ void ConsumerFrameEventHistory::initializeCompositorTiming( void ConsumerFrameEventHistory::addQueue(const NewFrameEventsEntry& newEntry) { // Overwrite all fields of the frame with default values unless set here. FrameEvents newTimestamps; + newTimestamps.connectId = mCurrentConnectId; newTimestamps.frameNumber = newEntry.frameNumber; newTimestamps.postedTime = newEntry.postedTime; newTimestamps.requestedPresentTime = newEntry.requestedPresentTime; @@ -409,7 +414,7 @@ void ConsumerFrameEventHistory::addPreComposition( } frame->lastRefreshStartTime = refreshStartTime; mFramesDirty[mCompositionOffset].setDirty<FrameEvent::LAST_REFRESH_START>(); - if (!Fence::isValidTimestamp(frame->firstRefreshStartTime)) { + if (!FrameEvents::isValidTimestamp(frame->firstRefreshStartTime)) { frame->firstRefreshStartTime = refreshStartTime; mFramesDirty[mCompositionOffset].setDirty<FrameEvent::FIRST_REFRESH_START>(); } @@ -431,7 +436,7 @@ void ConsumerFrameEventHistory::addPostComposition(uint64_t frameNumber, if (!frame->addPostCompositeCalled) { frame->addPostCompositeCalled = true; frame->gpuCompositionDoneFence = gpuCompositionDone; - mFramesDirty[mCompositionOffset].setDirty<FrameEvent::GL_COMPOSITION_DONE>(); + mFramesDirty[mCompositionOffset].setDirty<FrameEvent::GPU_COMPOSITION_DONE>(); if (!frame->displayPresentFence->isValid()) { frame->displayPresentFence = displayPresent; mFramesDirty[mCompositionOffset].setDirty<FrameEvent::DISPLAY_PRESENT>(); @@ -455,7 +460,7 @@ void ConsumerFrameEventHistory::addRelease(uint64_t frameNumber, nsecs_t dequeueReadyTime, std::shared_ptr<FenceTime>&& release) { FrameEvents* frame = getFrame(frameNumber, &mReleaseOffset); if (frame == nullptr) { - ALOGE("ConsumerFrameEventHistory::addRelease: Did not find frame."); + ALOGE_IF(mProducerWantsEvents, "addRelease: Did not find frame."); return; } frame->addReleaseCalled = true; @@ -470,13 +475,19 @@ void ConsumerFrameEventHistory::getFrameDelta( mProducerWantsEvents = true; size_t i = static_cast<size_t>(std::distance(mFrames.begin(), frame)); if (mFramesDirty[i].anyDirty()) { - delta->mDeltas.emplace_back(i, *frame, mFramesDirty[i]); + // Make sure only to send back deltas for the current connection + // since the producer won't have the correct state to apply a delta + // from a previous connection. + if (mFrames[i].connectId == mCurrentConnectId) { + delta->mDeltas.emplace_back(i, *frame, mFramesDirty[i]); + } mFramesDirty[i].reset(); } } void ConsumerFrameEventHistory::getAndResetDelta( FrameEventHistoryDelta* delta) { + mProducerWantsEvents = true; delta->mCompositorTiming = mCompositorTiming; // Write these in order of frame number so that it is easy to @@ -512,7 +523,7 @@ FrameEventsDelta::FrameEventsDelta( mFirstRefreshStartTime(frameTimestamps.firstRefreshStartTime), mLastRefreshStartTime(frameTimestamps.lastRefreshStartTime), mDequeueReadyTime(frameTimestamps.dequeueReadyTime) { - if (dirtyFields.isDirty<FrameEvent::GL_COMPOSITION_DONE>()) { + if (dirtyFields.isDirty<FrameEvent::GPU_COMPOSITION_DONE>()) { mGpuCompositionDoneFence = frameTimestamps.gpuCompositionDoneFence->getSnapshot(); } @@ -648,7 +659,7 @@ FrameEventHistoryDelta& FrameEventHistoryDelta::operator=( mCompositorTiming = src.mCompositorTiming; if (CC_UNLIKELY(!mDeltas.empty())) { - ALOGE("FrameEventHistoryDelta: Clobbering history."); + ALOGE("FrameEventHistoryDelta assign clobbering history."); } mDeltas = std::move(src.mDeltas); ALOGE_IF(src.mDeltas.empty(), "Source mDeltas not empty."); diff --git a/libs/gui/IConsumerListener.cpp b/libs/gui/IConsumerListener.cpp index 3d893b15d5..8cadc4de1b 100644 --- a/libs/gui/IConsumerListener.cpp +++ b/libs/gui/IConsumerListener.cpp @@ -28,7 +28,8 @@ namespace android { // --------------------------------------------------------------------------- enum { - ON_FRAME_AVAILABLE = IBinder::FIRST_CALL_TRANSACTION, + ON_DISCONNECT = IBinder::FIRST_CALL_TRANSACTION, + ON_FRAME_AVAILABLE, ON_BUFFER_RELEASED, ON_SIDEBAND_STREAM_CHANGED, GET_FRAME_TIMESTAMPS @@ -43,6 +44,12 @@ public: virtual ~BpConsumerListener(); + virtual void onDisconnect() { + Parcel data, reply; + data.writeInterfaceToken(IConsumerListener::getInterfaceDescriptor()); + remote()->transact(ON_DISCONNECT, data, &reply, IBinder::FLAG_ONEWAY); + } + virtual void onFrameAvailable(const BufferItem& item) { Parcel data, reply; data.writeInterfaceToken(IConsumerListener::getInterfaceDescriptor()); @@ -75,6 +82,10 @@ status_t BnConsumerListener::onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { switch(code) { + case ON_DISCONNECT: { + CHECK_INTERFACE(IConsumerListener, data, reply); + onDisconnect(); + return NO_ERROR; } case ON_FRAME_AVAILABLE: { CHECK_INTERFACE(IConsumerListener, data, reply); BufferItem item; diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index d285ef0ce9..efb15245a6 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -196,7 +196,7 @@ static bool checkConsumerForUpdates( const nsecs_t* outLatchTime, const nsecs_t* outFirstRefreshStartTime, const nsecs_t* outLastRefreshStartTime, - const nsecs_t* outGlCompositionDoneTime, + const nsecs_t* outGpuCompositionDoneTime, const nsecs_t* outDisplayPresentTime, const nsecs_t* outDisplayRetireTime, const nsecs_t* outDequeueReadyTime, @@ -204,7 +204,7 @@ static bool checkConsumerForUpdates( bool checkForLatch = (outLatchTime != nullptr) && !e->hasLatchInfo(); bool checkForFirstRefreshStart = (outFirstRefreshStartTime != nullptr) && !e->hasFirstRefreshStartInfo(); - bool checkForGlCompositionDone = (outGlCompositionDoneTime != nullptr) && + bool checkForGpuCompositionDone = (outGpuCompositionDoneTime != nullptr) && !e->hasGpuCompositionDoneInfo(); bool checkForDisplayPresent = (outDisplayPresentTime != nullptr) && !e->hasDisplayPresentInfo(); @@ -223,14 +223,14 @@ static bool checkConsumerForUpdates( // RequestedPresent and Acquire info are always available producer-side. return checkForLatch || checkForFirstRefreshStart || - checkForLastRefreshStart || checkForGlCompositionDone || + checkForLastRefreshStart || checkForGpuCompositionDone || checkForDisplayPresent || checkForDisplayRetire || checkForDequeueReady || checkForRelease; } static void getFrameTimestamp(nsecs_t *dst, const nsecs_t& src) { if (dst != nullptr) { - *dst = Fence::isValidTimestamp(src) ? src : 0; + *dst = FrameEvents::isValidTimestamp(src) ? src : 0; } } @@ -244,7 +244,7 @@ static void getFrameTimestampFence(nsecs_t *dst, const std::shared_ptr<FenceTime status_t Surface::getFrameTimestamps(uint64_t frameNumber, nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime, nsecs_t* outLatchTime, nsecs_t* outFirstRefreshStartTime, - nsecs_t* outLastRefreshStartTime, nsecs_t* outGlCompositionDoneTime, + nsecs_t* outLastRefreshStartTime, nsecs_t* outGpuCompositionDoneTime, nsecs_t* outDisplayPresentTime, nsecs_t* outDisplayRetireTime, nsecs_t* outDequeueReadyTime, nsecs_t* outReleaseTime) { ATRACE_CALL(); @@ -274,7 +274,7 @@ status_t Surface::getFrameTimestamps(uint64_t frameNumber, // Update our cache of events if the requested events are not available. if (checkConsumerForUpdates(events, mLastFrameNumber, outLatchTime, outFirstRefreshStartTime, outLastRefreshStartTime, - outGlCompositionDoneTime, outDisplayPresentTime, + outGpuCompositionDoneTime, outDisplayPresentTime, outDisplayRetireTime, outDequeueReadyTime, outReleaseTime)) { FrameEventHistoryDelta delta; mGraphicBufferProducer->getFrameTimestamps(&delta); @@ -296,7 +296,7 @@ status_t Surface::getFrameTimestamps(uint64_t frameNumber, getFrameTimestampFence(outAcquireTime, events->acquireFence); getFrameTimestampFence( - outGlCompositionDoneTime, events->gpuCompositionDoneFence); + outGpuCompositionDoneTime, events->gpuCompositionDoneFence); getFrameTimestampFence( outDisplayPresentTime, events->displayPresentFence); getFrameTimestampFence(outDisplayRetireTime, events->displayRetireFence); @@ -1032,7 +1032,7 @@ int Surface::dispatchGetFrameTimestamps(va_list args) { nsecs_t* outLatchTime = va_arg(args, int64_t*); nsecs_t* outFirstRefreshStartTime = va_arg(args, int64_t*); nsecs_t* outLastRefreshStartTime = va_arg(args, int64_t*); - nsecs_t* outGlCompositionDoneTime = va_arg(args, int64_t*); + nsecs_t* outGpuCompositionDoneTime = va_arg(args, int64_t*); nsecs_t* outDisplayPresentTime = va_arg(args, int64_t*); nsecs_t* outDisplayRetireTime = va_arg(args, int64_t*); nsecs_t* outDequeueReadyTime = va_arg(args, int64_t*); @@ -1040,7 +1040,7 @@ int Surface::dispatchGetFrameTimestamps(va_list args) { return getFrameTimestamps(frameId, outRequestedPresentTime, outAcquireTime, outLatchTime, outFirstRefreshStartTime, outLastRefreshStartTime, - outGlCompositionDoneTime, outDisplayPresentTime, + outGpuCompositionDoneTime, outDisplayPresentTime, outDisplayRetireTime, outDequeueReadyTime, outReleaseTime); } diff --git a/libs/gui/tests/DummyConsumer.h b/libs/gui/tests/DummyConsumer.h index 0511e165c2..502bdf981b 100644 --- a/libs/gui/tests/DummyConsumer.h +++ b/libs/gui/tests/DummyConsumer.h @@ -19,9 +19,9 @@ namespace android { struct DummyConsumer : public BnConsumerListener { - virtual void onFrameAvailable(const BufferItem& /* item */) {} - virtual void onBuffersReleased() {} - virtual void onSidebandStreamChanged() {} + void onFrameAvailable(const BufferItem& /* item */) override {} + void onBuffersReleased() override {} + void onSidebandStreamChanged() override {} }; } // namespace android diff --git a/libs/gui/tests/IGraphicBufferProducer_test.cpp b/libs/gui/tests/IGraphicBufferProducer_test.cpp index 0329a6d61f..aa071f68b0 100644 --- a/libs/gui/tests/IGraphicBufferProducer_test.cpp +++ b/libs/gui/tests/IGraphicBufferProducer_test.cpp @@ -17,6 +17,8 @@ #define LOG_TAG "IGraphicBufferProducer_test" //#define LOG_NDEBUG 0 +#include "DummyConsumer.h" + #include <gtest/gtest.h> #include <utils/String8.h> @@ -64,12 +66,6 @@ namespace { const sp<Fence> QUEUE_BUFFER_INPUT_FENCE = Fence::NO_FENCE; }; // namespace anonymous -struct DummyConsumer : public BnConsumerListener { - virtual void onFrameAvailable(const BufferItem& /* item */) {} - virtual void onBuffersReleased() {} - virtual void onSidebandStreamChanged() {} -}; - class IGraphicBufferProducerTest : public ::testing::Test { protected: diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index 52980270f2..ceeb90a4f6 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -364,7 +364,7 @@ public: FrameEvent::LATCH, FrameEvent::FIRST_REFRESH_START, FrameEvent::LAST_REFRESH_START, - FrameEvent::GL_COMPOSITION_DONE, + FrameEvent::GPU_COMPOSITION_DONE, FrameEvent::DEQUEUE_READY, FrameEvent::RELEASE }; diff --git a/libs/ui/FenceTime.cpp b/libs/ui/FenceTime.cpp index 8106b16009..14147663de 100644 --- a/libs/ui/FenceTime.cpp +++ b/libs/ui/FenceTime.cpp @@ -16,6 +16,8 @@ #include <ui/FenceTime.h> +#define LOG_TAG "FenceTime" + #include <cutils/compiler.h> // For CC_[UN]LIKELY #include <utils/Log.h> #include <inttypes.h> @@ -62,8 +64,11 @@ FenceTime::FenceTime(sp<Fence>&& fence) FenceTime::FenceTime(nsecs_t signalTime) : mState(Fence::isValidTimestamp(signalTime) ? State::VALID : State::INVALID), mFence(nullptr), - mSignalTime(signalTime == Fence::SIGNAL_TIME_PENDING ? - Fence::SIGNAL_TIME_INVALID : signalTime) { + mSignalTime(signalTime) { + if (CC_UNLIKELY(mSignalTime == Fence::SIGNAL_TIME_PENDING)) { + ALOGE("Pending signal time not allowed after signal."); + mSignalTime = Fence::SIGNAL_TIME_INVALID; + } } void FenceTime::applyTrustedSnapshot(const Snapshot& src) { @@ -71,7 +76,7 @@ void FenceTime::applyTrustedSnapshot(const Snapshot& src) { // Applying Snapshot::State::FENCE, could change the valid state of the // FenceTime, which is not allowed. Callers should create a new // FenceTime from the snapshot instead. - ALOGE("FenceTime::applyTrustedSnapshot: Unexpected fence."); + ALOGE("applyTrustedSnapshot: Unexpected fence."); return; } @@ -332,16 +337,13 @@ void FenceToFenceTimeMap::signalAllForTest( continue; } ALOGE_IF(!fenceTime->isValid(), - "FenceToFenceTimeMap::signalAllForTest: " - "Signaling invalid fence."); + "signalAllForTest: Signaling invalid fence."); fenceTime->signalForTest(signalTime); signaled = true; } } - if (!signaled) { - ALOGE("FenceToFenceTimeMap::signalAllForTest: Nothing to signal."); - } + ALOGE_IF(!signaled, "signalAllForTest: Nothing to signal."); } void FenceToFenceTimeMap::garbageCollectLocked() { |