From 729f721ae6ac3eb3e0c45b67f6c5f43c06065a22 Mon Sep 17 00:00:00 2001 From: Jim Shargo Date: Thu, 20 Feb 2025 20:26:24 +0000 Subject: Surface: Add 'isBufferOwned' call Camera's StreamSplitter keeps track of buffers and won't attach them if they're already owned. This allows us to keep that behavior as we move over from IGBP to surfaces. Ideally, I think, IGBPs should fail to attach the same buffer multiple times. Even if not, this call should probably be to the IGBP instead of the Surface for more accuracy. But this replicates the old behavior. Bug: 340933206 Flag: com.android.graphics.libgui.flags.wb_stream_splitter Test: new test Change-Id: Idbb200202012c9eae2668616dcff277c925c3907 --- libs/gui/Surface.cpp | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'libs/gui/Surface.cpp') diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 63dcfbcb9b..83c6b57289 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -2230,17 +2230,47 @@ int Surface::detachNextBuffer(sp* outBuffer, return NO_ERROR; } +int Surface::isBufferOwned(const sp& buffer, bool* outIsOwned) const { + ATRACE_CALL(); + + if (buffer == nullptr) { + ALOGE("%s: Bad input, buffer was null", __FUNCTION__); + return BAD_VALUE; + } + if (outIsOwned == nullptr) { + ALOGE("%s: Bad input, output was null", __FUNCTION__); + return BAD_VALUE; + } + + Mutex::Autolock lock(mMutex); + + int slot = this->getSlotFromBufferLocked(buffer->getNativeBuffer()); + if (slot == BAD_VALUE) { + ALOGV("%s: Buffer %" PRIu64 " is not owned", __FUNCTION__, buffer->getId()); + *outIsOwned = false; + return NO_ERROR; + } else if (slot < 0) { + ALOGV("%s: Buffer %" PRIu64 " look up failed (%d)", __FUNCTION__, buffer->getId(), slot); + *outIsOwned = false; + return slot; + } + + *outIsOwned = true; + return NO_ERROR; +} + int Surface::attachBuffer(ANativeWindowBuffer* buffer) { ATRACE_CALL(); - ALOGV("Surface::attachBuffer"); + sp graphicBuffer(static_cast(buffer)); + + ALOGV("Surface::attachBuffer bufferId=%" PRIu64, graphicBuffer->getId()); Mutex::Autolock lock(mMutex); if (mReportRemovedBuffers) { mRemovedBuffers.clear(); } - sp graphicBuffer(static_cast(buffer)); uint32_t priorGeneration = graphicBuffer->mGenerationNumber; graphicBuffer->mGenerationNumber = mGenerationNumber; int32_t attachedSlot = -1; -- cgit v1.2.3-59-g8ed1b