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