From 30fd9b9919ae4fbf32d5820c615039dc1a2881d3 Mon Sep 17 00:00:00 2001 From: chaviw Date: Fri, 22 Apr 2022 12:41:17 -0500 Subject: Send transaction callbacks even when no BSL The current transaction callback logic only accounts for 2 cases: 1. If there's a BSL in the transaction 2. If there are no layers in the transaction However, this doesn't account for cases where there's other layer types in the transaction that are not BSL. In those cases, we fail to invoke the transaction callbacks. Test: LayerCallbackTest Fixes: 229578553 Change-Id: I7483235617218a759bc9b1ea335e9fef80275728 --- services/surfaceflinger/Layer.cpp | 12 ++ services/surfaceflinger/Layer.h | 4 +- .../surfaceflinger/tests/LayerCallback_test.cpp | 121 ++++++++++++++++++--- 3 files changed, 119 insertions(+), 18 deletions(-) diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index d8a5601b8a..3a92ca49a2 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -2664,6 +2664,18 @@ void Layer::cloneDrawingState(const Layer* from) { mDrawingState.callbackHandles = {}; } +bool Layer::setTransactionCompletedListeners(const std::vector>& handles) { + if (handles.empty()) { + return false; + } + + for (const auto& handle : handles) { + mFlinger->getTransactionCallbackInvoker().registerUnpresentedCallbackHandle(handle); + } + + return true; +} + // --------------------------------------------------------------------------- std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate) { diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 565a6ff726..ecea74413c 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -431,9 +431,7 @@ public: virtual bool setApi(int32_t /*api*/) { return false; }; virtual bool setSidebandStream(const sp& /*sidebandStream*/) { return false; }; virtual bool setTransactionCompletedListeners( - const std::vector>& /*handles*/) { - return false; - }; + const std::vector>& /*handles*/); virtual bool addFrameEvent(const sp& /*acquireFence*/, nsecs_t /*postedTime*/, nsecs_t /*requestedPresentTime*/) { return false; diff --git a/services/surfaceflinger/tests/LayerCallback_test.cpp b/services/surfaceflinger/tests/LayerCallback_test.cpp index 8a2305b365..219db8c148 100644 --- a/services/surfaceflinger/tests/LayerCallback_test.cpp +++ b/services/surfaceflinger/tests/LayerCallback_test.cpp @@ -55,24 +55,34 @@ public: return createLayer(mClient, "test", 0, 0, ISurfaceComposerClient::eFXSurfaceBufferState); } + static int fillBuffer(Transaction& transaction, const sp& layer, + bool setBuffer = true, bool setBackgroundColor = false) { + sp buffer; + sp fence; + if (setBuffer) { + int err = getBuffer(&buffer, &fence); + if (err != NO_ERROR) { + return err; + } + + transaction.setBuffer(layer, buffer, fence); + } + + if (setBackgroundColor) { + transaction.setBackgroundColor(layer, /*color*/ half3(1.0f, 0, 0), /*alpha*/ 1.0f, + ui::Dataspace::UNKNOWN); + } + + return NO_ERROR; + } + static int fillTransaction(Transaction& transaction, CallbackHelper* callbackHelper, const sp& layer = nullptr, bool setBuffer = true, bool setBackgroundColor = false) { if (layer) { - sp buffer; - sp fence; - if (setBuffer) { - int err = getBuffer(&buffer, &fence); - if (err != NO_ERROR) { - return err; - } - - transaction.setBuffer(layer, buffer, fence); - } - - if (setBackgroundColor) { - transaction.setBackgroundColor(layer, /*color*/ half3(1.0f, 0, 0), /*alpha*/ 1.0f, - ui::Dataspace::UNKNOWN); + int err = fillBuffer(transaction, layer, setBuffer, setBackgroundColor); + if (err != NO_ERROR) { + return err; } } @@ -1115,7 +1125,7 @@ TEST_F(LayerCallbackTest, CommitCallbackOffscreenLayer) { Transaction transaction; CallbackHelper callback; int err = fillTransaction(transaction, &callback, layer, true); - err |= fillTransaction(transaction, &callback, offscreenLayer, true); + err |= fillBuffer(transaction, offscreenLayer); if (err) { GTEST_SUCCEED() << "test not supported"; return; @@ -1129,5 +1139,86 @@ TEST_F(LayerCallbackTest, CommitCallbackOffscreenLayer) { committedSc.insert(layer); committedSc.insert(offscreenLayer); EXPECT_NO_FATAL_FAILURE(waitForCommitCallback(callback, committedSc)); + + ExpectedResult expected; + expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); + expected.addSurface(ExpectedResult::Transaction::PRESENTED, offscreenLayer); + EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); } + +TEST_F(LayerCallbackTest, TransactionCommittedCallback_BSL) { + sp layer; + ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); + + Transaction transaction; + CallbackHelper callback; + int err = fillTransaction(transaction, &callback, layer, true); + if (err) { + GTEST_SUCCEED() << "test not supported"; + return; + } + transaction.addTransactionCommittedCallback(callback.function, callback.getContext()).apply(); + std::unordered_set, SCHash> committedSc; + committedSc.insert(layer); + EXPECT_NO_FATAL_FAILURE(waitForCommitCallback(callback, committedSc)); + ExpectedResult expected; + expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); + EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); +} + +TEST_F(LayerCallbackTest, TransactionCommittedCallback_EffectLayer) { + sp layer; + ASSERT_NO_FATAL_FAILURE(layer = createColorLayer("ColorLayer", Color::RED)); + + Transaction transaction; + CallbackHelper callback; + int err = fillTransaction(transaction, &callback); + if (err) { + GTEST_SUCCEED() << "test not supported"; + return; + } + transaction.addTransactionCommittedCallback(callback.function, callback.getContext()).apply(); + std::unordered_set, SCHash> committedSc; + EXPECT_NO_FATAL_FAILURE(waitForCommitCallback(callback, committedSc)); + + ExpectedResult expected; + EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); +} + +TEST_F(LayerCallbackTest, TransactionCommittedCallback_ContainerLayer) { + sp layer; + ASSERT_NO_FATAL_FAILURE(layer = createLayer(mClient, "Container Layer", 0, 0, + ISurfaceComposerClient::eFXSurfaceContainer)); + + Transaction transaction; + CallbackHelper callback; + int err = fillTransaction(transaction, &callback); + if (err) { + GTEST_SUCCEED() << "test not supported"; + return; + } + transaction.addTransactionCommittedCallback(callback.function, callback.getContext()).apply(); + std::unordered_set, SCHash> committedSc; + EXPECT_NO_FATAL_FAILURE(waitForCommitCallback(callback, committedSc)); + + ExpectedResult expected; + EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); +} + +TEST_F(LayerCallbackTest, TransactionCommittedCallback_NoLayer) { + Transaction transaction; + CallbackHelper callback; + int err = fillTransaction(transaction, &callback); + if (err) { + GTEST_SUCCEED() << "test not supported"; + return; + } + transaction.addTransactionCommittedCallback(callback.function, callback.getContext()).apply(); + std::unordered_set, SCHash> committedSc; + EXPECT_NO_FATAL_FAILURE(waitForCommitCallback(callback, committedSc)); + + ExpectedResult expected; + EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); +} + } // namespace android -- cgit v1.2.3-59-g8ed1b