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