| 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> | 
|  | 27 | #include <utils/String8.h> | 
|  | 28 |  | 
|  | 29 | #include "TestableScheduler.h" | 
|  | 30 | #include "TestableSurfaceFlinger.h" | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 31 | #include "mock/MockEventThread.h" | 
|  | 32 | #include "mock/MockMessageQueue.h" | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 33 | #include "mock/MockVsyncController.h" | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 34 |  | 
|  | 35 | namespace android { | 
|  | 36 |  | 
|  | 37 | using testing::_; | 
|  | 38 | using testing::Return; | 
|  | 39 |  | 
|  | 40 | using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; | 
|  | 41 |  | 
|  | 42 | class TransactionApplicationTest : public testing::Test { | 
|  | 43 | public: | 
|  | 44 | TransactionApplicationTest() { | 
|  | 45 | const ::testing::TestInfo* const test_info = | 
|  | 46 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 47 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); | 
|  | 48 |  | 
|  | 49 | mFlinger.mutableEventQueue().reset(mMessageQueue); | 
|  | 50 | setupScheduler(); | 
|  | 51 | } | 
|  | 52 |  | 
|  | 53 | ~TransactionApplicationTest() { | 
|  | 54 | const ::testing::TestInfo* const test_info = | 
|  | 55 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 56 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | void setupScheduler() { | 
|  | 60 | auto eventThread = std::make_unique<mock::EventThread>(); | 
|  | 61 | auto sfEventThread = std::make_unique<mock::EventThread>(); | 
|  | 62 |  | 
|  | 63 | EXPECT_CALL(*eventThread, registerDisplayEventConnection(_)); | 
|  | 64 | EXPECT_CALL(*eventThread, createEventConnection(_, _)) | 
| Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 65 | .WillOnce(Return(new EventThreadConnection(eventThread.get(), /*callingUid=*/0, | 
|  | 66 | ResyncCallback()))); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 67 |  | 
|  | 68 | EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_)); | 
|  | 69 | EXPECT_CALL(*sfEventThread, createEventConnection(_, _)) | 
| Ady Abraham | 62f216c | 2020-10-13 19:07:23 -0700 | [diff] [blame] | 70 | .WillOnce(Return(new EventThreadConnection(sfEventThread.get(), /*callingUid=*/0, | 
|  | 71 | ResyncCallback()))); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 72 |  | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 73 | EXPECT_CALL(*mVSyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0)); | 
|  | 74 | EXPECT_CALL(*mVSyncTracker, currentPeriod()) | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 75 | .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_VSYNC_PERIOD)); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 76 |  | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 77 | mFlinger.setupScheduler(std::unique_ptr<mock::VsyncController>(mVsyncController), | 
|  | 78 | std::unique_ptr<mock::VSyncTracker>(mVSyncTracker), | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 79 | std::move(eventThread), std::move(sfEventThread)); | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | TestableScheduler* mScheduler; | 
|  | 83 | TestableSurfaceFlinger mFlinger; | 
|  | 84 |  | 
|  | 85 | std::unique_ptr<mock::EventThread> mEventThread = std::make_unique<mock::EventThread>(); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 86 |  | 
|  | 87 | mock::MessageQueue* mMessageQueue = new mock::MessageQueue(); | 
| Ady Abraham | 8cb2188 | 2020-08-26 18:22:05 -0700 | [diff] [blame] | 88 | mock::VsyncController* mVsyncController = new mock::VsyncController(); | 
|  | 89 | mock::VSyncTracker* mVSyncTracker = new mock::VSyncTracker(); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 90 |  | 
|  | 91 | struct TransactionInfo { | 
|  | 92 | Vector<ComposerState> states; | 
|  | 93 | Vector<DisplayState> displays; | 
|  | 94 | uint32_t flags = 0; | 
|  | 95 | sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance()); | 
|  | 96 | InputWindowCommands inputWindowCommands; | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 97 | int64_t desiredPresentTime = 0; | 
|  | 98 | bool isAutoTimestamp = true; | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 99 | FrameTimelineInfo frameTimelineInfo; | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 100 | client_cache_t uncacheBuffer; | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 101 | uint64_t id = static_cast<uint64_t>(-1); | 
|  | 102 | static_assert(0xffffffffffffffff == static_cast<uint64_t>(-1)); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 103 | }; | 
|  | 104 |  | 
|  | 105 | void checkEqual(TransactionInfo info, SurfaceFlinger::TransactionState state) { | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 106 | EXPECT_EQ(0u, info.states.size()); | 
|  | 107 | EXPECT_EQ(0u, state.states.size()); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 108 |  | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 109 | EXPECT_EQ(0u, info.displays.size()); | 
|  | 110 | EXPECT_EQ(0u, state.displays.size()); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 111 | EXPECT_EQ(info.flags, state.flags); | 
|  | 112 | EXPECT_EQ(info.desiredPresentTime, state.desiredPresentTime); | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | void setupSingle(TransactionInfo& transaction, uint32_t flags, bool syncInputWindows, | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 116 | int64_t desiredPresentTime, bool isAutoTimestamp, | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 117 | const FrameTimelineInfo& frameTimelineInfo) { | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 118 | mTransactionNumber++; | 
|  | 119 | transaction.flags |= flags; // ISurfaceComposer::eSynchronous; | 
|  | 120 | transaction.inputWindowCommands.syncInputWindows = syncInputWindows; | 
|  | 121 | transaction.desiredPresentTime = desiredPresentTime; | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 122 | transaction.isAutoTimestamp = isAutoTimestamp; | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 123 | transaction.frameTimelineInfo = frameTimelineInfo; | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 124 | } | 
|  | 125 |  | 
|  | 126 | void NotPlacedOnTransactionQueue(uint32_t flags, bool syncInputWindows) { | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 127 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 128 | // called in SurfaceFlinger::signalTransaction | 
|  | 129 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 130 | TransactionInfo transaction; | 
|  | 131 | setupSingle(transaction, flags, syncInputWindows, | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 132 | /*desiredPresentTime*/ systemTime(), /*isAutoTimestamp*/ true, | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 133 | FrameTimelineInfo{}); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 134 | nsecs_t applicationTime = systemTime(); | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 135 | mFlinger.setTransactionState(transaction.frameTimelineInfo, transaction.states, | 
| Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 136 | transaction.displays, transaction.flags, | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 137 | transaction.applyToken, transaction.inputWindowCommands, | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 138 | transaction.desiredPresentTime, transaction.isAutoTimestamp, | 
|  | 139 | transaction.uncacheBuffer, mHasListenerCallbacks, mCallbacks, | 
|  | 140 | transaction.id); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 141 |  | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 142 | // If transaction is synchronous or syncs input windows, SF | 
|  | 143 | // applyTransactionState should time out (5s) wating for SF to commit | 
|  | 144 | // the transaction or to receive a signal that syncInputWindows has | 
|  | 145 | // completed.  If this is animation, it should not time out waiting. | 
|  | 146 | nsecs_t returnedTime = systemTime(); | 
|  | 147 | if (flags & ISurfaceComposer::eSynchronous || syncInputWindows) { | 
|  | 148 | EXPECT_GE(returnedTime, applicationTime + s2ns(5)); | 
|  | 149 | } else { | 
|  | 150 | EXPECT_LE(returnedTime, applicationTime + s2ns(5)); | 
|  | 151 | } | 
| Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 152 | // Each transaction should have been placed on the transaction queue | 
| Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 153 | auto transactionQueue = mFlinger.getTransactionQueue(); | 
| Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 154 | EXPECT_EQ(1u, transactionQueue.size()); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 155 | } | 
|  | 156 |  | 
|  | 157 | void PlaceOnTransactionQueue(uint32_t flags, bool syncInputWindows) { | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 158 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 159 | // called in SurfaceFlinger::signalTransaction | 
|  | 160 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 161 |  | 
|  | 162 | // first check will see desired present time has not passed, | 
|  | 163 | // but afterwards it will look like the desired present time has passed | 
|  | 164 | nsecs_t time = systemTime(); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 165 | TransactionInfo transaction; | 
|  | 166 | setupSingle(transaction, flags, syncInputWindows, | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 167 | /*desiredPresentTime*/ time + s2ns(1), false, FrameTimelineInfo{}); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 168 | nsecs_t applicationSentTime = systemTime(); | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 169 | mFlinger.setTransactionState(transaction.frameTimelineInfo, transaction.states, | 
| Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 170 | transaction.displays, transaction.flags, | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 171 | transaction.applyToken, transaction.inputWindowCommands, | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 172 | transaction.desiredPresentTime, transaction.isAutoTimestamp, | 
|  | 173 | transaction.uncacheBuffer, mHasListenerCallbacks, mCallbacks, | 
|  | 174 | transaction.id); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 175 |  | 
|  | 176 | nsecs_t returnedTime = systemTime(); | 
| Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 177 | if ((flags & ISurfaceComposer::eSynchronous) || syncInputWindows) { | 
|  | 178 | EXPECT_GE(systemTime(), applicationSentTime + s2ns(5)); | 
|  | 179 | } else { | 
|  | 180 | EXPECT_LE(returnedTime, applicationSentTime + s2ns(5)); | 
|  | 181 | } | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 182 | // This transaction should have been placed on the transaction queue | 
| Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 183 | auto transactionQueue = mFlinger.getTransactionQueue(); | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 184 | EXPECT_EQ(1u, transactionQueue.size()); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 185 | } | 
|  | 186 |  | 
|  | 187 | void BlockedByPriorTransaction(uint32_t flags, bool syncInputWindows) { | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 188 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 189 | // called in SurfaceFlinger::signalTransaction | 
|  | 190 | nsecs_t time = systemTime(); | 
| Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 191 | if (!syncInputWindows) { | 
|  | 192 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(2); | 
|  | 193 | } else { | 
|  | 194 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 195 | } | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 196 | // transaction that should go on the pending thread | 
|  | 197 | TransactionInfo transactionA; | 
|  | 198 | setupSingle(transactionA, /*flags*/ 0, /*syncInputWindows*/ false, | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 199 | /*desiredPresentTime*/ time + s2ns(1), false, FrameTimelineInfo{}); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 200 |  | 
|  | 201 | // transaction that would not have gone on the pending thread if not | 
|  | 202 | // blocked | 
|  | 203 | TransactionInfo transactionB; | 
|  | 204 | setupSingle(transactionB, flags, syncInputWindows, | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 205 | /*desiredPresentTime*/ systemTime(), /*isAutoTimestamp*/ true, | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 206 | FrameTimelineInfo{}); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 207 |  | 
|  | 208 | nsecs_t applicationSentTime = systemTime(); | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 209 | mFlinger.setTransactionState(transactionA.frameTimelineInfo, transactionA.states, | 
| Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 210 | transactionA.displays, transactionA.flags, | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 211 | transactionA.applyToken, transactionA.inputWindowCommands, | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 212 | transactionA.desiredPresentTime, transactionA.isAutoTimestamp, | 
|  | 213 | transactionA.uncacheBuffer, mHasListenerCallbacks, mCallbacks, | 
|  | 214 | transactionA.id); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 215 |  | 
|  | 216 | // This thread should not have been blocked by the above transaction | 
|  | 217 | // (5s is the timeout period that applyTransactionState waits for SF to | 
|  | 218 | // commit the transaction) | 
|  | 219 | EXPECT_LE(systemTime(), applicationSentTime + s2ns(5)); | 
| Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 220 | // transaction that would goes to pending transaciton queue. | 
|  | 221 | mFlinger.flushTransactionQueues(); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 222 |  | 
|  | 223 | applicationSentTime = systemTime(); | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 224 | mFlinger.setTransactionState(transactionB.frameTimelineInfo, transactionB.states, | 
| Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 225 | transactionB.displays, transactionB.flags, | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 226 | transactionB.applyToken, transactionB.inputWindowCommands, | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 227 | transactionB.desiredPresentTime, transactionB.isAutoTimestamp, | 
|  | 228 | transactionB.uncacheBuffer, mHasListenerCallbacks, mCallbacks, | 
|  | 229 | transactionB.id); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 230 |  | 
|  | 231 | // this thread should have been blocked by the above transaction | 
|  | 232 | // if this is an animation, this thread should be blocked for 5s | 
|  | 233 | // in setTransactionState waiting for transactionA to flush.  Otherwise, | 
|  | 234 | // the transaction should be placed on the pending queue | 
| Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 235 | if (flags & (ISurfaceComposer::eAnimation | ISurfaceComposer::eSynchronous) || | 
|  | 236 | syncInputWindows) { | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 237 | EXPECT_GE(systemTime(), applicationSentTime + s2ns(5)); | 
|  | 238 | } else { | 
|  | 239 | EXPECT_LE(systemTime(), applicationSentTime + s2ns(5)); | 
|  | 240 | } | 
|  | 241 |  | 
| Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 242 | // transaction that would goes to pending transaciton queue. | 
|  | 243 | mFlinger.flushTransactionQueues(); | 
|  | 244 |  | 
| Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 245 | // check that the transaction was applied. | 
| Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 246 | auto transactionQueue = mFlinger.getPendingTransactionQueue(); | 
| Ady Abraham | e46243a | 2021-02-23 19:33:49 -0800 | [diff] [blame] | 247 | EXPECT_EQ(0u, transactionQueue.size()); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 248 | } | 
|  | 249 |  | 
|  | 250 | bool mHasListenerCallbacks = false; | 
|  | 251 | std::vector<ListenerCallbacks> mCallbacks; | 
|  | 252 | int mTransactionNumber = 0; | 
|  | 253 | }; | 
|  | 254 |  | 
|  | 255 | TEST_F(TransactionApplicationTest, Flush_RemovesFromQueue) { | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 256 | ASSERT_EQ(0u, mFlinger.getTransactionQueue().size()); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 257 | // called in SurfaceFlinger::signalTransaction | 
|  | 258 | EXPECT_CALL(*mMessageQueue, invalidate()).Times(1); | 
|  | 259 |  | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 260 | TransactionInfo transactionA; // transaction to go on pending queue | 
|  | 261 | setupSingle(transactionA, /*flags*/ 0, /*syncInputWindows*/ false, | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 262 | /*desiredPresentTime*/ s2ns(1), false, FrameTimelineInfo{}); | 
|  | 263 | mFlinger.setTransactionState(transactionA.frameTimelineInfo, transactionA.states, | 
| Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 264 | transactionA.displays, transactionA.flags, transactionA.applyToken, | 
|  | 265 | transactionA.inputWindowCommands, transactionA.desiredPresentTime, | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 266 | transactionA.isAutoTimestamp, transactionA.uncacheBuffer, | 
|  | 267 | mHasListenerCallbacks, mCallbacks, transactionA.id); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 268 |  | 
| Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 269 | auto& transactionQueue = mFlinger.getTransactionQueue(); | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 270 | ASSERT_EQ(1u, transactionQueue.size()); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 271 |  | 
| Arthur Hung | 5814427 | 2021-01-16 03:43:53 +0000 | [diff] [blame] | 272 | auto& transactionState = transactionQueue.front(); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 273 | checkEqual(transactionA, transactionState); | 
|  | 274 |  | 
|  | 275 | // because flushing uses the cached expected present time, we send an empty | 
|  | 276 | // transaction here (sending a null applyToken to fake it as from a | 
|  | 277 | // different process) to re-query and reset the cached expected present time | 
|  | 278 | TransactionInfo empty; | 
|  | 279 | empty.applyToken = sp<IBinder>(); | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 280 | mFlinger.setTransactionState(empty.frameTimelineInfo, empty.states, empty.displays, empty.flags, | 
|  | 281 | empty.applyToken, empty.inputWindowCommands, | 
| Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 282 | empty.desiredPresentTime, empty.isAutoTimestamp, | 
|  | 283 | empty.uncacheBuffer, mHasListenerCallbacks, mCallbacks, empty.id); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 284 |  | 
| Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 285 | // flush transaction queue should flush as desiredPresentTime has | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 286 | // passed | 
| Zhuoyao Zhang | 3d3540d | 2021-01-14 05:14:54 +0000 | [diff] [blame] | 287 | mFlinger.flushTransactionQueues(); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 288 |  | 
| Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 289 | EXPECT_EQ(0u, transactionQueue.size()); | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 290 | } | 
|  | 291 |  | 
|  | 292 | TEST_F(TransactionApplicationTest, NotPlacedOnTransactionQueue_Synchronous) { | 
|  | 293 | NotPlacedOnTransactionQueue(ISurfaceComposer::eSynchronous, /*syncInputWindows*/ false); | 
|  | 294 | } | 
|  | 295 |  | 
|  | 296 | TEST_F(TransactionApplicationTest, NotPlacedOnTransactionQueue_Animation) { | 
|  | 297 | NotPlacedOnTransactionQueue(ISurfaceComposer::eAnimation, /*syncInputWindows*/ false); | 
|  | 298 | } | 
|  | 299 |  | 
|  | 300 | TEST_F(TransactionApplicationTest, NotPlacedOnTransactionQueue_SyncInputWindows) { | 
|  | 301 | NotPlacedOnTransactionQueue(/*flags*/ 0, /*syncInputWindows*/ true); | 
|  | 302 | } | 
|  | 303 |  | 
|  | 304 | TEST_F(TransactionApplicationTest, PlaceOnTransactionQueue_Synchronous) { | 
|  | 305 | PlaceOnTransactionQueue(ISurfaceComposer::eSynchronous, /*syncInputWindows*/ false); | 
|  | 306 | } | 
|  | 307 |  | 
|  | 308 | TEST_F(TransactionApplicationTest, PlaceOnTransactionQueue_Animation) { | 
|  | 309 | PlaceOnTransactionQueue(ISurfaceComposer::eAnimation, /*syncInputWindows*/ false); | 
|  | 310 | } | 
|  | 311 |  | 
|  | 312 | TEST_F(TransactionApplicationTest, PlaceOnTransactionQueue_SyncInputWindows) { | 
|  | 313 | PlaceOnTransactionQueue(/*flags*/ 0, /*syncInputWindows*/ true); | 
|  | 314 | } | 
|  | 315 |  | 
|  | 316 | TEST_F(TransactionApplicationTest, BlockWithPriorTransaction_Synchronous) { | 
|  | 317 | BlockedByPriorTransaction(ISurfaceComposer::eSynchronous, /*syncInputWindows*/ false); | 
|  | 318 | } | 
|  | 319 |  | 
|  | 320 | TEST_F(TransactionApplicationTest, BlockWithPriorTransaction_Animation) { | 
|  | 321 | BlockedByPriorTransaction(ISurfaceComposer::eSynchronous, /*syncInputWindows*/ false); | 
|  | 322 | } | 
|  | 323 |  | 
|  | 324 | TEST_F(TransactionApplicationTest, BlockWithPriorTransaction_SyncInputWindows) { | 
|  | 325 | BlockedByPriorTransaction(/*flags*/ 0, /*syncInputWindows*/ true); | 
|  | 326 | } | 
|  | 327 |  | 
| Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 328 | TEST_F(TransactionApplicationTest, FromHandle) { | 
|  | 329 | sp<IBinder> badHandle; | 
|  | 330 | auto ret = mFlinger.fromHandle(badHandle); | 
| Alec Mouri | 9a02eda | 2020-04-21 17:39:34 -0700 | [diff] [blame] | 331 | EXPECT_EQ(nullptr, ret.promote().get()); | 
| Valerie Hau | 09e6005 | 2019-12-15 14:51:15 -0800 | [diff] [blame] | 332 | } | 
| Valerie Hau | d251afb | 2019-03-29 14:19:02 -0700 | [diff] [blame] | 333 | } // namespace android |