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