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/RingBuffer.h" |
| 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(); } |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 41 | proto::TransactionTraceFile writeToProto() { return mTracing.writeToProto(); } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 42 | |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 43 | proto::TransactionTraceEntry bufferFront() { |
| 44 | std::scoped_lock<std::mutex> lock(mTracing.mTraceLock); |
Vishnu Nair | 6286355 | 2021-12-10 13:34:48 -0800 | [diff] [blame] | 45 | proto::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 | |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 63 | void verifyEntry(const proto::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 | |
Vishnu Nair | 0cc69e1 | 2021-11-18 09:05:49 -0800 | [diff] [blame] | 121 | proto::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; |
| 135 | update.layerCreationArgs.emplace_back(std::move( |
| 136 | getLayerCreationArgs(mParentLayerId, /*parentId=*/UNASSIGNED_LAYER_ID, |
| 137 | /*layerIdToMirror=*/UNASSIGNED_LAYER_ID, /*flags=*/123, |
| 138 | /*addToRoot=*/true))); |
| 139 | update.layerCreationArgs.emplace_back(std::move( |
| 140 | getLayerCreationArgs(mChildLayerId, mParentLayerId, |
| 141 | /*layerIdToMirror=*/UNASSIGNED_LAYER_ID, /*flags=*/456, |
| 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 | } |
| 207 | proto::TransactionTraceFile proto = writeToProto(); |
| 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 | 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 | } |
| 225 | proto::TransactionTraceFile proto = writeToProto(); |
| 226 | // verify starting states are updated correctly |
| 227 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(0).z(), 41); |
| 228 | } |
| 229 | |
| 230 | TEST_F(TransactionTracingLayerHandlingTest, removeStartingState) { |
| 231 | // add transactions until we drop the transaction which removes the child layer |
| 232 | while (bufferFront().vsync_id() <= VSYNC_ID_CHILD_LAYER_REMOVED) { |
| 233 | queueAndCommitTransaction(++mVsyncId); |
| 234 | } |
| 235 | proto::TransactionTraceFile proto = writeToProto(); |
| 236 | // verify the child layer has been removed from the trace |
| 237 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes().size(), 1); |
| 238 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(0).layer_id(), mParentLayerId); |
| 239 | } |
| 240 | |
| 241 | TEST_F(TransactionTracingLayerHandlingTest, startingStateSurvivesBufferFlush) { |
| 242 | // add transactions until we drop the transaction with the second layer change |
| 243 | while (bufferFront().vsync_id() <= VSYNC_ID_SECOND_LAYER_CHANGE) { |
| 244 | queueAndCommitTransaction(++mVsyncId); |
| 245 | } |
| 246 | proto::TransactionTraceFile proto = writeToProto(); |
| 247 | // verify we have two starting states |
| 248 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes().size(), 2); |
| 249 | |
| 250 | // Continue adding transactions until child layer is removed |
| 251 | while (bufferFront().vsync_id() <= VSYNC_ID_CHILD_LAYER_REMOVED) { |
| 252 | queueAndCommitTransaction(++mVsyncId); |
| 253 | } |
| 254 | proto = writeToProto(); |
| 255 | // verify we still have the parent layer state |
| 256 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes().size(), 1); |
| 257 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(0).layer_id(), mParentLayerId); |
| 258 | } |
| 259 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 260 | class TransactionTracingMirrorLayerTest : public TransactionTracingTest { |
| 261 | protected: |
| 262 | void SetUp() override { |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 263 | mTracing.setBufferSize(SMALL_BUFFER_SIZE); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 264 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 265 | // add layers and some layer transaction |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 266 | { |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 267 | frontend::Update update; |
| 268 | update.layerCreationArgs.emplace_back( |
| 269 | getLayerCreationArgs(mLayerId, /*parentId=*/UNASSIGNED_LAYER_ID, |
| 270 | /*layerIdToMirror=*/UNASSIGNED_LAYER_ID, /*flags=*/123, |
| 271 | /*addToRoot=*/true)); |
| 272 | update.layerCreationArgs.emplace_back( |
| 273 | getLayerCreationArgs(mMirrorLayerId, UNASSIGNED_LAYER_ID, |
| 274 | /*layerIdToMirror=*/mLayerId, /*flags=*/0, |
| 275 | /*addToRoot=*/false)); |
| 276 | |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 277 | TransactionState transaction; |
| 278 | transaction.id = 50; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 279 | ResolvedComposerState layerState; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 280 | layerState.layerId = mLayerId; |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 281 | layerState.state.what = layer_state_t::eLayerChanged; |
| 282 | layerState.state.z = 42; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 283 | transaction.states.emplace_back(layerState); |
| 284 | ResolvedComposerState mirrorState; |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 285 | mirrorState.layerId = mMirrorLayerId; |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 286 | mirrorState.state.what = layer_state_t::eLayerChanged; |
| 287 | mirrorState.state.z = 43; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 288 | transaction.states.emplace_back(mirrorState); |
Dominik Laskowski | 46471e6 | 2022-01-14 15:34:03 -0800 | [diff] [blame] | 289 | mTracing.addQueuedTransaction(transaction); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 290 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 291 | update.transactions.emplace_back(transaction); |
| 292 | mTracing.addCommittedTransactions(mVsyncId, 0, update, {}, false); |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame^] | 293 | flush(); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
Vishnu Nair | 8175062 | 2023-03-08 15:02:06 -0800 | [diff] [blame] | 297 | uint32_t mLayerId = 5; |
| 298 | uint32_t mMirrorLayerId = 55; |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 299 | int64_t mVsyncId = 0; |
| 300 | int64_t VSYNC_ID_FIRST_LAYER_CHANGE; |
| 301 | int64_t VSYNC_ID_SECOND_LAYER_CHANGE; |
| 302 | int64_t VSYNC_ID_CHILD_LAYER_REMOVED; |
| 303 | }; |
| 304 | |
| 305 | TEST_F(TransactionTracingMirrorLayerTest, canAddMirrorLayers) { |
| 306 | proto::TransactionTraceFile proto = writeToProto(); |
| 307 | // 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] | 308 | EXPECT_EQ(proto.entry().size(), 1); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 309 | |
| 310 | // Verify the mirror layer was added |
Vishnu Nair | b8f2a2d | 2022-01-13 08:10:10 -0800 | [diff] [blame] | 311 | EXPECT_EQ(proto.entry(0).transactions().size(), 1); |
| 312 | EXPECT_EQ(proto.entry(0).added_layers().size(), 2); |
| 313 | EXPECT_EQ(proto.entry(0).added_layers(1).layer_id(), mMirrorLayerId); |
| 314 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes().size(), 2); |
| 315 | EXPECT_EQ(proto.entry(0).transactions(0).layer_changes(1).z(), 43); |
Vishnu Nair | 84125ac | 2021-12-02 08:47:48 -0800 | [diff] [blame] | 316 | } |
Vishnu Nair | cb56533 | 2023-03-14 21:10:55 -0700 | [diff] [blame] | 317 | |
| 318 | // Verify we can write the layers traces by entry to reduce mem pressure |
| 319 | // on the system when generating large traces. |
| 320 | TEST(LayerTraceTest, canStreamLayersTrace) { |
| 321 | LayersTraceFileProto inProto = LayerTracing::createTraceFileProto(); |
| 322 | inProto.add_entry(); |
| 323 | inProto.add_entry(); |
| 324 | |
| 325 | std::string output; |
| 326 | inProto.SerializeToString(&output); |
| 327 | LayersTraceFileProto inProto2 = LayerTracing::createTraceFileProto(); |
| 328 | inProto2.add_entry(); |
| 329 | std::string output2; |
| 330 | inProto2.SerializeToString(&output2); |
| 331 | |
| 332 | LayersTraceFileProto outProto; |
| 333 | outProto.ParseFromString(output + output2); |
| 334 | // magic? |
| 335 | EXPECT_EQ(outProto.entry().size(), 3); |
| 336 | } |
Vishnu Nair | 7891e96 | 2021-11-11 12:07:21 -0800 | [diff] [blame] | 337 | } // namespace android |