Loading services/surfaceflinger/Layer.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -2664,6 +2664,18 @@ void Layer::cloneDrawingState(const Layer* from) { mDrawingState.callbackHandles = {}; } bool Layer::setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& 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) { Loading services/surfaceflinger/Layer.h +1 −3 Original line number Diff line number Diff line Loading @@ -431,9 +431,7 @@ public: virtual bool setApi(int32_t /*api*/) { return false; }; virtual bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/) { return false; }; virtual bool setTransactionCompletedListeners( const std::vector<sp<CallbackHandle>>& /*handles*/) { return false; }; const std::vector<sp<CallbackHandle>>& /*handles*/); virtual bool addFrameEvent(const sp<Fence>& /*acquireFence*/, nsecs_t /*postedTime*/, nsecs_t /*requestedPresentTime*/) { return false; Loading services/surfaceflinger/tests/LayerCallback_test.cpp +106 −15 Original line number Diff line number Diff line Loading @@ -55,10 +55,8 @@ public: return createLayer(mClient, "test", 0, 0, ISurfaceComposerClient::eFXSurfaceBufferState); } static int fillTransaction(Transaction& transaction, CallbackHelper* callbackHelper, const sp<SurfaceControl>& layer = nullptr, bool setBuffer = true, bool setBackgroundColor = false) { if (layer) { static int fillBuffer(Transaction& transaction, const sp<SurfaceControl>& layer, bool setBuffer = true, bool setBackgroundColor = false) { sp<GraphicBuffer> buffer; sp<Fence> fence; if (setBuffer) { Loading @@ -74,6 +72,18 @@ public: 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<SurfaceControl>& layer = nullptr, bool setBuffer = true, bool setBackgroundColor = false) { if (layer) { int err = fillBuffer(transaction, layer, setBuffer, setBackgroundColor); if (err != NO_ERROR) { return err; } } transaction.addTransactionCompletedCallback(callbackHelper->function, Loading Loading @@ -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; Loading @@ -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<SurfaceControl> 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<sp<SurfaceControl>, 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<SurfaceControl> 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<sp<SurfaceControl>, 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<SurfaceControl> 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<sp<SurfaceControl>, 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<sp<SurfaceControl>, SCHash> committedSc; EXPECT_NO_FATAL_FAILURE(waitForCommitCallback(callback, committedSc)); ExpectedResult expected; EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); } } // namespace android Loading
services/surfaceflinger/Layer.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -2664,6 +2664,18 @@ void Layer::cloneDrawingState(const Layer* from) { mDrawingState.callbackHandles = {}; } bool Layer::setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& 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) { Loading
services/surfaceflinger/Layer.h +1 −3 Original line number Diff line number Diff line Loading @@ -431,9 +431,7 @@ public: virtual bool setApi(int32_t /*api*/) { return false; }; virtual bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/) { return false; }; virtual bool setTransactionCompletedListeners( const std::vector<sp<CallbackHandle>>& /*handles*/) { return false; }; const std::vector<sp<CallbackHandle>>& /*handles*/); virtual bool addFrameEvent(const sp<Fence>& /*acquireFence*/, nsecs_t /*postedTime*/, nsecs_t /*requestedPresentTime*/) { return false; Loading
services/surfaceflinger/tests/LayerCallback_test.cpp +106 −15 Original line number Diff line number Diff line Loading @@ -55,10 +55,8 @@ public: return createLayer(mClient, "test", 0, 0, ISurfaceComposerClient::eFXSurfaceBufferState); } static int fillTransaction(Transaction& transaction, CallbackHelper* callbackHelper, const sp<SurfaceControl>& layer = nullptr, bool setBuffer = true, bool setBackgroundColor = false) { if (layer) { static int fillBuffer(Transaction& transaction, const sp<SurfaceControl>& layer, bool setBuffer = true, bool setBackgroundColor = false) { sp<GraphicBuffer> buffer; sp<Fence> fence; if (setBuffer) { Loading @@ -74,6 +72,18 @@ public: 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<SurfaceControl>& layer = nullptr, bool setBuffer = true, bool setBackgroundColor = false) { if (layer) { int err = fillBuffer(transaction, layer, setBuffer, setBackgroundColor); if (err != NO_ERROR) { return err; } } transaction.addTransactionCompletedCallback(callbackHelper->function, Loading Loading @@ -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; Loading @@ -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<SurfaceControl> 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<sp<SurfaceControl>, 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<SurfaceControl> 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<sp<SurfaceControl>, 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<SurfaceControl> 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<sp<SurfaceControl>, 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<sp<SurfaceControl>, SCHash> committedSc; EXPECT_NO_FATAL_FAILURE(waitForCommitCallback(callback, committedSc)); ExpectedResult expected; EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); } } // namespace android