diff options
| -rw-r--r-- | libs/gui/BLASTBufferQueue.cpp | 30 | ||||
| -rw-r--r-- | libs/gui/include/gui/BLASTBufferQueue.h | 26 |
2 files changed, 43 insertions, 13 deletions
diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp index 1e6fc2b217..82c9268feb 100644 --- a/libs/gui/BLASTBufferQueue.cpp +++ b/libs/gui/BLASTBufferQueue.cpp @@ -55,7 +55,7 @@ namespace android { ALOGE("[%s](f:%u,a:%u) " x, mName.c_str(), mNumFrameAvailable, mNumAcquired, ##__VA_ARGS__) void BLASTBufferItemConsumer::onDisconnect() { - Mutex::Autolock lock(mFrameEventHistoryMutex); + Mutex::Autolock lock(mMutex); mPreviouslyConnected = mCurrentlyConnected; mCurrentlyConnected = false; if (mPreviouslyConnected) { @@ -66,7 +66,7 @@ void BLASTBufferItemConsumer::onDisconnect() { void BLASTBufferItemConsumer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps, FrameEventHistoryDelta* outDelta) { - Mutex::Autolock lock(mFrameEventHistoryMutex); + Mutex::Autolock lock(mMutex); if (newTimestamps) { // BufferQueueProducer only adds a new timestamp on // queueBuffer @@ -90,7 +90,7 @@ void BLASTBufferItemConsumer::updateFrameTimestamps(uint64_t frameNumber, nsecs_ const sp<Fence>& prevReleaseFence, CompositorTiming compositorTiming, nsecs_t latchTime, nsecs_t dequeueReadyTime) { - Mutex::Autolock lock(mFrameEventHistoryMutex); + Mutex::Autolock lock(mMutex); // if the producer is not connected, don't bother updating, // the next producer that connects won't access this frame event @@ -108,7 +108,7 @@ void BLASTBufferItemConsumer::updateFrameTimestamps(uint64_t frameNumber, nsecs_ void BLASTBufferItemConsumer::getConnectionEvents(uint64_t frameNumber, bool* needsDisconnect) { bool disconnect = false; - Mutex::Autolock lock(mFrameEventHistoryMutex); + Mutex::Autolock lock(mMutex); while (!mDisconnectEvents.empty() && mDisconnectEvents.front() <= frameNumber) { disconnect = true; mDisconnectEvents.pop(); @@ -116,6 +116,19 @@ void BLASTBufferItemConsumer::getConnectionEvents(uint64_t frameNumber, bool* ne if (needsDisconnect != nullptr) *needsDisconnect = disconnect; } +void BLASTBufferItemConsumer::setBlastBufferQueue(BLASTBufferQueue* blastbufferqueue) { + Mutex::Autolock lock(mMutex); + mBLASTBufferQueue = blastbufferqueue; +} + +void BLASTBufferItemConsumer::onSidebandStreamChanged() { + Mutex::Autolock lock(mMutex); + if (mBLASTBufferQueue != nullptr) { + sp<NativeHandle> stream = getSidebandStream(); + mBLASTBufferQueue->setSidebandStream(stream); + } +} + BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface, int width, int height, int32_t format, bool enableTripleBuffering) @@ -145,6 +158,7 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceCont mBufferItemConsumer->setBufferFreedListener(this); mBufferItemConsumer->setDefaultBufferSize(mSize.width, mSize.height); mBufferItemConsumer->setDefaultBufferFormat(convertBufferFormat(format)); + mBufferItemConsumer->setBlastBufferQueue(this); mTransformHint = mSurfaceControl->getTransformHint(); mBufferItemConsumer->setTransformHint(mTransformHint); @@ -160,6 +174,7 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceCont } BLASTBufferQueue::~BLASTBufferQueue() { + mBufferItemConsumer->setBlastBufferQueue(nullptr); if (mPendingTransactions.empty()) { return; } @@ -557,6 +572,13 @@ status_t BLASTBufferQueue::setFrameTimelineInfo(const FrameTimelineInfo& frameTi return OK; } +void BLASTBufferQueue::setSidebandStream(const sp<NativeHandle>& stream) { + std::unique_lock _lock{mMutex}; + SurfaceComposerClient::Transaction t; + + t.setSidebandStream(mSurfaceControl, stream).apply(); +} + sp<Surface> BLASTBufferQueue::getSurface(bool includeSurfaceControlHandle) { std::unique_lock _lock{mMutex}; sp<IBinder> scHandle = nullptr; diff --git a/libs/gui/include/gui/BLASTBufferQueue.h b/libs/gui/include/gui/BLASTBufferQueue.h index bccb71b362..dd8e714e23 100644 --- a/libs/gui/include/gui/BLASTBufferQueue.h +++ b/libs/gui/include/gui/BLASTBufferQueue.h @@ -32,6 +32,7 @@ namespace android { +class BLASTBufferQueue; class BufferItemConsumer; class BLASTBufferItemConsumer : public BufferItemConsumer { @@ -40,27 +41,32 @@ public: int bufferCount, bool controlledByApp) : BufferItemConsumer(consumer, consumerUsage, bufferCount, controlledByApp), mCurrentlyConnected(false), - mPreviouslyConnected(false) {} + mPreviouslyConnected(false), + mBLASTBufferQueue(nullptr) {} void onDisconnect() override; void addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps, - FrameEventHistoryDelta* outDelta) override - REQUIRES(mFrameEventHistoryMutex); + FrameEventHistoryDelta* outDelta) override REQUIRES(mMutex); void updateFrameTimestamps(uint64_t frameNumber, nsecs_t refreshStartTime, const sp<Fence>& gpuCompositionDoneFence, const sp<Fence>& presentFence, const sp<Fence>& prevReleaseFence, CompositorTiming compositorTiming, nsecs_t latchTime, - nsecs_t dequeueReadyTime) REQUIRES(mFrameEventHistoryMutex); + nsecs_t dequeueReadyTime) REQUIRES(mMutex); void getConnectionEvents(uint64_t frameNumber, bool* needsDisconnect); + void setBlastBufferQueue(BLASTBufferQueue* blastbufferqueue) REQUIRES(mMutex); + +protected: + void onSidebandStreamChanged() override REQUIRES(mMutex); private: uint64_t mCurrentFrameNumber = 0; - Mutex mFrameEventHistoryMutex; - ConsumerFrameEventHistory mFrameEventHistory GUARDED_BY(mFrameEventHistoryMutex); - std::queue<uint64_t> mDisconnectEvents GUARDED_BY(mFrameEventHistoryMutex); - bool mCurrentlyConnected GUARDED_BY(mFrameEventHistoryMutex); - bool mPreviouslyConnected GUARDED_BY(mFrameEventHistoryMutex); + Mutex mMutex; + ConsumerFrameEventHistory mFrameEventHistory GUARDED_BY(mMutex); + std::queue<uint64_t> mDisconnectEvents GUARDED_BY(mMutex); + bool mCurrentlyConnected GUARDED_BY(mMutex); + bool mPreviouslyConnected GUARDED_BY(mMutex); + BLASTBufferQueue* mBLASTBufferQueue GUARDED_BY(mMutex); }; class BLASTBufferQueue @@ -94,6 +100,8 @@ public: status_t setFrameRate(float frameRate, int8_t compatibility, bool shouldBeSeamless); status_t setFrameTimelineInfo(const FrameTimelineInfo& info); + void setSidebandStream(const sp<NativeHandle>& stream); + virtual ~BLASTBufferQueue(); private: |