diff options
author | 2024-10-14 09:38:32 +0000 | |
---|---|---|
committer | 2024-10-17 01:17:16 +0000 | |
commit | 045a30e06207744f45d7defa109764a5565bf30e (patch) | |
tree | 089ae073800a0ecf123d2ac8002fac211a71a143 | |
parent | 0c01454656d28d34b9b24b0e647c4fc03356ca66 (diff) |
NewBufferCount'value changed:simplifying the steps of applying for new buffers
In Commit:0a3e784, the calculation method of newBufferCount was modified from newBufferCount = mCore->mFreeSlots.size(); to newBufferCount = mCore->mFreeSlots.empty() ? 0 : 1;. When the value of newBufferCount is 0, it means that the maximum number of GB has been applied for. At this time, no new GB will be applied for and the code will be returned directly. The maximum value of newBufferCount is 1, and the subsequent steps of applying for a new buffer will only be executed once. So the for loop can be removed here to simplify the code.
Change-Id: I6c72d7c9a672dc091bd462d384481bed5f88e226
Signed-off-by:
Shuangxi Xiang <xiangshuangxi@xiaomi.corp-partner.google.com>
-rw-r--r-- | libs/gui/BufferQueueProducer.cpp | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index a4d105d320..ead9f0f014 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -1501,7 +1501,6 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, const bool useDefaultSize = !width && !height; while (true) { - size_t newBufferCount = 0; uint32_t allocWidth = 0; uint32_t allocHeight = 0; PixelFormat allocFormat = PIXEL_FORMAT_UNKNOWN; @@ -1523,8 +1522,9 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, // Only allocate one buffer at a time to reduce risks of overlapping an allocation from // both allocateBuffers and dequeueBuffer. - newBufferCount = mCore->mFreeSlots.empty() ? 0 : 1; - if (newBufferCount == 0) { + if (mCore->mFreeSlots.empty()) { + BQ_LOGV("allocateBuffers: a slot was occupied while " + "allocating. Dropping allocated buffer."); return; } @@ -1566,27 +1566,23 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, }; #endif - Vector<sp<GraphicBuffer>> buffers; - for (size_t i = 0; i < newBufferCount; ++i) { #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) - sp<GraphicBuffer> graphicBuffer = new GraphicBuffer(allocRequest); + sp<GraphicBuffer> graphicBuffer = new GraphicBuffer(allocRequest); #else - sp<GraphicBuffer> graphicBuffer = new GraphicBuffer( - allocWidth, allocHeight, allocFormat, BQ_LAYER_COUNT, - allocUsage, allocName); + sp<GraphicBuffer> graphicBuffer = new GraphicBuffer( + allocWidth, allocHeight, allocFormat, BQ_LAYER_COUNT, + allocUsage, allocName); #endif - status_t result = graphicBuffer->initCheck(); + status_t result = graphicBuffer->initCheck(); - if (result != NO_ERROR) { - BQ_LOGE("allocateBuffers: failed to allocate buffer (%u x %u, format" - " %u, usage %#" PRIx64 ")", width, height, format, usage); - std::lock_guard<std::mutex> lock(mCore->mMutex); - mCore->mIsAllocating = false; - mCore->mIsAllocatingCondition.notify_all(); - return; - } - buffers.push_back(graphicBuffer); + if (result != NO_ERROR) { + BQ_LOGE("allocateBuffers: failed to allocate buffer (%u x %u, format" + " %u, usage %#" PRIx64 ")", width, height, format, usage); + std::lock_guard<std::mutex> lock(mCore->mMutex); + mCore->mIsAllocating = false; + mCore->mIsAllocatingCondition.notify_all(); + return; } { // Autolock scope @@ -1614,15 +1610,13 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height, continue; } - for (size_t i = 0; i < newBufferCount; ++i) { - if (mCore->mFreeSlots.empty()) { - BQ_LOGV("allocateBuffers: a slot was occupied while " - "allocating. Dropping allocated buffer."); - continue; - } + if (mCore->mFreeSlots.empty()) { + BQ_LOGV("allocateBuffers: a slot was occupied while " + "allocating. Dropping allocated buffer."); + } else { auto slot = mCore->mFreeSlots.begin(); mCore->clearBufferSlotLocked(*slot); // Clean up the slot first - mSlots[*slot].mGraphicBuffer = buffers[i]; + mSlots[*slot].mGraphicBuffer = graphicBuffer; mSlots[*slot].mFence = Fence::NO_FENCE; #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_EXTENDEDALLOCATE) mSlots[*slot].mAdditionalOptionsGenerationId = allocOptionsGenId; |