BBQ: Recreate BBQ when SurfaceControl changes 1/2
Alternative approach to fab15e55446080bdcfc05ba315e8ef914b0a6f65 which
was racy because the disconnect callback is called without the
BQ lock and the client can continue to modify the BQ state after
disconnecting from the queue.
This approach resets the BQ and BBQ states when the SurfaceControl is
updated. This solves one concrete problem of not relying on the old
SurfaceControl to be destroyed in order to release the currently presented
buffer back to BQ.
In addition this change resets the sync state in BBQ with the rationale
the system does not want to sync on buffers presented on an older
SurfaceControl.
Bug: 197269223
Test: atest BLASTBufferQueueTest
Test: labtest ag/16407859 cf-foldable * 3 (b/197269223#comment40)
Change-Id: Id7049c3fcb7f68ed1bcaed8b82bd13b4397af000
diff --git a/libs/gui/include/gui/BLASTBufferQueue.h b/libs/gui/include/gui/BLASTBufferQueue.h
index 8a2f392..8b2310d 100644
--- a/libs/gui/include/gui/BLASTBufferQueue.h
+++ b/libs/gui/include/gui/BLASTBufferQueue.h
@@ -82,6 +82,7 @@
return mProducer;
}
sp<Surface> getSurface(bool includeSurfaceControlHandle);
+ bool isSameSurfaceControl(const sp<SurfaceControl>& surfaceControl) const;
void onBufferFreed(const wp<GraphicBuffer>&/* graphicBuffer*/) override { /* TODO */ }
void onFrameReplaced(const BufferItem& item) override;
@@ -109,6 +110,7 @@
uint32_t getLastTransformHint() const;
uint64_t getLastAcquiredFrameNum();
+ void abandon();
virtual ~BLASTBufferQueue();
@@ -145,15 +147,15 @@
std::string mQueuedBufferTrace;
sp<SurfaceControl> mSurfaceControl;
- std::mutex mMutex;
+ mutable std::mutex mMutex;
std::condition_variable mCallbackCV;
// BufferQueue internally allows 1 more than
// the max to be acquired
int32_t mMaxAcquiredBuffers = 1;
- int32_t mNumFrameAvailable GUARDED_BY(mMutex);
- int32_t mNumAcquired GUARDED_BY(mMutex);
+ int32_t mNumFrameAvailable GUARDED_BY(mMutex) = 0;
+ int32_t mNumAcquired GUARDED_BY(mMutex) = 0;
// Keep a reference to the submitted buffers so we can release when surfaceflinger drops the
// buffer or the buffer has been presented and a new buffer is ready to be presented.