diff options
author | 2024-10-18 18:58:30 +0000 | |
---|---|---|
committer | 2024-10-18 18:58:30 +0000 | |
commit | 34df4e84a27e3800590170c2495c965131b98994 (patch) | |
tree | 5a80bb9ba4d2ce3b31c0ddab224afc8828369c5d | |
parent | 7128079c2ac9721ca123d0b5b8f974e0da6f8126 (diff) | |
parent | 4fbac0b4ce51125ca83dccde294cad2704535dce (diff) |
Merge "NewBufferCount'value changed:simplifying the steps of applying for new buffers" into main am: 326593b0ca am: 4fbac0b4ce
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3304525
Change-Id: I04348a87e5195302bd60be3e877ba6c32249c877
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.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 e58233cff3..473a374a59 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -1556,7 +1556,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; @@ -1578,8 +1577,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; } @@ -1621,27 +1621,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 @@ -1669,15 +1665,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; |