@@ -1501,7 +1501,6 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height,
15011501
15021502 const bool useDefaultSize = !width && !height;
15031503 while (true ) {
1504- size_t newBufferCount = 0 ;
15051504 uint32_t allocWidth = 0 ;
15061505 uint32_t allocHeight = 0 ;
15071506 PixelFormat allocFormat = PIXEL_FORMAT_UNKNOWN;
@@ -1523,8 +1522,9 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height,
15231522
15241523 // Only allocate one buffer at a time to reduce risks of overlapping an allocation from
15251524 // both allocateBuffers and dequeueBuffer.
1526- newBufferCount = mCore ->mFreeSlots .empty () ? 0 : 1 ;
1527- if (newBufferCount == 0 ) {
1525+ if (mCore ->mFreeSlots .empty ()) {
1526+ BQ_LOGV (" allocateBuffers: a slot was occupied while "
1527+ " allocating. Dropping allocated buffer." );
15281528 return ;
15291529 }
15301530
@@ -1566,27 +1566,23 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height,
15661566 };
15671567#endif
15681568
1569- Vector<sp<GraphicBuffer>> buffers;
1570- for (size_t i = 0 ; i < newBufferCount; ++i) {
15711569#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE)
1572- sp<GraphicBuffer> graphicBuffer = new GraphicBuffer (allocRequest);
1570+ sp<GraphicBuffer> graphicBuffer = new GraphicBuffer (allocRequest);
15731571#else
1574- sp<GraphicBuffer> graphicBuffer = new GraphicBuffer (
1575- allocWidth, allocHeight, allocFormat, BQ_LAYER_COUNT,
1576- allocUsage, allocName);
1572+ sp<GraphicBuffer> graphicBuffer = new GraphicBuffer (
1573+ allocWidth, allocHeight, allocFormat, BQ_LAYER_COUNT,
1574+ allocUsage, allocName);
15771575#endif
15781576
1579- status_t result = graphicBuffer->initCheck ();
1577+ status_t result = graphicBuffer->initCheck ();
15801578
1581- if (result != NO_ERROR) {
1582- BQ_LOGE (" allocateBuffers: failed to allocate buffer (%u x %u, format"
1583- " %u, usage %#" PRIx64 " )" , width, height, format, usage);
1584- std::lock_guard<std::mutex> lock (mCore ->mMutex );
1585- mCore ->mIsAllocating = false ;
1586- mCore ->mIsAllocatingCondition .notify_all ();
1587- return ;
1588- }
1589- buffers.push_back (graphicBuffer);
1579+ if (result != NO_ERROR) {
1580+ BQ_LOGE (" allocateBuffers: failed to allocate buffer (%u x %u, format"
1581+ " %u, usage %#" PRIx64 " )" , width, height, format, usage);
1582+ std::lock_guard<std::mutex> lock (mCore ->mMutex );
1583+ mCore ->mIsAllocating = false ;
1584+ mCore ->mIsAllocatingCondition .notify_all ();
1585+ return ;
15901586 }
15911587
15921588 { // Autolock scope
@@ -1614,15 +1610,13 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height,
16141610 continue ;
16151611 }
16161612
1617- for (size_t i = 0 ; i < newBufferCount; ++i) {
1618- if (mCore ->mFreeSlots .empty ()) {
1619- BQ_LOGV (" allocateBuffers: a slot was occupied while "
1620- " allocating. Dropping allocated buffer." );
1621- continue ;
1622- }
1613+ if (mCore ->mFreeSlots .empty ()) {
1614+ BQ_LOGV (" allocateBuffers: a slot was occupied while "
1615+ " allocating. Dropping allocated buffer." );
1616+ } else {
16231617 auto slot = mCore ->mFreeSlots .begin ();
16241618 mCore ->clearBufferSlotLocked (*slot); // Clean up the slot first
1625- mSlots [*slot].mGraphicBuffer = buffers[i] ;
1619+ mSlots [*slot].mGraphicBuffer = graphicBuffer ;
16261620 mSlots [*slot].mFence = Fence::NO_FENCE;
16271621#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE)
16281622 mSlots [*slot].mAdditionalOptionsGenerationId = allocOptionsGenId;
0 commit comments