Skip to content

Commit d7b71ac

Browse files
author
Anton Ivanov
committed
Revert^2 "Use TransactionState in SurfaceFlinger."
This reverts commit 4f8b4f3. Reason for revert: Rolling forward with fix for use-after-move in SurfaceFlinger::setTransactionState Flag: EXEMPT refactor Bug: 385156191 Test: presubmit Change-Id: I66d45b1e125dcb50cbe7a3cfcefa8eaa02705419
1 parent bcbec20 commit d7b71ac

18 files changed

+196
-649
lines changed

libs/gui/BLASTBufferQueue.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ void BLASTBufferQueue::mergeWithNextTransaction(SurfaceComposerClient::Transacti
10321032
// Apply the transaction since we have already acquired the desired frame.
10331033
t->setApplyToken(mApplyToken).apply();
10341034
} else {
1035-
mPendingTransactions.emplace_back(frameNumber, *t);
1035+
mPendingTransactions.emplace_back(frameNumber, std::move(*t));
10361036
// Clear the transaction so it can't be applied elsewhere.
10371037
t->clear();
10381038
}
@@ -1050,8 +1050,8 @@ void BLASTBufferQueue::applyPendingTransactions(uint64_t frameNumber) {
10501050
void BLASTBufferQueue::mergePendingTransactions(SurfaceComposerClient::Transaction* t,
10511051
uint64_t frameNumber) {
10521052
auto mergeTransaction =
1053-
[&t, currentFrameNumber = frameNumber](
1054-
std::tuple<uint64_t, SurfaceComposerClient::Transaction> pendingTransaction) {
1053+
[t, currentFrameNumber = frameNumber](
1054+
std::pair<uint64_t, SurfaceComposerClient::Transaction>& pendingTransaction) {
10551055
auto& [targetFrameNumber, transaction] = pendingTransaction;
10561056
if (currentFrameNumber < targetFrameNumber) {
10571057
return false;

libs/gui/ISurfaceComposer.cpp

Lines changed: 7 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <gui/ISurfaceComposer.h>
2727
#include <gui/LayerState.h>
2828
#include <gui/SchedulingPolicy.h>
29+
#include <gui/TransactionState.h>
2930
#include <private/gui/ParcelUtils.h>
3031
#include <stdint.h>
3132
#include <sys/types.h>
@@ -60,54 +61,12 @@ class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
6061

6162
virtual ~BpSurfaceComposer();
6263

63-
status_t setTransactionState(
64-
const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state,
65-
Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken,
66-
InputWindowCommands commands, int64_t desiredPresentTime, bool isAutoTimestamp,
67-
const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks,
68-
const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId,
69-
const std::vector<uint64_t>& mergedTransactionIds) override {
64+
status_t setTransactionState(TransactionState&& state) override {
7065
Parcel data, reply;
7166
data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
67+
SAFE_PARCEL(state.writeToParcel, &data);
7268

73-
frameTimelineInfo.writeToParcel(&data);
74-
75-
SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size()));
76-
for (const auto& s : state) {
77-
SAFE_PARCEL(s.write, data);
78-
}
79-
80-
SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size()));
81-
for (const auto& d : displays) {
82-
SAFE_PARCEL(d.write, data);
83-
}
84-
85-
SAFE_PARCEL(data.writeUint32, flags);
86-
SAFE_PARCEL(data.writeStrongBinder, applyToken);
87-
SAFE_PARCEL(commands.write, data);
88-
SAFE_PARCEL(data.writeInt64, desiredPresentTime);
89-
SAFE_PARCEL(data.writeBool, isAutoTimestamp);
90-
SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(uncacheBuffers.size()));
91-
for (const client_cache_t& uncacheBuffer : uncacheBuffers) {
92-
SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
93-
SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
94-
}
95-
SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
96-
97-
SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
98-
for (const auto& [listener, callbackIds] : listenerCallbacks) {
99-
SAFE_PARCEL(data.writeStrongBinder, listener);
100-
SAFE_PARCEL(data.writeParcelableVector, callbackIds);
101-
}
102-
103-
SAFE_PARCEL(data.writeUint64, transactionId);
104-
105-
SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(mergedTransactionIds.size()));
106-
for (auto mergedTransactionId : mergedTransactionIds) {
107-
SAFE_PARCEL(data.writeUint64, mergedTransactionId);
108-
}
109-
110-
if (flags & ISurfaceComposer::eOneWay) {
69+
if (state.mFlags & ISurfaceComposer::eOneWay) {
11170
return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
11271
data, &reply, IBinder::FLAG_ONEWAY);
11372
} else {
@@ -132,75 +91,9 @@ status_t BnSurfaceComposer::onTransact(
13291
case SET_TRANSACTION_STATE: {
13392
CHECK_INTERFACE(ISurfaceComposer, data, reply);
13493

135-
FrameTimelineInfo frameTimelineInfo;
136-
frameTimelineInfo.readFromParcel(&data);
137-
138-
uint32_t count = 0;
139-
SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
140-
Vector<ComposerState> state;
141-
state.setCapacity(count);
142-
for (size_t i = 0; i < count; i++) {
143-
ComposerState s;
144-
SAFE_PARCEL(s.read, data);
145-
state.add(s);
146-
}
147-
148-
SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
149-
DisplayState d;
150-
Vector<DisplayState> displays;
151-
displays.setCapacity(count);
152-
for (size_t i = 0; i < count; i++) {
153-
SAFE_PARCEL(d.read, data);
154-
displays.add(d);
155-
}
156-
157-
uint32_t stateFlags = 0;
158-
SAFE_PARCEL(data.readUint32, &stateFlags);
159-
sp<IBinder> applyToken;
160-
SAFE_PARCEL(data.readStrongBinder, &applyToken);
161-
InputWindowCommands inputWindowCommands;
162-
SAFE_PARCEL(inputWindowCommands.read, data);
163-
164-
int64_t desiredPresentTime = 0;
165-
bool isAutoTimestamp = true;
166-
SAFE_PARCEL(data.readInt64, &desiredPresentTime);
167-
SAFE_PARCEL(data.readBool, &isAutoTimestamp);
168-
169-
SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
170-
std::vector<client_cache_t> uncacheBuffers(count);
171-
sp<IBinder> tmpBinder;
172-
for (size_t i = 0; i < count; i++) {
173-
SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
174-
uncacheBuffers[i].token = tmpBinder;
175-
SAFE_PARCEL(data.readUint64, &uncacheBuffers[i].id);
176-
}
177-
178-
bool hasListenerCallbacks = false;
179-
SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
180-
181-
std::vector<ListenerCallbacks> listenerCallbacks;
182-
int32_t listenersSize = 0;
183-
SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
184-
for (int32_t i = 0; i < listenersSize; i++) {
185-
SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
186-
std::vector<CallbackId> callbackIds;
187-
SAFE_PARCEL(data.readParcelableVector, &callbackIds);
188-
listenerCallbacks.emplace_back(tmpBinder, callbackIds);
189-
}
190-
191-
uint64_t transactionId = -1;
192-
SAFE_PARCEL(data.readUint64, &transactionId);
193-
194-
SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
195-
std::vector<uint64_t> mergedTransactions(count);
196-
for (size_t i = 0; i < count; i++) {
197-
SAFE_PARCEL(data.readUint64, &mergedTransactions[i]);
198-
}
199-
200-
return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
201-
std::move(inputWindowCommands), desiredPresentTime,
202-
isAutoTimestamp, uncacheBuffers, hasListenerCallbacks,
203-
listenerCallbacks, transactionId, mergedTransactions);
94+
TransactionState state;
95+
SAFE_PARCEL(state.readFromParcel, &data);
96+
return setTransactionState(std::move(state));
20497
}
20598
case GET_SCHEDULING_POLICY: {
20699
gui::SchedulingPolicy policy;

0 commit comments

Comments
 (0)