Loading libs/gui/BLASTBufferQueue.cpp +35 −8 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define LOG_TAG "BLASTBufferQueue" #define ATRACE_TAG ATRACE_TAG_GRAPHICS // #define LOG_NDEBUG 0 #include <gui/BLASTBufferQueue.h> #include <gui/BufferItemConsumer.h> Loading @@ -29,8 +30,20 @@ using namespace std::chrono_literals; namespace { inline const char* toString(bool b) { return b ? "true" : "false"; } } // namespace namespace android { // Macros to include adapter info in log messages #define BQA_LOGV(x, ...) \ ALOGV("[%s](f:%u,a:%u) " x, mName.c_str(), mNumFrameAvailable, mNumAcquired, ##__VA_ARGS__) #define BQA_LOGE(x, ...) \ ALOGE("[%s](f:%u,a:%u) " x, mName.c_str(), mNumFrameAvailable, mNumAcquired, ##__VA_ARGS__) void BLASTBufferItemConsumer::onDisconnect() { Mutex::Autolock lock(mFrameEventHistoryMutex); mPreviouslyConnected = mCurrentlyConnected; Loading Loading @@ -93,9 +106,10 @@ void BLASTBufferItemConsumer::getConnectionEvents(uint64_t frameNumber, bool* ne if (needsDisconnect != nullptr) *needsDisconnect = disconnect; } BLASTBufferQueue::BLASTBufferQueue(const sp<SurfaceControl>& surface, int width, int height, bool enableTripleBuffering) : mSurfaceControl(surface), BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface, int width, int height, bool enableTripleBuffering) : mName(name), mSurfaceControl(surface), mWidth(width), mHeight(height), mNextTransaction(nullptr) { Loading @@ -110,9 +124,9 @@ BLASTBufferQueue::BLASTBufferQueue(const sp<SurfaceControl>& surface, int width, mBufferItemConsumer = new BLASTBufferItemConsumer(mConsumer, GraphicBuffer::USAGE_HW_COMPOSER, 1, true); static int32_t id = 0; auto name = std::string("BLAST Consumer") + std::to_string(id); auto consumerName = mName + "(BLAST Consumer)" + std::to_string(id); id++; mBufferItemConsumer->setName(String8(name.c_str())); mBufferItemConsumer->setName(String8(consumerName.c_str())); mBufferItemConsumer->setFrameAvailableListener(this); mBufferItemConsumer->setBufferFreedListener(this); mBufferItemConsumer->setDefaultBufferSize(mWidth, mHeight); Loading @@ -127,7 +141,7 @@ BLASTBufferQueue::BLASTBufferQueue(const sp<SurfaceControl>& surface, int width, mPendingReleaseItem.releaseFence = nullptr; } void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, int width, int height) { void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height) { std::unique_lock _lock{mMutex}; mSurfaceControl = surface; Loading @@ -153,6 +167,8 @@ void BLASTBufferQueue::transactionCallback(nsecs_t /*latchTime*/, const sp<Fence std::unique_lock _lock{mMutex}; ATRACE_CALL(); BQA_LOGV("transactionCallback"); if (!stats.empty()) { mTransformHint = stats[0].transformHint; mBufferItemConsumer->setTransformHint(mTransformHint); Loading Loading @@ -195,6 +211,8 @@ void BLASTBufferQueue::transactionCallback(nsecs_t /*latchTime*/, const sp<Fence void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { ATRACE_CALL(); BQA_LOGV("processNextBufferLocked useNextTransaction=%s", toString(useNextTransaction)); if (mNumFrameAvailable == 0 || mNumAcquired == MAX_ACQUIRED_BUFFERS + 1) { return; } Loading Loading @@ -246,7 +264,8 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { bufferItem.mFence ? new Fence(bufferItem.mFence->dup()) : Fence::NO_FENCE); t->addTransactionCompletedCallback(transactionCallbackThunk, static_cast<void*>(this)); t->setFrame(mSurfaceControl, {0, 0, mWidth, mHeight}); t->setFrame(mSurfaceControl, {0, 0, static_cast<int32_t>(mWidth), static_cast<int32_t>(mHeight)}); t->setCrop(mSurfaceControl, computeCrop(bufferItem)); t->setTransform(mSurfaceControl, bufferItem.mTransform); t->setTransformToDisplayInverse(mSurfaceControl, bufferItem.mTransformToDisplayInverse); Loading @@ -255,6 +274,11 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { if (applyTransaction) { t->apply(); } BQA_LOGV("processNextBufferLocked size=%dx%d mFrameNumber=%" PRIu64 " applyTransaction=%s mTimestamp=%" PRId64, mWidth, mHeight, bufferItem.mFrameNumber, toString(applyTransaction), bufferItem.mTimestamp); } Rect BLASTBufferQueue::computeCrop(const BufferItem& item) { Loading @@ -268,7 +292,10 @@ void BLASTBufferQueue::onFrameAvailable(const BufferItem& /*item*/) { ATRACE_CALL(); std::unique_lock _lock{mMutex}; if (mNextTransaction != nullptr) { const bool nextTransactionSet = mNextTransaction != nullptr; BQA_LOGV("onFrameAvailable nextTransactionSet=%s", toString(nextTransactionSet)); if (nextTransactionSet) { while (mNumFrameAvailable > 0 || mNumAcquired == MAX_ACQUIRED_BUFFERS + 1) { mCallbackCV.wait(_lock); } Loading libs/gui/include/gui/BLASTBufferQueue.h +8 −6 Original line number Diff line number Diff line Loading @@ -66,8 +66,8 @@ class BLASTBufferQueue : public ConsumerBase::FrameAvailableListener, public BufferItemConsumer::BufferFreedListener { public: BLASTBufferQueue(const sp<SurfaceControl>& surface, int width, int height, bool enableTripleBuffering = true); BLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface, int width, int height, bool enableTripleBuffering = true); sp<IGraphicBufferProducer> getIGraphicBufferProducer() const { return mProducer; Loading @@ -81,7 +81,7 @@ public: const std::vector<SurfaceControlStats>& stats); void setNextTransaction(SurfaceComposerClient::Transaction *t); void update(const sp<SurfaceControl>& surface, int width, int height); void update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height); virtual ~BLASTBufferQueue() = default; Loading @@ -95,6 +95,7 @@ private: void processNextBufferLocked(bool useNextTransaction) REQUIRES(mMutex); Rect computeCrop(const BufferItem& item); std::string mName; sp<SurfaceControl> mSurfaceControl; std::mutex mMutex; Loading @@ -106,17 +107,18 @@ private: int32_t mNumFrameAvailable GUARDED_BY(mMutex); int32_t mNumAcquired GUARDED_BY(mMutex); struct PendingReleaseItem { BufferItem item; sp<Fence> releaseFence; }; std::queue<const BufferItem> mSubmitted GUARDED_BY(mMutex); // Keep a reference to the currently presented buffer so we can release it when the next buffer // is ready to be presented. PendingReleaseItem mPendingReleaseItem GUARDED_BY(mMutex); int mWidth GUARDED_BY(mMutex); int mHeight GUARDED_BY(mMutex); uint32_t mWidth GUARDED_BY(mMutex); uint32_t mHeight GUARDED_BY(mMutex); uint32_t mTransformHint GUARDED_BY(mMutex); Loading libs/gui/tests/BLASTBufferQueue_test.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ using android::hardware::graphics::common::V1_2::BufferUsage; class BLASTBufferQueueHelper { public: BLASTBufferQueueHelper(const sp<SurfaceControl>& sc, int width, int height) { mBlastBufferQueueAdapter = new BLASTBufferQueue(sc, width, height); mBlastBufferQueueAdapter = new BLASTBufferQueue("TestBLASTBufferQueue", sc, width, height); } void update(const sp<SurfaceControl>& sc, int width, int height) { Loading Loading
libs/gui/BLASTBufferQueue.cpp +35 −8 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define LOG_TAG "BLASTBufferQueue" #define ATRACE_TAG ATRACE_TAG_GRAPHICS // #define LOG_NDEBUG 0 #include <gui/BLASTBufferQueue.h> #include <gui/BufferItemConsumer.h> Loading @@ -29,8 +30,20 @@ using namespace std::chrono_literals; namespace { inline const char* toString(bool b) { return b ? "true" : "false"; } } // namespace namespace android { // Macros to include adapter info in log messages #define BQA_LOGV(x, ...) \ ALOGV("[%s](f:%u,a:%u) " x, mName.c_str(), mNumFrameAvailable, mNumAcquired, ##__VA_ARGS__) #define BQA_LOGE(x, ...) \ ALOGE("[%s](f:%u,a:%u) " x, mName.c_str(), mNumFrameAvailable, mNumAcquired, ##__VA_ARGS__) void BLASTBufferItemConsumer::onDisconnect() { Mutex::Autolock lock(mFrameEventHistoryMutex); mPreviouslyConnected = mCurrentlyConnected; Loading Loading @@ -93,9 +106,10 @@ void BLASTBufferItemConsumer::getConnectionEvents(uint64_t frameNumber, bool* ne if (needsDisconnect != nullptr) *needsDisconnect = disconnect; } BLASTBufferQueue::BLASTBufferQueue(const sp<SurfaceControl>& surface, int width, int height, bool enableTripleBuffering) : mSurfaceControl(surface), BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface, int width, int height, bool enableTripleBuffering) : mName(name), mSurfaceControl(surface), mWidth(width), mHeight(height), mNextTransaction(nullptr) { Loading @@ -110,9 +124,9 @@ BLASTBufferQueue::BLASTBufferQueue(const sp<SurfaceControl>& surface, int width, mBufferItemConsumer = new BLASTBufferItemConsumer(mConsumer, GraphicBuffer::USAGE_HW_COMPOSER, 1, true); static int32_t id = 0; auto name = std::string("BLAST Consumer") + std::to_string(id); auto consumerName = mName + "(BLAST Consumer)" + std::to_string(id); id++; mBufferItemConsumer->setName(String8(name.c_str())); mBufferItemConsumer->setName(String8(consumerName.c_str())); mBufferItemConsumer->setFrameAvailableListener(this); mBufferItemConsumer->setBufferFreedListener(this); mBufferItemConsumer->setDefaultBufferSize(mWidth, mHeight); Loading @@ -127,7 +141,7 @@ BLASTBufferQueue::BLASTBufferQueue(const sp<SurfaceControl>& surface, int width, mPendingReleaseItem.releaseFence = nullptr; } void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, int width, int height) { void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height) { std::unique_lock _lock{mMutex}; mSurfaceControl = surface; Loading @@ -153,6 +167,8 @@ void BLASTBufferQueue::transactionCallback(nsecs_t /*latchTime*/, const sp<Fence std::unique_lock _lock{mMutex}; ATRACE_CALL(); BQA_LOGV("transactionCallback"); if (!stats.empty()) { mTransformHint = stats[0].transformHint; mBufferItemConsumer->setTransformHint(mTransformHint); Loading Loading @@ -195,6 +211,8 @@ void BLASTBufferQueue::transactionCallback(nsecs_t /*latchTime*/, const sp<Fence void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { ATRACE_CALL(); BQA_LOGV("processNextBufferLocked useNextTransaction=%s", toString(useNextTransaction)); if (mNumFrameAvailable == 0 || mNumAcquired == MAX_ACQUIRED_BUFFERS + 1) { return; } Loading Loading @@ -246,7 +264,8 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { bufferItem.mFence ? new Fence(bufferItem.mFence->dup()) : Fence::NO_FENCE); t->addTransactionCompletedCallback(transactionCallbackThunk, static_cast<void*>(this)); t->setFrame(mSurfaceControl, {0, 0, mWidth, mHeight}); t->setFrame(mSurfaceControl, {0, 0, static_cast<int32_t>(mWidth), static_cast<int32_t>(mHeight)}); t->setCrop(mSurfaceControl, computeCrop(bufferItem)); t->setTransform(mSurfaceControl, bufferItem.mTransform); t->setTransformToDisplayInverse(mSurfaceControl, bufferItem.mTransformToDisplayInverse); Loading @@ -255,6 +274,11 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { if (applyTransaction) { t->apply(); } BQA_LOGV("processNextBufferLocked size=%dx%d mFrameNumber=%" PRIu64 " applyTransaction=%s mTimestamp=%" PRId64, mWidth, mHeight, bufferItem.mFrameNumber, toString(applyTransaction), bufferItem.mTimestamp); } Rect BLASTBufferQueue::computeCrop(const BufferItem& item) { Loading @@ -268,7 +292,10 @@ void BLASTBufferQueue::onFrameAvailable(const BufferItem& /*item*/) { ATRACE_CALL(); std::unique_lock _lock{mMutex}; if (mNextTransaction != nullptr) { const bool nextTransactionSet = mNextTransaction != nullptr; BQA_LOGV("onFrameAvailable nextTransactionSet=%s", toString(nextTransactionSet)); if (nextTransactionSet) { while (mNumFrameAvailable > 0 || mNumAcquired == MAX_ACQUIRED_BUFFERS + 1) { mCallbackCV.wait(_lock); } Loading
libs/gui/include/gui/BLASTBufferQueue.h +8 −6 Original line number Diff line number Diff line Loading @@ -66,8 +66,8 @@ class BLASTBufferQueue : public ConsumerBase::FrameAvailableListener, public BufferItemConsumer::BufferFreedListener { public: BLASTBufferQueue(const sp<SurfaceControl>& surface, int width, int height, bool enableTripleBuffering = true); BLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface, int width, int height, bool enableTripleBuffering = true); sp<IGraphicBufferProducer> getIGraphicBufferProducer() const { return mProducer; Loading @@ -81,7 +81,7 @@ public: const std::vector<SurfaceControlStats>& stats); void setNextTransaction(SurfaceComposerClient::Transaction *t); void update(const sp<SurfaceControl>& surface, int width, int height); void update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height); virtual ~BLASTBufferQueue() = default; Loading @@ -95,6 +95,7 @@ private: void processNextBufferLocked(bool useNextTransaction) REQUIRES(mMutex); Rect computeCrop(const BufferItem& item); std::string mName; sp<SurfaceControl> mSurfaceControl; std::mutex mMutex; Loading @@ -106,17 +107,18 @@ private: int32_t mNumFrameAvailable GUARDED_BY(mMutex); int32_t mNumAcquired GUARDED_BY(mMutex); struct PendingReleaseItem { BufferItem item; sp<Fence> releaseFence; }; std::queue<const BufferItem> mSubmitted GUARDED_BY(mMutex); // Keep a reference to the currently presented buffer so we can release it when the next buffer // is ready to be presented. PendingReleaseItem mPendingReleaseItem GUARDED_BY(mMutex); int mWidth GUARDED_BY(mMutex); int mHeight GUARDED_BY(mMutex); uint32_t mWidth GUARDED_BY(mMutex); uint32_t mHeight GUARDED_BY(mMutex); uint32_t mTransformHint GUARDED_BY(mMutex); Loading
libs/gui/tests/BLASTBufferQueue_test.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ using android::hardware::graphics::common::V1_2::BufferUsage; class BLASTBufferQueueHelper { public: BLASTBufferQueueHelper(const sp<SurfaceControl>& sc, int width, int height) { mBlastBufferQueueAdapter = new BLASTBufferQueue(sc, width, height); mBlastBufferQueueAdapter = new BLASTBufferQueue("TestBLASTBufferQueue", sc, width, height); } void update(const sp<SurfaceControl>& sc, int width, int height) { Loading