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