Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 18 | #undef LOG_TAG |
| 19 | #define LOG_TAG "CompositionTest" |
| 20 | |
| 21 | #include <compositionengine/Display.h> |
| 22 | #include <compositionengine/mock/DisplaySurface.h> |
| 23 | #include <gmock/gmock.h> |
| 24 | #include <gtest/gtest.h> |
| 25 | #include <gui/SurfaceComposerClient.h> |
| 26 | #include <log/log.h> |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 27 | #include <ui/MockFence.h> |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 28 | #include <utils/String8.h> |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 29 | |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 30 | #include "TestableSurfaceFlinger.h" |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 31 | #include "mock/MockEventThread.h" |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 32 | #include "mock/MockVsyncController.h" |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 33 | |
| 34 | namespace android { |
| 35 | |
| 36 | using testing::_; |
| 37 | using testing::Return; |
| 38 | |
| 39 | using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; |
| 40 | |
| 41 | class TransactionApplicationTest : public testing::Test { |
| 42 | public: |
| 43 | TransactionApplicationTest() { |
| 44 | const ::testing::TestInfo* const test_info = |
| 45 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 46 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 47 | |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 48 | setupScheduler(); |
| 49 | } |
| 50 | |
| 51 | ~TransactionApplicationTest() { |
| 52 | const ::testing::TestInfo* const test_info = |
| 53 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 54 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 55 | } |
| 56 | |
| 57 | void setupScheduler() { |
| 58 | auto eventThread = std::make_unique<mock::EventThread>(); |
| 59 | auto sfEventThread = std::make_unique<mock::EventThread>(); |
| 60 | |
| 61 | EXPECT_CALL(*eventThread, registerDisplayEventConnection(_)); |
| 62 | EXPECT_CALL(*eventThread, createEventConnection(_, _)) |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 63 | .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0, |
| 64 | ResyncCallback()))); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 65 | |
| 66 | EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_)); |
| 67 | EXPECT_CALL(*sfEventThread, createEventConnection(_, _)) |
Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 68 | .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0, |
| 69 | ResyncCallback()))); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 70 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 71 | EXPECT_CALL(*mVSyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); |
| 72 | EXPECT_CALL(*mVSyncTracker, currentPeriod()) |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 73 | .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD)); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 74 | |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 75 | EXPECT_CALL(*mFenceUnsignaled, getStatus()) |
| 76 | .WillRepeatedly(Return(Fence::Status::Unsignaled)); |
| 77 | EXPECT_CALL(*mFenceUnsignaled2, getStatus()) |
| 78 | .WillRepeatedly(Return(Fence::Status::Unsignaled)); |
| 79 | EXPECT_CALL(*mFenceSignaled, getStatus()).WillRepeatedly(Return(Fence::Status::Signaled)); |
| 80 | EXPECT_CALL(*mFenceSignaled2, getStatus()).WillRepeatedly(Return(Fence::Status::Signaled)); |
| 81 | |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 82 | mFlinger.setupComposer(std::make_unique<Hwc2::mock::Composer>()); |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 83 | mFlinger.setupScheduler(std::unique_ptr<mock::VsyncController>(mVsyncController), |
| 84 | std::unique_ptr<mock::VSyncTracker>(mVSyncTracker), |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 85 | std::move(eventThread), std::move(sfEventThread)); |
| 86 | } |
| 87 | |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 88 | TestableSurfaceFlinger mFlinger; |
| 89 | |
Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 90 | mock::VsyncController* mVsyncController = new mock::VsyncController(); |
| 91 | mock::VSyncTracker* mVSyncTracker = new mock::VSyncTracker(); |
Ady Abraham | 853c6df | 2022-02-03 12:04:23 -0800 | [diff] [blame] | 92 | sp<mock::MockFence> mFenceUnsignaled = sp<mock::MockFence>::make(); |
| 93 | sp<mock::MockFence> mFenceSignaled = sp<mock::MockFence>::make(); |
| 94 | sp<mock::MockFence> mFenceUnsignaled2 = sp<mock::MockFence>::make(); |
| 95 | sp<mock::MockFence> mFenceSignaled2 = sp<mock::MockFence>::make(); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 96 | |
| 97 | struct TransactionInfo { |
| 98 | Vector<ComposerState> states; |
| 99 | Vector<DisplayState> displays; |
| 100 | uint32_t flags = 0; |
| 101 | sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance()); |
| 102 | InputWindowCommands inputWindowCommands; |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 103 | int64_t desiredPresentTime = 0; |
| 104 | bool isAutoTimestamp = true; |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 105 | FrameTimelineInfo frameTimelineInfo; |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 106 | client_cache_t uncacheBuffer; |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 107 | uint64_t id = static_cast<uint64_t>(-1); |
| 108 | static_assert(0xffffffffffffffff == static_cast<uint64_t>(-1)); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 111 | void checkEqual(TransactionInfo info, TransactionState state) { |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 112 | EXPECT_EQ(0u, info.states.size()); |
| 113 | EXPECT_EQ(0u, state.states.size()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 114 | |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 115 | EXPECT_EQ(0u, info.displays.size()); |
| 116 | EXPECT_EQ(0u, state.displays.size()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 117 | EXPECT_EQ(info.flags, state.flags); |
| 118 | EXPECT_EQ(info.desiredPresentTime, state.desiredPresentTime); |
| 119 | } |
| 120 | |
| 121 | void setupSingle(TransactionInfo& transaction, uint32_t flags, bool syncInputWindows, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 122 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 123 | const FrameTimelineInfo& frameTimelineInfo) { |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 124 | mTransactionNumber++; |
| 125 | transaction.flags |= flags; // ISurfaceComposer::eSynchronous; |
| 126 | transaction.inputWindowCommands.syncInputWindows = syncInputWindows; |
| 127 | transaction.desiredPresentTime = desiredPresentTime; |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 128 | transaction.isAutoTimestamp = isAutoTimestamp; |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 129 | transaction.frameTimelineInfo = frameTimelineInfo; |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 130 | } |
| 131 | |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 132 | void setupSingleWithComposer(TransactionInfo& transaction, uint32_t flags, |
| 133 | bool syncInputWindows, int64_t desiredPresentTime, |
| 134 | bool isAutoTimestamp, const FrameTimelineInfo& frameTimelineInfo, |
| 135 | const Vector<ComposerState>* states) { |
| 136 | setupSingle(transaction, flags, syncInputWindows, desiredPresentTime, isAutoTimestamp, |
| 137 | frameTimelineInfo); |
| 138 | transaction.states = *states; |
| 139 | } |
| 140 | |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 141 | void NotPlacedOnTransactionQueue(uint32_t flags, bool syncInputWindows) { |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 142 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 143 | EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 144 | TransactionInfo transaction; |
| 145 | setupSingle(transaction, flags, syncInputWindows, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 146 | /*desiredPresentTime*/ systemTime(), /*isAutoTimestamp*/ true, |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 147 | FrameTimelineInfo{}); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 148 | nsecs_t applicationTime = systemTime(); |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 149 | mFlinger.setTransactionState(transaction.frameTimelineInfo, transaction.states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 150 | transaction.displays, transaction.flags, |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 151 | transaction.applyToken, transaction.inputWindowCommands, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 152 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
| 153 | transaction.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 154 | transaction.id); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 155 | |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 156 | // If transaction is synchronous or syncs input windows, SF |
| 157 | // applyTransactionState should time out (5s) wating for SF to commit |
| 158 | // the transaction or to receive a signal that syncInputWindows has |
| 159 | // completed. If this is animation, it should not time out waiting. |
| 160 | nsecs_t returnedTime = systemTime(); |
| 161 | if (flags & ISurfaceComposer::eSynchronous || syncInputWindows) { |
Ady Abraham | e9ebce0 | 2022-02-03 12:05:06 -0800 | [diff] [blame^] | 162 | EXPECT_GE(returnedTime, applicationTime + mFlinger.getAnimationTransactionTimeout()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 163 | } else { |
Ady Abraham | e9ebce0 | 2022-02-03 12:05:06 -0800 | [diff] [blame^] | 164 | EXPECT_LE(returnedTime, applicationTime + mFlinger.getAnimationTransactionTimeout()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 165 | } |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 166 | // Each transaction should have been placed on the transaction queue |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 167 | auto transactionQueue = mFlinger.getTransactionQueue(); |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 168 | EXPECT_EQ(1u, transactionQueue.size()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void PlaceOnTransactionQueue(uint32_t flags, bool syncInputWindows) { |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 172 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 173 | EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 174 | |
| 175 | // first check will see desired present time has not passed, |
| 176 | // but afterwards it will look like the desired present time has passed |
| 177 | nsecs_t time = systemTime(); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 178 | TransactionInfo transaction; |
| 179 | setupSingle(transaction, flags, syncInputWindows, |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 180 | /*desiredPresentTime*/ time + s2ns(1), false, FrameTimelineInfo{}); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 181 | nsecs_t applicationSentTime = systemTime(); |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 182 | mFlinger.setTransactionState(transaction.frameTimelineInfo, transaction.states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 183 | transaction.displays, transaction.flags, |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 184 | transaction.applyToken, transaction.inputWindowCommands, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 185 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
| 186 | transaction.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 187 | transaction.id); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 188 | |
| 189 | nsecs_t returnedTime = systemTime(); |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 190 | if ((flags & ISurfaceComposer::eSynchronous) || syncInputWindows) { |
Ady Abraham | e9ebce0 | 2022-02-03 12:05:06 -0800 | [diff] [blame^] | 191 | EXPECT_GE(systemTime(), |
| 192 | applicationSentTime + mFlinger.getAnimationTransactionTimeout()); |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 193 | } else { |
Ady Abraham | e9ebce0 | 2022-02-03 12:05:06 -0800 | [diff] [blame^] | 194 | EXPECT_LE(returnedTime, |
| 195 | applicationSentTime + mFlinger.getAnimationTransactionTimeout()); |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 196 | } |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 197 | // This transaction should have been placed on the transaction queue |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 198 | auto transactionQueue = mFlinger.getTransactionQueue(); |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 199 | EXPECT_EQ(1u, transactionQueue.size()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void BlockedByPriorTransaction(uint32_t flags, bool syncInputWindows) { |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 203 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 204 | nsecs_t time = systemTime(); |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 205 | if (!syncInputWindows) { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 206 | EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(2); |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 207 | } else { |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 208 | EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1); |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 209 | } |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 210 | // transaction that should go on the pending thread |
| 211 | TransactionInfo transactionA; |
| 212 | setupSingle(transactionA, /*flags*/ 0, /*syncInputWindows*/ false, |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 213 | /*desiredPresentTime*/ time + s2ns(1), false, FrameTimelineInfo{}); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 214 | |
| 215 | // transaction that would not have gone on the pending thread if not |
| 216 | // blocked |
| 217 | TransactionInfo transactionB; |
| 218 | setupSingle(transactionB, flags, syncInputWindows, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 219 | /*desiredPresentTime*/ systemTime(), /*isAutoTimestamp*/ true, |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 220 | FrameTimelineInfo{}); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 221 | |
| 222 | nsecs_t applicationSentTime = systemTime(); |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 223 | mFlinger.setTransactionState(transactionA.frameTimelineInfo, transactionA.states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 224 | transactionA.displays, transactionA.flags, |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 225 | transactionA.applyToken, transactionA.inputWindowCommands, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 226 | transactionA.desiredPresentTime, transactionA.isAutoTimestamp, |
| 227 | transactionA.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 228 | transactionA.id); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 229 | |
| 230 | // This thread should not have been blocked by the above transaction |
| 231 | // (5s is the timeout period that applyTransactionState waits for SF to |
| 232 | // commit the transaction) |
Ady Abraham | e9ebce0 | 2022-02-03 12:05:06 -0800 | [diff] [blame^] | 233 | EXPECT_LE(systemTime(), applicationSentTime + mFlinger.getAnimationTransactionTimeout()); |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 234 | // transaction that would goes to pending transaciton queue. |
| 235 | mFlinger.flushTransactionQueues(); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 236 | |
| 237 | applicationSentTime = systemTime(); |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 238 | mFlinger.setTransactionState(transactionB.frameTimelineInfo, transactionB.states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 239 | transactionB.displays, transactionB.flags, |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 240 | transactionB.applyToken, transactionB.inputWindowCommands, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 241 | transactionB.desiredPresentTime, transactionB.isAutoTimestamp, |
| 242 | transactionB.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 243 | transactionB.id); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 244 | |
| 245 | // this thread should have been blocked by the above transaction |
| 246 | // if this is an animation, this thread should be blocked for 5s |
| 247 | // in setTransactionState waiting for transactionA to flush. Otherwise, |
| 248 | // the transaction should be placed on the pending queue |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 249 | if (flags & (ISurfaceComposer::eAnimation | ISurfaceComposer::eSynchronous) || |
| 250 | syncInputWindows) { |
Ady Abraham | e9ebce0 | 2022-02-03 12:05:06 -0800 | [diff] [blame^] | 251 | EXPECT_GE(systemTime(), |
| 252 | applicationSentTime + mFlinger.getAnimationTransactionTimeout()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 253 | } else { |
Ady Abraham | e9ebce0 | 2022-02-03 12:05:06 -0800 | [diff] [blame^] | 254 | EXPECT_LE(systemTime(), |
| 255 | applicationSentTime + mFlinger.getAnimationTransactionTimeout()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 258 | // transaction that would goes to pending transaciton queue. |
| 259 | mFlinger.flushTransactionQueues(); |
| 260 | |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 261 | // check that the transaction was applied. |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 262 | auto transactionQueue = mFlinger.getPendingTransactionQueue(); |
Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 263 | EXPECT_EQ(0u, transactionQueue.size()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 264 | } |
| 265 | |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 266 | void Flush_removesUnsignaledFromTheQueue(Vector<ComposerState> state1, |
| 267 | Vector<ComposerState> state2, |
| 268 | bool updateApplyToken = true) { |
| 269 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); |
| 270 | |
| 271 | TransactionInfo transactionA; |
| 272 | setupSingleWithComposer(transactionA, ISurfaceComposer::eSynchronous, |
| 273 | /*syncInputWindows*/ false, |
| 274 | /*desiredPresentTime*/ systemTime(), /*isAutoTimestamp*/ true, |
| 275 | FrameTimelineInfo{}, &state1); |
| 276 | |
| 277 | mFlinger.setTransactionState(transactionA.frameTimelineInfo, transactionA.states, |
| 278 | transactionA.displays, transactionA.flags, |
| 279 | transactionA.applyToken, transactionA.inputWindowCommands, |
| 280 | transactionA.desiredPresentTime, transactionA.isAutoTimestamp, |
| 281 | transactionA.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 282 | transactionA.id); |
| 283 | |
| 284 | TransactionInfo transactionB; |
| 285 | if (updateApplyToken) { |
| 286 | transactionB.applyToken = sp<IBinder>(); |
| 287 | } |
| 288 | setupSingleWithComposer(transactionB, ISurfaceComposer::eSynchronous, |
| 289 | /*syncInputWindows*/ false, |
| 290 | /*desiredPresentTime*/ systemTime(), /*isAutoTimestamp*/ true, |
| 291 | FrameTimelineInfo{}, &state2); |
| 292 | mFlinger.setTransactionState(transactionB.frameTimelineInfo, transactionB.states, |
| 293 | transactionB.displays, transactionB.flags, |
| 294 | transactionB.applyToken, transactionB.inputWindowCommands, |
| 295 | transactionB.desiredPresentTime, transactionB.isAutoTimestamp, |
| 296 | transactionB.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 297 | transactionB.id); |
| 298 | |
| 299 | mFlinger.flushTransactionQueues(); |
| 300 | EXPECT_EQ(0u, mFlinger.getPendingTransactionQueue().size()); |
| 301 | EXPECT_EQ(0u, mFlinger.getTransactionQueue().size()); |
| 302 | EXPECT_EQ(2ul, mFlinger.getTransactionCommittedSignals().size()); |
| 303 | } |
| 304 | |
| 305 | void Flush_removesFromTheQueue(const Vector<ComposerState>& state) { |
| 306 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); |
| 307 | EXPECT_EQ(0u, mFlinger.getPendingTransactionQueue().size()); |
| 308 | |
| 309 | TransactionInfo transaction; |
| 310 | setupSingleWithComposer(transaction, ISurfaceComposer::eSynchronous, |
| 311 | /*syncInputWindows*/ false, |
| 312 | /*desiredPresentTime*/ systemTime(), /*isAutoTimestamp*/ true, |
| 313 | FrameTimelineInfo{}, &state); |
| 314 | |
| 315 | mFlinger.setTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 316 | transaction.displays, transaction.flags, |
| 317 | transaction.applyToken, transaction.inputWindowCommands, |
| 318 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
| 319 | transaction.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 320 | transaction.id); |
| 321 | |
| 322 | mFlinger.flushTransactionQueues(); |
| 323 | EXPECT_EQ(0u, mFlinger.getPendingTransactionQueue().size()); |
| 324 | EXPECT_EQ(0u, mFlinger.getTransactionQueue().size()); |
| 325 | EXPECT_EQ(1u, mFlinger.getTransactionCommittedSignals().size()); |
| 326 | } |
| 327 | |
| 328 | void Flush_keepsInTheQueue(const Vector<ComposerState>& state) { |
| 329 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); |
| 330 | EXPECT_EQ(0u, mFlinger.getPendingTransactionQueue().size()); |
| 331 | |
| 332 | TransactionInfo transaction; |
| 333 | setupSingleWithComposer(transaction, ISurfaceComposer::eSynchronous, |
| 334 | /*syncInputWindows*/ false, |
| 335 | /*desiredPresentTime*/ systemTime(), /*isAutoTimestamp*/ true, |
| 336 | FrameTimelineInfo{}, &state); |
| 337 | |
| 338 | mFlinger.setTransactionState(transaction.frameTimelineInfo, transaction.states, |
| 339 | transaction.displays, transaction.flags, |
| 340 | transaction.applyToken, transaction.inputWindowCommands, |
| 341 | transaction.desiredPresentTime, transaction.isAutoTimestamp, |
| 342 | transaction.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 343 | transaction.id); |
| 344 | |
| 345 | mFlinger.flushTransactionQueues(); |
| 346 | EXPECT_EQ(1u, mFlinger.getPendingTransactionQueue().size()); |
| 347 | EXPECT_EQ(0u, mFlinger.getTransactionQueue().size()); |
| 348 | EXPECT_EQ(0ul, mFlinger.getTransactionCommittedSignals().size()); |
| 349 | } |
| 350 | |
| 351 | void Flush_KeepsUnsignaledInTheQueue(const Vector<ComposerState>& state1, |
| 352 | const Vector<ComposerState>& state2, |
| 353 | bool updateApplyToken = true, |
| 354 | uint32_t pendingTransactionQueueSize = 1u) { |
| 355 | EXPECT_EQ(0u, mFlinger.getPendingTransactionQueue().size()); |
| 356 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); |
| 357 | auto time = systemTime(); |
| 358 | TransactionInfo transactionA; |
| 359 | TransactionInfo transactionB; |
| 360 | setupSingleWithComposer(transactionA, ISurfaceComposer::eSynchronous, |
| 361 | /*syncInputWindows*/ false, |
| 362 | /*desiredPresentTime*/ time, /*isAutoTimestamp*/ true, |
| 363 | FrameTimelineInfo{}, &state1); |
| 364 | setupSingleWithComposer(transactionB, ISurfaceComposer::eSynchronous, |
| 365 | /*syncInputWindows*/ false, |
| 366 | /*desiredPresentTime*/ time, /*isAutoTimestamp*/ true, |
| 367 | FrameTimelineInfo{}, &state2); |
| 368 | mFlinger.setTransactionState(transactionA.frameTimelineInfo, transactionA.states, |
| 369 | transactionA.displays, transactionA.flags, |
| 370 | transactionA.applyToken, transactionA.inputWindowCommands, |
| 371 | transactionA.desiredPresentTime, transactionA.isAutoTimestamp, |
| 372 | transactionA.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 373 | transactionA.id); |
| 374 | if (updateApplyToken) { |
| 375 | transactionB.applyToken = sp<IBinder>(); |
| 376 | } |
| 377 | mFlinger.setTransactionState(transactionB.frameTimelineInfo, transactionB.states, |
| 378 | transactionB.displays, transactionB.flags, |
| 379 | transactionB.applyToken, transactionB.inputWindowCommands, |
| 380 | transactionB.desiredPresentTime, transactionB.isAutoTimestamp, |
| 381 | transactionB.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 382 | transactionB.id); |
| 383 | |
| 384 | mFlinger.flushTransactionQueues(); |
| 385 | EXPECT_EQ(pendingTransactionQueueSize, mFlinger.getPendingTransactionQueue().size()); |
| 386 | EXPECT_EQ(0u, mFlinger.getTransactionQueue().size()); |
| 387 | } |
| 388 | |
| 389 | void Flush_removesSignaledFromTheQueue(const Vector<ComposerState>& state1, |
| 390 | const Vector<ComposerState>& state2) { |
| 391 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); |
| 392 | EXPECT_EQ(0u, mFlinger.getPendingTransactionQueue().size()); |
| 393 | |
| 394 | auto time = systemTime(); |
| 395 | TransactionInfo transactionA; |
| 396 | TransactionInfo transactionB; |
| 397 | setupSingleWithComposer(transactionA, ISurfaceComposer::eSynchronous, |
| 398 | /*syncInputWindows*/ false, |
| 399 | /*desiredPresentTime*/ time, /*isAutoTimestamp*/ true, |
| 400 | FrameTimelineInfo{}, &state1); |
| 401 | setupSingleWithComposer(transactionB, ISurfaceComposer::eSynchronous, |
| 402 | /*syncInputWindows*/ false, |
| 403 | /*desiredPresentTime*/ time, /*isAutoTimestamp*/ true, |
| 404 | FrameTimelineInfo{}, &state2); |
| 405 | mFlinger.setTransactionState(transactionA.frameTimelineInfo, transactionA.states, |
| 406 | transactionA.displays, transactionA.flags, |
| 407 | transactionA.applyToken, transactionA.inputWindowCommands, |
| 408 | transactionA.desiredPresentTime, transactionA.isAutoTimestamp, |
| 409 | transactionA.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 410 | transactionA.id); |
| 411 | mFlinger.setTransactionState(transactionB.frameTimelineInfo, transactionB.states, |
| 412 | transactionB.displays, transactionB.flags, |
| 413 | transactionB.applyToken, transactionB.inputWindowCommands, |
| 414 | transactionB.desiredPresentTime, transactionB.isAutoTimestamp, |
| 415 | transactionB.uncacheBuffer, mHasListenerCallbacks, mCallbacks, |
| 416 | transactionB.id); |
| 417 | |
| 418 | mFlinger.flushTransactionQueues(); |
| 419 | EXPECT_EQ(0u, mFlinger.getPendingTransactionQueue().size()); |
| 420 | EXPECT_EQ(0u, mFlinger.getTransactionQueue().size()); |
| 421 | EXPECT_EQ(2ul, mFlinger.getTransactionCommittedSignals().size()); |
| 422 | } |
| 423 | |
| 424 | static Vector<ComposerState> createComposerStateVector(const ComposerState& state1, |
| 425 | const ComposerState& state2) { |
| 426 | Vector<ComposerState> states; |
| 427 | states.push_back(state1); |
| 428 | states.push_back(state2); |
| 429 | return states; |
| 430 | } |
| 431 | |
| 432 | static Vector<ComposerState> createComposerStateVector(const ComposerState& state) { |
| 433 | Vector<ComposerState> states; |
| 434 | states.push_back(state); |
| 435 | return states; |
| 436 | } |
| 437 | |
| 438 | static ComposerState createComposerState(int layerId, sp<Fence> fence, |
| 439 | uint32_t stateFlags = layer_state_t::eBufferChanged) { |
| 440 | ComposerState composer_state; |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame] | 441 | composer_state.state.bufferData = std::make_shared<BufferData>(); |
| 442 | composer_state.state.bufferData->acquireFence = std::move(fence); |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 443 | composer_state.state.layerId = layerId; |
Vishnu Nair | 9f0835e | 2022-01-07 09:33:19 -0800 | [diff] [blame] | 444 | composer_state.state.bufferData->flags = BufferData::BufferDataChange::fenceChanged; |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 445 | composer_state.state.flags = stateFlags; |
| 446 | return composer_state; |
| 447 | } |
| 448 | |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 449 | bool mHasListenerCallbacks = false; |
| 450 | std::vector<ListenerCallbacks> mCallbacks; |
| 451 | int mTransactionNumber = 0; |
| 452 | }; |
| 453 | |
| 454 | TEST_F(TransactionApplicationTest, Flush_RemovesFromQueue) { |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 455 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); |
Dominik Laskowski | 46f3e3b | 2021-08-10 11:44:24 -0700 | [diff] [blame] | 456 | EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 457 | |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 458 | TransactionInfo transactionA; // transaction to go on pending queue |
| 459 | setupSingle(transactionA, /*flags*/ 0, /*syncInputWindows*/ false, |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 460 | /*desiredPresentTime*/ s2ns(1), false, FrameTimelineInfo{}); |
| 461 | mFlinger.setTransactionState(transactionA.frameTimelineInfo, transactionA.states, |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 462 | transactionA.displays, transactionA.flags, transactionA.applyToken, |
| 463 | transactionA.inputWindowCommands, transactionA.desiredPresentTime, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 464 | transactionA.isAutoTimestamp, transactionA.uncacheBuffer, |
| 465 | mHasListenerCallbacks, mCallbacks, transactionA.id); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 466 | |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 467 | auto& transactionQueue = mFlinger.getTransactionQueue(); |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 468 | ASSERT_EQ(1u, transactionQueue.size()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 469 | |
Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 470 | auto& transactionState = transactionQueue.front(); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 471 | checkEqual(transactionA, transactionState); |
| 472 | |
| 473 | // because flushing uses the cached expected present time, we send an empty |
| 474 | // transaction here (sending a null applyToken to fake it as from a |
| 475 | // different process) to re-query and reset the cached expected present time |
| 476 | TransactionInfo empty; |
| 477 | empty.applyToken = sp<IBinder>(); |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 478 | mFlinger.setTransactionState(empty.frameTimelineInfo, empty.states, empty.displays, empty.flags, |
| 479 | empty.applyToken, empty.inputWindowCommands, |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 480 | empty.desiredPresentTime, empty.isAutoTimestamp, |
| 481 | empty.uncacheBuffer, mHasListenerCallbacks, mCallbacks, empty.id); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 482 | |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 483 | // flush transaction queue should flush as desiredPresentTime has |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 484 | // passed |
Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 485 | mFlinger.flushTransactionQueues(); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 486 | |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 487 | EXPECT_EQ(0u, transactionQueue.size()); |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | TEST_F(TransactionApplicationTest, NotPlacedOnTransactionQueue_Synchronous) { |
| 491 | NotPlacedOnTransactionQueue(ISurfaceComposer::eSynchronous, /*syncInputWindows*/ false); |
| 492 | } |
| 493 | |
| 494 | TEST_F(TransactionApplicationTest, NotPlacedOnTransactionQueue_Animation) { |
| 495 | NotPlacedOnTransactionQueue(ISurfaceComposer::eAnimation, /*syncInputWindows*/ false); |
| 496 | } |
| 497 | |
| 498 | TEST_F(TransactionApplicationTest, NotPlacedOnTransactionQueue_SyncInputWindows) { |
| 499 | NotPlacedOnTransactionQueue(/*flags*/ 0, /*syncInputWindows*/ true); |
| 500 | } |
| 501 | |
| 502 | TEST_F(TransactionApplicationTest, PlaceOnTransactionQueue_Synchronous) { |
| 503 | PlaceOnTransactionQueue(ISurfaceComposer::eSynchronous, /*syncInputWindows*/ false); |
| 504 | } |
| 505 | |
| 506 | TEST_F(TransactionApplicationTest, PlaceOnTransactionQueue_Animation) { |
| 507 | PlaceOnTransactionQueue(ISurfaceComposer::eAnimation, /*syncInputWindows*/ false); |
| 508 | } |
| 509 | |
| 510 | TEST_F(TransactionApplicationTest, PlaceOnTransactionQueue_SyncInputWindows) { |
| 511 | PlaceOnTransactionQueue(/*flags*/ 0, /*syncInputWindows*/ true); |
| 512 | } |
| 513 | |
| 514 | TEST_F(TransactionApplicationTest, BlockWithPriorTransaction_Synchronous) { |
| 515 | BlockedByPriorTransaction(ISurfaceComposer::eSynchronous, /*syncInputWindows*/ false); |
| 516 | } |
| 517 | |
| 518 | TEST_F(TransactionApplicationTest, BlockWithPriorTransaction_Animation) { |
| 519 | BlockedByPriorTransaction(ISurfaceComposer::eSynchronous, /*syncInputWindows*/ false); |
| 520 | } |
| 521 | |
| 522 | TEST_F(TransactionApplicationTest, BlockWithPriorTransaction_SyncInputWindows) { |
| 523 | BlockedByPriorTransaction(/*flags*/ 0, /*syncInputWindows*/ true); |
| 524 | } |
| 525 | |
Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 526 | TEST_F(TransactionApplicationTest, FromHandle) { |
| 527 | sp<IBinder> badHandle; |
| 528 | auto ret = mFlinger.fromHandle(badHandle); |
Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 529 | EXPECT_EQ(nullptr, ret.promote().get()); |
Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 530 | } |
ramindani | 4d48f90 | 2021-09-20 21:07:45 +0000 | [diff] [blame] | 531 | |
| 532 | TEST_F(TransactionApplicationTest, Flush_RemovesSingleSignaledFromTheQueue_LatchUnsignaled_Auto) { |
| 533 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Auto; |
| 534 | Flush_removesFromTheQueue( |
| 535 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceSignaled))); |
| 536 | } |
| 537 | |
| 538 | TEST_F(TransactionApplicationTest, Flush_RemovesSingleUnSignaledFromTheQueue_LatchUnsignaled_Auto) { |
| 539 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Auto; |
| 540 | Flush_removesFromTheQueue( |
| 541 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceUnsignaled))); |
| 542 | } |
| 543 | |
| 544 | TEST_F(TransactionApplicationTest, |
| 545 | Flush_KeepsUnSignaledInTheQueue_NonBufferCropChange_LatchUnsignaled_Auto) { |
| 546 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Auto; |
| 547 | Flush_keepsInTheQueue(createComposerStateVector( |
| 548 | createComposerState(/*layerId*/ 1, mFenceUnsignaled, layer_state_t::eCropChanged))); |
| 549 | } |
| 550 | |
| 551 | TEST_F(TransactionApplicationTest, |
| 552 | Flush_KeepsUnSignaledInTheQueue_NonBufferChangeClubed_LatchUnsignaled_Auto) { |
| 553 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Auto; |
| 554 | Flush_keepsInTheQueue(createComposerStateVector( |
| 555 | createComposerState(/*layerId*/ 1, mFenceUnsignaled, |
| 556 | layer_state_t::eCropChanged | layer_state_t::eBufferChanged))); |
| 557 | } |
| 558 | |
| 559 | TEST_F(TransactionApplicationTest, |
| 560 | Flush_KeepsInTheQueueSameApplyTokenMultiState_LatchUnsignaled_Auto) { |
| 561 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Auto; |
| 562 | Flush_keepsInTheQueue( |
| 563 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceUnsignaled), |
| 564 | createComposerState(/*layerId*/ 1, mFenceSignaled))); |
| 565 | } |
| 566 | |
| 567 | TEST_F(TransactionApplicationTest, Flush_KeepsInTheQueue_MultipleStateTransaction_Auto) { |
| 568 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Auto; |
| 569 | Flush_keepsInTheQueue( |
| 570 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceUnsignaled), |
| 571 | createComposerState(/*layerId*/ 2, mFenceSignaled))); |
| 572 | } |
| 573 | |
| 574 | TEST_F(TransactionApplicationTest, Flush_RemovesSignaledFromTheQueue_LatchUnsignaled_Auto) { |
| 575 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Auto; |
| 576 | Flush_removesSignaledFromTheQueue(createComposerStateVector( |
| 577 | createComposerState(/*layerId*/ 1, mFenceSignaled)), |
| 578 | createComposerStateVector( |
| 579 | createComposerState(/*layerId*/ 2, mFenceSignaled2))); |
| 580 | } |
| 581 | |
| 582 | TEST_F(TransactionApplicationTest, Flush_RemoveSignaledWithUnsignaledIntact_LatchUnsignaled_Auto) { |
| 583 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Auto; |
| 584 | Flush_KeepsUnsignaledInTheQueue(createComposerStateVector( |
| 585 | createComposerState(/*layerId*/ 1, mFenceSignaled)), |
| 586 | createComposerStateVector( |
| 587 | createComposerState(/*layerId*/ 2, mFenceUnsignaled))); |
| 588 | EXPECT_EQ(1ul, mFlinger.getTransactionCommittedSignals().size()); |
| 589 | } |
| 590 | |
| 591 | TEST_F(TransactionApplicationTest, |
| 592 | Flush_KeepsTransactionInTheQueueSameApplyToken_LatchUnsignaled_Auto) { |
| 593 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Auto; |
| 594 | Flush_KeepsUnsignaledInTheQueue(createComposerStateVector( |
| 595 | createComposerState(/*layerId*/ 1, mFenceUnsignaled)), |
| 596 | createComposerStateVector( |
| 597 | createComposerState(/*layerId*/ 2, mFenceSignaled)), |
| 598 | /*updateApplyToken*/ false); |
| 599 | EXPECT_EQ(1ul, mFlinger.getTransactionCommittedSignals().size()); |
| 600 | } |
| 601 | |
| 602 | TEST_F(TransactionApplicationTest, Flush_KeepsTransactionInTheQueue_LatchUnsignaled_Auto) { |
| 603 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Auto; |
| 604 | Flush_KeepsUnsignaledInTheQueue(createComposerStateVector( |
| 605 | createComposerState(/*layerId*/ 1, mFenceUnsignaled)), |
| 606 | createComposerStateVector( |
| 607 | createComposerState(/*layerId*/ 2, mFenceUnsignaled)), |
| 608 | /*updateApplyToken*/ true, |
| 609 | /*pendingTransactionQueueSize*/ 2u); |
| 610 | EXPECT_EQ(0ul, mFlinger.getTransactionCommittedSignals().size()); |
| 611 | } |
| 612 | |
| 613 | TEST_F(TransactionApplicationTest, Flush_RemovesSignaledFromTheQueue_LatchUnsignaled_Disabled) { |
| 614 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Disabled; |
| 615 | Flush_removesFromTheQueue( |
| 616 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceSignaled))); |
| 617 | } |
| 618 | |
| 619 | TEST_F(TransactionApplicationTest, Flush_KeepsInTheQueue_LatchUnsignaled_Disabled) { |
| 620 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Disabled; |
| 621 | Flush_keepsInTheQueue( |
| 622 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceUnsignaled))); |
| 623 | } |
| 624 | |
| 625 | TEST_F(TransactionApplicationTest, Flush_KeepsInTheQueueSameLayerId_LatchUnsignaled_Disabled) { |
| 626 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Disabled; |
| 627 | Flush_keepsInTheQueue( |
| 628 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceUnsignaled), |
| 629 | createComposerState(/*layerId*/ 1, mFenceUnsignaled))); |
| 630 | } |
| 631 | |
| 632 | TEST_F(TransactionApplicationTest, Flush_KeepsInTheQueueDifferentLayerId_LatchUnsignaled_Disabled) { |
| 633 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Disabled; |
| 634 | Flush_keepsInTheQueue( |
| 635 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceUnsignaled), |
| 636 | createComposerState(/*layerId*/ 2, mFenceUnsignaled))); |
| 637 | } |
| 638 | |
| 639 | TEST_F(TransactionApplicationTest, Flush_RemovesSignaledFromTheQueue_LatchUnSignaled_Disabled) { |
| 640 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Disabled; |
| 641 | Flush_removesSignaledFromTheQueue(createComposerStateVector( |
| 642 | createComposerState(/*layerId*/ 1, mFenceSignaled)), |
| 643 | createComposerStateVector( |
| 644 | createComposerState(/*layerId*/ 2, mFenceSignaled2))); |
| 645 | } |
| 646 | |
| 647 | TEST_F(TransactionApplicationTest, |
| 648 | Flush_KeepInTheQueueDifferentApplyToken_LatchUnsignaled_Disabled) { |
| 649 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Disabled; |
| 650 | Flush_KeepsUnsignaledInTheQueue(createComposerStateVector( |
| 651 | createComposerState(/*layerId*/ 1, mFenceUnsignaled)), |
| 652 | createComposerStateVector( |
| 653 | createComposerState(/*layerId*/ 2, mFenceSignaled))); |
| 654 | EXPECT_EQ(1ul, mFlinger.getTransactionCommittedSignals().size()); |
| 655 | } |
| 656 | |
| 657 | TEST_F(TransactionApplicationTest, Flush_KeepInTheQueueSameApplyToken_LatchUnsignaled_Disabled) { |
| 658 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Disabled; |
| 659 | Flush_KeepsUnsignaledInTheQueue(createComposerStateVector( |
| 660 | createComposerState(/*layerId*/ 1, mFenceSignaled)), |
| 661 | createComposerStateVector( |
| 662 | createComposerState(/*layerId*/ 2, mFenceUnsignaled)), |
| 663 | /*updateApplyToken*/ false); |
| 664 | EXPECT_EQ(1ul, mFlinger.getTransactionCommittedSignals().size()); |
| 665 | } |
| 666 | |
| 667 | TEST_F(TransactionApplicationTest, Flush_KeepInTheUnsignaledTheQueue_LatchUnsignaled_Disabled) { |
| 668 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Disabled; |
| 669 | Flush_KeepsUnsignaledInTheQueue(createComposerStateVector( |
| 670 | createComposerState(/*layerId*/ 1, mFenceUnsignaled)), |
| 671 | createComposerStateVector( |
| 672 | createComposerState(/*layerId*/ 2, mFenceUnsignaled)), |
| 673 | /*updateApplyToken*/ false); |
| 674 | EXPECT_EQ(0ul, mFlinger.getTransactionCommittedSignals().size()); |
| 675 | } |
| 676 | |
| 677 | TEST_F(TransactionApplicationTest, Flush_RemovesSignaledFromTheQueue_LatchUnsignaled_Always) { |
| 678 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Always; |
| 679 | Flush_removesFromTheQueue( |
| 680 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceSignaled))); |
| 681 | } |
| 682 | |
| 683 | TEST_F(TransactionApplicationTest, Flush_RemovesFromTheQueue_LatchUnsignaled_Always) { |
| 684 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Always; |
| 685 | Flush_removesFromTheQueue( |
| 686 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceUnsignaled))); |
| 687 | } |
| 688 | |
| 689 | TEST_F(TransactionApplicationTest, Flush_RemovesFromTheQueueSameLayerId_LatchUnsignaled_Always) { |
| 690 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Always; |
| 691 | Flush_removesFromTheQueue( |
| 692 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceUnsignaled), |
| 693 | createComposerState(/*layerId*/ 1, mFenceSignaled))); |
| 694 | } |
| 695 | |
| 696 | TEST_F(TransactionApplicationTest, |
| 697 | Flush_RemovesFromTheQueueDifferentLayerId_LatchUnsignaled_Always) { |
| 698 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Always; |
| 699 | Flush_removesFromTheQueue( |
| 700 | createComposerStateVector(createComposerState(/*layerId*/ 1, mFenceUnsignaled), |
| 701 | createComposerState(/*layerId*/ 2, mFenceSignaled))); |
| 702 | } |
| 703 | |
| 704 | TEST_F(TransactionApplicationTest, Flush_RemovesSignaledFromTheQueue_LatchUnSignaled_Always) { |
| 705 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Always; |
| 706 | Flush_removesSignaledFromTheQueue(createComposerStateVector( |
| 707 | createComposerState(/*layerId*/ 1, mFenceSignaled)), |
| 708 | createComposerStateVector( |
| 709 | createComposerState(/*layerId*/ 2, mFenceSignaled2))); |
| 710 | } |
| 711 | |
| 712 | TEST_F(TransactionApplicationTest, |
| 713 | Flush_RemovesFromTheQueueDifferentApplyToken_LatchUnsignaled_Always) { |
| 714 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Always; |
| 715 | Flush_removesUnsignaledFromTheQueue(createComposerStateVector( |
| 716 | createComposerState(/*layerId*/ 1, mFenceSignaled)), |
| 717 | createComposerStateVector( |
| 718 | createComposerState(/*layerId*/ 2, |
| 719 | mFenceUnsignaled))); |
| 720 | } |
| 721 | |
| 722 | TEST_F(TransactionApplicationTest, |
| 723 | Flush_RemovesUnsignaledFromTheQueueSameApplyToken_LatchUnsignaled_Always) { |
| 724 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Always; |
| 725 | Flush_removesUnsignaledFromTheQueue(createComposerStateVector( |
| 726 | createComposerState(/*layerId*/ 1, |
| 727 | mFenceUnsignaled)), |
| 728 | createComposerStateVector( |
| 729 | createComposerState(/*layerId*/ 2, mFenceSignaled)), |
| 730 | /*updateApplyToken*/ false); |
| 731 | } |
| 732 | |
| 733 | TEST_F(TransactionApplicationTest, Flush_RemovesUnsignaledFromTheQueue_LatchUnsignaled_Always) { |
| 734 | SurfaceFlinger::enableLatchUnsignaledConfig = LatchUnsignaledConfig::Always; |
| 735 | Flush_removesUnsignaledFromTheQueue(createComposerStateVector( |
| 736 | createComposerState(/*layerId*/ 1, |
| 737 | mFenceUnsignaled)), |
| 738 | createComposerStateVector( |
| 739 | createComposerState(/*layerId*/ 2, |
| 740 | mFenceUnsignaled))); |
| 741 | } |
| 742 | |
Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 743 | } // namespace android |