blob: 69f7894d07d3c339a64b97beb0e7aa8e1d60ac8d [file] [log] [blame]
Marissa Wall7a9b6ff2018-08-21 17:26:20 -07001/*
2 * Copyright 2018 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#define LOG_TAG "ITransactionCompletedListener"
18//#define LOG_NDEBUG 0
19
20#include <gui/ITransactionCompletedListener.h>
21
22namespace android {
23
24namespace { // Anonymous
25
26enum class Tag : uint32_t {
27 ON_TRANSACTION_COMPLETED = IBinder::FIRST_CALL_TRANSACTION,
28 LAST = ON_TRANSACTION_COMPLETED,
29};
30
31} // Anonymous namespace
32
Valerie Hau871d6352020-01-29 08:44:02 -080033status_t FrameEventHistoryStats::writeToParcel(Parcel* output) const {
34 status_t err = output->writeUint64(frameNumber);
35 if (err != NO_ERROR) return err;
36
37 if (gpuCompositionDoneFence) {
38 err = output->writeBool(true);
39 if (err != NO_ERROR) return err;
40
41 err = output->write(*gpuCompositionDoneFence);
42 } else {
43 err = output->writeBool(false);
44 }
45 if (err != NO_ERROR) return err;
46
47 err = output->writeInt64(compositorTiming.deadline);
48 if (err != NO_ERROR) return err;
49
50 err = output->writeInt64(compositorTiming.interval);
51 if (err != NO_ERROR) return err;
52
53 err = output->writeInt64(compositorTiming.presentLatency);
54 if (err != NO_ERROR) return err;
55
56 err = output->writeInt64(refreshStartTime);
57 if (err != NO_ERROR) return err;
58
59 err = output->writeInt64(dequeueReadyTime);
60 return err;
61}
62
63status_t FrameEventHistoryStats::readFromParcel(const Parcel* input) {
64 status_t err = input->readUint64(&frameNumber);
65 if (err != NO_ERROR) return err;
66
67 bool hasFence = false;
68 err = input->readBool(&hasFence);
69 if (err != NO_ERROR) return err;
70
71 if (hasFence) {
72 gpuCompositionDoneFence = new Fence();
73 err = input->read(*gpuCompositionDoneFence);
74 if (err != NO_ERROR) return err;
75 }
76
77 err = input->readInt64(&(compositorTiming.deadline));
78 if (err != NO_ERROR) return err;
79
80 err = input->readInt64(&(compositorTiming.interval));
81 if (err != NO_ERROR) return err;
82
83 err = input->readInt64(&(compositorTiming.presentLatency));
84 if (err != NO_ERROR) return err;
85
86 err = input->readInt64(&refreshStartTime);
87 if (err != NO_ERROR) return err;
88
89 err = input->readInt64(&dequeueReadyTime);
90 return err;
91}
92
Marissa Walle2ffb422018-10-12 11:33:52 -070093status_t SurfaceStats::writeToParcel(Parcel* output) const {
Marissa Wallfda30bb2018-10-12 11:34:28 -070094 status_t err = output->writeStrongBinder(surfaceControl);
95 if (err != NO_ERROR) {
96 return err;
97 }
98 err = output->writeInt64(acquireTime);
99 if (err != NO_ERROR) {
100 return err;
101 }
Marissa Wall5a68a772018-12-22 17:43:42 -0800102 if (previousReleaseFence) {
103 err = output->writeBool(true);
104 if (err != NO_ERROR) {
105 return err;
106 }
107 err = output->write(*previousReleaseFence);
108 } else {
109 err = output->writeBool(false);
110 }
Valerie Hau32cdc1f2019-10-21 14:45:54 -0700111 err = output->writeUint32(transformHint);
Valerie Hau871d6352020-01-29 08:44:02 -0800112 if (err != NO_ERROR) {
113 return err;
114 }
115
116 err = output->writeParcelable(eventStats);
Marissa Wall5a68a772018-12-22 17:43:42 -0800117 return err;
Marissa Walle2ffb422018-10-12 11:33:52 -0700118}
119
120status_t SurfaceStats::readFromParcel(const Parcel* input) {
Marissa Wallfda30bb2018-10-12 11:34:28 -0700121 status_t err = input->readStrongBinder(&surfaceControl);
122 if (err != NO_ERROR) {
123 return err;
124 }
125 err = input->readInt64(&acquireTime);
126 if (err != NO_ERROR) {
127 return err;
128 }
Marissa Wall5a68a772018-12-22 17:43:42 -0800129 bool hasFence = false;
130 err = input->readBool(&hasFence);
131 if (err != NO_ERROR) {
132 return err;
133 }
134 if (hasFence) {
135 previousReleaseFence = new Fence();
136 err = input->read(*previousReleaseFence);
137 if (err != NO_ERROR) {
138 return err;
139 }
140 }
Valerie Hau32cdc1f2019-10-21 14:45:54 -0700141 err = input->readUint32(&transformHint);
Valerie Hau871d6352020-01-29 08:44:02 -0800142 if (err != NO_ERROR) {
143 return err;
144 }
145
146 err = input->readParcelable(&eventStats);
Valerie Hau32cdc1f2019-10-21 14:45:54 -0700147 return err;
Marissa Walle2ffb422018-10-12 11:33:52 -0700148}
149
150status_t TransactionStats::writeToParcel(Parcel* output) const {
Marissa Walld600d572019-03-26 15:38:50 -0700151 status_t err = output->writeInt64Vector(callbackIds);
152 if (err != NO_ERROR) {
153 return err;
154 }
155 err = output->writeInt64(latchTime);
Marissa Wallfda30bb2018-10-12 11:34:28 -0700156 if (err != NO_ERROR) {
157 return err;
158 }
Valerie Hau63258a12018-12-14 14:31:48 -0800159 if (presentFence) {
160 err = output->writeBool(true);
161 if (err != NO_ERROR) {
162 return err;
163 }
164 err = output->write(*presentFence);
165 } else {
166 err = output->writeBool(false);
167 }
Marissa Wallfda30bb2018-10-12 11:34:28 -0700168 if (err != NO_ERROR) {
169 return err;
170 }
Marissa Walle2ffb422018-10-12 11:33:52 -0700171 return output->writeParcelableVector(surfaceStats);
172}
173
174status_t TransactionStats::readFromParcel(const Parcel* input) {
Marissa Walld600d572019-03-26 15:38:50 -0700175 status_t err = input->readInt64Vector(&callbackIds);
176 if (err != NO_ERROR) {
177 return err;
178 }
179 err = input->readInt64(&latchTime);
Marissa Wallfda30bb2018-10-12 11:34:28 -0700180 if (err != NO_ERROR) {
181 return err;
182 }
Valerie Hau63258a12018-12-14 14:31:48 -0800183 bool hasFence = false;
184 err = input->readBool(&hasFence);
Marissa Wallfda30bb2018-10-12 11:34:28 -0700185 if (err != NO_ERROR) {
186 return err;
187 }
Valerie Hau63258a12018-12-14 14:31:48 -0800188 if (hasFence) {
189 presentFence = new Fence();
190 err = input->read(*presentFence);
191 if (err != NO_ERROR) {
192 return err;
193 }
194 }
Marissa Walle2ffb422018-10-12 11:33:52 -0700195 return input->readParcelableVector(&surfaceStats);
196}
197
198status_t ListenerStats::writeToParcel(Parcel* output) const {
199 status_t err = output->writeInt32(static_cast<int32_t>(transactionStats.size()));
200 if (err != NO_ERROR) {
201 return err;
202 }
Marissa Walld600d572019-03-26 15:38:50 -0700203 for (const auto& stats : transactionStats) {
Marissa Walle2ffb422018-10-12 11:33:52 -0700204 err = output->writeParcelable(stats);
205 if (err != NO_ERROR) {
206 return err;
207 }
Marissa Walle2ffb422018-10-12 11:33:52 -0700208 }
209 return NO_ERROR;
210}
211
212status_t ListenerStats::readFromParcel(const Parcel* input) {
213 int32_t transactionStats_size = input->readInt32();
214
215 for (int i = 0; i < transactionStats_size; i++) {
216 TransactionStats stats;
Marissa Walle2ffb422018-10-12 11:33:52 -0700217 status_t err = input->readParcelable(&stats);
218 if (err != NO_ERROR) {
219 return err;
220 }
Marissa Walld600d572019-03-26 15:38:50 -0700221 transactionStats.push_back(stats);
Marissa Walle2ffb422018-10-12 11:33:52 -0700222 }
223 return NO_ERROR;
224}
225
Valerie Hau5de3ad22019-08-20 07:47:43 -0700226ListenerStats ListenerStats::createEmpty(const sp<IBinder>& listener,
Marissa Walle2ffb422018-10-12 11:33:52 -0700227 const std::unordered_set<CallbackId>& callbackIds) {
228 ListenerStats listenerStats;
229 listenerStats.listener = listener;
Marissa Walld600d572019-03-26 15:38:50 -0700230 listenerStats.transactionStats.emplace_back(callbackIds);
231
Marissa Walle2ffb422018-10-12 11:33:52 -0700232 return listenerStats;
233}
234
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700235class BpTransactionCompletedListener : public SafeBpInterface<ITransactionCompletedListener> {
236public:
237 explicit BpTransactionCompletedListener(const sp<IBinder>& impl)
238 : SafeBpInterface<ITransactionCompletedListener>(impl, "BpTransactionCompletedListener") {
239 }
240
241 ~BpTransactionCompletedListener() override;
242
Marissa Walle2ffb422018-10-12 11:33:52 -0700243 void onTransactionCompleted(ListenerStats stats) override {
244 callRemoteAsync<decltype(&ITransactionCompletedListener::
245 onTransactionCompleted)>(Tag::ON_TRANSACTION_COMPLETED,
246 stats);
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700247 }
248};
249
250// Out-of-line virtual method definitions to trigger vtable emission in this translation unit (see
251// clang warning -Wweak-vtables)
252BpTransactionCompletedListener::~BpTransactionCompletedListener() = default;
253
254IMPLEMENT_META_INTERFACE(TransactionCompletedListener, "android.gui.ITransactionComposerListener");
255
256status_t BnTransactionCompletedListener::onTransact(uint32_t code, const Parcel& data,
257 Parcel* reply, uint32_t flags) {
258 if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) {
259 return BBinder::onTransact(code, data, reply, flags);
260 }
261 auto tag = static_cast<Tag>(code);
262 switch (tag) {
263 case Tag::ON_TRANSACTION_COMPLETED:
264 return callLocalAsync(data, reply,
265 &ITransactionCompletedListener::onTransactionCompleted);
266 }
267}
268
269}; // namespace android