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 | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame^] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Valerie Hau | 9cfc6d8 | 2019-09-23 13:54:07 -0700 | [diff] [blame] | 21 | #include "LayerTransactionTest.h" |
| 22 | #include "utils/CallbackUtils.h" |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | using android::hardware::graphics::common::V1_1::BufferUsage; |
| 27 | |
| 28 | ::testing::Environment* const binderEnv = |
| 29 | ::testing::AddGlobalTestEnvironment(new BinderEnvironment()); |
| 30 | |
| 31 | class LayerCallbackTest : public LayerTransactionTest { |
| 32 | public: |
| 33 | virtual sp<SurfaceControl> createBufferStateLayer() { |
| 34 | return createLayer(mClient, "test", 0, 0, ISurfaceComposerClient::eFXSurfaceBufferState); |
| 35 | } |
| 36 | |
| 37 | static int fillTransaction(Transaction& transaction, CallbackHelper* callbackHelper, |
| 38 | const sp<SurfaceControl>& layer = nullptr, bool setBuffer = true, |
| 39 | bool setBackgroundColor = false) { |
| 40 | if (layer) { |
| 41 | sp<GraphicBuffer> buffer; |
| 42 | sp<Fence> fence; |
| 43 | if (setBuffer) { |
| 44 | int err = getBuffer(&buffer, &fence); |
| 45 | if (err != NO_ERROR) { |
| 46 | return err; |
| 47 | } |
| 48 | |
| 49 | transaction.setBuffer(layer, buffer); |
| 50 | transaction.setAcquireFence(layer, fence); |
| 51 | } |
| 52 | |
| 53 | if (setBackgroundColor) { |
| 54 | transaction.setBackgroundColor(layer, /*color*/ half3(1.0f, 0, 0), /*alpha*/ 1.0f, |
| 55 | ui::Dataspace::UNKNOWN); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | transaction.addTransactionCompletedCallback(callbackHelper->function, |
| 60 | callbackHelper->getContext()); |
| 61 | return NO_ERROR; |
| 62 | } |
| 63 | |
| 64 | static void waitForCallback(CallbackHelper& helper, const ExpectedResult& expectedResult, |
| 65 | bool finalState = false) { |
| 66 | CallbackData callbackData; |
| 67 | ASSERT_NO_FATAL_FAILURE(helper.getCallbackData(&callbackData)); |
| 68 | EXPECT_NO_FATAL_FAILURE(expectedResult.verifyCallbackData(callbackData)); |
| 69 | |
| 70 | if (finalState) { |
| 71 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | static void waitForCallbacks(CallbackHelper& helper, |
| 76 | const std::vector<ExpectedResult>& expectedResults, |
| 77 | bool finalState = false) { |
| 78 | for (const auto& expectedResult : expectedResults) { |
| 79 | waitForCallback(helper, expectedResult); |
| 80 | } |
| 81 | if (finalState) { |
| 82 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 83 | } |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | TEST_F(LayerCallbackTest, BufferColor) { |
| 88 | sp<SurfaceControl> layer; |
| 89 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 90 | |
| 91 | Transaction transaction; |
| 92 | CallbackHelper callback; |
| 93 | int err = fillTransaction(transaction, &callback, layer, true, true); |
| 94 | if (err) { |
| 95 | GTEST_SUCCEED() << "test not supported"; |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | transaction.apply(); |
| 100 | |
| 101 | ExpectedResult expected; |
| 102 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 103 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 104 | } |
| 105 | |
| 106 | TEST_F(LayerCallbackTest, NoBufferNoColor) { |
| 107 | sp<SurfaceControl> layer; |
| 108 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 109 | |
| 110 | Transaction transaction; |
| 111 | CallbackHelper callback; |
| 112 | int err = fillTransaction(transaction, &callback, layer, false, false); |
| 113 | if (err) { |
| 114 | GTEST_SUCCEED() << "test not supported"; |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
| 119 | |
| 120 | ExpectedResult expected; |
| 121 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, |
| 122 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 123 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 124 | } |
| 125 | |
| 126 | TEST_F(LayerCallbackTest, BufferNoColor) { |
| 127 | sp<SurfaceControl> layer; |
| 128 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 129 | |
| 130 | Transaction transaction; |
| 131 | CallbackHelper callback; |
| 132 | int err = fillTransaction(transaction, &callback, layer, true, false); |
| 133 | if (err) { |
| 134 | GTEST_SUCCEED() << "test not supported"; |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
| 139 | |
| 140 | ExpectedResult expected; |
| 141 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 142 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 143 | } |
| 144 | |
| 145 | TEST_F(LayerCallbackTest, NoBufferColor) { |
| 146 | sp<SurfaceControl> layer; |
| 147 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 148 | |
| 149 | Transaction transaction; |
| 150 | CallbackHelper callback; |
| 151 | int err = fillTransaction(transaction, &callback, layer, false, true); |
| 152 | if (err) { |
| 153 | GTEST_SUCCEED() << "test not supported"; |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
| 158 | |
| 159 | ExpectedResult expected; |
| 160 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 161 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 162 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 163 | } |
| 164 | |
| 165 | TEST_F(LayerCallbackTest, NoStateChange) { |
| 166 | Transaction transaction; |
| 167 | CallbackHelper callback; |
| 168 | int err = fillTransaction(transaction, &callback); |
| 169 | if (err) { |
| 170 | GTEST_SUCCEED() << "test not supported"; |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | transaction.apply(); |
| 175 | |
| 176 | ExpectedResult expected; |
| 177 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 178 | } |
| 179 | |
| 180 | TEST_F(LayerCallbackTest, OffScreen) { |
| 181 | sp<SurfaceControl> layer; |
| 182 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 183 | |
| 184 | Transaction transaction; |
| 185 | CallbackHelper callback; |
| 186 | int err = fillTransaction(transaction, &callback, layer); |
| 187 | if (err) { |
| 188 | GTEST_SUCCEED() << "test not supported"; |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | transaction.setFrame(layer, Rect(-100, -100, 100, 100)).apply(); |
| 193 | |
| 194 | ExpectedResult expected; |
| 195 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 196 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 197 | } |
| 198 | |
| 199 | TEST_F(LayerCallbackTest, MergeBufferNoColor) { |
| 200 | sp<SurfaceControl> layer1, layer2; |
| 201 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 202 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 203 | |
| 204 | Transaction transaction1, transaction2; |
| 205 | CallbackHelper callback1, callback2; |
| 206 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 207 | if (err) { |
| 208 | GTEST_SUCCEED() << "test not supported"; |
| 209 | return; |
| 210 | } |
| 211 | err = fillTransaction(transaction2, &callback2, layer2); |
| 212 | if (err) { |
| 213 | GTEST_SUCCEED() << "test not supported"; |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 218 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
| 219 | |
| 220 | ExpectedResult expected; |
| 221 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 222 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 223 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 224 | } |
| 225 | |
| 226 | TEST_F(LayerCallbackTest, MergeNoBufferColor) { |
| 227 | sp<SurfaceControl> layer1, layer2; |
| 228 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 229 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 230 | |
| 231 | Transaction transaction1, transaction2; |
| 232 | CallbackHelper callback1, callback2; |
| 233 | int err = fillTransaction(transaction1, &callback1, layer1, false, true); |
| 234 | if (err) { |
| 235 | GTEST_SUCCEED() << "test not supported"; |
| 236 | return; |
| 237 | } |
| 238 | err = fillTransaction(transaction2, &callback2, layer2, false, true); |
| 239 | if (err) { |
| 240 | GTEST_SUCCEED() << "test not supported"; |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 245 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
| 246 | |
| 247 | ExpectedResult expected; |
| 248 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
| 249 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 250 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 251 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 252 | } |
| 253 | |
| 254 | TEST_F(LayerCallbackTest, MergeOneBufferOneColor) { |
| 255 | sp<SurfaceControl> layer1, layer2; |
| 256 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 257 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 258 | |
| 259 | Transaction transaction1, transaction2; |
| 260 | CallbackHelper callback1, callback2; |
| 261 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 262 | if (err) { |
| 263 | GTEST_SUCCEED() << "test not supported"; |
| 264 | return; |
| 265 | } |
| 266 | err = fillTransaction(transaction2, &callback2, layer2, false, true); |
| 267 | if (err) { |
| 268 | GTEST_SUCCEED() << "test not supported"; |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 273 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
| 274 | |
| 275 | ExpectedResult expected; |
| 276 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer1); |
| 277 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer2, |
| 278 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 279 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 280 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 281 | } |
| 282 | TEST_F(LayerCallbackTest, Merge_SameCallback) { |
| 283 | sp<SurfaceControl> layer1, layer2; |
| 284 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 285 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 286 | |
| 287 | Transaction transaction1, transaction2; |
| 288 | CallbackHelper callback; |
| 289 | int err = fillTransaction(transaction1, &callback, layer1); |
| 290 | if (err) { |
| 291 | GTEST_SUCCEED() << "test not supported"; |
| 292 | return; |
| 293 | } |
| 294 | err = fillTransaction(transaction2, &callback, layer2); |
| 295 | if (err) { |
| 296 | GTEST_SUCCEED() << "test not supported"; |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | transaction2.merge(std::move(transaction1)).apply(); |
| 301 | |
| 302 | ExpectedResult expected; |
| 303 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 304 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 305 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 306 | } |
| 307 | |
| 308 | TEST_F(LayerCallbackTest, Merge_SameLayer) { |
| 309 | sp<SurfaceControl> layer; |
| 310 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 311 | |
| 312 | Transaction transaction1, transaction2; |
| 313 | CallbackHelper callback1, callback2; |
| 314 | int err = fillTransaction(transaction1, &callback1, layer); |
| 315 | if (err) { |
| 316 | GTEST_SUCCEED() << "test not supported"; |
| 317 | return; |
| 318 | } |
| 319 | err = fillTransaction(transaction2, &callback2, layer); |
| 320 | if (err) { |
| 321 | GTEST_SUCCEED() << "test not supported"; |
| 322 | return; |
| 323 | } |
| 324 | |
| 325 | transaction2.merge(std::move(transaction1)).apply(); |
| 326 | |
| 327 | ExpectedResult expected; |
| 328 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 329 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 330 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 331 | } |
| 332 | |
| 333 | TEST_F(LayerCallbackTest, Merge_DifferentClients) { |
| 334 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 335 | client2(new SurfaceComposerClient); |
| 336 | |
| 337 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 338 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 339 | |
| 340 | sp<SurfaceControl> layer1, layer2; |
| 341 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
| 342 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 343 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
| 344 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 345 | |
| 346 | Transaction transaction1, transaction2; |
| 347 | CallbackHelper callback1, callback2; |
| 348 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 349 | if (err) { |
| 350 | GTEST_SUCCEED() << "test not supported"; |
| 351 | return; |
| 352 | } |
| 353 | err = fillTransaction(transaction2, &callback2, layer2); |
| 354 | if (err) { |
| 355 | GTEST_SUCCEED() << "test not supported"; |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 360 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
| 361 | |
| 362 | ExpectedResult expected; |
| 363 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 364 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 365 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 366 | } |
| 367 | |
| 368 | TEST_F(LayerCallbackTest, MultipleTransactions) { |
| 369 | sp<SurfaceControl> layer; |
| 370 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 371 | |
| 372 | Transaction transaction; |
| 373 | CallbackHelper callback; |
| 374 | for (size_t i = 0; i < 10; i++) { |
| 375 | int err = fillTransaction(transaction, &callback, layer); |
| 376 | if (err) { |
| 377 | GTEST_SUCCEED() << "test not supported"; |
| 378 | return; |
| 379 | } |
| 380 | |
| 381 | transaction.apply(); |
| 382 | |
| 383 | ExpectedResult expected; |
| 384 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 385 | ExpectedResult::Buffer::ACQUIRED, |
| 386 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 387 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 388 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 389 | } |
| 390 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 391 | } |
| 392 | |
| 393 | TEST_F(LayerCallbackTest, MultipleTransactions_NoStateChange) { |
| 394 | sp<SurfaceControl> layer; |
| 395 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 396 | |
| 397 | Transaction transaction; |
| 398 | CallbackHelper callback; |
| 399 | for (size_t i = 0; i < 10; i++) { |
| 400 | ExpectedResult expected; |
| 401 | |
| 402 | if (i == 0) { |
| 403 | int err = fillTransaction(transaction, &callback, layer); |
| 404 | if (err) { |
| 405 | GTEST_SUCCEED() << "test not supported"; |
| 406 | return; |
| 407 | } |
| 408 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 409 | } else { |
| 410 | int err = fillTransaction(transaction, &callback); |
| 411 | if (err) { |
| 412 | GTEST_SUCCEED() << "test not supported"; |
| 413 | return; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | transaction.apply(); |
| 418 | |
| 419 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 420 | } |
| 421 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 422 | } |
| 423 | |
| 424 | TEST_F(LayerCallbackTest, MultipleTransactions_SameStateChange) { |
| 425 | sp<SurfaceControl> layer; |
| 426 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 427 | |
| 428 | Transaction transaction; |
| 429 | CallbackHelper callback; |
| 430 | for (size_t i = 0; i < 10; i++) { |
| 431 | if (i == 0) { |
| 432 | int err = fillTransaction(transaction, &callback, layer); |
| 433 | if (err) { |
| 434 | GTEST_SUCCEED() << "test not supported"; |
| 435 | return; |
| 436 | } |
| 437 | } else { |
| 438 | int err = fillTransaction(transaction, &callback); |
| 439 | if (err) { |
| 440 | GTEST_SUCCEED() << "test not supported"; |
| 441 | return; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
| 446 | |
| 447 | ExpectedResult expected; |
| 448 | expected.addSurface((i == 0) ? ExpectedResult::Transaction::PRESENTED |
| 449 | : ExpectedResult::Transaction::NOT_PRESENTED, |
| 450 | layer, |
| 451 | (i == 0) ? ExpectedResult::Buffer::ACQUIRED |
| 452 | : ExpectedResult::Buffer::NOT_ACQUIRED); |
| 453 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, i == 0)); |
| 454 | } |
| 455 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 456 | } |
| 457 | |
| 458 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge) { |
| 459 | sp<SurfaceControl> layer1, layer2; |
| 460 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 461 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 462 | |
| 463 | Transaction transaction1, transaction2; |
| 464 | CallbackHelper callback1, callback2; |
| 465 | for (size_t i = 0; i < 10; i++) { |
| 466 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 467 | if (err) { |
| 468 | GTEST_SUCCEED() << "test not supported"; |
| 469 | return; |
| 470 | } |
| 471 | err = fillTransaction(transaction2, &callback2, layer2); |
| 472 | if (err) { |
| 473 | GTEST_SUCCEED() << "test not supported"; |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 478 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
| 479 | |
| 480 | ExpectedResult expected; |
| 481 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
| 482 | ExpectedResult::Buffer::ACQUIRED, |
| 483 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 484 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 485 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 486 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 487 | } |
| 488 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 489 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 490 | } |
| 491 | |
| 492 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients) { |
| 493 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 494 | client2(new SurfaceComposerClient); |
| 495 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 496 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 497 | |
| 498 | sp<SurfaceControl> layer1, layer2; |
| 499 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
| 500 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 501 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
| 502 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 503 | |
| 504 | Transaction transaction1, transaction2; |
| 505 | CallbackHelper callback1, callback2; |
| 506 | for (size_t i = 0; i < 10; i++) { |
| 507 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 508 | if (err) { |
| 509 | GTEST_SUCCEED() << "test not supported"; |
| 510 | return; |
| 511 | } |
| 512 | err = fillTransaction(transaction2, &callback2, layer2); |
| 513 | if (err) { |
| 514 | GTEST_SUCCEED() << "test not supported"; |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 519 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
| 520 | |
| 521 | ExpectedResult expected; |
| 522 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
| 523 | ExpectedResult::Buffer::ACQUIRED, |
| 524 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 525 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 526 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 527 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 528 | } |
| 529 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 530 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 531 | } |
| 532 | |
| 533 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_NoStateChange) { |
| 534 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 535 | client2(new SurfaceComposerClient); |
| 536 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 537 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 538 | |
| 539 | sp<SurfaceControl> layer1, layer2; |
| 540 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
| 541 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 542 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
| 543 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 544 | |
| 545 | Transaction transaction1, transaction2; |
| 546 | CallbackHelper callback1, callback2; |
| 547 | |
| 548 | // Normal call to set up test |
| 549 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 550 | if (err) { |
| 551 | GTEST_SUCCEED() << "test not supported"; |
| 552 | return; |
| 553 | } |
| 554 | err = fillTransaction(transaction2, &callback2, layer2); |
| 555 | if (err) { |
| 556 | GTEST_SUCCEED() << "test not supported"; |
| 557 | return; |
| 558 | } |
| 559 | |
| 560 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 561 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
| 562 | |
| 563 | ExpectedResult expected; |
| 564 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 565 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 566 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 567 | expected.reset(); |
| 568 | |
| 569 | // Test |
| 570 | err = fillTransaction(transaction1, &callback1); |
| 571 | if (err) { |
| 572 | GTEST_SUCCEED() << "test not supported"; |
| 573 | return; |
| 574 | } |
| 575 | err = fillTransaction(transaction2, &callback2); |
| 576 | if (err) { |
| 577 | GTEST_SUCCEED() << "test not supported"; |
| 578 | return; |
| 579 | } |
| 580 | |
| 581 | transaction2.merge(std::move(transaction1)).apply(); |
| 582 | |
| 583 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 584 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 585 | } |
| 586 | |
| 587 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_SameStateChange) { |
| 588 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 589 | client2(new SurfaceComposerClient); |
| 590 | |
| 591 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 592 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 593 | |
| 594 | sp<SurfaceControl> layer1, layer2; |
| 595 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
| 596 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 597 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
| 598 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 599 | |
| 600 | Transaction transaction1, transaction2; |
| 601 | CallbackHelper callback1, callback2; |
| 602 | |
| 603 | // Normal call to set up test |
| 604 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 605 | if (err) { |
| 606 | GTEST_SUCCEED() << "test not supported"; |
| 607 | return; |
| 608 | } |
| 609 | err = fillTransaction(transaction2, &callback2, layer2); |
| 610 | if (err) { |
| 611 | GTEST_SUCCEED() << "test not supported"; |
| 612 | return; |
| 613 | } |
| 614 | |
| 615 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 616 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
| 617 | |
| 618 | ExpectedResult expected; |
| 619 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 620 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 621 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 622 | expected.reset(); |
| 623 | |
| 624 | // Test |
| 625 | err = fillTransaction(transaction1, &callback1); |
| 626 | if (err) { |
| 627 | GTEST_SUCCEED() << "test not supported"; |
| 628 | return; |
| 629 | } |
| 630 | err = fillTransaction(transaction2, &callback2); |
| 631 | if (err) { |
| 632 | GTEST_SUCCEED() << "test not supported"; |
| 633 | return; |
| 634 | } |
| 635 | |
| 636 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
| 637 | |
| 638 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer2, |
| 639 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 640 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 641 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 642 | } |
| 643 | |
| 644 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame) { |
| 645 | sp<SurfaceControl> layer; |
| 646 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 647 | |
| 648 | Transaction transaction; |
| 649 | CallbackHelper callback; |
| 650 | std::vector<ExpectedResult> expectedResults(50); |
| 651 | for (auto& expected : expectedResults) { |
| 652 | expected.reset(); |
| 653 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 654 | ExpectedResult::Buffer::ACQUIRED, |
| 655 | ExpectedResult::PreviousBuffer::UNKNOWN); |
| 656 | |
| 657 | int err = fillTransaction(transaction, &callback, layer); |
| 658 | if (err) { |
| 659 | GTEST_SUCCEED() << "test not supported"; |
| 660 | return; |
| 661 | } |
| 662 | |
| 663 | transaction.apply(); |
| 664 | } |
| 665 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 666 | } |
| 667 | |
| 668 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_NoStateChange) { |
| 669 | sp<SurfaceControl> layer; |
| 670 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 671 | |
| 672 | // Normal call to set up test |
| 673 | Transaction transaction; |
| 674 | CallbackHelper callback; |
| 675 | int err = fillTransaction(transaction, &callback, layer); |
| 676 | if (err) { |
| 677 | GTEST_SUCCEED() << "test not supported"; |
| 678 | return; |
| 679 | } |
| 680 | |
| 681 | transaction.apply(); |
| 682 | |
| 683 | ExpectedResult expected; |
| 684 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 685 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 686 | |
| 687 | // Test |
| 688 | std::vector<ExpectedResult> expectedResults(50); |
| 689 | for (auto& expected : expectedResults) { |
| 690 | expected.reset(); |
| 691 | |
| 692 | err = fillTransaction(transaction, &callback); |
| 693 | if (err) { |
| 694 | GTEST_SUCCEED() << "test not supported"; |
| 695 | return; |
| 696 | } |
| 697 | |
| 698 | transaction.apply(); |
| 699 | } |
| 700 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 701 | } |
| 702 | |
| 703 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_SameStateChange) { |
| 704 | sp<SurfaceControl> layer; |
| 705 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 706 | |
| 707 | // Normal call to set up test |
| 708 | Transaction transaction; |
| 709 | CallbackHelper callback; |
| 710 | int err = fillTransaction(transaction, &callback, layer); |
| 711 | if (err) { |
| 712 | GTEST_SUCCEED() << "test not supported"; |
| 713 | return; |
| 714 | } |
| 715 | |
| 716 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
| 717 | |
| 718 | ExpectedResult expectedResult; |
| 719 | expectedResult.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 720 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expectedResult, true)); |
| 721 | |
| 722 | // Test |
| 723 | std::vector<ExpectedResult> expectedResults(50); |
| 724 | for (auto& expected : expectedResults) { |
| 725 | expected.reset(); |
| 726 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, |
| 727 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 728 | |
| 729 | err = fillTransaction(transaction, &callback); |
| 730 | if (err) { |
| 731 | GTEST_SUCCEED() << "test not supported"; |
| 732 | return; |
| 733 | } |
| 734 | |
| 735 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
| 736 | } |
| 737 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 738 | } |
| 739 | |
| 740 | TEST_F(LayerCallbackTest, DesiredPresentTime) { |
| 741 | sp<SurfaceControl> layer; |
| 742 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 743 | |
| 744 | Transaction transaction; |
| 745 | CallbackHelper callback; |
| 746 | int err = fillTransaction(transaction, &callback, layer); |
| 747 | if (err) { |
| 748 | GTEST_SUCCEED() << "test not supported"; |
| 749 | return; |
| 750 | } |
| 751 | |
| 752 | // Try to present 100ms in the future |
| 753 | nsecs_t time = systemTime() + (100 * 1e6); |
| 754 | |
| 755 | transaction.setDesiredPresentTime(time); |
| 756 | transaction.apply(); |
| 757 | |
| 758 | ExpectedResult expected; |
| 759 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 760 | expected.addExpectedPresentTime(time); |
| 761 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 762 | } |
| 763 | |
| 764 | TEST_F(LayerCallbackTest, DesiredPresentTime_Multiple) { |
| 765 | sp<SurfaceControl> layer; |
| 766 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 767 | |
| 768 | Transaction transaction; |
| 769 | CallbackHelper callback1; |
| 770 | int err = fillTransaction(transaction, &callback1, layer); |
| 771 | if (err) { |
| 772 | GTEST_SUCCEED() << "test not supported"; |
| 773 | return; |
| 774 | } |
| 775 | |
| 776 | // Try to present 100ms in the future |
| 777 | nsecs_t time = systemTime() + (100 * 1e6); |
| 778 | |
| 779 | transaction.setDesiredPresentTime(time); |
| 780 | transaction.apply(); |
| 781 | |
| 782 | ExpectedResult expected1; |
| 783 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 784 | expected1.addExpectedPresentTime(time); |
| 785 | |
| 786 | CallbackHelper callback2; |
| 787 | err = fillTransaction(transaction, &callback2, layer); |
| 788 | if (err) { |
| 789 | GTEST_SUCCEED() << "test not supported"; |
| 790 | return; |
| 791 | } |
| 792 | |
| 793 | // Try to present 33ms after the first frame |
| 794 | time += (33.3 * 1e6); |
| 795 | |
| 796 | transaction.setDesiredPresentTime(time); |
| 797 | transaction.apply(); |
| 798 | |
| 799 | ExpectedResult expected2; |
| 800 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 801 | ExpectedResult::Buffer::ACQUIRED, |
| 802 | ExpectedResult::PreviousBuffer::RELEASED); |
| 803 | expected2.addExpectedPresentTime(time); |
| 804 | |
| 805 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); |
| 806 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); |
| 807 | } |
| 808 | |
| 809 | TEST_F(LayerCallbackTest, DesiredPresentTime_OutOfOrder) { |
| 810 | sp<SurfaceControl> layer; |
| 811 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 812 | |
| 813 | Transaction transaction; |
| 814 | CallbackHelper callback1; |
| 815 | int err = fillTransaction(transaction, &callback1, layer); |
| 816 | if (err) { |
| 817 | GTEST_SUCCEED() << "test not supported"; |
| 818 | return; |
| 819 | } |
| 820 | |
| 821 | // Try to present 100ms in the future |
| 822 | nsecs_t time = systemTime() + (100 * 1e6); |
| 823 | |
| 824 | transaction.setDesiredPresentTime(time); |
| 825 | transaction.apply(); |
| 826 | |
| 827 | ExpectedResult expected1; |
| 828 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 829 | expected1.addExpectedPresentTime(time); |
| 830 | |
| 831 | CallbackHelper callback2; |
| 832 | err = fillTransaction(transaction, &callback2, layer); |
| 833 | if (err) { |
| 834 | GTEST_SUCCEED() << "test not supported"; |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | // Try to present 33ms before the previous frame |
| 839 | time -= (33.3 * 1e6); |
| 840 | |
| 841 | transaction.setDesiredPresentTime(time); |
| 842 | transaction.apply(); |
| 843 | |
| 844 | ExpectedResult expected2; |
| 845 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 846 | ExpectedResult::Buffer::ACQUIRED, |
| 847 | ExpectedResult::PreviousBuffer::RELEASED); |
| 848 | |
| 849 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); |
| 850 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); |
| 851 | } |
| 852 | |
| 853 | TEST_F(LayerCallbackTest, DesiredPresentTime_Past) { |
| 854 | sp<SurfaceControl> layer; |
| 855 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 856 | |
| 857 | Transaction transaction; |
| 858 | CallbackHelper callback; |
| 859 | int err = fillTransaction(transaction, &callback, layer); |
| 860 | if (err) { |
| 861 | GTEST_SUCCEED() << "test not supported"; |
| 862 | return; |
| 863 | } |
| 864 | |
| 865 | // Try to present 100ms in the past |
| 866 | nsecs_t time = systemTime() - (100 * 1e6); |
| 867 | |
| 868 | transaction.setDesiredPresentTime(time); |
| 869 | transaction.apply(); |
| 870 | |
| 871 | ExpectedResult expected; |
| 872 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 873 | expected.addExpectedPresentTime(systemTime()); |
| 874 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 875 | } |
| 876 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame^] | 877 | |
| 878 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 879 | #pragma clang diagnostic pop // ignored "-Wconversion" |