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