Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 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 <gmock/gmock.h> |
| 18 | #include <gtest/gtest.h> |
| 19 | |
| 20 | #include <gui/SurfaceComposerClient.h> |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 21 | #include <cstdint> |
| 22 | #include "Client.h" |
Vishnu Nair | a12c5c7 | 2024-08-28 15:42:17 -0700 | [diff] [blame] | 23 | #include "Layer.h" |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 24 | |
Vishnu Nair | cb56533 | 2023-03-14 21:10:55 -0700 | [diff] [blame] | 25 | #include <layerproto/LayerProtoHeader.h> |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 26 | #include "FrontEnd/LayerCreationArgs.h" |
| 27 | #include "FrontEnd/Update.h" |
Vishnu Nair | cb56533 | 2023-03-14 21:10:55 -0700 | [diff] [blame] | 28 | #include "Tracing/LayerTracing.h" |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 29 | #include "Tracing/TransactionTracing.h" |
| 30 | |
| 31 | using namespace android::surfaceflinger; |
| 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | class TransactionTracingTest : public testing::Test { |
| 36 | protected: |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 37 | static constexpr size_t SMALL_BUFFER_SIZE = 1024; |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 38 | TransactionTracing mTracing; |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 39 | |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 40 | void flush() { mTracing.flush(); } |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 41 | perfetto::protos::TransactionTraceFile writeToProto() { return mTracing.writeToProto(); } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 42 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 43 | perfetto::protos::TransactionTraceEntry bufferFront() { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 44 | std::scoped_lock<std::mutex> lock(mTracing.mTraceLock); |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 45 | perfetto::protos::TransactionTraceEntry entry; |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 46 | entry.ParseFromString(mTracing.mBuffer.front()); |
Vishnu Nair | 6286355 | 2021-12-10 13:34:48 -0800 | [diff] [blame] | 47 | return entry; |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 50 | void queueAndCommitTransaction(int64_t vsyncId) { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 51 | frontend::Update update; |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 52 | TransactionState transaction; |
| 53 | transaction.id = static_cast<uint64_t>(vsyncId * 3); |
| 54 | transaction.originUid = 1; |
| 55 | transaction.originPid = 2; |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 56 | mTracing.addQueuedTransaction(transaction); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 57 | std::vector<TransactionState> transactions; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 58 | update.transactions.emplace_back(transaction); |
| 59 | mTracing.addCommittedTransactions(vsyncId, 0, update, {}, false); |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 60 | flush(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 61 | } |
| 62 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 63 | void verifyEntry(const perfetto::protos::TransactionTraceEntry& actualProto, |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 64 | const std::vector<TransactionState>& expectedTransactions, |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 65 | int64_t expectedVsyncId) { |
| 66 | EXPECT_EQ(actualProto.vsync_id(), expectedVsyncId); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 67 | ASSERT_EQ(actualProto.transactions().size(), |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 68 | static_cast<int32_t>(expectedTransactions.size())); |
| 69 | for (uint32_t i = 0; i < expectedTransactions.size(); i++) { |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 70 | const auto expectedTransaction = expectedTransactions[i]; |
| 71 | const auto protoTransaction = actualProto.transactions(static_cast<int32_t>(i)); |
| 72 | EXPECT_EQ(protoTransaction.transaction_id(), expectedTransaction.id); |
| 73 | EXPECT_EQ(protoTransaction.pid(), expectedTransaction.originPid); |
| 74 | for (uint32_t i = 0; i < expectedTransaction.mergedTransactionIds.size(); i++) { |
| 75 | EXPECT_EQ(protoTransaction.merged_transaction_ids(static_cast<int32_t>(i)), |
| 76 | expectedTransaction.mergedTransactionIds[i]); |
| 77 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 78 | } |
| 79 | } |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 80 | |
| 81 | LayerCreationArgs getLayerCreationArgs(uint32_t layerId, uint32_t parentId, |
| 82 | uint32_t layerIdToMirror, uint32_t flags, |
| 83 | bool addToRoot) { |
| 84 | LayerCreationArgs args; |
| 85 | args.sequence = layerId; |
| 86 | args.parentId = parentId; |
| 87 | args.layerIdToMirror = layerIdToMirror; |
| 88 | args.flags = flags; |
| 89 | args.addToRoot = addToRoot; |
| 90 | return args; |
| 91 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 94 | TEST_F(TransactionTracingTest, addTransactions) { |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 95 | std::vector<TransactionState> transactions; |
| 96 | transactions.reserve(100); |
| 97 | for (uint64_t i = 0; i < 100; i++) { |
| 98 | TransactionState transaction; |
| 99 | transaction.id = i; |
| 100 | transaction.originPid = static_cast<int32_t>(i); |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 101 | transaction.mergedTransactionIds = std::vector<uint64_t>{i + 100, i + 102}; |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 102 | transactions.emplace_back(transaction); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 103 | mTracing.addQueuedTransaction(transaction); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | // Split incoming transactions into two and commit them in reverse order to test out of order |
| 107 | // commits. |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 108 | int64_t firstTransactionSetVsyncId = 42; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 109 | frontend::Update firstUpdate; |
| 110 | firstUpdate.transactions = |
| 111 | std::vector<TransactionState>(transactions.begin() + 50, transactions.end()); |
| 112 | mTracing.addCommittedTransactions(firstTransactionSetVsyncId, 0, firstUpdate, {}, false); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 113 | |
| 114 | int64_t secondTransactionSetVsyncId = 43; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 115 | frontend::Update secondUpdate; |
| 116 | secondUpdate.transactions = |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 117 | std::vector<TransactionState>(transactions.begin(), transactions.begin() + 50); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 118 | mTracing.addCommittedTransactions(secondTransactionSetVsyncId, 0, secondUpdate, {}, false); |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 119 | flush(); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 120 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 121 | perfetto::protos::TransactionTraceFile proto = writeToProto(); |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 122 | ASSERT_EQ(proto.entry().size(), 2); |
| 123 | verifyEntry(proto.entry(0), firstUpdate.transactions, firstTransactionSetVsyncId); |
| 124 | verifyEntry(proto.entry(1), secondUpdate.transactions, secondTransactionSetVsyncId); |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 127 | class TransactionTracingLayerHandlingTest : public TransactionTracingTest { |
| 128 | protected: |
| 129 | void SetUp() override { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 130 | mTracing.setBufferSize(SMALL_BUFFER_SIZE); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 131 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 132 | // add layers and add some layer transaction |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 133 | { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 134 | frontend::Update update; |
Yi Kong | 01b8126 | 2024-08-12 07:30:15 +0800 | [diff] [blame] | 135 | update.layerCreationArgs.emplace_back( |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 136 | getLayerCreationArgs(mParentLayerId, /*parentId=*/UNASSIGNED_LAYER_ID, |
| 137 | /*layerIdToMirror=*/UNASSIGNED_LAYER_ID, /*flags=*/123, |
Yi Kong | 01b8126 | 2024-08-12 07:30:15 +0800 | [diff] [blame] | 138 | /*addToRoot=*/true)); |
| 139 | update.layerCreationArgs.emplace_back( |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 140 | getLayerCreationArgs(mChildLayerId, mParentLayerId, |
| 141 | /*layerIdToMirror=*/UNASSIGNED_LAYER_ID, /*flags=*/456, |
Yi Kong | 01b8126 | 2024-08-12 07:30:15 +0800 | [diff] [blame] | 142 | /*addToRoot=*/true)); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 143 | TransactionState transaction; |
| 144 | transaction.id = 50; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 145 | ResolvedComposerState layerState; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 146 | layerState.layerId = mParentLayerId; |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 147 | layerState.state.what = layer_state_t::eLayerChanged; |
| 148 | layerState.state.z = 42; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 149 | transaction.states.emplace_back(layerState); |
| 150 | ResolvedComposerState childState; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 151 | childState.layerId = mChildLayerId; |
Vishnu Nair | 473838d | 2021-12-08 09:46:02 -0800 | [diff] [blame] | 152 | childState.state.what = layer_state_t::eLayerChanged; |
| 153 | childState.state.z = 43; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 154 | transaction.states.emplace_back(childState); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 155 | mTracing.addQueuedTransaction(transaction); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 156 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 157 | update.transactions.emplace_back(transaction); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 158 | VSYNC_ID_FIRST_LAYER_CHANGE = ++mVsyncId; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 159 | mTracing.addCommittedTransactions(VSYNC_ID_FIRST_LAYER_CHANGE, 0, update, {}, false); |
| 160 | |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 161 | flush(); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | // add transactions that modify the layer state further so we can test that layer state |
| 165 | // gets merged |
| 166 | { |
| 167 | TransactionState transaction; |
| 168 | transaction.id = 51; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 169 | ResolvedComposerState layerState; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 170 | layerState.layerId = mParentLayerId; |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 171 | layerState.state.what = layer_state_t::eLayerChanged | layer_state_t::ePositionChanged; |
| 172 | layerState.state.z = 41; |
| 173 | layerState.state.x = 22; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 174 | transaction.states.emplace_back(layerState); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 175 | mTracing.addQueuedTransaction(transaction); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 176 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 177 | frontend::Update update; |
| 178 | update.transactions.emplace_back(transaction); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 179 | VSYNC_ID_SECOND_LAYER_CHANGE = ++mVsyncId; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 180 | mTracing.addCommittedTransactions(VSYNC_ID_SECOND_LAYER_CHANGE, 0, update, {}, false); |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 181 | flush(); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | // remove child layer |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 185 | mTracing.onLayerRemoved(2); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 186 | VSYNC_ID_CHILD_LAYER_REMOVED = ++mVsyncId; |
| 187 | queueAndCommitTransaction(VSYNC_ID_CHILD_LAYER_REMOVED); |
| 188 | |
| 189 | // remove layer |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 190 | mTracing.onLayerRemoved(1); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 191 | queueAndCommitTransaction(++mVsyncId); |
| 192 | } |
| 193 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 194 | uint32_t mParentLayerId = 1; |
| 195 | uint32_t mChildLayerId = 2; |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 196 | int64_t mVsyncId = 0; |
| 197 | int64_t VSYNC_ID_FIRST_LAYER_CHANGE; |
| 198 | int64_t VSYNC_ID_SECOND_LAYER_CHANGE; |
| 199 | int64_t VSYNC_ID_CHILD_LAYER_REMOVED; |
| 200 | }; |
| 201 | |
| 202 | TEST_F(TransactionTracingLayerHandlingTest, addStartingState) { |
| 203 | // add transactions until we drop the transaction with the first layer change |
| 204 | while (bufferFront().vsync_id() <= VSYNC_ID_FIRST_LAYER_CHANGE) { |
| 205 | queueAndCommitTransaction(++mVsyncId); |
| 206 | } |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 207 | perfetto::protos::TransactionTraceFile proto = writeToProto(); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 208 | // verify we can still retrieve the layer change from the first entry containing starting |
| 209 | // states. |
| 210 | EXPECT_GT(proto.entry().size(), 0); |
Vishnu Nair | 685cfef | 2022-02-02 10:01:25 -0800 | [diff] [blame] | 211 | EXPECT_EQ(proto.entry(0).transactions().size(), 1); |
| 212 | EXPECT_EQ(proto.entry(0).added_layers().size(), 2); |
Vishnu Nair | 473838d | 2021-12-08 09:46:02 -0800 | [diff] [blame] | 213 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes().size(), 2); |
| 214 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(0).layer_id(), mParentLayerId); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 215 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(0).z(), 42); |
Vishnu Nair | 473838d | 2021-12-08 09:46:02 -0800 | [diff] [blame] | 216 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(1).layer_id(), mChildLayerId); |
| 217 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(1).z(), 43); |
Vishnu Nair | 7bebc9f | 2023-12-08 22:56:28 +0000 | [diff] [blame] | 218 | EXPECT_TRUE(proto.entry(0).displays_changed()); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | TEST_F(TransactionTracingLayerHandlingTest, updateStartingState) { |
| 222 | // add transactions until we drop the transaction with the second layer change |
| 223 | while (bufferFront().vsync_id() <= VSYNC_ID_SECOND_LAYER_CHANGE) { |
| 224 | queueAndCommitTransaction(++mVsyncId); |
| 225 | } |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 226 | perfetto::protos::TransactionTraceFile proto = writeToProto(); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 227 | // verify starting states are updated correctly |
| 228 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(0).z(), 41); |
Vishnu Nair | 7bebc9f | 2023-12-08 22:56:28 +0000 | [diff] [blame] | 229 | EXPECT_TRUE(proto.entry(0).displays_changed()); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | TEST_F(TransactionTracingLayerHandlingTest, removeStartingState) { |
| 233 | // add transactions until we drop the transaction which removes the child layer |
| 234 | while (bufferFront().vsync_id() <= VSYNC_ID_CHILD_LAYER_REMOVED) { |
| 235 | queueAndCommitTransaction(++mVsyncId); |
| 236 | } |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 237 | perfetto::protos::TransactionTraceFile proto = writeToProto(); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 238 | // verify the child layer has been removed from the trace |
| 239 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes().size(), 1); |
| 240 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(0).layer_id(), mParentLayerId); |
Vishnu Nair | 7bebc9f | 2023-12-08 22:56:28 +0000 | [diff] [blame] | 241 | EXPECT_TRUE(proto.entry(0).displays_changed()); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | TEST_F(TransactionTracingLayerHandlingTest, startingStateSurvivesBufferFlush) { |
| 245 | // add transactions until we drop the transaction with the second layer change |
| 246 | while (bufferFront().vsync_id() <= VSYNC_ID_SECOND_LAYER_CHANGE) { |
| 247 | queueAndCommitTransaction(++mVsyncId); |
| 248 | } |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 249 | perfetto::protos::TransactionTraceFile proto = writeToProto(); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 250 | // verify we have two starting states |
| 251 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes().size(), 2); |
| 252 | |
| 253 | // Continue adding transactions until child layer is removed |
| 254 | while (bufferFront().vsync_id() <= VSYNC_ID_CHILD_LAYER_REMOVED) { |
| 255 | queueAndCommitTransaction(++mVsyncId); |
| 256 | } |
| 257 | proto = writeToProto(); |
| 258 | // verify we still have the parent layer state |
| 259 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes().size(), 1); |
| 260 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(0).layer_id(), mParentLayerId); |
Vishnu Nair | 7bebc9f | 2023-12-08 22:56:28 +0000 | [diff] [blame] | 261 | EXPECT_TRUE(proto.entry(0).displays_changed()); |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 264 | class TransactionTracingMirrorLayerTest : public TransactionTracingTest { |
| 265 | protected: |
| 266 | void SetUp() override { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 267 | mTracing.setBufferSize(SMALL_BUFFER_SIZE); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 268 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 269 | // add layers and some layer transaction |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 270 | { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 271 | frontend::Update update; |
| 272 | update.layerCreationArgs.emplace_back( |
| 273 | getLayerCreationArgs(mLayerId, /*parentId=*/UNASSIGNED_LAYER_ID, |
| 274 | /*layerIdToMirror=*/UNASSIGNED_LAYER_ID, /*flags=*/123, |
| 275 | /*addToRoot=*/true)); |
| 276 | update.layerCreationArgs.emplace_back( |
| 277 | getLayerCreationArgs(mMirrorLayerId, UNASSIGNED_LAYER_ID, |
| 278 | /*layerIdToMirror=*/mLayerId, /*flags=*/0, |
| 279 | /*addToRoot=*/false)); |
| 280 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 281 | TransactionState transaction; |
| 282 | transaction.id = 50; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 283 | ResolvedComposerState layerState; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 284 | layerState.layerId = mLayerId; |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 285 | layerState.state.what = layer_state_t::eLayerChanged; |
| 286 | layerState.state.z = 42; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 287 | transaction.states.emplace_back(layerState); |
| 288 | ResolvedComposerState mirrorState; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 289 | mirrorState.layerId = mMirrorLayerId; |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 290 | mirrorState.state.what = layer_state_t::eLayerChanged; |
| 291 | mirrorState.state.z = 43; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 292 | transaction.states.emplace_back(mirrorState); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 293 | mTracing.addQueuedTransaction(transaction); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 294 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 295 | update.transactions.emplace_back(transaction); |
| 296 | mTracing.addCommittedTransactions(mVsyncId, 0, update, {}, false); |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 297 | flush(); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 301 | uint32_t mLayerId = 5; |
| 302 | uint32_t mMirrorLayerId = 55; |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 303 | int64_t mVsyncId = 0; |
| 304 | int64_t VSYNC_ID_FIRST_LAYER_CHANGE; |
| 305 | int64_t VSYNC_ID_SECOND_LAYER_CHANGE; |
| 306 | int64_t VSYNC_ID_CHILD_LAYER_REMOVED; |
| 307 | }; |
| 308 | |
| 309 | TEST_F(TransactionTracingMirrorLayerTest, canAddMirrorLayers) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 310 | perfetto::protos::TransactionTraceFile proto = writeToProto(); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 311 | // We don't have any starting states since no layer was removed from. |
Vishnu Nair | b8f2a2d | 2022-01-13 08:10:10 -0800 | [diff] [blame] | 312 | EXPECT_EQ(proto.entry().size(), 1); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 313 | |
| 314 | // Verify the mirror layer was added |
Vishnu Nair | b8f2a2d | 2022-01-13 08:10:10 -0800 | [diff] [blame] | 315 | EXPECT_EQ(proto.entry(0).transactions().size(), 1); |
| 316 | EXPECT_EQ(proto.entry(0).added_layers().size(), 2); |
| 317 | EXPECT_EQ(proto.entry(0).added_layers(1).layer_id(), mMirrorLayerId); |
| 318 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes().size(), 2); |
| 319 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(1).z(), 43); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 320 | } |
Vishnu Nair | cb56533 | 2023-03-14 21:10:55 -0700 | [diff] [blame] | 321 | |
| 322 | // Verify we can write the layers traces by entry to reduce mem pressure |
| 323 | // on the system when generating large traces. |
| 324 | TEST(LayerTraceTest, canStreamLayersTrace) { |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 325 | perfetto::protos::LayersTraceFileProto inProto = LayerTracing::createTraceFileProto(); |
Vishnu Nair | cb56533 | 2023-03-14 21:10:55 -0700 | [diff] [blame] | 326 | inProto.add_entry(); |
| 327 | inProto.add_entry(); |
| 328 | |
| 329 | std::string output; |
| 330 | inProto.SerializeToString(&output); |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 331 | perfetto::protos::LayersTraceFileProto inProto2 = LayerTracing::createTraceFileProto(); |
Vishnu Nair | cb56533 | 2023-03-14 21:10:55 -0700 | [diff] [blame] | 332 | inProto2.add_entry(); |
| 333 | std::string output2; |
| 334 | inProto2.SerializeToString(&output2); |
| 335 | |
Kean Mariotti | 4ba343c | 2023-04-19 13:31:02 +0000 | [diff] [blame] | 336 | perfetto::protos::LayersTraceFileProto outProto; |
Vishnu Nair | cb56533 | 2023-03-14 21:10:55 -0700 | [diff] [blame] | 337 | outProto.ParseFromString(output + output2); |
| 338 | // magic? |
| 339 | EXPECT_EQ(outProto.entry().size(), 3); |
| 340 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 341 | } // namespace android |