Loading libs/gui/BLASTBufferQueue.cpp +36 −15 Original line number Diff line number Diff line Loading @@ -146,6 +146,10 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceCont mTransformHint = mSurfaceControl->getTransformHint(); mBufferItemConsumer->setTransformHint(mTransformHint); SurfaceComposerClient::Transaction() .setFlags(surface, layer_state_t::eEnableBackpressure, layer_state_t::eEnableBackpressure) .apply(); mNumAcquired = 0; mNumFrameAvailable = 0; Loading @@ -169,13 +173,20 @@ BLASTBufferQueue::~BLASTBufferQueue() { void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height, int32_t format) { std::unique_lock _lock{mMutex}; mSurfaceControl = surface; if (mFormat != format) { mFormat = format; mBufferItemConsumer->setDefaultBufferFormat(format); } SurfaceComposerClient::Transaction t; bool applyTransaction = false; if (!SurfaceControl::isSameSurface(mSurfaceControl, surface)) { mSurfaceControl = surface; t.setFlags(mSurfaceControl, layer_state_t::eEnableBackpressure, layer_state_t::eEnableBackpressure); applyTransaction = true; } ui::Size newSize(width, height); if (mRequestedSize != newSize) { mRequestedSize.set(newSize); Loading @@ -184,12 +195,14 @@ void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width, // If the buffer supports scaling, update the frame immediately since the client may // want to scale the existing buffer to the new size. mSize = mRequestedSize; SurfaceComposerClient::Transaction t; t.setFrame(mSurfaceControl, {0, 0, static_cast<int32_t>(mSize.width), static_cast<int32_t>(mSize.height)}); t.apply(); applyTransaction = true; } } if (applyTransaction) { t.apply(); } } Loading Loading @@ -248,7 +261,7 @@ void BLASTBufferQueue::transactionCallback(nsecs_t /*latchTime*/, const sp<Fence mPendingReleaseItem.item = std::move(mSubmitted.front()); mSubmitted.pop(); processNextBufferLocked(false); processNextBufferLocked(false /* useNextTransaction */); currFrameNumber = mPendingReleaseItem.item.mFrameNumber; if (mTransactionCompleteCallback && mTransactionCompleteFrameNumber == currFrameNumber) { Loading @@ -269,9 +282,10 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { ATRACE_CALL(); BQA_LOGV("processNextBufferLocked useNextTransaction=%s", toString(useNextTransaction)); // Wait to acquire a buffer if there are no frames available or we have acquired the max // number of buffers. if (mNumFrameAvailable == 0 || maxBuffersAcquired()) { // If the next transaction is set, we want to guarantee the our acquire will not fail, so don't // include the extra buffer when checking if we can acquire the next buffer. const bool includeExtraAcquire = !useNextTransaction; if (mNumFrameAvailable == 0 || maxBuffersAcquired(includeExtraAcquire)) { BQA_LOGV("processNextBufferLocked waiting for frame available or callback"); mCallbackCV.notify_all(); return; Loading @@ -295,7 +309,10 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { status_t status = mBufferItemConsumer->acquireBuffer(&bufferItem, 0 /* expectedPresent */, false); if (status != OK) { if (status == BufferQueue::NO_BUFFER_AVAILABLE) { BQA_LOGV("Failed to acquire a buffer, err=NO_BUFFER_AVAILABLE"); return; } else if (status != OK) { BQA_LOGE("Failed to acquire a buffer, err=%s", statusToString(status).c_str()); return; } Loading Loading @@ -414,7 +431,7 @@ void BLASTBufferQueue::onFrameAvailable(const BufferItem& item) { item.mFrameNumber, toString(nextTransactionSet), toString(mFlushShadowQueue)); if (nextTransactionSet || mFlushShadowQueue) { while (mNumFrameAvailable > 0 || maxBuffersAcquired()) { while (mNumFrameAvailable > 0 || maxBuffersAcquired(false /* includeExtraAcquire */)) { BQA_LOGV("waiting in onFrameAvailable..."); mCallbackCV.wait(_lock); } Loading @@ -422,7 +439,7 @@ void BLASTBufferQueue::onFrameAvailable(const BufferItem& item) { mFlushShadowQueue = false; // add to shadow queue mNumFrameAvailable++; processNextBufferLocked(true); processNextBufferLocked(nextTransactionSet /* useNextTransaction */); } void BLASTBufferQueue::onFrameReplaced(const BufferItem& item) { Loading Loading @@ -482,9 +499,12 @@ void BLASTBufferQueue::setTransactionCompleteCallback( // Check if we have acquired the maximum number of buffers. // As a special case, we wait for the first callback before acquiring the second buffer so we // can ensure the first buffer is presented if multiple buffers are queued in succession. bool BLASTBufferQueue::maxBuffersAcquired() const { return mNumAcquired == MAX_ACQUIRED_BUFFERS + 1 || (!mInitialCallbackReceived && mNumAcquired == 1); // Consumer can acquire an additional buffer if that buffer is not droppable. Set // includeExtraAcquire is true to include this buffer to the count. Since this depends on the state // of the buffer, the next acquire may return with NO_BUFFER_AVAILABLE. bool BLASTBufferQueue::maxBuffersAcquired(bool includeExtraAcquire) const { int maxAcquiredBuffers = MAX_ACQUIRED_BUFFERS + (includeExtraAcquire ? 2 : 1); return mNumAcquired == maxAcquiredBuffers || (!mInitialCallbackReceived && mNumAcquired == 1); } class BBQSurface : public Surface { Loading Loading @@ -654,7 +674,8 @@ void BLASTBufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer LOG_ALWAYS_FATAL_IF(producer == nullptr, "BLASTBufferQueue: failed to create BBQBufferQueueProducer"); sp<IGraphicBufferConsumer> consumer(new BufferQueueConsumer(core)); sp<BufferQueueConsumer> consumer(new BufferQueueConsumer(core)); consumer->setAllowExtraAcquire(true); LOG_ALWAYS_FATAL_IF(consumer == nullptr, "BLASTBufferQueue: failed to create BufferQueueConsumer"); Loading libs/gui/BufferQueueConsumer.cpp +12 −1 Original line number Diff line number Diff line Loading @@ -94,7 +94,10 @@ status_t BufferQueueConsumer::acquireBuffer(BufferItem* outBuffer, ++numAcquiredBuffers; } } if (numAcquiredBuffers >= mCore->mMaxAcquiredBufferCount + 1) { const bool acquireNonDroppableBuffer = mCore->mAllowExtraAcquire && numAcquiredBuffers == mCore->mMaxAcquiredBufferCount + 1; if (numAcquiredBuffers >= mCore->mMaxAcquiredBufferCount + 1 && !acquireNonDroppableBuffer) { BQ_LOGE("acquireBuffer: max acquired buffer count reached: %d (max %d)", numAcquiredBuffers, mCore->mMaxAcquiredBufferCount); return INVALID_OPERATION; Loading Loading @@ -254,6 +257,9 @@ status_t BufferQueueConsumer::acquireBuffer(BufferItem* outBuffer, outBuffer->mIsStale = false; outBuffer->mAutoRefresh = mCore->mSharedBufferMode && mCore->mAutoRefresh; } else if (acquireNonDroppableBuffer && front->mIsDroppable) { BQ_LOGV("acquireBuffer: front buffer is not droppable"); return NO_BUFFER_AVAILABLE; } else { slot = front->mSlot; *outBuffer = *front; Loading Loading @@ -824,4 +830,9 @@ status_t BufferQueueConsumer::dumpState(const String8& prefix, String8* outResul return NO_ERROR; } void BufferQueueConsumer::setAllowExtraAcquire(bool allow) { std::lock_guard<std::mutex> lock(mCore->mMutex); mCore->mAllowExtraAcquire = allow; } } // namespace android libs/gui/LayerState.cpp +3 −5 Original line number Diff line number Diff line Loading @@ -183,12 +183,9 @@ status_t layer_state_t::read(const Parcel& input) SAFE_PARCEL(input.readUint32, &layerStack); SAFE_PARCEL(input.readFloat, &alpha); uint32_t tmpUint32 = 0; SAFE_PARCEL(input.readUint32, &tmpUint32); flags = static_cast<uint8_t>(tmpUint32); SAFE_PARCEL(input.readUint32, &flags); SAFE_PARCEL(input.readUint32, &tmpUint32); mask = static_cast<uint8_t>(tmpUint32); SAFE_PARCEL(input.readUint32, &mask); SAFE_PARCEL(matrix.read, input); SAFE_PARCEL(input.read, crop_legacy); Loading Loading @@ -229,6 +226,7 @@ status_t layer_state_t::read(const Parcel& input) SAFE_PARCEL(input.read, *acquireFence); } uint32_t tmpUint32 = 0; SAFE_PARCEL(input.readUint32, &tmpUint32); dataspace = static_cast<ui::Dataspace>(tmpUint32); Loading libs/gui/SurfaceComposerClient.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -929,7 +929,8 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFlags return *this; } if ((mask & layer_state_t::eLayerOpaque) || (mask & layer_state_t::eLayerHidden) || (mask & layer_state_t::eLayerSecure) || (mask & layer_state_t::eLayerSkipScreenshot)) { (mask & layer_state_t::eLayerSecure) || (mask & layer_state_t::eLayerSkipScreenshot) || (mask & layer_state_t::eEnableBackpressure)) { s->what |= layer_state_t::eFlagsChanged; } s->flags &= ~mask; Loading libs/gui/include/gui/BLASTBufferQueue.h +1 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ private: Rect computeCrop(const BufferItem& item) REQUIRES(mMutex); // Return true if we need to reject the buffer based on the scaling mode and the buffer size. bool rejectBuffer(const BufferItem& item) REQUIRES(mMutex); bool maxBuffersAcquired() const REQUIRES(mMutex); bool maxBuffersAcquired(bool includeExtraAcquire) const REQUIRES(mMutex); std::string mName; sp<SurfaceControl> mSurfaceControl; Loading Loading
libs/gui/BLASTBufferQueue.cpp +36 −15 Original line number Diff line number Diff line Loading @@ -146,6 +146,10 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceCont mTransformHint = mSurfaceControl->getTransformHint(); mBufferItemConsumer->setTransformHint(mTransformHint); SurfaceComposerClient::Transaction() .setFlags(surface, layer_state_t::eEnableBackpressure, layer_state_t::eEnableBackpressure) .apply(); mNumAcquired = 0; mNumFrameAvailable = 0; Loading @@ -169,13 +173,20 @@ BLASTBufferQueue::~BLASTBufferQueue() { void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height, int32_t format) { std::unique_lock _lock{mMutex}; mSurfaceControl = surface; if (mFormat != format) { mFormat = format; mBufferItemConsumer->setDefaultBufferFormat(format); } SurfaceComposerClient::Transaction t; bool applyTransaction = false; if (!SurfaceControl::isSameSurface(mSurfaceControl, surface)) { mSurfaceControl = surface; t.setFlags(mSurfaceControl, layer_state_t::eEnableBackpressure, layer_state_t::eEnableBackpressure); applyTransaction = true; } ui::Size newSize(width, height); if (mRequestedSize != newSize) { mRequestedSize.set(newSize); Loading @@ -184,12 +195,14 @@ void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width, // If the buffer supports scaling, update the frame immediately since the client may // want to scale the existing buffer to the new size. mSize = mRequestedSize; SurfaceComposerClient::Transaction t; t.setFrame(mSurfaceControl, {0, 0, static_cast<int32_t>(mSize.width), static_cast<int32_t>(mSize.height)}); t.apply(); applyTransaction = true; } } if (applyTransaction) { t.apply(); } } Loading Loading @@ -248,7 +261,7 @@ void BLASTBufferQueue::transactionCallback(nsecs_t /*latchTime*/, const sp<Fence mPendingReleaseItem.item = std::move(mSubmitted.front()); mSubmitted.pop(); processNextBufferLocked(false); processNextBufferLocked(false /* useNextTransaction */); currFrameNumber = mPendingReleaseItem.item.mFrameNumber; if (mTransactionCompleteCallback && mTransactionCompleteFrameNumber == currFrameNumber) { Loading @@ -269,9 +282,10 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { ATRACE_CALL(); BQA_LOGV("processNextBufferLocked useNextTransaction=%s", toString(useNextTransaction)); // Wait to acquire a buffer if there are no frames available or we have acquired the max // number of buffers. if (mNumFrameAvailable == 0 || maxBuffersAcquired()) { // If the next transaction is set, we want to guarantee the our acquire will not fail, so don't // include the extra buffer when checking if we can acquire the next buffer. const bool includeExtraAcquire = !useNextTransaction; if (mNumFrameAvailable == 0 || maxBuffersAcquired(includeExtraAcquire)) { BQA_LOGV("processNextBufferLocked waiting for frame available or callback"); mCallbackCV.notify_all(); return; Loading @@ -295,7 +309,10 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { status_t status = mBufferItemConsumer->acquireBuffer(&bufferItem, 0 /* expectedPresent */, false); if (status != OK) { if (status == BufferQueue::NO_BUFFER_AVAILABLE) { BQA_LOGV("Failed to acquire a buffer, err=NO_BUFFER_AVAILABLE"); return; } else if (status != OK) { BQA_LOGE("Failed to acquire a buffer, err=%s", statusToString(status).c_str()); return; } Loading Loading @@ -414,7 +431,7 @@ void BLASTBufferQueue::onFrameAvailable(const BufferItem& item) { item.mFrameNumber, toString(nextTransactionSet), toString(mFlushShadowQueue)); if (nextTransactionSet || mFlushShadowQueue) { while (mNumFrameAvailable > 0 || maxBuffersAcquired()) { while (mNumFrameAvailable > 0 || maxBuffersAcquired(false /* includeExtraAcquire */)) { BQA_LOGV("waiting in onFrameAvailable..."); mCallbackCV.wait(_lock); } Loading @@ -422,7 +439,7 @@ void BLASTBufferQueue::onFrameAvailable(const BufferItem& item) { mFlushShadowQueue = false; // add to shadow queue mNumFrameAvailable++; processNextBufferLocked(true); processNextBufferLocked(nextTransactionSet /* useNextTransaction */); } void BLASTBufferQueue::onFrameReplaced(const BufferItem& item) { Loading Loading @@ -482,9 +499,12 @@ void BLASTBufferQueue::setTransactionCompleteCallback( // Check if we have acquired the maximum number of buffers. // As a special case, we wait for the first callback before acquiring the second buffer so we // can ensure the first buffer is presented if multiple buffers are queued in succession. bool BLASTBufferQueue::maxBuffersAcquired() const { return mNumAcquired == MAX_ACQUIRED_BUFFERS + 1 || (!mInitialCallbackReceived && mNumAcquired == 1); // Consumer can acquire an additional buffer if that buffer is not droppable. Set // includeExtraAcquire is true to include this buffer to the count. Since this depends on the state // of the buffer, the next acquire may return with NO_BUFFER_AVAILABLE. bool BLASTBufferQueue::maxBuffersAcquired(bool includeExtraAcquire) const { int maxAcquiredBuffers = MAX_ACQUIRED_BUFFERS + (includeExtraAcquire ? 2 : 1); return mNumAcquired == maxAcquiredBuffers || (!mInitialCallbackReceived && mNumAcquired == 1); } class BBQSurface : public Surface { Loading Loading @@ -654,7 +674,8 @@ void BLASTBufferQueue::createBufferQueue(sp<IGraphicBufferProducer>* outProducer LOG_ALWAYS_FATAL_IF(producer == nullptr, "BLASTBufferQueue: failed to create BBQBufferQueueProducer"); sp<IGraphicBufferConsumer> consumer(new BufferQueueConsumer(core)); sp<BufferQueueConsumer> consumer(new BufferQueueConsumer(core)); consumer->setAllowExtraAcquire(true); LOG_ALWAYS_FATAL_IF(consumer == nullptr, "BLASTBufferQueue: failed to create BufferQueueConsumer"); Loading
libs/gui/BufferQueueConsumer.cpp +12 −1 Original line number Diff line number Diff line Loading @@ -94,7 +94,10 @@ status_t BufferQueueConsumer::acquireBuffer(BufferItem* outBuffer, ++numAcquiredBuffers; } } if (numAcquiredBuffers >= mCore->mMaxAcquiredBufferCount + 1) { const bool acquireNonDroppableBuffer = mCore->mAllowExtraAcquire && numAcquiredBuffers == mCore->mMaxAcquiredBufferCount + 1; if (numAcquiredBuffers >= mCore->mMaxAcquiredBufferCount + 1 && !acquireNonDroppableBuffer) { BQ_LOGE("acquireBuffer: max acquired buffer count reached: %d (max %d)", numAcquiredBuffers, mCore->mMaxAcquiredBufferCount); return INVALID_OPERATION; Loading Loading @@ -254,6 +257,9 @@ status_t BufferQueueConsumer::acquireBuffer(BufferItem* outBuffer, outBuffer->mIsStale = false; outBuffer->mAutoRefresh = mCore->mSharedBufferMode && mCore->mAutoRefresh; } else if (acquireNonDroppableBuffer && front->mIsDroppable) { BQ_LOGV("acquireBuffer: front buffer is not droppable"); return NO_BUFFER_AVAILABLE; } else { slot = front->mSlot; *outBuffer = *front; Loading Loading @@ -824,4 +830,9 @@ status_t BufferQueueConsumer::dumpState(const String8& prefix, String8* outResul return NO_ERROR; } void BufferQueueConsumer::setAllowExtraAcquire(bool allow) { std::lock_guard<std::mutex> lock(mCore->mMutex); mCore->mAllowExtraAcquire = allow; } } // namespace android
libs/gui/LayerState.cpp +3 −5 Original line number Diff line number Diff line Loading @@ -183,12 +183,9 @@ status_t layer_state_t::read(const Parcel& input) SAFE_PARCEL(input.readUint32, &layerStack); SAFE_PARCEL(input.readFloat, &alpha); uint32_t tmpUint32 = 0; SAFE_PARCEL(input.readUint32, &tmpUint32); flags = static_cast<uint8_t>(tmpUint32); SAFE_PARCEL(input.readUint32, &flags); SAFE_PARCEL(input.readUint32, &tmpUint32); mask = static_cast<uint8_t>(tmpUint32); SAFE_PARCEL(input.readUint32, &mask); SAFE_PARCEL(matrix.read, input); SAFE_PARCEL(input.read, crop_legacy); Loading Loading @@ -229,6 +226,7 @@ status_t layer_state_t::read(const Parcel& input) SAFE_PARCEL(input.read, *acquireFence); } uint32_t tmpUint32 = 0; SAFE_PARCEL(input.readUint32, &tmpUint32); dataspace = static_cast<ui::Dataspace>(tmpUint32); Loading
libs/gui/SurfaceComposerClient.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -929,7 +929,8 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFlags return *this; } if ((mask & layer_state_t::eLayerOpaque) || (mask & layer_state_t::eLayerHidden) || (mask & layer_state_t::eLayerSecure) || (mask & layer_state_t::eLayerSkipScreenshot)) { (mask & layer_state_t::eLayerSecure) || (mask & layer_state_t::eLayerSkipScreenshot) || (mask & layer_state_t::eEnableBackpressure)) { s->what |= layer_state_t::eFlagsChanged; } s->flags &= ~mask; Loading
libs/gui/include/gui/BLASTBufferQueue.h +1 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ private: Rect computeCrop(const BufferItem& item) REQUIRES(mMutex); // Return true if we need to reject the buffer based on the scaling mode and the buffer size. bool rejectBuffer(const BufferItem& item) REQUIRES(mMutex); bool maxBuffersAcquired() const REQUIRES(mMutex); bool maxBuffersAcquired(bool includeExtraAcquire) const REQUIRES(mMutex); std::string mName; sp<SurfaceControl> mSurfaceControl; Loading