Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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 | 29d16cb | 2021-03-08 13:19:21 -0800 | [diff] [blame] | 17 | #include <sys/epoll.h> |
| 18 | |
| 19 | #include <gui/DisplayEventReceiver.h> |
| 20 | |
chaviw | d7deef7 | 2021-10-06 11:53:40 -0500 | [diff] [blame] | 21 | #include <gui/test/CallbackUtils.h> |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 22 | #include "LayerTransactionTest.h" |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 23 | |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 24 | using namespace std::chrono_literals; |
| 25 | |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 26 | namespace android { |
| 27 | |
| 28 | using android::hardware::graphics::common::V1_1::BufferUsage; |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 29 | using SCHash = SurfaceComposerClient::SCHash; |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 30 | |
| 31 | ::testing::Environment* const binderEnv = |
| 32 | ::testing::AddGlobalTestEnvironment(new BinderEnvironment()); |
| 33 | |
| 34 | class LayerCallbackTest : public LayerTransactionTest { |
| 35 | public: |
Ady Abraham | 29d16cb | 2021-03-08 13:19:21 -0800 | [diff] [blame] | 36 | void SetUp() override { |
| 37 | LayerTransactionTest::SetUp(); |
| 38 | |
| 39 | EXPECT_EQ(NO_ERROR, mDisplayEventReceiver.initCheck()); |
| 40 | |
| 41 | mEpollFd = epoll_create1(EPOLL_CLOEXEC); |
| 42 | EXPECT_GT(mEpollFd, 1); |
| 43 | |
| 44 | epoll_event event; |
| 45 | event.events = EPOLLIN; |
| 46 | EXPECT_EQ(0, epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mDisplayEventReceiver.getFd(), &event)); |
| 47 | } |
| 48 | |
| 49 | void TearDown() override { |
| 50 | close(mEpollFd); |
| 51 | LayerTransactionTest::TearDown(); |
| 52 | } |
| 53 | |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 54 | virtual sp<SurfaceControl> createBufferStateLayer() { |
| 55 | return createLayer(mClient, "test", 0, 0, ISurfaceComposerClient::eFXSurfaceBufferState); |
| 56 | } |
| 57 | |
| 58 | static int fillTransaction(Transaction& transaction, CallbackHelper* callbackHelper, |
| 59 | const sp<SurfaceControl>& layer = nullptr, bool setBuffer = true, |
| 60 | bool setBackgroundColor = false) { |
| 61 | if (layer) { |
| 62 | sp<GraphicBuffer> buffer; |
| 63 | sp<Fence> fence; |
| 64 | if (setBuffer) { |
| 65 | int err = getBuffer(&buffer, &fence); |
| 66 | if (err != NO_ERROR) { |
| 67 | return err; |
| 68 | } |
| 69 | |
chaviw | ba4320c | 2021-09-15 15:20:53 -0500 | [diff] [blame] | 70 | transaction.setBuffer(layer, buffer, fence); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | if (setBackgroundColor) { |
| 74 | transaction.setBackgroundColor(layer, /*color*/ half3(1.0f, 0, 0), /*alpha*/ 1.0f, |
| 75 | ui::Dataspace::UNKNOWN); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | transaction.addTransactionCompletedCallback(callbackHelper->function, |
| 80 | callbackHelper->getContext()); |
| 81 | return NO_ERROR; |
| 82 | } |
| 83 | |
| 84 | static void waitForCallback(CallbackHelper& helper, const ExpectedResult& expectedResult, |
| 85 | bool finalState = false) { |
| 86 | CallbackData callbackData; |
| 87 | ASSERT_NO_FATAL_FAILURE(helper.getCallbackData(&callbackData)); |
| 88 | EXPECT_NO_FATAL_FAILURE(expectedResult.verifyCallbackData(callbackData)); |
| 89 | |
| 90 | if (finalState) { |
| 91 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | static void waitForCallbacks(CallbackHelper& helper, |
| 96 | const std::vector<ExpectedResult>& expectedResults, |
| 97 | bool finalState = false) { |
| 98 | for (const auto& expectedResult : expectedResults) { |
| 99 | waitForCallback(helper, expectedResult); |
| 100 | } |
| 101 | if (finalState) { |
| 102 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 103 | } |
| 104 | } |
Ady Abraham | 29d16cb | 2021-03-08 13:19:21 -0800 | [diff] [blame] | 105 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 106 | static void waitForCommitCallback( |
| 107 | CallbackHelper& helper, |
| 108 | const std::unordered_set<sp<SurfaceControl>, SCHash>& committedSc) { |
| 109 | CallbackData callbackData; |
| 110 | ASSERT_NO_FATAL_FAILURE(helper.getCallbackData(&callbackData)); |
| 111 | |
| 112 | const auto& surfaceControlStats = callbackData.surfaceControlStats; |
| 113 | |
| 114 | ASSERT_EQ(surfaceControlStats.size(), committedSc.size()) << "wrong number of surfaces"; |
| 115 | |
| 116 | for (const auto& stats : surfaceControlStats) { |
| 117 | ASSERT_NE(stats.surfaceControl, nullptr) << "returned null surface control"; |
| 118 | |
| 119 | const auto& expectedSc = committedSc.find(stats.surfaceControl); |
| 120 | ASSERT_NE(expectedSc, committedSc.end()) << "unexpected surface control"; |
| 121 | } |
| 122 | } |
| 123 | |
Ady Abraham | 29d16cb | 2021-03-08 13:19:21 -0800 | [diff] [blame] | 124 | DisplayEventReceiver mDisplayEventReceiver; |
| 125 | int mEpollFd; |
| 126 | |
| 127 | struct Vsync { |
| 128 | int64_t vsyncId = FrameTimelineInfo::INVALID_VSYNC_ID; |
| 129 | nsecs_t expectedPresentTime = std::numeric_limits<nsecs_t>::max(); |
| 130 | }; |
| 131 | |
| 132 | Vsync waitForNextVsync() { |
| 133 | mDisplayEventReceiver.requestNextVsync(); |
| 134 | epoll_event epollEvent; |
| 135 | Vsync vsync; |
| 136 | EXPECT_EQ(1, epoll_wait(mEpollFd, &epollEvent, 1, 1000)) |
| 137 | << "Timeout waiting for vsync event"; |
| 138 | DisplayEventReceiver::Event event; |
| 139 | while (mDisplayEventReceiver.getEvents(&event, 1) > 0) { |
| 140 | if (event.header.type != DisplayEventReceiver::DISPLAY_EVENT_VSYNC) { |
| 141 | continue; |
| 142 | } |
| 143 | |
| 144 | vsync = {event.vsync.vsyncId, event.vsync.expectedVSyncTimestamp}; |
| 145 | } |
| 146 | |
| 147 | EXPECT_GE(vsync.vsyncId, 1); |
| 148 | EXPECT_GT(event.vsync.expectedVSyncTimestamp, systemTime()); |
| 149 | |
| 150 | return vsync; |
| 151 | } |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | TEST_F(LayerCallbackTest, BufferColor) { |
| 155 | sp<SurfaceControl> layer; |
| 156 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 157 | |
| 158 | Transaction transaction; |
| 159 | CallbackHelper callback; |
| 160 | int err = fillTransaction(transaction, &callback, layer, true, true); |
| 161 | if (err) { |
| 162 | GTEST_SUCCEED() << "test not supported"; |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | transaction.apply(); |
| 167 | |
| 168 | ExpectedResult expected; |
| 169 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 170 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 171 | } |
| 172 | |
| 173 | TEST_F(LayerCallbackTest, NoBufferNoColor) { |
| 174 | sp<SurfaceControl> layer; |
| 175 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 176 | |
| 177 | Transaction transaction; |
| 178 | CallbackHelper callback; |
| 179 | int err = fillTransaction(transaction, &callback, layer, false, false); |
| 180 | if (err) { |
| 181 | GTEST_SUCCEED() << "test not supported"; |
| 182 | return; |
| 183 | } |
| 184 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 185 | ui::Size bufferSize = getBufferSize(); |
| 186 | TransactionUtils::setFrame(transaction, layer, Rect(0, 0, bufferSize.width, bufferSize.height), |
| 187 | Rect(0, 0, 32, 32)); |
| 188 | transaction.apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 189 | |
| 190 | ExpectedResult expected; |
| 191 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, |
| 192 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 193 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 194 | } |
| 195 | |
| 196 | TEST_F(LayerCallbackTest, BufferNoColor) { |
| 197 | sp<SurfaceControl> layer; |
| 198 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 199 | |
| 200 | Transaction transaction; |
| 201 | CallbackHelper callback; |
| 202 | int err = fillTransaction(transaction, &callback, layer, true, false); |
| 203 | if (err) { |
| 204 | GTEST_SUCCEED() << "test not supported"; |
| 205 | return; |
| 206 | } |
| 207 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 208 | ui::Size bufferSize = getBufferSize(); |
| 209 | TransactionUtils::setFrame(transaction, layer, Rect(0, 0, bufferSize.width, bufferSize.height), |
| 210 | Rect(0, 0, 32, 32)); |
| 211 | transaction.apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 212 | |
| 213 | ExpectedResult expected; |
| 214 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 215 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 216 | } |
| 217 | |
| 218 | TEST_F(LayerCallbackTest, NoBufferColor) { |
| 219 | sp<SurfaceControl> layer; |
| 220 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 221 | |
| 222 | Transaction transaction; |
| 223 | CallbackHelper callback; |
| 224 | int err = fillTransaction(transaction, &callback, layer, false, true); |
| 225 | if (err) { |
| 226 | GTEST_SUCCEED() << "test not supported"; |
| 227 | return; |
| 228 | } |
| 229 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 230 | ui::Size bufferSize = getBufferSize(); |
| 231 | TransactionUtils::setFrame(transaction, layer, Rect(0, 0, bufferSize.width, bufferSize.height), |
| 232 | Rect(0, 0, 32, 32)); |
| 233 | transaction.apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 234 | |
| 235 | ExpectedResult expected; |
| 236 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 237 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 238 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 239 | } |
| 240 | |
| 241 | TEST_F(LayerCallbackTest, NoStateChange) { |
| 242 | Transaction transaction; |
| 243 | CallbackHelper callback; |
| 244 | int err = fillTransaction(transaction, &callback); |
| 245 | if (err) { |
| 246 | GTEST_SUCCEED() << "test not supported"; |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | transaction.apply(); |
| 251 | |
| 252 | ExpectedResult expected; |
| 253 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 254 | } |
| 255 | |
| 256 | TEST_F(LayerCallbackTest, OffScreen) { |
| 257 | sp<SurfaceControl> layer; |
| 258 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 259 | |
| 260 | Transaction transaction; |
| 261 | CallbackHelper callback; |
| 262 | int err = fillTransaction(transaction, &callback, layer); |
| 263 | if (err) { |
| 264 | GTEST_SUCCEED() << "test not supported"; |
| 265 | return; |
| 266 | } |
| 267 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 268 | ui::Size bufferSize = getBufferSize(); |
| 269 | TransactionUtils::setFrame(transaction, layer, Rect(0, 0, bufferSize.width, bufferSize.height), |
| 270 | Rect(-100, -100, 100, 100)); |
| 271 | transaction.apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 272 | |
| 273 | ExpectedResult expected; |
| 274 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 275 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 276 | } |
| 277 | |
| 278 | TEST_F(LayerCallbackTest, MergeBufferNoColor) { |
| 279 | sp<SurfaceControl> layer1, layer2; |
| 280 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 281 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 282 | |
| 283 | Transaction transaction1, transaction2; |
| 284 | CallbackHelper callback1, callback2; |
| 285 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 286 | if (err) { |
| 287 | GTEST_SUCCEED() << "test not supported"; |
| 288 | return; |
| 289 | } |
| 290 | err = fillTransaction(transaction2, &callback2, layer2); |
| 291 | if (err) { |
| 292 | GTEST_SUCCEED() << "test not supported"; |
| 293 | return; |
| 294 | } |
| 295 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 296 | ui::Size bufferSize = getBufferSize(); |
| 297 | |
| 298 | TransactionUtils::setFrame(transaction1, layer1, |
| 299 | Rect(0, 0, bufferSize.width, bufferSize.height), Rect(0, 0, 32, 32)); |
| 300 | TransactionUtils::setFrame(transaction2, layer2, |
| 301 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 302 | Rect(32, 32, 64, 64)); |
| 303 | |
| 304 | transaction2.merge(std::move(transaction1)).apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 305 | |
| 306 | ExpectedResult expected; |
| 307 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 308 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 309 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 310 | } |
| 311 | |
| 312 | TEST_F(LayerCallbackTest, MergeNoBufferColor) { |
| 313 | sp<SurfaceControl> layer1, layer2; |
| 314 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 315 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 316 | |
| 317 | Transaction transaction1, transaction2; |
| 318 | CallbackHelper callback1, callback2; |
| 319 | int err = fillTransaction(transaction1, &callback1, layer1, false, true); |
| 320 | if (err) { |
| 321 | GTEST_SUCCEED() << "test not supported"; |
| 322 | return; |
| 323 | } |
| 324 | err = fillTransaction(transaction2, &callback2, layer2, false, true); |
| 325 | if (err) { |
| 326 | GTEST_SUCCEED() << "test not supported"; |
| 327 | return; |
| 328 | } |
| 329 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 330 | ui::Size bufferSize = getBufferSize(); |
| 331 | |
| 332 | TransactionUtils::setFrame(transaction1, layer1, |
| 333 | Rect(0, 0, bufferSize.width, bufferSize.height), Rect(0, 0, 32, 32)); |
| 334 | TransactionUtils::setFrame(transaction2, layer2, |
| 335 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 336 | Rect(32, 32, 64, 64)); |
| 337 | |
| 338 | transaction2.merge(std::move(transaction1)).apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 339 | |
| 340 | ExpectedResult expected; |
| 341 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
| 342 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 343 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 344 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 345 | } |
| 346 | |
| 347 | TEST_F(LayerCallbackTest, MergeOneBufferOneColor) { |
| 348 | sp<SurfaceControl> layer1, layer2; |
| 349 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 350 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 351 | |
| 352 | Transaction transaction1, transaction2; |
| 353 | CallbackHelper callback1, callback2; |
| 354 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 355 | if (err) { |
| 356 | GTEST_SUCCEED() << "test not supported"; |
| 357 | return; |
| 358 | } |
| 359 | err = fillTransaction(transaction2, &callback2, layer2, false, true); |
| 360 | if (err) { |
| 361 | GTEST_SUCCEED() << "test not supported"; |
| 362 | return; |
| 363 | } |
| 364 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 365 | ui::Size bufferSize = getBufferSize(); |
| 366 | |
| 367 | TransactionUtils::setFrame(transaction1, layer1, |
| 368 | Rect(0, 0, bufferSize.width, bufferSize.height), Rect(0, 0, 32, 32)); |
| 369 | TransactionUtils::setFrame(transaction2, layer2, |
| 370 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 371 | Rect(32, 32, 64, 64)); |
| 372 | |
| 373 | transaction2.merge(std::move(transaction1)).apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 374 | |
| 375 | ExpectedResult expected; |
| 376 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer1); |
| 377 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer2, |
| 378 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 379 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 380 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 381 | } |
| 382 | TEST_F(LayerCallbackTest, Merge_SameCallback) { |
| 383 | sp<SurfaceControl> layer1, layer2; |
| 384 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 385 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 386 | |
| 387 | Transaction transaction1, transaction2; |
| 388 | CallbackHelper callback; |
| 389 | int err = fillTransaction(transaction1, &callback, layer1); |
| 390 | if (err) { |
| 391 | GTEST_SUCCEED() << "test not supported"; |
| 392 | return; |
| 393 | } |
| 394 | err = fillTransaction(transaction2, &callback, layer2); |
| 395 | if (err) { |
| 396 | GTEST_SUCCEED() << "test not supported"; |
| 397 | return; |
| 398 | } |
| 399 | |
| 400 | transaction2.merge(std::move(transaction1)).apply(); |
| 401 | |
| 402 | ExpectedResult expected; |
| 403 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 404 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 405 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 406 | } |
| 407 | |
| 408 | TEST_F(LayerCallbackTest, Merge_SameLayer) { |
| 409 | sp<SurfaceControl> layer; |
| 410 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 411 | |
| 412 | Transaction transaction1, transaction2; |
| 413 | CallbackHelper callback1, callback2; |
| 414 | int err = fillTransaction(transaction1, &callback1, layer); |
| 415 | if (err) { |
| 416 | GTEST_SUCCEED() << "test not supported"; |
| 417 | return; |
| 418 | } |
| 419 | err = fillTransaction(transaction2, &callback2, layer); |
| 420 | if (err) { |
| 421 | GTEST_SUCCEED() << "test not supported"; |
| 422 | return; |
| 423 | } |
| 424 | |
| 425 | transaction2.merge(std::move(transaction1)).apply(); |
| 426 | |
| 427 | ExpectedResult expected; |
| 428 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 429 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 430 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 431 | } |
| 432 | |
| 433 | TEST_F(LayerCallbackTest, Merge_DifferentClients) { |
| 434 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 435 | client2(new SurfaceComposerClient); |
| 436 | |
| 437 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 438 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 439 | |
| 440 | sp<SurfaceControl> layer1, layer2; |
| 441 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
| 442 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 443 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
| 444 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 445 | |
| 446 | Transaction transaction1, transaction2; |
| 447 | CallbackHelper callback1, callback2; |
| 448 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 449 | if (err) { |
| 450 | GTEST_SUCCEED() << "test not supported"; |
| 451 | return; |
| 452 | } |
| 453 | err = fillTransaction(transaction2, &callback2, layer2); |
| 454 | if (err) { |
| 455 | GTEST_SUCCEED() << "test not supported"; |
| 456 | return; |
| 457 | } |
| 458 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 459 | ui::Size bufferSize = getBufferSize(); |
| 460 | |
| 461 | TransactionUtils::setFrame(transaction1, layer1, |
| 462 | Rect(0, 0, bufferSize.width, bufferSize.height), Rect(0, 0, 32, 32)); |
| 463 | TransactionUtils::setFrame(transaction2, layer2, |
| 464 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 465 | Rect(32, 32, 64, 64)); |
| 466 | |
| 467 | transaction2.merge(std::move(transaction1)).apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 468 | |
| 469 | ExpectedResult expected; |
| 470 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 471 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 472 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 473 | } |
| 474 | |
| 475 | TEST_F(LayerCallbackTest, MultipleTransactions) { |
| 476 | sp<SurfaceControl> layer; |
| 477 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 478 | |
| 479 | Transaction transaction; |
| 480 | CallbackHelper callback; |
| 481 | for (size_t i = 0; i < 10; i++) { |
| 482 | int err = fillTransaction(transaction, &callback, layer); |
| 483 | if (err) { |
| 484 | GTEST_SUCCEED() << "test not supported"; |
| 485 | return; |
| 486 | } |
| 487 | |
| 488 | transaction.apply(); |
| 489 | |
| 490 | ExpectedResult expected; |
| 491 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 492 | ExpectedResult::Buffer::ACQUIRED, |
| 493 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 494 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 495 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 496 | } |
| 497 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 498 | } |
| 499 | |
| 500 | TEST_F(LayerCallbackTest, MultipleTransactions_NoStateChange) { |
| 501 | sp<SurfaceControl> layer; |
| 502 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 503 | |
| 504 | Transaction transaction; |
| 505 | CallbackHelper callback; |
| 506 | for (size_t i = 0; i < 10; i++) { |
| 507 | ExpectedResult expected; |
| 508 | |
| 509 | if (i == 0) { |
| 510 | int err = fillTransaction(transaction, &callback, layer); |
| 511 | if (err) { |
| 512 | GTEST_SUCCEED() << "test not supported"; |
| 513 | return; |
| 514 | } |
| 515 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 516 | } else { |
| 517 | int err = fillTransaction(transaction, &callback); |
| 518 | if (err) { |
| 519 | GTEST_SUCCEED() << "test not supported"; |
| 520 | return; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | transaction.apply(); |
| 525 | |
| 526 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 527 | } |
| 528 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 529 | } |
| 530 | |
| 531 | TEST_F(LayerCallbackTest, MultipleTransactions_SameStateChange) { |
| 532 | sp<SurfaceControl> layer; |
| 533 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 534 | |
| 535 | Transaction transaction; |
| 536 | CallbackHelper callback; |
| 537 | for (size_t i = 0; i < 10; i++) { |
| 538 | if (i == 0) { |
| 539 | int err = fillTransaction(transaction, &callback, layer); |
| 540 | if (err) { |
| 541 | GTEST_SUCCEED() << "test not supported"; |
| 542 | return; |
| 543 | } |
| 544 | } else { |
| 545 | int err = fillTransaction(transaction, &callback); |
| 546 | if (err) { |
| 547 | GTEST_SUCCEED() << "test not supported"; |
| 548 | return; |
| 549 | } |
| 550 | } |
| 551 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 552 | ui::Size bufferSize = getBufferSize(); |
| 553 | TransactionUtils::setFrame(transaction, layer, |
| 554 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 555 | Rect(0, 0, 32, 32)); |
| 556 | transaction.apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 557 | |
| 558 | ExpectedResult expected; |
| 559 | expected.addSurface((i == 0) ? ExpectedResult::Transaction::PRESENTED |
| 560 | : ExpectedResult::Transaction::NOT_PRESENTED, |
| 561 | layer, |
| 562 | (i == 0) ? ExpectedResult::Buffer::ACQUIRED |
| 563 | : ExpectedResult::Buffer::NOT_ACQUIRED); |
| 564 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, i == 0)); |
| 565 | } |
| 566 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 567 | } |
| 568 | |
| 569 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge) { |
| 570 | sp<SurfaceControl> layer1, layer2; |
| 571 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 572 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 573 | |
| 574 | Transaction transaction1, transaction2; |
| 575 | CallbackHelper callback1, callback2; |
| 576 | for (size_t i = 0; i < 10; i++) { |
| 577 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 578 | if (err) { |
| 579 | GTEST_SUCCEED() << "test not supported"; |
| 580 | return; |
| 581 | } |
| 582 | err = fillTransaction(transaction2, &callback2, layer2); |
| 583 | if (err) { |
| 584 | GTEST_SUCCEED() << "test not supported"; |
| 585 | return; |
| 586 | } |
| 587 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 588 | ui::Size bufferSize = getBufferSize(); |
| 589 | |
| 590 | TransactionUtils::setFrame(transaction1, layer1, |
| 591 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 592 | Rect(0, 0, 32, 32)); |
| 593 | TransactionUtils::setFrame(transaction2, layer2, |
| 594 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 595 | Rect(32, 32, 64, 64)); |
| 596 | |
| 597 | transaction2.merge(std::move(transaction1)).apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 598 | |
| 599 | ExpectedResult expected; |
| 600 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
| 601 | ExpectedResult::Buffer::ACQUIRED, |
| 602 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 603 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 604 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 605 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 606 | } |
| 607 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 608 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 609 | } |
| 610 | |
| 611 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients) { |
| 612 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 613 | client2(new SurfaceComposerClient); |
| 614 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 615 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 616 | |
| 617 | sp<SurfaceControl> layer1, layer2; |
| 618 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
| 619 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 620 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
| 621 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 622 | |
| 623 | Transaction transaction1, transaction2; |
| 624 | CallbackHelper callback1, callback2; |
| 625 | for (size_t i = 0; i < 10; i++) { |
| 626 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 627 | if (err) { |
| 628 | GTEST_SUCCEED() << "test not supported"; |
| 629 | return; |
| 630 | } |
| 631 | err = fillTransaction(transaction2, &callback2, layer2); |
| 632 | if (err) { |
| 633 | GTEST_SUCCEED() << "test not supported"; |
| 634 | return; |
| 635 | } |
| 636 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 637 | ui::Size bufferSize = getBufferSize(); |
| 638 | |
| 639 | TransactionUtils::setFrame(transaction1, layer1, |
| 640 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 641 | Rect(0, 0, 32, 32)); |
| 642 | TransactionUtils::setFrame(transaction2, layer2, |
| 643 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 644 | Rect(32, 32, 64, 64)); |
| 645 | |
| 646 | transaction2.merge(std::move(transaction1)).apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 647 | |
| 648 | ExpectedResult expected; |
| 649 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
| 650 | ExpectedResult::Buffer::ACQUIRED, |
| 651 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 652 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 653 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 654 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 655 | } |
| 656 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 657 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 658 | } |
| 659 | |
| 660 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_NoStateChange) { |
| 661 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 662 | client2(new SurfaceComposerClient); |
| 663 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 664 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 665 | |
| 666 | sp<SurfaceControl> layer1, layer2; |
| 667 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
| 668 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 669 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
| 670 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 671 | |
| 672 | Transaction transaction1, transaction2; |
| 673 | CallbackHelper callback1, callback2; |
| 674 | |
| 675 | // Normal call to set up test |
| 676 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 677 | if (err) { |
| 678 | GTEST_SUCCEED() << "test not supported"; |
| 679 | return; |
| 680 | } |
| 681 | err = fillTransaction(transaction2, &callback2, layer2); |
| 682 | if (err) { |
| 683 | GTEST_SUCCEED() << "test not supported"; |
| 684 | return; |
| 685 | } |
| 686 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 687 | ui::Size bufferSize = getBufferSize(); |
| 688 | |
| 689 | TransactionUtils::setFrame(transaction1, layer1, |
| 690 | Rect(0, 0, bufferSize.width, bufferSize.height), Rect(0, 0, 32, 32)); |
| 691 | TransactionUtils::setFrame(transaction2, layer2, |
| 692 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 693 | Rect(32, 32, 64, 64)); |
| 694 | |
| 695 | transaction2.merge(std::move(transaction1)).apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 696 | |
| 697 | ExpectedResult expected; |
| 698 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 699 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 700 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 701 | expected.reset(); |
| 702 | |
| 703 | // Test |
| 704 | err = fillTransaction(transaction1, &callback1); |
| 705 | if (err) { |
| 706 | GTEST_SUCCEED() << "test not supported"; |
| 707 | return; |
| 708 | } |
| 709 | err = fillTransaction(transaction2, &callback2); |
| 710 | if (err) { |
| 711 | GTEST_SUCCEED() << "test not supported"; |
| 712 | return; |
| 713 | } |
| 714 | |
| 715 | transaction2.merge(std::move(transaction1)).apply(); |
| 716 | |
| 717 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 718 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 719 | } |
| 720 | |
| 721 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_SameStateChange) { |
| 722 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 723 | client2(new SurfaceComposerClient); |
| 724 | |
| 725 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 726 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 727 | |
| 728 | sp<SurfaceControl> layer1, layer2; |
| 729 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
| 730 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 731 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
| 732 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 733 | |
| 734 | Transaction transaction1, transaction2; |
| 735 | CallbackHelper callback1, callback2; |
| 736 | |
| 737 | // Normal call to set up test |
| 738 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 739 | if (err) { |
| 740 | GTEST_SUCCEED() << "test not supported"; |
| 741 | return; |
| 742 | } |
| 743 | err = fillTransaction(transaction2, &callback2, layer2); |
| 744 | if (err) { |
| 745 | GTEST_SUCCEED() << "test not supported"; |
| 746 | return; |
| 747 | } |
| 748 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 749 | ui::Size bufferSize = getBufferSize(); |
| 750 | |
| 751 | TransactionUtils::setFrame(transaction1, layer1, |
| 752 | Rect(0, 0, bufferSize.width, bufferSize.height), Rect(0, 0, 32, 32)); |
| 753 | TransactionUtils::setFrame(transaction2, layer2, |
| 754 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 755 | Rect(32, 32, 64, 64)); |
| 756 | |
| 757 | transaction2.merge(std::move(transaction1)).apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 758 | |
| 759 | ExpectedResult expected; |
| 760 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 761 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 762 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 763 | expected.reset(); |
| 764 | |
| 765 | // Test |
| 766 | err = fillTransaction(transaction1, &callback1); |
| 767 | if (err) { |
| 768 | GTEST_SUCCEED() << "test not supported"; |
| 769 | return; |
| 770 | } |
| 771 | err = fillTransaction(transaction2, &callback2); |
| 772 | if (err) { |
| 773 | GTEST_SUCCEED() << "test not supported"; |
| 774 | return; |
| 775 | } |
| 776 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 777 | TransactionUtils::setFrame(transaction2, layer2, |
| 778 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 779 | Rect(32, 32, 64, 64)); |
| 780 | transaction2.merge(std::move(transaction1)).apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 781 | |
| 782 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer2, |
| 783 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 784 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 785 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 786 | } |
| 787 | |
John Reck | 97c7891 | 2021-04-27 14:04:37 -0400 | [diff] [blame] | 788 | // TODO (b/183181768): Fix & re-enable |
| 789 | TEST_F(LayerCallbackTest, DISABLED_MultipleTransactions_SingleFrame) { |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 790 | sp<SurfaceControl> layer; |
| 791 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 792 | |
| 793 | Transaction transaction; |
| 794 | CallbackHelper callback; |
| 795 | std::vector<ExpectedResult> expectedResults(50); |
| 796 | for (auto& expected : expectedResults) { |
| 797 | expected.reset(); |
| 798 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 799 | ExpectedResult::Buffer::ACQUIRED, |
| 800 | ExpectedResult::PreviousBuffer::UNKNOWN); |
| 801 | |
| 802 | int err = fillTransaction(transaction, &callback, layer); |
| 803 | if (err) { |
| 804 | GTEST_SUCCEED() << "test not supported"; |
| 805 | return; |
| 806 | } |
| 807 | |
| 808 | transaction.apply(); |
| 809 | } |
| 810 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 811 | } |
| 812 | |
| 813 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_NoStateChange) { |
| 814 | sp<SurfaceControl> layer; |
| 815 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 816 | |
| 817 | // Normal call to set up test |
| 818 | Transaction transaction; |
| 819 | CallbackHelper callback; |
| 820 | int err = fillTransaction(transaction, &callback, layer); |
| 821 | if (err) { |
| 822 | GTEST_SUCCEED() << "test not supported"; |
| 823 | return; |
| 824 | } |
| 825 | |
| 826 | transaction.apply(); |
| 827 | |
| 828 | ExpectedResult expected; |
| 829 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 830 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 831 | |
| 832 | // Test |
| 833 | std::vector<ExpectedResult> expectedResults(50); |
| 834 | for (auto& expected : expectedResults) { |
| 835 | expected.reset(); |
| 836 | |
| 837 | err = fillTransaction(transaction, &callback); |
| 838 | if (err) { |
| 839 | GTEST_SUCCEED() << "test not supported"; |
| 840 | return; |
| 841 | } |
| 842 | |
| 843 | transaction.apply(); |
| 844 | } |
| 845 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 846 | } |
| 847 | |
| 848 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_SameStateChange) { |
| 849 | sp<SurfaceControl> layer; |
| 850 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 851 | |
| 852 | // Normal call to set up test |
| 853 | Transaction transaction; |
| 854 | CallbackHelper callback; |
| 855 | int err = fillTransaction(transaction, &callback, layer); |
| 856 | if (err) { |
| 857 | GTEST_SUCCEED() << "test not supported"; |
| 858 | return; |
| 859 | } |
| 860 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 861 | ui::Size bufferSize = getBufferSize(); |
| 862 | TransactionUtils::setFrame(transaction, layer, Rect(0, 0, bufferSize.width, bufferSize.height), |
| 863 | Rect(0, 0, 32, 32)); |
| 864 | transaction.apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 865 | |
| 866 | ExpectedResult expectedResult; |
| 867 | expectedResult.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 868 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expectedResult, true)); |
| 869 | |
| 870 | // Test |
| 871 | std::vector<ExpectedResult> expectedResults(50); |
| 872 | for (auto& expected : expectedResults) { |
| 873 | expected.reset(); |
| 874 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, |
| 875 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 876 | |
| 877 | err = fillTransaction(transaction, &callback); |
| 878 | if (err) { |
| 879 | GTEST_SUCCEED() << "test not supported"; |
| 880 | return; |
| 881 | } |
| 882 | |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 883 | TransactionUtils::setFrame(transaction, layer, |
| 884 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 885 | Rect(0, 0, 32, 32)); |
| 886 | transaction.apply(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 887 | } |
| 888 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 889 | } |
| 890 | |
| 891 | TEST_F(LayerCallbackTest, DesiredPresentTime) { |
| 892 | sp<SurfaceControl> layer; |
| 893 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 894 | |
| 895 | Transaction transaction; |
| 896 | CallbackHelper callback; |
| 897 | int err = fillTransaction(transaction, &callback, layer); |
| 898 | if (err) { |
| 899 | GTEST_SUCCEED() << "test not supported"; |
| 900 | return; |
| 901 | } |
| 902 | |
| 903 | // Try to present 100ms in the future |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 904 | nsecs_t time = systemTime() + std::chrono::nanoseconds(100ms).count(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 905 | |
| 906 | transaction.setDesiredPresentTime(time); |
| 907 | transaction.apply(); |
| 908 | |
| 909 | ExpectedResult expected; |
| 910 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 911 | expected.addExpectedPresentTime(time); |
| 912 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 913 | } |
| 914 | |
| 915 | TEST_F(LayerCallbackTest, DesiredPresentTime_Multiple) { |
| 916 | sp<SurfaceControl> layer; |
| 917 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 918 | |
| 919 | Transaction transaction; |
| 920 | CallbackHelper callback1; |
| 921 | int err = fillTransaction(transaction, &callback1, layer); |
| 922 | if (err) { |
| 923 | GTEST_SUCCEED() << "test not supported"; |
| 924 | return; |
| 925 | } |
| 926 | |
| 927 | // Try to present 100ms in the future |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 928 | nsecs_t time = systemTime() + std::chrono::nanoseconds(100ms).count(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 929 | |
| 930 | transaction.setDesiredPresentTime(time); |
| 931 | transaction.apply(); |
| 932 | |
| 933 | ExpectedResult expected1; |
| 934 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 935 | expected1.addExpectedPresentTime(time); |
| 936 | |
| 937 | CallbackHelper callback2; |
| 938 | err = fillTransaction(transaction, &callback2, layer); |
| 939 | if (err) { |
| 940 | GTEST_SUCCEED() << "test not supported"; |
| 941 | return; |
| 942 | } |
| 943 | |
| 944 | // Try to present 33ms after the first frame |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 945 | time += std::chrono::nanoseconds(33ms).count(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 946 | |
| 947 | transaction.setDesiredPresentTime(time); |
| 948 | transaction.apply(); |
| 949 | |
| 950 | ExpectedResult expected2; |
| 951 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 952 | ExpectedResult::Buffer::ACQUIRED, |
| 953 | ExpectedResult::PreviousBuffer::RELEASED); |
| 954 | expected2.addExpectedPresentTime(time); |
| 955 | |
| 956 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); |
| 957 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); |
| 958 | } |
| 959 | |
John Reck | 97c7891 | 2021-04-27 14:04:37 -0400 | [diff] [blame] | 960 | // TODO (b/183181768): Fix & re-enable |
| 961 | TEST_F(LayerCallbackTest, DISABLED_DesiredPresentTime_OutOfOrder) { |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 962 | sp<SurfaceControl> layer; |
| 963 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 964 | |
| 965 | Transaction transaction; |
| 966 | CallbackHelper callback1; |
| 967 | int err = fillTransaction(transaction, &callback1, layer); |
| 968 | if (err) { |
| 969 | GTEST_SUCCEED() << "test not supported"; |
| 970 | return; |
| 971 | } |
| 972 | |
| 973 | // Try to present 100ms in the future |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 974 | nsecs_t time = systemTime() + std::chrono::nanoseconds(100ms).count(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 975 | |
| 976 | transaction.setDesiredPresentTime(time); |
| 977 | transaction.apply(); |
| 978 | |
| 979 | ExpectedResult expected1; |
| 980 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 981 | expected1.addExpectedPresentTime(time); |
| 982 | |
| 983 | CallbackHelper callback2; |
| 984 | err = fillTransaction(transaction, &callback2, layer); |
| 985 | if (err) { |
| 986 | GTEST_SUCCEED() << "test not supported"; |
| 987 | return; |
| 988 | } |
| 989 | |
| 990 | // Try to present 33ms before the previous frame |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 991 | time -= std::chrono::nanoseconds(33ms).count(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 992 | |
| 993 | transaction.setDesiredPresentTime(time); |
| 994 | transaction.apply(); |
| 995 | |
| 996 | ExpectedResult expected2; |
| 997 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 998 | ExpectedResult::Buffer::ACQUIRED, |
| 999 | ExpectedResult::PreviousBuffer::RELEASED); |
| 1000 | |
| 1001 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); |
| 1002 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); |
| 1003 | } |
| 1004 | |
| 1005 | TEST_F(LayerCallbackTest, DesiredPresentTime_Past) { |
| 1006 | sp<SurfaceControl> layer; |
| 1007 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 1008 | |
| 1009 | Transaction transaction; |
| 1010 | CallbackHelper callback; |
| 1011 | int err = fillTransaction(transaction, &callback, layer); |
| 1012 | if (err) { |
| 1013 | GTEST_SUCCEED() << "test not supported"; |
| 1014 | return; |
| 1015 | } |
| 1016 | |
| 1017 | // Try to present 100ms in the past |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 1018 | nsecs_t time = systemTime() - std::chrono::nanoseconds(100ms).count(); |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 1019 | |
| 1020 | transaction.setDesiredPresentTime(time); |
| 1021 | transaction.apply(); |
| 1022 | |
| 1023 | ExpectedResult expected; |
| 1024 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 1025 | expected.addExpectedPresentTime(systemTime()); |
| 1026 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 1027 | } |
Ady Abraham | 29d16cb | 2021-03-08 13:19:21 -0800 | [diff] [blame] | 1028 | |
| 1029 | TEST_F(LayerCallbackTest, ExpectedPresentTime) { |
| 1030 | sp<SurfaceControl> layer; |
| 1031 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 1032 | |
| 1033 | Transaction transaction; |
| 1034 | CallbackHelper callback; |
| 1035 | int err = fillTransaction(transaction, &callback, layer); |
| 1036 | if (err) { |
| 1037 | GTEST_SUCCEED() << "test not supported"; |
| 1038 | return; |
| 1039 | } |
| 1040 | |
| 1041 | const Vsync vsync = waitForNextVsync(); |
| 1042 | transaction.setFrameTimelineInfo({vsync.vsyncId, 0}); |
| 1043 | transaction.apply(); |
| 1044 | |
| 1045 | ExpectedResult expected; |
| 1046 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 1047 | expected.addExpectedPresentTimeForVsyncId(vsync.expectedPresentTime); |
| 1048 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 1049 | } |
| 1050 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 1051 | // b202394221 |
| 1052 | TEST_F(LayerCallbackTest, EmptyBufferStateChanges) { |
| 1053 | sp<SurfaceControl> bufferLayer, emptyBufferLayer; |
| 1054 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createBufferStateLayer()); |
| 1055 | ASSERT_NO_FATAL_FAILURE(emptyBufferLayer = createBufferStateLayer()); |
| 1056 | |
| 1057 | Transaction transaction; |
| 1058 | CallbackHelper callback; |
| 1059 | for (size_t i = 0; i < 10; i++) { |
| 1060 | int err = fillTransaction(transaction, &callback, bufferLayer); |
| 1061 | if (err) { |
| 1062 | GTEST_SUCCEED() << "test not supported"; |
| 1063 | return; |
| 1064 | } |
| 1065 | |
| 1066 | ui::Size bufferSize = getBufferSize(); |
| 1067 | |
| 1068 | TransactionUtils::setFrame(transaction, bufferLayer, |
| 1069 | Rect(0, 0, bufferSize.width, bufferSize.height), |
| 1070 | Rect(0, 0, 32, 32)); |
| 1071 | transaction.setPosition(emptyBufferLayer, 1 + i, 2 + i); |
| 1072 | transaction.apply(); |
| 1073 | |
| 1074 | ExpectedResult expected; |
| 1075 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, bufferLayer, |
| 1076 | ExpectedResult::Buffer::ACQUIRED, |
| 1077 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 1078 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 1079 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, emptyBufferLayer, |
| 1080 | ExpectedResult::Buffer::NOT_ACQUIRED, |
| 1081 | ExpectedResult::PreviousBuffer::NOT_RELEASED); |
| 1082 | |
| 1083 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 1084 | } |
| 1085 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 1086 | } |
| 1087 | |
| 1088 | // b202394221 |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 1089 | TEST_F(LayerCallbackTest, DISABLED_NonBufferLayerStateChanges) { |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 1090 | sp<SurfaceControl> layer; |
| 1091 | ASSERT_NO_FATAL_FAILURE(layer = createColorLayer("ColorLayer", Color::RED)); |
| 1092 | |
| 1093 | Transaction transaction; |
| 1094 | CallbackHelper callback; |
| 1095 | int err = fillTransaction(transaction, &callback); |
| 1096 | if (err) { |
| 1097 | GTEST_SUCCEED() << "test not supported"; |
| 1098 | return; |
| 1099 | } |
| 1100 | transaction.setPosition(layer, 1, 2); |
| 1101 | transaction.apply(); |
| 1102 | |
| 1103 | ExpectedResult expected; |
| 1104 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 1105 | } |
| 1106 | |
chaviw | 6b9ffea | 2021-11-08 09:25:48 -0600 | [diff] [blame] | 1107 | TEST_F(LayerCallbackTest, CommitCallbackOffscreenLayer) { |
| 1108 | sp<SurfaceControl> layer; |
| 1109 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 1110 | sp<SurfaceControl> offscreenLayer = |
| 1111 | createSurface(mClient, "Offscreen Layer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 1112 | ISurfaceComposerClient::eFXSurfaceBufferState, layer.get()); |
| 1113 | |
| 1114 | Transaction transaction; |
| 1115 | CallbackHelper callback; |
| 1116 | int err = fillTransaction(transaction, &callback, layer, true); |
| 1117 | err |= fillTransaction(transaction, &callback, offscreenLayer, true); |
| 1118 | if (err) { |
| 1119 | GTEST_SUCCEED() << "test not supported"; |
| 1120 | return; |
| 1121 | } |
| 1122 | |
| 1123 | transaction.reparent(offscreenLayer, nullptr) |
| 1124 | .addTransactionCommittedCallback(callback.function, callback.getContext()); |
| 1125 | transaction.apply(); |
| 1126 | |
| 1127 | std::unordered_set<sp<SurfaceControl>, SCHash> committedSc; |
| 1128 | committedSc.insert(layer); |
| 1129 | committedSc.insert(offscreenLayer); |
| 1130 | EXPECT_NO_FATAL_FAILURE(waitForCommitCallback(callback, committedSc)); |
| 1131 | } |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 1132 | } // namespace android |