@@ -187,37 +187,30 @@ void BLASTBufferItemConsumer::resizeFrameEventHistory(size_t newSize) {
187187 mFrameEventHistory .resize (newSize);
188188}
189189
190- BLASTBufferQueue::BLASTBufferQueue (const std::string& name, bool updateDestinationFrame)
191- : mSurfaceControl (nullptr ),
192- mSize (1 , 1 ),
193- mRequestedSize(mSize ),
194- mFormat(PIXEL_FORMAT_RGBA_8888),
195- mTransactionReadyCallback(nullptr ),
196- mSyncTransaction(nullptr ),
197- mUpdateDestinationFrame(updateDestinationFrame) {
190+ void BLASTBufferQueue::initialize () {
191+ std::lock_guard _lock{mMutex };
198192 createBufferQueue (&mProducer , &mConsumer );
199193#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
200- mBufferItemConsumer = sp<BLASTBufferItemConsumer>::make (mProducer , mConsumer ,
201- GraphicBuffer::USAGE_HW_COMPOSER |
202- GraphicBuffer::USAGE_HW_TEXTURE,
203- 1 , false , this );
194+ mBufferItemConsumer =
195+ sp<BLASTBufferItemConsumer>::make (mProducer , mConsumer ,
196+ GraphicBuffer::USAGE_HW_COMPOSER |
197+ GraphicBuffer::USAGE_HW_TEXTURE,
198+ 1 , false , wp<BLASTBufferQueue>::fromExisting (this ));
204199#else
205- mBufferItemConsumer = sp<BLASTBufferItemConsumer>::make (mConsumer ,
206- GraphicBuffer::USAGE_HW_COMPOSER |
207- GraphicBuffer::USAGE_HW_TEXTURE,
208- 1 , false , this );
200+ mBufferItemConsumer =
201+ sp<BLASTBufferItemConsumer>::make (mConsumer ,
202+ GraphicBuffer::USAGE_HW_COMPOSER |
203+ GraphicBuffer::USAGE_HW_TEXTURE,
204+ 1 , false , wp<BLASTBufferQueue>::fromExisting (this ));
209205#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_CONSUMER_BASE_OWNS_BQ)
210206 // since the adapter is in the client process, set dequeue timeout
211207 // explicitly so that dequeueBuffer will block
212208 mProducer ->setDequeueTimeout (std::numeric_limits<int64_t >::max ());
213209
214- static std::atomic<uint32_t > nextId = 0 ;
215- mProducerId = nextId++;
216- mName = name + " #" + std::to_string (mProducerId );
217210 auto consumerName = mName + " (BLAST Consumer)" + std::to_string (mProducerId );
218211 mQueuedBufferTrace = " QueuedBuffer - " + mName + " BLAST#" + std::to_string (mProducerId );
219212 mBufferItemConsumer ->setName (String8 (consumerName.c_str ()));
220- mBufferItemConsumer ->setFrameAvailableListener (this );
213+ mBufferItemConsumer ->setFrameAvailableListener (wp<BLASTBufferQueue>:: fromExisting ( this ) );
221214
222215 ComposerServiceAIDL::getComposerService ()->getMaxAcquiredBufferCount (&mMaxAcquiredBuffers );
223216 mBufferItemConsumer ->setMaxAcquiredBufferCount (mMaxAcquiredBuffers );
@@ -239,9 +232,25 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, bool updateDestinati
239232 mBufferReleaseReader .emplace (*this );
240233#endif
241234
235+ // safe default, most producers are expected to override this
236+ mProducer ->setMaxDequeuedBufferCount (2 );
237+
242238 BQA_LOGV (" BLASTBufferQueue created" );
243239}
244240
241+ BLASTBufferQueue::BLASTBufferQueue (const std::string& name, bool updateDestinationFrame)
242+ : mSurfaceControl (nullptr ),
243+ mSize (1 , 1 ),
244+ mRequestedSize(mSize ),
245+ mFormat(PIXEL_FORMAT_RGBA_8888),
246+ mTransactionReadyCallback(nullptr ),
247+ mSyncTransaction(nullptr ),
248+ mUpdateDestinationFrame(updateDestinationFrame) {
249+ static std::atomic<uint32_t > nextId = 0 ;
250+ mProducerId = nextId++;
251+ mName = name + " #" + std::to_string (mProducerId );
252+ }
253+
245254BLASTBufferQueue::~BLASTBufferQueue () {
246255 TransactionCompletedListener::getInstance ()->removeQueueStallListener (this );
247256 if (mPendingTransactions .empty ()) {
@@ -260,8 +269,7 @@ BLASTBufferQueue::~BLASTBufferQueue() {
260269}
261270
262271void BLASTBufferQueue::onFirstRef () {
263- // safe default, most producers are expected to override this
264- mProducer ->setMaxDequeuedBufferCount (2 );
272+ initialize ();
265273}
266274
267275void BLASTBufferQueue::update (const sp<SurfaceControl>& surface, uint32_t width, uint32_t height,
@@ -1022,7 +1030,8 @@ sp<Surface> BLASTBufferQueue::getSurface(bool includeSurfaceControlHandle) {
10221030 if (includeSurfaceControlHandle && mSurfaceControl ) {
10231031 scHandle = mSurfaceControl ->getHandle ();
10241032 }
1025- return sp<BBQSurface>::make (mProducer , true , scHandle, this );
1033+ return sp<BBQSurface>::make (mProducer , true , scHandle,
1034+ sp<BLASTBufferQueue>::fromExisting (this ));
10261035}
10271036
10281037void BLASTBufferQueue::mergeWithNextTransaction (SurfaceComposerClient::Transaction* t,
@@ -1278,13 +1287,14 @@ void BLASTBufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer
12781287 LOG_ALWAYS_FATAL_IF (outConsumer == nullptr , " BLASTBufferQueue: outConsumer must not be NULL" );
12791288
12801289#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BUFFER_RELEASE_CHANNEL)
1281- auto core = sp<BBQBufferQueueCore>::make (this );
1290+ auto core = sp<BBQBufferQueueCore>::make (wp<BLASTBufferQueue>:: fromExisting ( this ) );
12821291#else
12831292 auto core = sp<BufferQueueCore>::make ();
12841293#endif
12851294 LOG_ALWAYS_FATAL_IF (core == nullptr , " BLASTBufferQueue: failed to create BufferQueueCore" );
12861295
1287- auto producer = sp<BBQBufferQueueProducer>::make (core, this );
1296+ auto producer =
1297+ sp<BBQBufferQueueProducer>::make (core, wp<BLASTBufferQueue>::fromExisting (this ));
12881298 LOG_ALWAYS_FATAL_IF (producer == nullptr ,
12891299 " BLASTBufferQueue: failed to create BBQBufferQueueProducer" );
12901300
0 commit comments