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