| 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 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 167 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 168 |  | 
|  | 169 | ExpectedResult expected; | 
|  | 170 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, | 
|  | 171 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
|  | 172 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 173 | } | 
|  | 174 |  | 
|  | 175 | TEST_F(LayerCallbackTest, BufferNoColor) { | 
|  | 176 | sp<SurfaceControl> layer; | 
|  | 177 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 178 |  | 
|  | 179 | Transaction transaction; | 
|  | 180 | CallbackHelper callback; | 
|  | 181 | int err = fillTransaction(transaction, &callback, layer, true, false); | 
|  | 182 | if (err) { | 
|  | 183 | GTEST_SUCCEED() << "test not supported"; | 
|  | 184 | return; | 
|  | 185 | } | 
|  | 186 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 187 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 188 |  | 
|  | 189 | ExpectedResult expected; | 
|  | 190 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 191 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 192 | } | 
|  | 193 |  | 
|  | 194 | TEST_F(LayerCallbackTest, NoBufferColor) { | 
|  | 195 | sp<SurfaceControl> layer; | 
|  | 196 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 197 |  | 
|  | 198 | Transaction transaction; | 
|  | 199 | CallbackHelper callback; | 
|  | 200 | int err = fillTransaction(transaction, &callback, layer, false, true); | 
|  | 201 | if (err) { | 
|  | 202 | GTEST_SUCCEED() << "test not supported"; | 
|  | 203 | return; | 
|  | 204 | } | 
|  | 205 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 206 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 207 |  | 
|  | 208 | ExpectedResult expected; | 
|  | 209 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
|  | 210 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
|  | 211 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 212 | } | 
|  | 213 |  | 
|  | 214 | TEST_F(LayerCallbackTest, NoStateChange) { | 
|  | 215 | Transaction transaction; | 
|  | 216 | CallbackHelper callback; | 
|  | 217 | int err = fillTransaction(transaction, &callback); | 
|  | 218 | if (err) { | 
|  | 219 | GTEST_SUCCEED() << "test not supported"; | 
|  | 220 | return; | 
|  | 221 | } | 
|  | 222 |  | 
|  | 223 | transaction.apply(); | 
|  | 224 |  | 
|  | 225 | ExpectedResult expected; | 
|  | 226 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 227 | } | 
|  | 228 |  | 
|  | 229 | TEST_F(LayerCallbackTest, OffScreen) { | 
|  | 230 | sp<SurfaceControl> layer; | 
|  | 231 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 232 |  | 
|  | 233 | Transaction transaction; | 
|  | 234 | CallbackHelper callback; | 
|  | 235 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 236 | if (err) { | 
|  | 237 | GTEST_SUCCEED() << "test not supported"; | 
|  | 238 | return; | 
|  | 239 | } | 
|  | 240 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 241 | transaction.setFrame(layer, Rect(-100, -100, 100, 100)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 242 |  | 
|  | 243 | ExpectedResult expected; | 
|  | 244 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 245 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 246 | } | 
|  | 247 |  | 
|  | 248 | TEST_F(LayerCallbackTest, MergeBufferNoColor) { | 
|  | 249 | sp<SurfaceControl> layer1, layer2; | 
|  | 250 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 251 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 252 |  | 
|  | 253 | Transaction transaction1, transaction2; | 
|  | 254 | CallbackHelper callback1, callback2; | 
|  | 255 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 256 | if (err) { | 
|  | 257 | GTEST_SUCCEED() << "test not supported"; | 
|  | 258 | return; | 
|  | 259 | } | 
|  | 260 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 261 | if (err) { | 
|  | 262 | GTEST_SUCCEED() << "test not supported"; | 
|  | 263 | return; | 
|  | 264 | } | 
|  | 265 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 266 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 267 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 268 |  | 
|  | 269 | ExpectedResult expected; | 
|  | 270 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 271 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 272 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 273 | } | 
|  | 274 |  | 
|  | 275 | TEST_F(LayerCallbackTest, MergeNoBufferColor) { | 
|  | 276 | sp<SurfaceControl> layer1, layer2; | 
|  | 277 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 278 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 279 |  | 
|  | 280 | Transaction transaction1, transaction2; | 
|  | 281 | CallbackHelper callback1, callback2; | 
|  | 282 | int err = fillTransaction(transaction1, &callback1, layer1, false, true); | 
|  | 283 | if (err) { | 
|  | 284 | GTEST_SUCCEED() << "test not supported"; | 
|  | 285 | return; | 
|  | 286 | } | 
|  | 287 | err = fillTransaction(transaction2, &callback2, layer2, false, true); | 
|  | 288 | if (err) { | 
|  | 289 | GTEST_SUCCEED() << "test not supported"; | 
|  | 290 | return; | 
|  | 291 | } | 
|  | 292 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 293 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 294 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 295 |  | 
|  | 296 | ExpectedResult expected; | 
|  | 297 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, | 
|  | 298 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
|  | 299 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 300 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 301 | } | 
|  | 302 |  | 
|  | 303 | TEST_F(LayerCallbackTest, MergeOneBufferOneColor) { | 
|  | 304 | sp<SurfaceControl> layer1, layer2; | 
|  | 305 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 306 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 307 |  | 
|  | 308 | Transaction transaction1, transaction2; | 
|  | 309 | CallbackHelper callback1, callback2; | 
|  | 310 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 311 | if (err) { | 
|  | 312 | GTEST_SUCCEED() << "test not supported"; | 
|  | 313 | return; | 
|  | 314 | } | 
|  | 315 | err = fillTransaction(transaction2, &callback2, layer2, false, true); | 
|  | 316 | if (err) { | 
|  | 317 | GTEST_SUCCEED() << "test not supported"; | 
|  | 318 | return; | 
|  | 319 | } | 
|  | 320 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 321 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 322 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 323 |  | 
|  | 324 | ExpectedResult expected; | 
|  | 325 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer1); | 
|  | 326 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer2, | 
|  | 327 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
|  | 328 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 329 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 330 | } | 
|  | 331 | TEST_F(LayerCallbackTest, Merge_SameCallback) { | 
|  | 332 | sp<SurfaceControl> layer1, layer2; | 
|  | 333 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 334 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 335 |  | 
|  | 336 | Transaction transaction1, transaction2; | 
|  | 337 | CallbackHelper callback; | 
|  | 338 | int err = fillTransaction(transaction1, &callback, layer1); | 
|  | 339 | if (err) { | 
|  | 340 | GTEST_SUCCEED() << "test not supported"; | 
|  | 341 | return; | 
|  | 342 | } | 
|  | 343 | err = fillTransaction(transaction2, &callback, layer2); | 
|  | 344 | if (err) { | 
|  | 345 | GTEST_SUCCEED() << "test not supported"; | 
|  | 346 | return; | 
|  | 347 | } | 
|  | 348 |  | 
|  | 349 | transaction2.merge(std::move(transaction1)).apply(); | 
|  | 350 |  | 
|  | 351 | ExpectedResult expected; | 
|  | 352 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 353 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); | 
|  | 354 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 355 | } | 
|  | 356 |  | 
|  | 357 | TEST_F(LayerCallbackTest, Merge_SameLayer) { | 
|  | 358 | sp<SurfaceControl> layer; | 
|  | 359 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 360 |  | 
|  | 361 | Transaction transaction1, transaction2; | 
|  | 362 | CallbackHelper callback1, callback2; | 
|  | 363 | int err = fillTransaction(transaction1, &callback1, layer); | 
|  | 364 | if (err) { | 
|  | 365 | GTEST_SUCCEED() << "test not supported"; | 
|  | 366 | return; | 
|  | 367 | } | 
|  | 368 | err = fillTransaction(transaction2, &callback2, layer); | 
|  | 369 | if (err) { | 
|  | 370 | GTEST_SUCCEED() << "test not supported"; | 
|  | 371 | return; | 
|  | 372 | } | 
|  | 373 |  | 
|  | 374 | transaction2.merge(std::move(transaction1)).apply(); | 
|  | 375 |  | 
|  | 376 | ExpectedResult expected; | 
|  | 377 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 378 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 379 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 380 | } | 
|  | 381 |  | 
|  | 382 | TEST_F(LayerCallbackTest, Merge_DifferentClients) { | 
|  | 383 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 384 | client2(new SurfaceComposerClient); | 
|  | 385 |  | 
|  | 386 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 387 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 388 |  | 
|  | 389 | sp<SurfaceControl> layer1, layer2; | 
|  | 390 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
|  | 391 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 392 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
|  | 393 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 394 |  | 
|  | 395 | Transaction transaction1, transaction2; | 
|  | 396 | CallbackHelper callback1, callback2; | 
|  | 397 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 398 | if (err) { | 
|  | 399 | GTEST_SUCCEED() << "test not supported"; | 
|  | 400 | return; | 
|  | 401 | } | 
|  | 402 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 403 | if (err) { | 
|  | 404 | GTEST_SUCCEED() << "test not supported"; | 
|  | 405 | return; | 
|  | 406 | } | 
|  | 407 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 408 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 409 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 410 |  | 
|  | 411 | ExpectedResult expected; | 
|  | 412 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 413 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 414 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 415 | } | 
|  | 416 |  | 
|  | 417 | TEST_F(LayerCallbackTest, MultipleTransactions) { | 
|  | 418 | sp<SurfaceControl> layer; | 
|  | 419 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 420 |  | 
|  | 421 | Transaction transaction; | 
|  | 422 | CallbackHelper callback; | 
|  | 423 | for (size_t i = 0; i < 10; i++) { | 
|  | 424 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 425 | if (err) { | 
|  | 426 | GTEST_SUCCEED() << "test not supported"; | 
|  | 427 | return; | 
|  | 428 | } | 
|  | 429 |  | 
|  | 430 | transaction.apply(); | 
|  | 431 |  | 
|  | 432 | ExpectedResult expected; | 
|  | 433 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
|  | 434 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 435 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED | 
|  | 436 | : ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 437 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); | 
|  | 438 | } | 
|  | 439 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); | 
|  | 440 | } | 
|  | 441 |  | 
|  | 442 | TEST_F(LayerCallbackTest, MultipleTransactions_NoStateChange) { | 
|  | 443 | sp<SurfaceControl> layer; | 
|  | 444 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 445 |  | 
|  | 446 | Transaction transaction; | 
|  | 447 | CallbackHelper callback; | 
|  | 448 | for (size_t i = 0; i < 10; i++) { | 
|  | 449 | ExpectedResult expected; | 
|  | 450 |  | 
|  | 451 | if (i == 0) { | 
|  | 452 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 453 | if (err) { | 
|  | 454 | GTEST_SUCCEED() << "test not supported"; | 
|  | 455 | return; | 
|  | 456 | } | 
|  | 457 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 458 | } else { | 
|  | 459 | int err = fillTransaction(transaction, &callback); | 
|  | 460 | if (err) { | 
|  | 461 | GTEST_SUCCEED() << "test not supported"; | 
|  | 462 | return; | 
|  | 463 | } | 
|  | 464 | } | 
|  | 465 |  | 
|  | 466 | transaction.apply(); | 
|  | 467 |  | 
|  | 468 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); | 
|  | 469 | } | 
|  | 470 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); | 
|  | 471 | } | 
|  | 472 |  | 
|  | 473 | TEST_F(LayerCallbackTest, MultipleTransactions_SameStateChange) { | 
|  | 474 | sp<SurfaceControl> layer; | 
|  | 475 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 476 |  | 
|  | 477 | Transaction transaction; | 
|  | 478 | CallbackHelper callback; | 
|  | 479 | for (size_t i = 0; i < 10; i++) { | 
|  | 480 | if (i == 0) { | 
|  | 481 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 482 | if (err) { | 
|  | 483 | GTEST_SUCCEED() << "test not supported"; | 
|  | 484 | return; | 
|  | 485 | } | 
|  | 486 | } else { | 
|  | 487 | int err = fillTransaction(transaction, &callback); | 
|  | 488 | if (err) { | 
|  | 489 | GTEST_SUCCEED() << "test not supported"; | 
|  | 490 | return; | 
|  | 491 | } | 
|  | 492 | } | 
|  | 493 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 494 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 495 |  | 
|  | 496 | ExpectedResult expected; | 
|  | 497 | expected.addSurface((i == 0) ? ExpectedResult::Transaction::PRESENTED | 
|  | 498 | : ExpectedResult::Transaction::NOT_PRESENTED, | 
|  | 499 | layer, | 
|  | 500 | (i == 0) ? ExpectedResult::Buffer::ACQUIRED | 
|  | 501 | : ExpectedResult::Buffer::NOT_ACQUIRED); | 
|  | 502 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, i == 0)); | 
|  | 503 | } | 
|  | 504 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); | 
|  | 505 | } | 
|  | 506 |  | 
|  | 507 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge) { | 
|  | 508 | sp<SurfaceControl> layer1, layer2; | 
|  | 509 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 510 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 511 |  | 
|  | 512 | Transaction transaction1, transaction2; | 
|  | 513 | CallbackHelper callback1, callback2; | 
|  | 514 | for (size_t i = 0; i < 10; i++) { | 
|  | 515 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 516 | if (err) { | 
|  | 517 | GTEST_SUCCEED() << "test not supported"; | 
|  | 518 | return; | 
|  | 519 | } | 
|  | 520 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 521 | if (err) { | 
|  | 522 | GTEST_SUCCEED() << "test not supported"; | 
|  | 523 | return; | 
|  | 524 | } | 
|  | 525 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 526 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 527 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 528 |  | 
|  | 529 | ExpectedResult expected; | 
|  | 530 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, | 
|  | 531 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 532 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED | 
|  | 533 | : ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 534 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); | 
|  | 535 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); | 
|  | 536 | } | 
|  | 537 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); | 
|  | 538 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); | 
|  | 539 | } | 
|  | 540 |  | 
|  | 541 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients) { | 
|  | 542 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 543 | client2(new SurfaceComposerClient); | 
|  | 544 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 545 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 546 |  | 
|  | 547 | sp<SurfaceControl> layer1, layer2; | 
|  | 548 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
|  | 549 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 550 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
|  | 551 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 552 |  | 
|  | 553 | Transaction transaction1, transaction2; | 
|  | 554 | CallbackHelper callback1, callback2; | 
|  | 555 | for (size_t i = 0; i < 10; i++) { | 
|  | 556 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 557 | if (err) { | 
|  | 558 | GTEST_SUCCEED() << "test not supported"; | 
|  | 559 | return; | 
|  | 560 | } | 
|  | 561 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 562 | if (err) { | 
|  | 563 | GTEST_SUCCEED() << "test not supported"; | 
|  | 564 | return; | 
|  | 565 | } | 
|  | 566 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 567 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 568 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 569 |  | 
|  | 570 | ExpectedResult expected; | 
|  | 571 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, | 
|  | 572 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 573 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED | 
|  | 574 | : ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 575 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); | 
|  | 576 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); | 
|  | 577 | } | 
|  | 578 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); | 
|  | 579 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); | 
|  | 580 | } | 
|  | 581 |  | 
|  | 582 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_NoStateChange) { | 
|  | 583 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 584 | client2(new SurfaceComposerClient); | 
|  | 585 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 586 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 587 |  | 
|  | 588 | sp<SurfaceControl> layer1, layer2; | 
|  | 589 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
|  | 590 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 591 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
|  | 592 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 593 |  | 
|  | 594 | Transaction transaction1, transaction2; | 
|  | 595 | CallbackHelper callback1, callback2; | 
|  | 596 |  | 
|  | 597 | // Normal call to set up test | 
|  | 598 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 599 | if (err) { | 
|  | 600 | GTEST_SUCCEED() << "test not supported"; | 
|  | 601 | return; | 
|  | 602 | } | 
|  | 603 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 604 | if (err) { | 
|  | 605 | GTEST_SUCCEED() << "test not supported"; | 
|  | 606 | return; | 
|  | 607 | } | 
|  | 608 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 609 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 610 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 611 |  | 
|  | 612 | ExpectedResult expected; | 
|  | 613 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 614 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 615 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 616 | expected.reset(); | 
|  | 617 |  | 
|  | 618 | // Test | 
|  | 619 | err = fillTransaction(transaction1, &callback1); | 
|  | 620 | if (err) { | 
|  | 621 | GTEST_SUCCEED() << "test not supported"; | 
|  | 622 | return; | 
|  | 623 | } | 
|  | 624 | err = fillTransaction(transaction2, &callback2); | 
|  | 625 | if (err) { | 
|  | 626 | GTEST_SUCCEED() << "test not supported"; | 
|  | 627 | return; | 
|  | 628 | } | 
|  | 629 |  | 
|  | 630 | transaction2.merge(std::move(transaction1)).apply(); | 
|  | 631 |  | 
|  | 632 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 633 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 634 | } | 
|  | 635 |  | 
|  | 636 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_SameStateChange) { | 
|  | 637 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 638 | client2(new SurfaceComposerClient); | 
|  | 639 |  | 
|  | 640 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 641 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 642 |  | 
|  | 643 | sp<SurfaceControl> layer1, layer2; | 
|  | 644 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
|  | 645 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 646 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
|  | 647 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 648 |  | 
|  | 649 | Transaction transaction1, transaction2; | 
|  | 650 | CallbackHelper callback1, callback2; | 
|  | 651 |  | 
|  | 652 | // Normal call to set up test | 
|  | 653 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 654 | if (err) { | 
|  | 655 | GTEST_SUCCEED() << "test not supported"; | 
|  | 656 | return; | 
|  | 657 | } | 
|  | 658 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 659 | if (err) { | 
|  | 660 | GTEST_SUCCEED() << "test not supported"; | 
|  | 661 | return; | 
|  | 662 | } | 
|  | 663 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 664 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 665 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 666 |  | 
|  | 667 | ExpectedResult expected; | 
|  | 668 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 669 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 670 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 671 | expected.reset(); | 
|  | 672 |  | 
|  | 673 | // Test | 
|  | 674 | err = fillTransaction(transaction1, &callback1); | 
|  | 675 | if (err) { | 
|  | 676 | GTEST_SUCCEED() << "test not supported"; | 
|  | 677 | return; | 
|  | 678 | } | 
|  | 679 | err = fillTransaction(transaction2, &callback2); | 
|  | 680 | if (err) { | 
|  | 681 | GTEST_SUCCEED() << "test not supported"; | 
|  | 682 | return; | 
|  | 683 | } | 
|  | 684 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 685 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 686 |  | 
|  | 687 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer2, | 
|  | 688 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
|  | 689 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 690 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 691 | } | 
|  | 692 |  | 
|  | 693 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame) { | 
|  | 694 | sp<SurfaceControl> layer; | 
|  | 695 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 696 |  | 
|  | 697 | Transaction transaction; | 
|  | 698 | CallbackHelper callback; | 
|  | 699 | std::vector<ExpectedResult> expectedResults(50); | 
|  | 700 | for (auto& expected : expectedResults) { | 
|  | 701 | expected.reset(); | 
|  | 702 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
|  | 703 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 704 | ExpectedResult::PreviousBuffer::UNKNOWN); | 
|  | 705 |  | 
|  | 706 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 707 | if (err) { | 
|  | 708 | GTEST_SUCCEED() << "test not supported"; | 
|  | 709 | return; | 
|  | 710 | } | 
|  | 711 |  | 
|  | 712 | transaction.apply(); | 
|  | 713 | } | 
|  | 714 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); | 
|  | 715 | } | 
|  | 716 |  | 
|  | 717 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_NoStateChange) { | 
|  | 718 | sp<SurfaceControl> layer; | 
|  | 719 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 720 |  | 
|  | 721 | // Normal call to set up test | 
|  | 722 | Transaction transaction; | 
|  | 723 | CallbackHelper callback; | 
|  | 724 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 725 | if (err) { | 
|  | 726 | GTEST_SUCCEED() << "test not supported"; | 
|  | 727 | return; | 
|  | 728 | } | 
|  | 729 |  | 
|  | 730 | transaction.apply(); | 
|  | 731 |  | 
|  | 732 | ExpectedResult expected; | 
|  | 733 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 734 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 735 |  | 
|  | 736 | // Test | 
|  | 737 | std::vector<ExpectedResult> expectedResults(50); | 
|  | 738 | for (auto& expected : expectedResults) { | 
|  | 739 | expected.reset(); | 
|  | 740 |  | 
|  | 741 | err = fillTransaction(transaction, &callback); | 
|  | 742 | if (err) { | 
|  | 743 | GTEST_SUCCEED() << "test not supported"; | 
|  | 744 | return; | 
|  | 745 | } | 
|  | 746 |  | 
|  | 747 | transaction.apply(); | 
|  | 748 | } | 
|  | 749 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); | 
|  | 750 | } | 
|  | 751 |  | 
|  | 752 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_SameStateChange) { | 
|  | 753 | sp<SurfaceControl> layer; | 
|  | 754 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 755 |  | 
|  | 756 | // Normal call to set up test | 
|  | 757 | Transaction transaction; | 
|  | 758 | CallbackHelper callback; | 
|  | 759 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 760 | if (err) { | 
|  | 761 | GTEST_SUCCEED() << "test not supported"; | 
|  | 762 | return; | 
|  | 763 | } | 
|  | 764 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 765 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 766 |  | 
|  | 767 | ExpectedResult expectedResult; | 
|  | 768 | expectedResult.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 769 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expectedResult, true)); | 
|  | 770 |  | 
|  | 771 | // Test | 
|  | 772 | std::vector<ExpectedResult> expectedResults(50); | 
|  | 773 | for (auto& expected : expectedResults) { | 
|  | 774 | expected.reset(); | 
|  | 775 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, | 
|  | 776 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
|  | 777 |  | 
|  | 778 | err = fillTransaction(transaction, &callback); | 
|  | 779 | if (err) { | 
|  | 780 | GTEST_SUCCEED() << "test not supported"; | 
|  | 781 | return; | 
|  | 782 | } | 
|  | 783 |  | 
| Orion Hodson | 1014c4b | 2021-04-08 12:30:21 +0000 | [diff] [blame] | 784 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 785 | } | 
|  | 786 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); | 
|  | 787 | } | 
|  | 788 |  | 
|  | 789 | TEST_F(LayerCallbackTest, DesiredPresentTime) { | 
|  | 790 | sp<SurfaceControl> layer; | 
|  | 791 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 792 |  | 
|  | 793 | Transaction transaction; | 
|  | 794 | CallbackHelper callback; | 
|  | 795 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 796 | if (err) { | 
|  | 797 | GTEST_SUCCEED() << "test not supported"; | 
|  | 798 | return; | 
|  | 799 | } | 
|  | 800 |  | 
|  | 801 | // Try to present 100ms in the future | 
| Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 802 | nsecs_t time = systemTime() + std::chrono::nanoseconds(100ms).count(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 803 |  | 
|  | 804 | transaction.setDesiredPresentTime(time); | 
|  | 805 | transaction.apply(); | 
|  | 806 |  | 
|  | 807 | ExpectedResult expected; | 
|  | 808 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 809 | expected.addExpectedPresentTime(time); | 
|  | 810 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 811 | } | 
|  | 812 |  | 
|  | 813 | TEST_F(LayerCallbackTest, DesiredPresentTime_Multiple) { | 
|  | 814 | sp<SurfaceControl> layer; | 
|  | 815 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 816 |  | 
|  | 817 | Transaction transaction; | 
|  | 818 | CallbackHelper callback1; | 
|  | 819 | int err = fillTransaction(transaction, &callback1, layer); | 
|  | 820 | if (err) { | 
|  | 821 | GTEST_SUCCEED() << "test not supported"; | 
|  | 822 | return; | 
|  | 823 | } | 
|  | 824 |  | 
|  | 825 | // Try to present 100ms in the future | 
| Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 826 | nsecs_t time = systemTime() + std::chrono::nanoseconds(100ms).count(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 827 |  | 
|  | 828 | transaction.setDesiredPresentTime(time); | 
|  | 829 | transaction.apply(); | 
|  | 830 |  | 
|  | 831 | ExpectedResult expected1; | 
|  | 832 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 833 | expected1.addExpectedPresentTime(time); | 
|  | 834 |  | 
|  | 835 | CallbackHelper callback2; | 
|  | 836 | err = fillTransaction(transaction, &callback2, layer); | 
|  | 837 | if (err) { | 
|  | 838 | GTEST_SUCCEED() << "test not supported"; | 
|  | 839 | return; | 
|  | 840 | } | 
|  | 841 |  | 
|  | 842 | // Try to present 33ms after the first frame | 
| Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 843 | time += std::chrono::nanoseconds(33ms).count(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 844 |  | 
|  | 845 | transaction.setDesiredPresentTime(time); | 
|  | 846 | transaction.apply(); | 
|  | 847 |  | 
|  | 848 | ExpectedResult expected2; | 
|  | 849 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
|  | 850 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 851 | ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 852 | expected2.addExpectedPresentTime(time); | 
|  | 853 |  | 
|  | 854 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); | 
|  | 855 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); | 
|  | 856 | } | 
|  | 857 |  | 
|  | 858 | TEST_F(LayerCallbackTest, DesiredPresentTime_OutOfOrder) { | 
|  | 859 | sp<SurfaceControl> layer; | 
|  | 860 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 861 |  | 
|  | 862 | Transaction transaction; | 
|  | 863 | CallbackHelper callback1; | 
|  | 864 | int err = fillTransaction(transaction, &callback1, layer); | 
|  | 865 | if (err) { | 
|  | 866 | GTEST_SUCCEED() << "test not supported"; | 
|  | 867 | return; | 
|  | 868 | } | 
|  | 869 |  | 
|  | 870 | // Try to present 100ms in the future | 
| Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 871 | nsecs_t time = systemTime() + std::chrono::nanoseconds(100ms).count(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 872 |  | 
|  | 873 | transaction.setDesiredPresentTime(time); | 
|  | 874 | transaction.apply(); | 
|  | 875 |  | 
|  | 876 | ExpectedResult expected1; | 
|  | 877 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 878 | expected1.addExpectedPresentTime(time); | 
|  | 879 |  | 
|  | 880 | CallbackHelper callback2; | 
|  | 881 | err = fillTransaction(transaction, &callback2, layer); | 
|  | 882 | if (err) { | 
|  | 883 | GTEST_SUCCEED() << "test not supported"; | 
|  | 884 | return; | 
|  | 885 | } | 
|  | 886 |  | 
|  | 887 | // Try to present 33ms before the previous frame | 
| Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 888 | time -= std::chrono::nanoseconds(33ms).count(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 889 |  | 
|  | 890 | transaction.setDesiredPresentTime(time); | 
|  | 891 | transaction.apply(); | 
|  | 892 |  | 
|  | 893 | ExpectedResult expected2; | 
|  | 894 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
|  | 895 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 896 | ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 897 |  | 
|  | 898 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); | 
|  | 899 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); | 
|  | 900 | } | 
|  | 901 |  | 
|  | 902 | TEST_F(LayerCallbackTest, DesiredPresentTime_Past) { | 
|  | 903 | sp<SurfaceControl> layer; | 
|  | 904 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 905 |  | 
|  | 906 | Transaction transaction; | 
|  | 907 | CallbackHelper callback; | 
|  | 908 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 909 | if (err) { | 
|  | 910 | GTEST_SUCCEED() << "test not supported"; | 
|  | 911 | return; | 
|  | 912 | } | 
|  | 913 |  | 
|  | 914 | // Try to present 100ms in the past | 
| Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 915 | nsecs_t time = systemTime() - std::chrono::nanoseconds(100ms).count(); | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 916 |  | 
|  | 917 | transaction.setDesiredPresentTime(time); | 
|  | 918 | transaction.apply(); | 
|  | 919 |  | 
|  | 920 | ExpectedResult expected; | 
|  | 921 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 922 | expected.addExpectedPresentTime(systemTime()); | 
|  | 923 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 924 | } | 
| Ady Abraham | 29d16cb | 2021-03-08 13:19:21 -0800 | [diff] [blame] | 925 |  | 
|  | 926 | TEST_F(LayerCallbackTest, ExpectedPresentTime) { | 
|  | 927 | sp<SurfaceControl> layer; | 
|  | 928 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 929 |  | 
|  | 930 | Transaction transaction; | 
|  | 931 | CallbackHelper callback; | 
|  | 932 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 933 | if (err) { | 
|  | 934 | GTEST_SUCCEED() << "test not supported"; | 
|  | 935 | return; | 
|  | 936 | } | 
|  | 937 |  | 
|  | 938 | const Vsync vsync = waitForNextVsync(); | 
|  | 939 | transaction.setFrameTimelineInfo({vsync.vsyncId, 0}); | 
|  | 940 | transaction.apply(); | 
|  | 941 |  | 
|  | 942 | ExpectedResult expected; | 
|  | 943 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 944 | expected.addExpectedPresentTimeForVsyncId(vsync.expectedPresentTime); | 
|  | 945 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 946 | } | 
|  | 947 |  | 
| Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 948 | } // namespace android |